Example #1
0
    def call_custom_script(self, name, params=''):
        data_dir = generic_utility.data_dir()
        if not generic_utility.windows():
            bash = 'sh '
            ending = '.sh'
            double_quotes = ''
        else:
            bash = ''
            ending = '.cmd'
            double_quotes = '"'
        custom_script = data_dir + 'custom' + os.sep + name + ending

        if generic_utility.windows():
            custom_script = custom_script.replace('/', '\\')

#        generic_utility.log('custom: '+custom_script)
        if os.path.isfile(custom_script):
            generic_utility.debug('calling: ' + custom_script)
            if params != '':
                params = ' ' + params
            if generic_utility.darwin():
                custom_script = generic_utility.sh_escape(custom_script)
            else:
                custom_script = double_quotes + custom_script + double_quotes

            self.call_script(bash + custom_script + params)
            return True

        return False
Example #2
0
    def call_custom_script(self, name, params = ''):
        data_dir = generic_utility.data_dir()
        if not generic_utility.windows():
            bash = 'sh '
            ending = '.sh'
            double_quotes = ''
        else:
            bash = ''
            ending = '.cmd'
            double_quotes = '"'
        custom_script = data_dir + 'custom' + os.sep + name + ending

        if generic_utility.windows():
            custom_script = custom_script.replace('/','\\')

#        generic_utility.log('custom: '+custom_script)
        if os.path.isfile(custom_script):
            generic_utility.debug('calling: '+custom_script)
            if params != '':
                params = ' '+params
            if generic_utility.darwin():
                custom_script = generic_utility.sh_escape(custom_script)
            else:
                custom_script = double_quotes+custom_script+double_quotes

            self.call_script(bash+custom_script+params)
            return True

        return False
Example #3
0
def add_or_remove(video_id, is_add):
    root_list = get_root_list()

    my_list = get_mylist(root_list)[0]
    auth = generic_utility.get_setting('authorization_url')
    track_id = get.track_id_list(my_list)

    if is_add:
        add_or_remove_str = 'addToList'
        add_or_remove_msg = 'added'
    else:
        add_or_remove_str = 'removeFromList'
        add_or_remove_msg = 'removed'

    post = ('{"callPath":["lolomos","%s","%s"],"params":["%s",2,["videos",%s],%s,null,null],' +
            '"authURL":"%s"}') % (root_list, add_or_remove_str, my_list, video_id, track_id, auth)

    content = connect.load_netflix_site(generic_utility.evaluator()+'&method=call', post, options=True)

    jsn = json.loads(content)

    generic_utility.log('mylist: '+my_list)
    generic_utility.log(str(jsn))
    if '"invalidated"' in content:
        generic_utility.notification('Successfully '+add_or_remove_msg)
    elif 'already exists' in content:
        generic_utility.notification('already exists')

    generic_utility.debug('add to mylist content: '+content)
def load_netflix_site(url,
                      post=None,
                      new_session=False,
                      lock=None,
                      login_process=False,
                      options=False):

    generic_utility.debug('Loading netflix: ' + url + ' Post: ' + str(post))
    if lock != None:
        lock.acquire()

    session = get_netflix_session(new_session)

    try:
        ret, status_code = load_site_internal(url,
                                              session,
                                              post,
                                              netflix=True,
                                              options=False)
        ret = ret.decode('utf-8')
        not_logged_in = '"template":"torii/nonmemberHome.jsx"' in ret
    except requests.exceptions.TooManyRedirects:
        status_code = 'redirected'

    if status_code != requests.codes.ok or (not_logged_in
                                            and not login_process):
        if not login_process and (should_retry(url, status_code)
                                  or not_logged_in):
            if lock:
                lock.release()
            if do_login():
                session = get_netflix_session(new_session)
                ret, status_code = load_site_internal(url,
                                                      session,
                                                      post,
                                                      netflix=True,
                                                      options=False)
                ret = ret.decode('utf-8')
                if status_code != requests.codes.ok:
                    raise ValueError('!HTTP-ERROR!: ' + str(status_code) +
                                     ' loading: "' + url + '", post: "' +
                                     str(post) + '"')
            else:
                raise ValueError('re-login failed')

        else:
            raise ValueError('!HTTP-ERROR!: ' + str(status_code) +
                             ' loading: "' + url + '", post: "' + str(post) +
                             '"')

    save_cookies(session)
    save_headers(session)

    if lock:
        lock.release()

    try_to_read_auth_url(ret)

    #    generic_utility.debug('Returning : '+ret)
    return ret
