def load_site_internal(url,
                       session,
                       post=None,
                       options=False,
                       headers=None,
                       cookies=None,
                       netflix=False):
    session.max_redirects = 10

    if options:
        response = session.options(url,
                                   headers=headers,
                                   cookies=cookies,
                                   verify=False)
        if response.status_code != 200:
            generic_utility.error('error options! url: ' + url)
            response.raise_for_status()
    if post:
        response = session.post(url,
                                headers=headers,
                                cookies=cookies,
                                data=post,
                                verify=False)
    else:
        response = session.get(url,
                               headers=headers,
                               cookies=cookies,
                               verify=False)

    content = response.content
    status = response.status_code
    return content, status
示例#2
0
    def get_launch_script(self, type):
        path = addon_path + '/resources/scripts/' + type + '/'
        browser_name = None
        double_quotes = ''
        bash = ''
        if generic_utility.windows():
            path += 'windows/'
            ending = '.cmd'
            double_quotes = '"'
        elif generic_utility.darwin():
            path += 'darwin/'
            ending = '.sh'
            bash = 'sh '
        else:
            path += 'linux/'
            ending = '.sh'
            bash = 'sh '
        browser_name = self.get_browser_scriptname(browser_name)

        script = path + browser_name + ending

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

        if not os.path.isfile(script):
            generic_utility.error('Script: ' + script + ' not found!')
            script = ''

        if generic_utility.darwin():
            script = bash + generic_utility.sh_escape(script)
        else:
            script = bash + double_quotes + script + double_quotes

        return script
示例#3
0
def load_site_internal(url, session, post=None, options=False, headers=None, cookies=None, netflix=False):
#    generic_utility.log(str(cookies))
    session.max_redirects = 10
#    generic_utility.debug('load site internal')
#    generic_utility.debug(url)
#    generic_utility.debug(str(session.headers))
#    generic_utility.debug(str(session.cookies))

#    generic_utility.debug(options)
#    generic_utility.debug(str(headers))
#    generic_utility.debug(str(cookies))
#    generic_utility.debug(str(post))

    if options:
        response = session.options(url, headers=headers, cookies=cookies, verify=False)
        if response.status_code != 200:
            generic_utility.error('error options! url: '+url)
            response.raise_for_status()
    if post:
        response = session.post(url, headers=headers, cookies=cookies, data=post, verify=False)
    else:
        response = session.get(url, headers=headers, cookies=cookies, verify=False)

    content = response.content
    status = response.status_code
    return content, status
示例#4
0
    def get_launch_script(self, type):
        path = addon_path + '/resources/scripts/'+type+'/'
        browser_name = None
        double_quotes=''
        bash = ''
        if generic_utility.windows():
            path += 'windows/'
            ending = '.cmd'
            double_quotes = '"'
        elif generic_utility.darwin():
            path += 'darwin/'
            ending = '.sh'
            bash = 'sh '
        else:
            path += 'linux/'
            ending = '.sh'
            bash = 'sh '
        browser_name = self.get_browser_scriptname(browser_name)

        script = path+browser_name+ending

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

        if not os.path.isfile(script):
            generic_utility.error('Script: '+script+' not found!')
            script = ''

        if generic_utility.darwin():
            script = bash + generic_utility.sh_escape(script)
        else:
            script = bash + double_quotes+script+double_quotes

        return script
示例#5
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()))
示例#6
0
def login():
    if not test:
        login_progress = xbmcgui.DialogProgress()
        login_progress.create('Netflix', generic_utility.get_string(30200) + '...')
        generic_utility.progress_window(login_progress, 25, generic_utility.get_string(30201))
    content = connect.load_netflix_site(generic_utility.main_url + 'Login', new_session=True, login_process=True)
    if not 'Sorry, Netflix ' in content:

        match = re.compile('locale: "(.+?)"', re.DOTALL|re.UNICODE).findall(content)
        locale = None
        if(len(match)) == 0:
            match = re.compile('"pageName":"login","locale":"(.+?)"', re.DOTALL|re.UNICODE).findall(content)
            if(len(match)) == 0:
                generic_utility.error('Cannot find locale on page. content: '+content)
                login_url = 'Login'
            else:
                locale = match[0]
                login_url = 'Login?locale=' + locale
        else:
            locale = match[0]
            login_url = 'Login?locale=' + locale
        generic_utility.set_setting('language', locale)

        post_data = {'authURL': generic_utility.get_setting('authorization_url'), 'email': generic_utility.get_setting('username'),
                     'password': generic_utility.get_setting('password'), 'RememberMe': 'on'}
        if not test:
            generic_utility.progress_window(login_progress, 50, generic_utility.get_string(30202))

        content = connect.load_netflix_site(
            generic_utility.main_url + login_url,
            post=post_data, login_process=True)

        if 'id="page-LOGIN"' in content:
            if not test:
                generic_utility.notification(generic_utility.get_string(30303))
            return False

        parse_data_set_cookies(content)

        if not test:
            generic_utility.progress_window(login_progress, 75, generic_utility.get_string(30203))

        profile_selection()

        if login_progress:
            if not test:
                if not generic_utility.progress_window(login_progress, 100, generic_utility.get_string(30204)):
                    return False
                xbmc.sleep(500)
                login_progress.close()
        return True
    else:
        if not test:
            generic_utility.notification(generic_utility.get_string(30300))
            if login_progress:
                login_progress.close()
        return False
