Пример #1
0
def discover_roku():
    """ Search LAN for available Roku devices. Returns a Roku object. """

    print("Searching for Roku devices within LAN ...")
    rokus = Roku.discover()
    if not rokus:
        print("Unable to discover Roku devices. " +
              "Try again, or manually specify the IP address with " +
              "\'roku <ipaddr>\' (e.g. roku 192.168.1.130)")
        return None

    print("Found the following Roku devices:")
    for i, r in enumerate(rokus):
        print("[" + str(i+1) + "]   " + str(r.host) + ":" + str(r.port))
    print("")

    if len(rokus) == 1:
        print("Selecting Roku 1 by default")
        return rokus[0]
    else:
        print("Multiple Rokus found. Select the index of the Roku to control:")

        while True:
            try:
                query = "Select (1 to " + str(len(rokus)) + ") > "
                sel = int(raw_input(query)) - 1
                if sel >= len(rokus):
                    raise ValueError
                else:
                    break
            except ValueError:
                print("Invalid selection")

        return rokus[sel]
Пример #2
0
def scan_for_rokus(hass):
    """Scan for devices and present a notification of the ones found."""

    rokus = Roku.discover()

    devices = []
    for roku in rokus:
        try:
            r_info = roku.device_info
        except RokuException:  # skip non-roku device
            continue
        devices.append("Name: {0}<br />Host: {1}<br />".format(
            r_info.userdevicename if r_info.userdevicename else
            f"{r_info.modelname} {r_info.serial_num}",
            roku.host,
        ))
    if not devices:
        devices = ["No device(s) found"]

    hass.components.persistent_notification.create(
        "The following devices were found:<br /><br />" +
        "<br /><br />".join(devices),
        title=NOTIFICATION_SCAN_TITLE,
        notification_id=NOTIFICATION_SCAN_ID,
    )
Пример #3
0
def device_setup():
    global plug, denon, roku, trigger_map
    trigger_map = TriggerMap()
    denon = DenonConnection(device_details.denon_ip_address(), "23", trigger_map)
    roku = Roku.discover(timeout=5)[0]
    plug_ip = list(pyHS100.Discover().discover())[0]
    plug = pyHS100.SmartPlug(plug_ip)
Пример #4
0
def choose_roku():
    global current_roku
    req = request.get_json()
    host = req['host']

    rokus = Roku.discover()
    matches = [roku for roku in rokus if roku.host == host]
    current_roku = list(matches)[0]

    return "OK", 200
Пример #5
0
    def __init__(self, timeout: int = 5):
        logger.info("Searching for roku devices...")
        self.devices = Roku.discover(timeout=timeout)
        if self.devices is None:
            logger.error("unable to find roku device")
            exit(-1)

        if self.devices is None or len(self.devices) == 0:
            logger.error("unable to find roku on network")
            exit(-1)
        logger.info(f'Found {len(self.devices)} roku devices')
def main():
    # Locate the roku device
    printing("Finding roku device ...")
    rokus = Roku.discover()
    printing("Done finding roku device ...")

    # IF no devices found ...
    if len(rokus) == 0:
        print("No rokus found")
        sys.exit(-1)
    # Otherwise, get the ip and port of the device
    else:
        roku_ip_address = rokus[0].host
        roku_port = rokus[0].port

    # Setup API object to make requests to the roku device
    print("Connecting ...")
    roku = Roku(host=roku_ip_address, port=roku_port)
    print("Done connecting ...")

    # Find youtube app
    print("Finding youtube app ...")
    youtube_app = [a for a in roku.apps if 'youtube' in a.name.lower()][0]
    print("Done finding youtube app ...")

    # Wait for the app to start
    print("Starting youtube app ...")
    APP_LAUNCH_TIMEOUT = 15
    youtube_app.launch()
    time.sleep(APP_LAUNCH_TIMEOUT)
    print("Done starting youtube app ...")

    # Series of remote clicks to get to youtube Watch Later playlist
    # TODO: sleeps may not be needed
    roku.left()
    time.sleep(1)
    roku.left()
    time.sleep(1)
    roku.down()
    time.sleep(1)
    roku.down()
    time.sleep(1)
    roku.right()
    time.sleep(1)
    roku.down()
    time.sleep(1)
    roku.down()
    time.sleep(1)
    roku.right()
    time.sleep(1)
    roku.select()