def add_or_remove(video_id, is_add):

    content = connect.load_netflix_site("https://www.netflix.com/")
    falkor_cache = generic_utility.parse_falkorcache(content)

    root_list, my_list = generic_utility.extract_mylist_id(falkor_cache)
    auth = generic_utility.get_setting('authorization_url')

    track_id = get_track_id(my_list)

    if is_add:
        add_or_remove_str = 'addToList'
        add_or_remove_msg = 'added'
    else:
        add_or_remove_str = 'removeFromList'
        add_or_remove_msg = 'removed'

    post = ('{"callPath":["lolomos","%s","%s"],"params":["%s",2,["videos",%s],%s,null,null],'+\
           '"authURL":"%s"}') % (root_list, add_or_remove_str, my_list, video_id, track_id, auth)

    content = connect.load_netflix_site(generic_utility.evaluator()+'&method=call', post, options=True)

    if '"invalidated"' in content:
        generic_utility.notification('Successfully '+add_or_remove_msg)
    elif 'already exists' in content:
        generic_utility.notification('already exists')

    generic_utility.debug('add to mylist content: '+content)
Example #6
0
    def onAction(self, action):
        generic_utility.debug('caught action: ' + str(action.getId()))
        ACTION_NAV_BACK = 92
        ACTION_PREVIOUS_MENU = 10
        ACTION_STOP = 13

        ACTION_SELECT_ITEM = 7
        ACTION_PLAYER_PLAY = 79
        ACTION_PLAYER_PLAYPAUSE = 229
        ACTION_PAUSE = 12

        ACTION_PLAYER_REWIND = 78
        ACTION_MOVE_LEFT = 1
        ACTION_REWIND = 17

        ACTION_PLAYER_FORWARD = 77
        ACTION_MOVE_RIGHT = 2
        ACTION_FORWARD = 16

        ACTION_MOVE_UP = 3
        ACTION_MOVE_DOWN = 4

        ACTION_KEY_1 = 59
        ACTION_KEY_2 = 142
        ACTION_CONTEXT_MENU = 117
        ACTION_SHOW_INFO = 11

        if action.getId() in (ACTION_NAV_BACK, ACTION_PREVIOUS_MENU,
                              ACTION_STOP):
            self.control('close')
        elif action.getId() in (ACTION_SELECT_ITEM, ACTION_PLAYER_PLAY,
                                ACTION_PLAYER_PLAYPAUSE, ACTION_PAUSE):
            self.control('pause')
        elif action.getId() in (ACTION_PLAYER_REWIND, ACTION_MOVE_LEFT,
                                ACTION_REWIND):
            self.control('backward')
        elif action.getId() in (ACTION_PLAYER_FORWARD, ACTION_MOVE_RIGHT,
                                ACTION_FORWARD):
            self.control('forward')
        elif action.getId() == ACTION_MOVE_UP:
            self.control('up')
        elif action.getId() == ACTION_MOVE_DOWN:
            self.control('down')
        elif action.getId() in (ACTION_KEY_1, ACTION_CONTEXT_MENU):
            self.control('toggle_lang' + str(self.lang_count))
            if self.lang_count == MAX_LANG:
                self.lang_count = 0
            else:
                self.lang_count += 1

        elif action.getId() in (ACTION_KEY_2, ACTION_SHOW_INFO):
            self.control('toggle_sub' + str(self.subtitle_count))
            if self.subtitle_count == MAX_SUB:
                self.subtitle_count = 0
            else:
                self.subtitle_count += 1

        else:
            generic_utility.error('unknown action: ' + str(action.getId()))
Example #7
0
 def call_script(self, callstr):
     generic_utility.debug('launching: ' + callstr)
     info = None
     if generic_utility.windows():
         info = subprocess.STARTUPINFO()
         info.dwFlags = subprocess.STARTF_USESHOWWINDOW
         info.wShowWindow = subprocess.SW_HIDE
     process = subprocess.Popen(callstr, startupinfo=info, shell=True)
     process.wait()
Example #8
0
 def call_script(self, callstr):
     generic_utility.debug('launching: ' + callstr)
     info = None
     if generic_utility.windows():
         info = subprocess.STARTUPINFO()
         info.dwFlags = subprocess.STARTF_USESHOWWINDOW
         info.wShowWindow = subprocess.SW_HIDE
     process = subprocess.Popen(callstr, startupinfo=info, shell=True)
     process.wait()