示例#7
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()))
def parse_api_url(content):
    apiroot = re.compile('"SHAKTI_API_ROOT":"(.+?)",',
                         re.UNICODE).findall(content)
    apibuild = re.compile('"BUILD_IDENTIFIER":"(.+?)",',
                          re.UNICODE).findall(content)
    if len(apiroot) > 0 and len(apibuild) > 0:
        epstr = apiroot[0] + "/" + apibuild[0]
        epstr = generic_utility.replace_netfix_secret_code(epstr)

        generic_utility.set_setting('api_url', epstr)
    else:
        generic_utility.error('Cannot find api url! Source: ' + content)
示例#9
0
def parse_endpoints(content):
    match = re.compile('"endpointIdentifiers":({.+?}),', re.UNICODE).findall(content)
    if len(match) > 0:
        epstr = match[0]
        if epstr.endswith("}}"):
            epstr = epstr[:-1]

        epstr = generic_utility.replace_netfix_secret_code(epstr)

        generic_utility.set_setting("endpoints", epstr)
    else:
        generic_utility.error("Cannot find api endpoints! Source: " + content)
示例#10
0
def parse_endpoints(content):
    match = re.compile('"endpointIdentifiers":({.+?}),',
                       re.UNICODE).findall(content)
    if len(match) > 0:
        epstr = match[0]
        if epstr.endswith('}}'):
            epstr = epstr[:-1]

        epstr = generic_utility.replace_netfix_secret_code(epstr)

        generic_utility.set_setting('endpoints', epstr)
    else:
        generic_utility.error('Cannot find api endpoints! Source: ' + content)
示例#11
0
def load_site_internal(url, session, post=None, options=False, headers=None, cookies=None, netflix=False):
    session.max_redirects = 10

    if options:
        response = session.options(url, headers=headers, cookies=cookies, verify=False)
        if response.status_code != 200:
            generic_utility.error('error options! url: '+url)
            response.raise_for_status()
    if post:
        if url == generic_utility.evaluator():
            session.cookies['profilesNewSession']='0'
            response = session.post(url, json = post)
        else:
            response = session.post(url, headers=headers, cookies=cookies, data=post, verify=False)
    else:
        response = session.get(url, headers=headers, cookies=cookies, verify=False)

    content = response.content
    status = response.status_code
    return content, status
示例#12
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()))
示例#13
0
def login():
    if not test:
        login_progress = xbmcgui.DialogProgress()
        login_progress.create("Netflix", generic_utility.get_string(30200) + "...")
        generic_utility.progress_window(login_progress, 25, generic_utility.get_string(30201))
    content = connect.load_netflix_site(generic_utility.main_url + "Login", new_session=True, login_process=True)
    if "Sorry, Netflix " not in content:

        match = re.compile('locale: "(.+?)"', re.DOTALL | re.UNICODE).findall(content)
        locale = None
        if (len(match)) == 0:
            match = re.compile('"pageName":"login","locale":"(.+?)"', re.DOTALL | re.UNICODE).findall(content)
            if (len(match)) == 0:
                generic_utility.error("Cannot find locale on page. content: " + content)
                login_url = "Login"
            else:
                locale = match[0]
                login_url = "Login?locale=" + locale
        else:
            locale = match[0]
            login_url = "Login?locale=" + locale
        generic_utility.set_setting("language", locale)

        post_data = {
            "authURL": generic_utility.get_setting("authorization_url"),
            "email": generic_utility.get_setting("username"),
            "password": generic_utility.get_setting("password"),
            "rememberMe": "true",
            "flow": "websiteSignUp",
            "mode": "loginPassword",
            "action": "loginAction",
            "withFields": "email,password,rememberMe,nextPage",
            "nextPage": "",
        }

        if not test:
            generic_utility.progress_window(login_progress, 50, generic_utility.get_string(30202))

        content = connect.load_netflix_site(generic_utility.main_url + login_url, post=post_data, login_process=True)

        if 'id="page-LOGIN"' in content:
            if not test:
                generic_utility.notification(generic_utility.get_string(30303))
            return False

        parse_data_set_cookies(content)

        if not test:
            generic_utility.progress_window(login_progress, 75, generic_utility.get_string(30203))

        profile_selection()

        if login_progress:
            if not test:
                if not generic_utility.progress_window(login_progress, 100, generic_utility.get_string(30204)):
                    return False
                xbmc.sleep(500)
                login_progress.close()
        return True
    else:
        if not test:
            generic_utility.notification(generic_utility.get_string(30300))
            if login_progress:
                login_progress.close()
        return False
def parse_type(match):
    type = match['summary']['type']
    if type not in ('movie', 'show', 'episode'):
        generic_utility.error('Unknown type: "'+type+'"')
    return type
示例#15
0
def parse_api_url(content):
    match = re.compile('"apiUrl":"(.+?)",', re.UNICODE).findall(content)
    if len(match) > 0:
        generic_utility.set_setting('api_url', match[0])
    else:
        generic_utility.error('Cannot find apiUrl! Source: ' + content)
示例#16
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()))
示例#17
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()))
示例#18
0
def parse_endpoints(content):
    match = re.compile('"endpointIdentifiers":({.+?}),', re.UNICODE).findall(content)
    if len(match) > 0:
        generic_utility.set_setting('endpoints', match[0])
    else:
        generic_utility.error('Cannot find api endpoints! Source: ' + content)
示例#19
0
def parse_type(match):
    type = match['summary']['type']
    if type not in ('movie', 'show', 'episode'):
        generic_utility.error('Unknown type: "'+type+'"')
    return type