Пример #7
0
def scan_for_rokus(hass):
    """Scan for devices and present a notification of the ones found."""
    from roku import Roku, RokuException
    rokus = Roku.discover()

    devices = []
    for roku in rokus:
        try:
            r_info = roku.device_info
        except RokuException:  # skip non-roku device
            continue
        devices.append('Name: {0}<br />Host: {1}<br />'.format(
            r_info.userdevicename if r_info.userdevicename else "{} {}".format(
                r_info.modelname, r_info.sernum), roku.host))
    if not devices:
        devices = ['No device(s) found']

    hass.components.persistent_notification.create(
        'The following devices were found:<br /><br />' +
        '<br /><br />'.join(devices),
        title=NOTIFICATION_SCAN_TITLE,
        notification_id=NOTIFICATION_SCAN_ID)
Пример #8
0
def discover_roku():
    """ Search LAN for available Roku devices. Returns a Roku object. """

    print("Searching for Roku devices within LAN ...")
    rokus = Roku.discover()

    """ Ignore devices that aren't Rokus like Phillips Hue. """
    rokus = [r for r in rokus if r.port != 80]

    if not rokus:
        print("Unable to discover Roku devices. " +
              "Try again, or manually specify the IP address with " +
              "\'roku <ipaddr>\' (e.g. roku 192.168.1.130)")
        return None

    print("Found the following Roku devices:")
    for i, r in enumerate(rokus):
        print("[" + str(i+1) + "]   " + str(r.host) + ":" + str(r.port))
    print("")

    if len(rokus) == 1:
        print("Selecting Roku 1 by default")
        return rokus[0]
    else:
        print("Multiple Rokus found. Select the index of the Roku to control:")

        while True:
            try:
                query = "Select (1 to " + str(len(rokus)) + ") > "
                sel = int(raw_input(query)) - 1
                if sel >= len(rokus):
                    raise ValueError
                else:
                    break
            except ValueError:
                print("Invalid selection")

        return rokus[sel]
Пример #9
0
def discover_roku():
    """ Search LAN for available Roku devices. Returns a Roku object. """

    print("Searching for Roku devices within LAN ...")
    rokus = Roku.discover()
    if not rokus:
        print("Unable to discover Roku devices. " +
              "Try again, or manually specify the IP address with " +
              "\'roku <ipaddr>\' (e.g. roku 192.168.1.130)")
        return None

    print("Found the following Roku devices:")
    for i, r in enumerate(rokus):
        dinfo = ' '.join(re.split(', |: ', str(r.device_info))[1:3])
        print(
            "[" + str(i+1) + "]   " +
            str(r.host) + ":" + str(r.port) +
            ' (' + dinfo + ' (' + r.device_info.roku_type + '))')
    print("")

    if len(rokus) == 1:
        print("Selecting Roku 1 by default")
        return rokus[0]
    else:
        print("Multiple Rokus found. Select the index of the Roku to control:")

        while True:
            try:
                query = "Select (1 to " + str(len(rokus)) + ") > "
                sel = int(input(query)) - 1
                if sel >= len(rokus):
                    raise ValueError
                else:
                    break
            except ValueError:
                print("Invalid selection")

        return rokus[sel]
Пример #10
0
def scan_for_rokus(hass):
    """Scan for devices and present a notification of the ones found."""
    from roku import Roku, RokuException
    rokus = Roku.discover()

    devices = []
    for roku in rokus:
        try:
            r_info = roku.device_info
        except RokuException:  # skip non-roku device
            continue
        devices.append('Name: {0}<br />Host: {1}<br />'.format(
            r_info.userdevicename if r_info.userdevicename
            else "{} {}".format(r_info.modelname, r_info.sernum),
            roku.host))
    if not devices:
        devices = ['No device(s) found']

    hass.components.persistent_notification.create(
        'The following devices were found:<br /><br />' +
        '<br /><br />'.join(devices),
        title=NOTIFICATION_SCAN_TITLE,
        notification_id=NOTIFICATION_SCAN_ID)