Example #9
0
    def onAction(self, action):
        generic_utility.debug('caught action: '+str(action.getId()))
        ACTION_NAV_BACK = 92
        ACTION_PREVIOUS_MENU = 10
        ACTION_STOP = 13

        ACTION_SELECT_ITEM = 7
        ACTION_PLAYER_PLAY = 79
        ACTION_PLAYER_PLAYPAUSE = 229
        ACTION_PAUSE = 12

        ACTION_PLAYER_REWIND = 78
        ACTION_MOVE_LEFT = 1
        ACTION_REWIND = 17

        ACTION_PLAYER_FORWARD = 77
        ACTION_MOVE_RIGHT = 2
        ACTION_FORWARD = 16

        ACTION_MOVE_UP = 3
        ACTION_MOVE_DOWN = 4

        ACTION_KEY_1 = 59
        ACTION_KEY_2 = 142
        ACTION_CONTEXT_MENU = 117
        ACTION_SHOW_INFO = 11

        if action.getId() in(ACTION_NAV_BACK, ACTION_PREVIOUS_MENU, ACTION_STOP):
            self.control('close')
        elif action.getId() in(ACTION_SELECT_ITEM, ACTION_PLAYER_PLAY, ACTION_PLAYER_PLAYPAUSE, ACTION_PAUSE):
            self.control('pause')
        elif action.getId() in(ACTION_PLAYER_REWIND, ACTION_MOVE_LEFT, ACTION_REWIND):
            self.control('backward')
        elif action.getId() in(ACTION_PLAYER_FORWARD, ACTION_MOVE_RIGHT, ACTION_FORWARD):
            self.control('forward')
        elif action.getId() == ACTION_MOVE_UP:
            self.control('up')
        elif action.getId() == ACTION_MOVE_DOWN:
            self.control('down')
        elif action.getId() in (ACTION_KEY_1, ACTION_CONTEXT_MENU):
            self.control('toggle_lang'+str(self.lang_count))
            if self.lang_count == MAX_LANG:
                self.lang_count = 0
            else:
                self.lang_count += 1

        elif action.getId() in(ACTION_KEY_2, ACTION_SHOW_INFO):
            self.control('toggle_sub'+str(self.subtitle_count))
            if self.subtitle_count == MAX_SUB:
                self.subtitle_count = 0
            else:
                self.subtitle_count += 1

        else:
            generic_utility.error('unknown action: ' + str(action.getId()))
Example #10
0
    def launch_browser(self, url):
        self.before_launch()

        if not self.call_custom_script('playback', url):
            script = self.get_launch_script('launcher')

            if script:
                callstr = script + ' ' + url
                self.call_script(callstr)
                generic_utility.debug('browser terminated')
        self.after_launch()
Example #11
0
    def launch_browser(self, url):
        self.before_launch()

        if not self.call_custom_script('playback', url):
            script = self.get_launch_script('launcher')

            if script:
                callstr = script + ' ' + url
                self.call_script(callstr)
                generic_utility.debug('browser terminated')
        self.after_launch()
Example #12
0
def try_to_read_auth_url(ret):
    match = re.compile('"authURL":"(.+?)"', re.DOTALL | re.UNICODE).findall(ret)
    if len(match) > 0:
        generic_utility.debug('Setting authorization url: ' + match[0])
        if not test:
            generic_utility.set_setting('authorization_url', match[0])
    else:
        match = re.compile('name="authURL" value="(.+?)"', re.DOTALL | re.UNICODE).findall(ret)
        if len(match) > 0:
            generic_utility.debug('Setting authorization url: ' + match[0])
            if not test:
                generic_utility.set_setting('authorization_url', match[0])
def try_to_read_auth_url(ret):
    match = re.compile('"authURL":"(.+?)"',
                       re.DOTALL | re.UNICODE).findall(ret)
    if len(match) > 0:
        generic_utility.debug('Setting authorization url: ' + match[0])
        if not test:
            generic_utility.set_setting('authorization_url', match[0])
    else:
        match = re.compile('name="authURL" value="(.+?)"',
                           re.DOTALL | re.UNICODE).findall(ret)
        if len(match) > 0:
            generic_utility.debug('Setting authorization url: ' + match[0])
            if not test:
                generic_utility.set_setting('authorization_url', match[0])
    def launch_browser(self, url):
        info = None
        if generic_utility.windows():
            info = subprocess.STARTUPINFO()
            info.dwFlags = subprocess.STARTF_USESHOWWINDOW
            info.wShowWindow = subprocess.SW_HIDE

        script = self.get_launch_script('launcher')

        if script:
            generic_utility.debug('launching: '+script)

            process = subprocess.Popen(script + ' ' +url, startupinfo=info, shell=True)
            process.wait()
            generic_utility.debug('browser terminated')
    def launch_browser(self, url):
        info = None
        if generic_utility.windows():
            info = subprocess.STARTUPINFO()
            info.dwFlags = subprocess.STARTF_USESHOWWINDOW
            info.wShowWindow = subprocess.SW_HIDE

        script = self.get_launch_script('launcher')

        if script:
            generic_utility.debug('launching: ' + script)

            process = subprocess.Popen(script + ' ' + url,
                                       startupinfo=info,
                                       shell=True)
            process.wait()
            generic_utility.debug('browser terminated')