Пример #11
0
def roku(bot, event, *args):
    try:
        # https://pypi.python.org/pypi/roku/1.0
        admins_list = bot.get_config_suboption(event.conv_id, 'admins') or []
        if event.user_id.chat_id in admins_list:
            ip = bot.user_memory_get(event.user.id_.chat_id, 'roku')
            if ip is None:
                rokuControl = Roku.discover(timeout=10)[0]
                bot.user_memory_set(event.user.id_.chat_id, 'roku', rokuControl.host)
                ip = rokuControl.host
            
            rokuControl = Roku(ip)
            
            
            command = {'up' : rokuControl.up,
                       'down' : rokuControl.down,
                       'left' : rokuControl.left,
                       'right' : rokuControl.right,
                       'select' : rokuControl.select,
                       'home' : rokuControl.home,
                       'back' : rokuControl.back,
                       'play' : rokuControl.play
                       
                       }
            arg = args[0]
            if arg in command:
                command[args[0].lower()]()
            else:
                rokuControl[arg].launch()
            return
        else:
            html_text = "You can't control my roku, you so crazy"
    except:
        html_text = "Unable to control the roku right now"
        logger.exception(html_text)

    yield from bot.coro_send_message(event.conv_id, html_text)
Пример #12
0
from roku import Roku
from roku import RokuException
import RPi.GPIO as GPIO
import time

PIN1 = 3
PIN2 = 18
PIN3 = 25
PIN4 = 16

# Connecting to Roku
roku = 0
rList = Roku.discover()
for r in rList:
    # On my personal network there are two Roku devices listed by the SSDP crawl; One of them is the remote
    # the remote uses port 80, so we can filter it out with nothing more than the port here.
    if r.port == 8060:
        roku = r
if roku == 0:
    # using systemD to handle upkeep, simpler than doing my own loop and probably more resource efficient
    raise Exception('No valid Rokus found on network')