def load_netflix_site(url, post=None, new_session=False, lock = None, login_process = False, options = False):

    generic_utility.debug('Loading netflix: ' + url + ' Post: ' + str(post))
    if lock != None:
        lock.acquire()

    session = get_netflix_session(new_session)

    try:
        ret, status_code = load_site_internal(url, session, post, netflix=True, options=False)
        ret = ret.decode('utf-8')
        not_logged_in = '"template":"torii/nonmemberHome.jsx"' in ret
    except requests.exceptions.TooManyRedirects:
        status_code = 'redirected'

    if status_code != requests.codes.ok or (not_logged_in and not login_process):
        if not test and not login_process and (should_retry(url, status_code) or not_logged_in):
            if lock:
                lock.release()

            try:
                refresh_data()
            except CannotRefreshDataException:
                if not do_login():
                    raise ValueError('re-login failed')

            session = get_netflix_session(new_session)
            ret, status_code = load_site_internal(url, session, post, netflix=True, options=False)
            ret = ret.decode('utf-8')
            if status_code != requests.codes.ok:
                    raise ValueError('!HTTP-ERROR1!: '+str(status_code)+' loading: "'+url+'", post: "'+ str(post)+'"')

        else:
            raise ValueError('!HTTP-ERROR2!: '+str(status_code)+' loading: "'+url+'", post: "'+ str(post)+'"')

    save_cookies(session)
    save_headers(session)

    if lock:
        lock.release()

    try_to_read_auth_url(ret)

#    generic_utility.debug('Returning : '+ret)
    return ret
def try_to_read_auth_url(ret):
    match = re.compile('"authURL":"(.+?)"', re.DOTALL | re.UNICODE).findall(ret)
    if len(match) > 0:
        authurl = generic_utility.replace_netfix_secret_code(match[0])
        generic_utility.debug('Setting authorization url: ' + authurl)
        if not test:
            generic_utility.set_setting('authorization_url', authurl)
        else:
            return authurl
    else:
        match = re.compile('name="authURL" value="(.+?)"', re.DOTALL | re.UNICODE).findall(ret)
        if len(match) > 0:
            authurl = generic_utility.replace_netfix_secret_code(match[0])

            generic_utility.debug('Setting authorization url: ' + authurl)
            if not test:
                generic_utility.set_setting('authorization_url', authurl)
            else:
                    return authurl
def try_to_read_auth_url(ret):
    match = re.compile('"authURL":"(.+?)"',
                       re.DOTALL | re.UNICODE).findall(ret)
    if len(match) > 0:
        authurl = generic_utility.replace_netfix_secret_code(match[0])
        generic_utility.debug('Setting authorization url: ' + authurl)
        if not test:
            generic_utility.set_setting('authorization_url', authurl)
        else:
            return authurl
    else:
        match = re.compile('name="authURL" value="(.+?)"',
                           re.DOTALL | re.UNICODE).findall(ret)
        if len(match) > 0:
            authurl = generic_utility.replace_netfix_secret_code(match[0])

            generic_utility.debug('Setting authorization url: ' + authurl)
            if not test:
                generic_utility.set_setting('authorization_url', authurl)
            else:
                return authurl
def load_netflix_site(url, post=None, new_session=False, lock = None):
    generic_utility.debug('Loading netflix: ' + url + ' Post: ' + str(post))
    if lock != None:
        lock.acquire()

    if new_session == True:
        session = create_session(netflix=True)
    else:
        session = requests.Session()
        session.headers = read_headers()
        session.cookies = read_cookies()
    ret = load_site_internal(url, session, post)
    ret = ret.decode('utf-8')
    save_cookies(session)
    save_headers(session)

    if lock != None:
        lock.release()

#    utility.debug('Returning : '+ret)
    return ret
Example #20
0
    def onAction(self, action):
        generic_utility.debug('caught action: ' + str(action.getId()))
        ACTION_NAV_BACK = 92
        ACTION_PREVIOUS_MENU = 10
        ACTION_STOP = 13

        ACTION_SELECT_ITEM = 7
        ACTION_PLAYER_PLAY = 79
        ACTION_PLAYER_PLAYPAUSE = 229
        ACTION_PAUSE = 12

        ACTION_PLAYER_REWIND = 78
        ACTION_MOVE_LEFT = 1
        ACTION_REWIND = 17

        ACTION_PLAYER_FORWARD = 77
        ACTION_MOVE_RIGHT = 2
        ACTION_FORWARD = 16

        ACTION_MOVE_UP = 3
        ACTION_MOVE_DOWN = 4

        if action.getId() in (ACTION_NAV_BACK, ACTION_PREVIOUS_MENU,
                              ACTION_STOP):
            self.control('close')
        elif action.getId() in (ACTION_SELECT_ITEM, ACTION_PLAYER_PLAY,
                                ACTION_PLAYER_PLAYPAUSE, ACTION_PAUSE):
            self.control('pause')
        elif action.getId() in (ACTION_PLAYER_REWIND, ACTION_MOVE_LEFT,
                                ACTION_REWIND):
            self.control('backward')
        elif action.getId() in (ACTION_PLAYER_FORWARD, ACTION_MOVE_RIGHT,
                                ACTION_FORWARD):
            self.control('forward')
        elif action.getId() == ACTION_MOVE_UP:
            self.control('up')
        elif action.getId() == ACTION_MOVE_DOWN:
            self.control('down')
        else:
            generic_utility.error('unknown action: ' + str(action.getId()))
Example #21
0
def load_netflix_site(url, post=None, new_session=False, lock=None):
    generic_utility.debug('Loading netflix: ' + url + ' Post: ' + str(post))
    if lock != None:
        lock.acquire()

    if new_session == True:
        session = create_session(netflix=True)
    else:
        session = requests.Session()
        session.headers = read_headers()
        session.cookies = read_cookies()
    ret = load_site_internal(url, session, post)
    ret = ret.decode('utf-8')
    save_cookies(session)
    save_headers(session)

    if lock != None:
        lock.release()


#    utility.debug('Returning : '+ret)
    return ret
Example #22
0
    def onAction(self, action):
        if generic_utility.get_setting('alternate_remote') == 'true':
            #from plugin.video.netflixbmc
            ACTION_SELECT_ITEM = 7
            ACTION_PARENT_DIR = 9
            ACTION_PREVIOUS_MENU = 10
            ACTION_PAUSE = 12
            ACTION_STOP = 13
            ACTION_SHOW_INFO = 11
            ACTION_SHOW_GUI = 18
            ACTION_MOVE_LEFT = 1
            ACTION_MOVE_RIGHT = 2
            ACTION_MOVE_UP = 3
            ACTION_MOVE_DOWN = 4
            ACTION_PLAYER_PLAY = 79
            ACTION_VOLUME_UP = 88
            ACTION_VOLUME_DOWN = 89
            ACTION_MUTE = 91
            ACTION_CONTEXT_MENU = 117
            ACTION_BUILT_IN_FUNCTION = 122
            KEY_BUTTON_BACK = 275

            if generic_utility.windows():
                proc = subprocess.Popen('WMIC PROCESS get Caption',
                                        shell=True,
                                        stdout=subprocess.PIPE)
                procAll = ""
                for line in proc.stdout:
                    procAll += line
                if "chrome.exe" in procAll:
                    if action in [
                            ACTION_SHOW_INFO, ACTION_SHOW_GUI, ACTION_STOP,
                            ACTION_PARENT_DIR, ACTION_PREVIOUS_MENU,
                            KEY_BUTTON_BACK
                    ]:
                        subprocess.Popen('"' + sendKeysPath + '"' +
                                         ' sendKey=Close',
                                         shell=False)
                        self.close()
                    elif action == ACTION_SELECT_ITEM:
                        subprocess.Popen('"' + sendKeysPath + '"' +
                                         ' sendKey=PlayPause',
                                         shell=False)
                    elif action == ACTION_MOVE_LEFT:
                        subprocess.Popen('"' + sendKeysPath + '"' +
                                         ' sendKey=SeekLeft',
                                         shell=False)
                    elif action == ACTION_MOVE_RIGHT:
                        subprocess.Popen('"' + sendKeysPath + '"' +
                                         ' sendKey=SeekRight',
                                         shell=False)
                    elif action == ACTION_MOVE_UP:
                        subprocess.Popen('"' + sendKeysPath + '"' +
                                         ' sendKey=VolumeUp',
                                         shell=False)
                    elif action == ACTION_MOVE_DOWN:
                        subprocess.Popen('"' + sendKeysPath + '"' +
                                         ' sendKey=VolumeDown',
                                         shell=False)
                else:
                    self.close()
            elif generic_utility.darwin():
                proc = subprocess.Popen('/bin/ps ax',
                                        shell=True,
                                        stdout=subprocess.PIPE)
                procAll = ""
                for line in proc.stdout:
                    procAll += line
                if "chrome" in procAll:
                    if action in [
                            ACTION_SHOW_INFO, ACTION_SHOW_GUI, ACTION_STOP,
                            ACTION_PARENT_DIR, ACTION_PREVIOUS_MENU,
                            KEY_BUTTON_BACK
                    ]:
                        subprocess.Popen('cliclick kd:cmd t:q ku:cmd',
                                         shell=True)
                        self.close()
                    elif action == ACTION_SELECT_ITEM:
                        subprocess.Popen('cliclick t:p', shell=True)
                    elif action == ACTION_MOVE_LEFT:
                        subprocess.Popen('cliclick kp:arrow-left', shell=True)
                    elif action == ACTION_MOVE_RIGHT:
                        subprocess.Popen('cliclick kp:arrow-right', shell=True)
                    elif action == ACTION_MOVE_UP:
                        subprocess.Popen('cliclick kp:arrow-up', shell=True)
                    elif action == ACTION_MOVE_DOWN:
                        subprocess.Popen('cliclick kp:arrow-down', shell=True)
                else:
                    self.close()
            else:  #linux
                doClose = False
                key = None
                if action in [
                        ACTION_SHOW_GUI, ACTION_STOP, ACTION_PARENT_DIR,
                        ACTION_PREVIOUS_MENU, KEY_BUTTON_BACK
                ]:
                    key = "control+shift+q"
                    doClose = True
                elif action in [
                        ACTION_SELECT_ITEM, ACTION_PLAYER_PLAY, ACTION_PAUSE
                ]:
                    key = "space"
                elif action == ACTION_MOVE_LEFT:
                    key = "Left"
                elif action == ACTION_MOVE_RIGHT:
                    key = "Right"
                elif action == ACTION_SHOW_INFO:
                    key = "question"
                elif action == ACTION_VOLUME_UP:
                    key = "Up"
                elif action == ACTION_VOLUME_DOWN:
                    key = "Down"
                elif action == ACTION_MUTE:
                    key = "M"
                elif action == ACTION_CONTEXT_MENU:
                    key = "ctrl+alt+shift+d"
                if key is not None:
                    p = subprocess.Popen(
                        'xdotool search --onlyvisible --class "google-chrome|Chromium" key %s'
                        % key,
                        shell=True)
                    p.wait()
                    # 0 for success, 127 if xdotool not found in PATH. Return code is 1 if window not found (indicating should close).
                    if not p.returncode in [0, 127] or doClose:
                        self.close()

        else:
            generic_utility.debug('caught action: ' + str(action.getId()))
            ACTION_NAV_BACK = 92
            ACTION_PREVIOUS_MENU = 10
            ACTION_STOP = 13

            ACTION_SELECT_ITEM = 7
            ACTION_PLAYER_PLAY = 79
            ACTION_PLAYER_PLAYPAUSE = 229
            ACTION_PAUSE = 12

            ACTION_PLAYER_REWIND = 78
            ACTION_MOVE_LEFT = 1
            ACTION_REWIND = 17

            ACTION_PLAYER_FORWARD = 77
            ACTION_MOVE_RIGHT = 2
            ACTION_FORWARD = 16

            ACTION_MOVE_UP = 3
            ACTION_MOVE_DOWN = 4

            ACTION_KEY_1 = 59
            ACTION_KEY_2 = 142
            ACTION_CONTEXT_MENU = 117
            ACTION_SHOW_INFO = 11

            if action.getId() in (ACTION_NAV_BACK, ACTION_PREVIOUS_MENU,
                                  ACTION_STOP):
                self.control('close')
            elif action.getId() in (ACTION_SELECT_ITEM, ACTION_PLAYER_PLAY,
                                    ACTION_PLAYER_PLAYPAUSE, ACTION_PAUSE):
                self.control('pause')
            elif action.getId() in (ACTION_PLAYER_REWIND, ACTION_MOVE_LEFT,
                                    ACTION_REWIND):
                self.control('backward')
            elif action.getId() in (ACTION_PLAYER_FORWARD, ACTION_MOVE_RIGHT,
                                    ACTION_FORWARD):
                self.control('forward')
            elif action.getId() == ACTION_MOVE_UP:
                self.control('up')
            elif action.getId() == ACTION_MOVE_DOWN:
                self.control('down')
            elif action.getId() in (ACTION_KEY_1, ACTION_CONTEXT_MENU):
                self.control('toggle_lang' + str(self.lang_count))
                if self.lang_count == MAX_LANG:
                    self.lang_count = 0
                else:
                    self.lang_count += 1

            elif action.getId() in (ACTION_KEY_2, ACTION_SHOW_INFO):
                self.control('toggle_sub' + str(self.subtitle_count))
                if self.subtitle_count == MAX_SUB:
                    self.subtitle_count = 0
                else:
                    self.subtitle_count += 1

            else:
                generic_utility.error('unknown action: ' + str(action.getId()))
def load_other_site(url):
    generic_utility.debug('loading-other: ' + url)
    session = create_session()
    content = load_site_internal(url, session)[0]
    return content
Example #24
0
    def onAction(self, action):
        if generic_utility.get_setting('alternate_remote') == 'true':
            #from plugin.video.netflixbmc
            ACTION_SELECT_ITEM = 7
            ACTION_PARENT_DIR = 9
            ACTION_PREVIOUS_MENU = 10
            ACTION_PAUSE = 12
            ACTION_STOP = 13
            ACTION_SHOW_INFO = 11
            ACTION_SHOW_GUI = 18
            ACTION_MOVE_LEFT = 1
            ACTION_MOVE_RIGHT = 2
            ACTION_MOVE_UP = 3
            ACTION_MOVE_DOWN = 4
            ACTION_PLAYER_PLAY = 79
            ACTION_VOLUME_UP = 88
            ACTION_VOLUME_DOWN = 89
            ACTION_MUTE = 91
            ACTION_CONTEXT_MENU = 117
            ACTION_BUILT_IN_FUNCTION = 122
            KEY_BUTTON_BACK = 275

            if generic_utility.windows():
                proc = subprocess.Popen('WMIC PROCESS get Caption', shell=True, stdout=subprocess.PIPE)
                procAll = ""
                for line in proc.stdout:
                    procAll+=line
                if "chrome.exe" in procAll:
                    if action in [ACTION_SHOW_INFO, ACTION_SHOW_GUI, ACTION_STOP, ACTION_PARENT_DIR, ACTION_PREVIOUS_MENU, KEY_BUTTON_BACK]:
                        subprocess.Popen('"'+sendKeysPath+'"'+' sendKey=Close', shell=False)
                        self.close()
                    elif action==ACTION_SELECT_ITEM:
                        subprocess.Popen('"'+sendKeysPath+'"'+' sendKey=PlayPause', shell=False)
                    elif action==ACTION_MOVE_LEFT:
                        subprocess.Popen('"'+sendKeysPath+'"'+' sendKey=SeekLeft', shell=False)
                    elif action==ACTION_MOVE_RIGHT:
                        subprocess.Popen('"'+sendKeysPath+'"'+' sendKey=SeekRight', shell=False)
                    elif action==ACTION_MOVE_UP:
                        subprocess.Popen('"'+sendKeysPath+'"'+' sendKey=VolumeUp', shell=False)
                    elif action==ACTION_MOVE_DOWN:
                        subprocess.Popen('"'+sendKeysPath+'"'+' sendKey=VolumeDown', shell=False)
                else:
                    self.close()                
            elif generic_utility.darwin():
                proc = subprocess.Popen('/bin/ps ax', shell=True, stdout=subprocess.PIPE)
                procAll = ""
                for line in proc.stdout:
                    procAll+=line
                if "chrome" in procAll:
                    if action in [ACTION_SHOW_INFO, ACTION_SHOW_GUI, ACTION_STOP, ACTION_PARENT_DIR, ACTION_PREVIOUS_MENU, KEY_BUTTON_BACK]:
                        subprocess.Popen('cliclick kd:cmd t:q ku:cmd', shell=True)
                        self.close()
                    elif action==ACTION_SELECT_ITEM:
                        subprocess.Popen('cliclick t:p', shell=True)
                    elif action==ACTION_MOVE_LEFT:
                        subprocess.Popen('cliclick kp:arrow-left', shell=True)
                    elif action==ACTION_MOVE_RIGHT:
                        subprocess.Popen('cliclick kp:arrow-right', shell=True)
                    elif action==ACTION_MOVE_UP:
                        subprocess.Popen('cliclick kp:arrow-up', shell=True)
                    elif action==ACTION_MOVE_DOWN:
                        subprocess.Popen('cliclick kp:arrow-down', shell=True)
                else:
                    self.close()
            else: #linux
                doClose = False
                key=None
                if action in [ACTION_SHOW_GUI, ACTION_STOP, ACTION_PARENT_DIR, ACTION_PREVIOUS_MENU, KEY_BUTTON_BACK]:
                    key="control+shift+q"
                    doClose=True
                elif action in [ ACTION_SELECT_ITEM, ACTION_PLAYER_PLAY, ACTION_PAUSE ]:
                    key="space"
                elif action==ACTION_MOVE_LEFT:
                    key="Left"
                elif action==ACTION_MOVE_RIGHT:
                    key="Right"
                elif action==ACTION_SHOW_INFO:
                    key="question"
                elif action==ACTION_VOLUME_UP:
                    key="Up"
                elif action==ACTION_VOLUME_DOWN:
                    key="Down"
                elif action==ACTION_MUTE:
                    key="M"
                elif action==ACTION_CONTEXT_MENU:
                    key="ctrl+alt+shift+d"
                if key is not None:
                    p = subprocess.Popen('xdotool search --onlyvisible --class "google-chrome|Chromium" key %s' % key, shell=True)
                    p.wait()
                    # 0 for success, 127 if xdotool not found in PATH. Return code is 1 if window not found (indicating should close).
                    if not p.returncode in [0,127] or doClose:
                        self.close()

        else:
            generic_utility.debug('caught action: '+str(action.getId()))
            ACTION_NAV_BACK = 92
            ACTION_PREVIOUS_MENU = 10
            ACTION_STOP = 13

            ACTION_SELECT_ITEM = 7
            ACTION_PLAYER_PLAY = 79
            ACTION_PLAYER_PLAYPAUSE = 229
            ACTION_PAUSE = 12

            ACTION_PLAYER_REWIND = 78
            ACTION_MOVE_LEFT = 1
            ACTION_REWIND = 17

            ACTION_PLAYER_FORWARD = 77
            ACTION_MOVE_RIGHT = 2
            ACTION_FORWARD = 16

            ACTION_MOVE_UP = 3
            ACTION_MOVE_DOWN = 4

            ACTION_KEY_1 = 59
            ACTION_KEY_2 = 142
            ACTION_CONTEXT_MENU = 117
            ACTION_SHOW_INFO = 11

            if action.getId() in(ACTION_NAV_BACK, ACTION_PREVIOUS_MENU, ACTION_STOP):
                self.control('close')
            elif action.getId() in(ACTION_SELECT_ITEM, ACTION_PLAYER_PLAY, ACTION_PLAYER_PLAYPAUSE, ACTION_PAUSE):
                self.control('pause')
            elif action.getId() in(ACTION_PLAYER_REWIND, ACTION_MOVE_LEFT, ACTION_REWIND):
                self.control('backward')
            elif action.getId() in(ACTION_PLAYER_FORWARD, ACTION_MOVE_RIGHT, ACTION_FORWARD):
                self.control('forward')
            elif action.getId() == ACTION_MOVE_UP:
                self.control('up')
            elif action.getId() == ACTION_MOVE_DOWN:
                self.control('down')
            elif action.getId() in (ACTION_KEY_1, ACTION_CONTEXT_MENU):
                self.control('toggle_lang'+str(self.lang_count))
                if self.lang_count == MAX_LANG:
                    self.lang_count = 0
                else:
                    self.lang_count += 1

            elif action.getId() in(ACTION_KEY_2, ACTION_SHOW_INFO):
                self.control('toggle_sub'+str(self.subtitle_count))
                if self.subtitle_count == MAX_SUB:
                    self.subtitle_count = 0
                else:
                    self.subtitle_count += 1

            else:
                generic_utility.error('unknown action: ' + str(action.getId()))
def load_other_site(url):
    generic_utility.debug('loading-other: ' + url)
    session = create_session()
    content = load_site_internal(url, session)[0]
    return content