GPIO.setmode(GPIO.BCM)
# Buttons setup, using an internal pull up resistor to simplify the physical circuit I have to build
GPIO.setup(PIN1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(PIN2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(PIN3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(PIN4, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:
    button1 = GPIO.input(PIN1)
Пример #13
0
def discover_roku():
    # this gives an 'IndexError: list index out of range' error if no roku is found
    # TODO: handle this better
    roku = Roku.discover(timeout=10)
    print(roku)
    return roku
Пример #14
0
 def scan_devices(self):
     print(Roku.discover(timeout=30))
Пример #15
0
getkey = _Getch()

if __name__ == '__main__':
    os.system('cls' if os.name == 'nt' else 'clear')
    print """
Welcome to Rokudo, your command-line Roku remote.

Supported commands:
- Arrow keys to navigate
- Enter to select
- Backspace to go back

Enter can also be used to pause/play
"""
    print "Finding Roku on local network..."
    rokus = Roku.discover(timeout=10)
    if len(rokus) == 0:
       print "Couldn't find any Rokus :(. Buy one and try again."
       exit(0)

    print "Found at least one Roku. Using the first."
    roku = rokus[0]

    done = False
    while not done:
        try:
            key = getkey()
            if key == 27:
                done = True
            # arrow keys
            elif key == 1080:
Пример #16
0
    def main(self):

        # Banner
        print('==========================================================')
        print('Discovering Rokus')

        num_rokus = 0
        my_rokus = {}
        rokus = {}

        for x in range(0, 2):
            rokus = Roku.discover(10, 1)
            if len(rokus) > 0:
                break
        else:
            print('No Rokus discovered on network. Exiting program.')
            quit()

        my_apps_xml = ''

        print(rokus)
        for device in rokus:
            device = parse("<Roku: {}:{}>", str(device))
            device_ip = device[0]
            device_port = device[1]

            baseurl = 'http://' + device_ip + ':' + device_port
            url = baseurl + '/query/device-info'
            print(url)
            try:
                response = urllib.request.urlopen(str(url))
                content = response.read()
            except urllib.error.HTTPError as e:
                print(('HTTPError = ' + str(e.code)))
                continue
            except urllib.error.URLError as e:
                print(('URLError = ' + str(e.reason)))
                continue
            except httplib.HTTPException as e:
                print('HTTPException')
                continue

            # find the names of the rokus
            device_tree = etree.XML(content)
            device_name = device_tree.find('user-device-name')
            my_rokus[device_name.text] = baseurl

            # find the apps installed on the first roku found
            if my_apps_xml == '':
                try:
                    response = urllib.request.urlopen(baseurl + '/query/apps')
                    my_apps_xml = response.read()
                except urllib.error.HTTPError as e:
                    print(('HTTPError = ' + str(e.code)))
                    continue
                except urllib.error.URLError as e:
                    print(('URLError = ' + str(e.reason)))
                    continue
                except httplib.HTTPException as e:
                    print('HTTPException')
                    continue

        # write the rokus to a file for use by the roku_trigger script
        with open("my-rokus.txt", "wb") as myFile:
            pickle.dump(my_rokus, myFile)

        # write the apps list xml to a file for use by the roku_trigger script
        with open("roku-apps.xml", "wb") as myFile:
            myFile.write(my_apps_xml)

        print('Saving the following Rokus and the apps installed on them')
        print(my_rokus)
Пример #17
0
 def discover_devices(self):
     for _ in range(3):
         obj = Roku.discover()
         if obj:
             return obj
     return []
Пример #18
0
#!/usr/bin/env python
from roku import Roku
retour = ''
discovered = Roku.discover()
for roku in discovered:
    retour += roku + ';'
print retour[:-1]
Пример #19
0
from Tkinter import *
from roku import Roku

roku = Roku.discover(timeout=5)[0]
apps = roku.apps

text = None


def main():

    window = Tk()
    # window.geometry("800x600")
    window.title("Pyku Controller")

    build_tk_window(window)
    mainloop()


def build_tk_window(window):

    text_box = Entry(window, textvariable=text)
    text_box.pack()

    enter_button = Button(window,
                          text="enter",
                          command=lambda: enter_search(text_box))
    enter_button.pack()

    home_button = Button(window, text="home", command=home)
    home_button.pack()
Пример #20
0
def discover():
    rokus = Roku.discover()
    hosts = list(map(lambda r: r.host, rokus))

    return make_response(jsonify(hosts), 200)
Пример #21
0
def roku_url():
    """Return the roku url using SSDP discovery."""
    rok = Roku.discover(timeout=5)
    if len(rok) > 0:
        return 'http://{}:{}'.format(rok[0].host, rok[0].port)
Пример #22
0
from roku import Roku
rokuls = Roku.discover(timeout=10)
print(rokuls)
ip = input('IP: ')
roku = Roku(ip)
appinput = input('APP (i.e. YouTube): ')
apptolaunch = roku[appinput]
apptolaunch.launch()
Пример #23
0
     try:
         print("Wikipedia - Ready.")
         tts.get_pronunciation("Wikipedia is ready for a request.")
         recogntionAudio = r.listen(source)
         output = wikipedia.summary(recogntionAudio);
         print(output)
         response = tts.get_pronunciation(output)
     except sr.UnknownValueError:
         print("Wikipedia - could not understand audio.")
         tts.get_pronunciation("Sorry, I couldn't understand you.")
     except sr.RequestError as e:
          print("Wikipedia - could not connect to audio recognition servers.")
          tts.get_pronunciation("Sorry, I couldn't connect to the audio recogntion service.")
 elif "connect" in question and "Roku" in question: 
     try:
         Roku.discover(timeout=10)
         print("Roku connect - Ready.")
         tts.get_pronunciation("Please use the keyboard to type the IP")
         rokuIP = input("ROKU IP:")
         roku = Roku(rokuIP)
     except:
         print("ERROR. Are you sure that device exists?")
 elif "Roku" in question and "home" in question:
     try:
         print("Doing roku function.")
         tts.get_pronunciation("OK. Going to roku home screen.")
         roku.home()
     except:
         print("ERROR. I don't think you are connected...")
         tts.get_pronunciation("Whoops! Are you sure you are connected?")
 elif "Roku" in question and "Hulu" in question: