Example #1
0
 def refreshToken(self):
     url = self.ApiUrl + "/oauth/token"
     postData = {
         'refresh_token': self.RefreshToken,
         'client_id': self.ClientID,
         'client_secret': self.ClientSecret,
         'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob',
         'grant_type': 'refresh_token'
     }
     response = requests.post(url, data=postData)
     try:
         response = json.loads(response.text)
         tools.setSetting('trakt.auth', response['access_token'])
         tools.setSetting('trakt.refresh', response['refresh_token'])
         self.AccessToken = response['access_token']
         self.RefreshToken = response['refresh_token']
         tools.log('Refreshed Trakt Token')
         if not self.AccessToken is '':
             self.headers['Authorization'] = self.AccessToken
         return
     except:
         import traceback
         traceback.print_exc()
         tools.log('Failed to refresh Trakt Access Token', 'error')
         return
def check_for_addon_update():

    try:
        if tools.getSetting('general.checkAddonUpdates') == 'false':
            return
        update_timestamp = float(
            tools.getSetting('addon.updateCheckTimeStamp'))

        if time.time() > (update_timestamp + (24 * (60 * 60))):
            repo_xml = requests.get(
                'https://raw.githubusercontent.com/nixgates/nixgates/master/packages/addons.xml'
            )
            if not repo_xml.status_code == 200:
                tools.log(
                    'Could not connect to repo XML, status: %s' %
                    repo_xml.status_code, 'error')
                return
            repo_version = re.findall(
                r'<addon id=\"plugin.video.seren\" version=\"(\d*.\d*.\d*)\"',
                repo_xml.text)[0]
            local_verison = tools.addonVersion
            if tools.check_version_numbers(local_verison, repo_version):
                tools.showDialog.ok(tools.addonName,
                                    tools.lang(40136) % repo_version)
            tools.setSetting('addon.updateCheckTimeStamp', str(time.time()))
    except:
        pass
Example #3
0
    def poll_auth(self, **params):
        resp = self.get_json('pin/check', **params)
        if resp['activated']:
            tools.setSetting('alldebrid.apikey', resp['apikey'])
            self.apikey = resp['apikey']
            return True, 0

        return False, int(resp['expires_in'])
Example #4
0
    def poll_auth(self, poll_url):

        resp = requests.get(poll_url).json()
        if resp['activated']:
            tools.setSetting('alldebrid.token', resp['token'])
            self.token = resp['token']
            return True, 0

        return False, int(resp['expires_in'])
    def _mark_skin_active(self, skin_name):

        cursor = self._get_skin_cursor()

        cursor.execute('UPDATE skins SET active=? WHERE active=?', ('0', '1'))

        cursor.execute('UPDATE skins SET active=? WHERE skin_name=?', ('1', skin_name))

        cursor.connection.commit()
        cursor.close()

        tools.setSetting('skin.active', skin_name)
Example #6
0
def update_provider_packages():
    if tools.getSetting('providers.autoupdates') == 'false':
        return
    try:
        provider_check_stamp = int(
            tools.getSetting('provider.updateCheckTimeStamp'))
    except:
        provider_check_stamp = 0

    if time.time() > (provider_check_stamp - (30 * 60)):
        customProviders.providers().check_for_updates(silent=True,
                                                      automatic=True)
        tools.setSetting('provider.updateCheckTimeStamp', str(time.time()))
    def token_request(self):
        import time
        if self.ClientSecret is '':
            return

        postData = {
            'client_id': self.ClientID,
            'client_secret': self.ClientSecret,
            'code': self.DeviceCode,
            'grant_type': 'http://oauth.net/grant_type/device/1.0'
        }

        url = self.OauthUrl + self.TokenUrl
        response = requests.post(url, data=postData).text
        response = json.loads(response)
        tools.setSetting('rd.auth', response['access_token'])
        tools.setSetting('rd.refresh', response['refresh_token'])
        self.token = response['access_token']
        self.refresh = response['refresh_token']
        tools.setSetting('rd.expiry',
                         str(time.time() + int(response['expires_in'])))
        username = self.get_url('user')['username']
        tools.setSetting('rd.username', username)
        tools.showDialog.ok(tools.addonName,
                            'Real Debrid ' + tools.lang(32026).encode('utf-8'))
        tools.log('Authorised Real Debrid successfully', 'info')
    def pre_scrape(self):

        try:
            current_position = tools.playList.getposition()
            url = tools.playList[current_position + 1].getPath()
        except:
            url = None

        if url is None: return

        url = url.replace('getSources', 'preScrape')

        tools.setSetting(id='general.tempSilent', value='true')
        tools.execute('RunPlugin("%s")' % url)
Example #9
0
 def newToken(self):
     url = self.baseUrl + "login"
     postdata = {"apikey": self.apiKey}
     postdata = json.dumps(postdata)
     headers = self.headers
     if 'Authorization' in headers:
         headers.pop('Authorization')
     response = json.loads(
         requests.post(url, data=postdata, headers=self.headers).text)
     self.jwToken = response['token']
     tools.setSetting('tvdb.jw', self.jwToken)
     self.headers['Authorization'] = self.jwToken
     tools.log('Refreshed TVDB Token')
     tools.setSetting('tvdb.expiry', str(time.time() + (24 * (60 * 60))))
     return response
Example #10
0
    def poll_token(self, device_code):
        data = {'client_id': self.client_id, 'code': device_code, 'grant_type': 'device_code'}
        token = requests.post('https://www.premiumize.me/token', data=data).json()

        if 'error' in token:
            if token['error'] == "access_denied":
                return False, False
            return True, False

        tools.setSetting('premiumize.token', token['access_token'])
        self.headers['Authorization'] = 'Bearer {}'.format(token['access_token'])

        account_info = self.account_info()
        tools.setSetting('premiumize.username', account_info['customer_id'])

        return False, True
Example #11
0
def update_provider_packages():

    try:
        provider_check_stamp = float(tools.getSetting('provider.updateCheckTimeStamp'))
    except:
        import traceback
        traceback.print_exc()
        provider_check_stamp = 0

    if time.time() > (provider_check_stamp + (24 * (60 * 60))):
        if tools.getSetting('providers.autoupdates') == 'false':
            available_updates = customProviders.providers().check_for_updates(silent=True, automatic=False)
            if len(available_updates) > 0:
                tools.showDialog.notification(tools.addonName, tools.lang(40239))
        else:
            customProviders.providers().check_for_updates(silent=True, automatic=True)
        tools.setSetting('provider.updateCheckTimeStamp', str(time.time()))
Example #12
0
    def renewToken(self):

        refresh_lock = self.refresh_lock()
        if not refresh_lock:
            tools.tvdb_refreshing = True
        else:
            return
        url = self.baseUrl + 'refresh_token'
        response = requests.post(url, headers=self.headers)
        response = json.loads(response.text)
        if 'Error' in response:
            self.newToken(True)
        else:
            self.jwToken = response['token']
            tools.tvdb_refresh = self.jwToken
            tools.setSetting('tvdb.jw', self.jwToken)
            tools.setSetting('tvdb.expiry',
                             str(time.time() + (24 * (60 * 60))))
        return
Example #13
0
 def auth_loop(self):
     if tools.progressDialog.iscanceled():
         tools.progressDialog.close()
         return
     time.sleep(self.OauthTimeStep)
     url = "client_id=%s&code=%s" % (self.ClientID, self.DeviceCode)
     url = self.OauthUrl + self.DeviceCredUrl % url
     response = json.loads(requests.get(url).text)
     if 'error' in response:
         return
     else:
         try:
             tools.progressDialog.close()
             tools.setSetting('rd.client_id', response['client_id'])
             tools.setSetting('rd.secret', response['client_secret'])
             self.ClientSecret = response['client_secret']
             self.ClientID = response['client_id']
         except:
             tools.showDialog.ok(tools.addonName, tools.lang(32100))
         return
Example #14
0
    def auth(self):
        user_code = ''
        url = 'https://api.trakt.tv/oauth/device/code'
        postData = {'client_id': self.ClientID}
        response = requests.post(url, data=postData)
        response = json.loads(response.text)
        try:
            user_code = response['user_code']
            device = response['device_code']
            interval = int(response['interval'])
            expiry = int(response['expires_in'])
        except:
            tools.showDialog.ok(tools.addonName,
                                tools.lang(32032).encode('utf-8'))
            return

        currentTime = 0
        tools.copy2clip(user_code)
        tools.progressDialog.create(
            tools.addonName + ': ' + tools.lang(32031).encode('utf-8'),
            tools.lang(32024).encode('utf-8') +
            tools.colorString('https://trakt.tv/activate \n') +
            tools.lang(32025).encode('utf-8') + tools.colorString(user_code) +
            "\n" + tools.lang(32071).encode('utf-8'))
        tools.progressDialog.update(100)
        while currentTime < (expiry - interval):
            if tools.progressDialog.iscanceled():
                tools.progressDialog.close()
                return
            progressPercent = int(100 - ((float(currentTime) / expiry) * 100))
            tools.progressDialog.update(progressPercent)
            sleep(interval)
            postData = {
                'code': device,
                'client_id': self.ClientID,
                'client_secret': self.ClientSecret
            }
            url = 'https://api.trakt.tv/oauth/device/token'
            response = requests.post(url, data=postData)

            if '200' in str(response):
                response = json.loads(response.text)
                tools.setSetting('trakt.auth', response['access_token'])
                tools.setSetting('trakt.refresh', response['refresh_token'])
                self.headers[
                    'Authorization'] = 'Bearer %s' % response['access_token']
                username = self.get_username()
                tools.setSetting('trakt.username', username)
                tools.progressDialog.close()
                tools.showDialog.ok(tools.addonName,
                                    'Sucessfully authenticated with Trakt')
                break
            if '400' in str(response):
                pass
            else:
                tools.showDialog.ok(tools.addonName,
                                    tools.lang(32032).encode('utf-8'))
                tools.progressDialog.close()
                tools.showDialog.ok(tools.addonName,
                                    tools.lang(32033).encode('utf-8'))
Example #15
0
 def revokeAuth(self):
     url = "oauth/revoke"
     postData = {"token": tools.getSetting('trakt.auth')}
     self.post_request(url, postData, limit=False)
     tools.setSetting('trakt.auth', '')
     tools.setSetting('trakt.refresh', '')
     tools.setSetting('trakt.username', '')
     tools.showDialog.ok(tools.addonName, tools.lang(32030))
Example #16
0
    def newToken(self, ignore_lock=False):

        refresh_lock = self.refresh_lock()
        if not ignore_lock:
            if not refresh_lock:
                tools.tvdb_refreshing = True
            else:
                return
        url = self.baseUrl + "login"
        postdata = {"apikey": self.apiKey}
        postdata = json.dumps(postdata)
        headers = self.headers
        if 'Authorization' in headers:
            headers.pop('Authorization')
        response = json.loads(
            requests.post(url, data=postdata, headers=self.headers).text)
        self.jwToken = response['token']
        tools.tvdb_refresh = self.jwToken
        tools.setSetting('tvdb.jw', self.jwToken)
        self.headers['Authorization'] = self.jwToken
        tools.log('Refreshed TVDB Token')
        tools.setSetting('tvdb.expiry', str(time.time() + (24 * (60 * 60))))
        return response
Example #17
0
 def revokeAuth(self):
     url = "oauth/revoke"
     postData = {"token": tools.getSetting('trakt.auth')}
     self.post_request(url, postData, limit=False)
     tools.setSetting('trakt.auth', '')
     tools.setSetting('trakt.refresh', '')
     tools.setSetting('trakt.username', '')
     from resources.lib.modules.trakt_sync import activities
     database = activities.TraktSyncDatabase()
     database.clear_user_information()
     tools.showDialog.ok(tools.addonName, tools.lang(32030))
Example #18
0
 def refreshToken(self):
     import time
     postData = {'grant_type': 'http://oauth.net/grant_type/device/1.0',
                 'code': self.refresh,
                 'client_secret': self.ClientSecret,
                 'client_id': self.ClientID
                 }
     url = self.OauthUrl + 'token'
     response = requests.post(url, data=postData)
     response = json.loads(response.text)
     if 'access_token' in response:
         self.token = response['access_token']
     else:
         pass
     if 'refresh_token' in response:
         self.refresh = response['refresh_token']
     tools.setSetting('rd.auth', self.token)
     tools.setSetting('rd.refresh', self.refresh)
     tools.setSetting('rd.expiry', str(time.time() + int(response['expires_in'])))
     tools.log('Real Debrid Token Refreshed')
Example #19
0
 def store_user_info(self):
     user_information = self.get_url('user/login', True)
     tools.setSetting('alldebrid.username',
                      user_information['user']['username'])
     return
Example #20
0
def source_tests():
    try:
        scrape_failures = False
        resolve_failures = False
        tools.setSetting('general.tempSilent', 'true')
        tools.setSetting('general.playstyleEpisodes', 1)
        tools.setSetting('preem.enabled', 'false')
        tools.setSetting('preem.cloudfiles', 'false')
        run_action('clearTorrentCache')

        from resources.lib.modules import getSources
        uncached_sources, source_results, args = getSources.Sources().doModal(
            episode_object)

        if len(source_results) == 0:
            scrape_failures = True
            log('Scraping: FAILED', 'error')
            return

        if len([
                i
                for i in source_results if i['debrid_provider'] == 'premiumize'
        ]) > 0:
            log('Premiumize Cache Check: OK', 'info')
        else:
            scrape_failures = True
            log('Premiumize Cache Check: FAILED', 'error')

        if len([
                i for i in source_results
                if i['debrid_provider'] == 'real_debrid'
        ]) > 0:
            log('Real Debrid Cache Check: OK', 'info')
        else:
            scrape_failures = True
            log('Real Debrid Cache Check: FAILED', 'error')

        if len([
                i for i in source_results if i['source'] == 'Real Debrid Cloud'
        ]) > 0:
            log('Real Debrid Cloud Scraping: OK', 'info')
        else:
            scrape_failures = True
            log('Real Debrid Cloud Scraping: FAILED', 'error')

        if len([
                i for i in source_results if i['source'] == 'Premiumize Cloud'
        ]) > 0:
            log('Premiumize Cloud Scraping: OK', 'info')
        else:
            scrape_failures = True
            log('Premiumize Cloud Scraping: FAILED', 'error')

        if not scrape_failures:
            log('Episode Scraping: OK', 'info')
        else:
            log('Episode Scraping: FAILED', 'error')

        rd_sources = [
            i for i in source_results if i['debrid_provider'] == 'real_debrid'
            and i['source'] != 'Real Debrid Cloud'
        ]

        from resources.lib.modules import resolver
        stream_link = resolver.Resolver().doModal(rd_sources, args, False)

        if stream_link is None:
            log('Real Debrid Resolving: Failed', 'error')
            resolve_failures = True
        else:
            log('Real Debrid Resolving: OK', 'info')

        prem_sources = [
            i for i in source_results if i['debrid_provider'] == 'premiumize'
            and i['source'] != 'Pemiumize Cloud'
        ]

        from resources.lib.modules import resolver

        stream_link = resolver.Resolver().doModal(prem_sources, args, False)

        if stream_link is None:
            log('Premiumize Resolving: Failed', 'error')
            resolve_failures = True
        else:
            log('Premiumize Resolving: OK', 'info')

        if not resolve_failures:
            log('Episode Resolving: OK', 'info')
        else:
            log('Episode Resolving: Failed', 'error')

        uncached_sources, source_results, args = getSources.Sources().doModal(
            movie_object)

        if len(source_results) == 0:
            log('Movie Scraping: Failed', 'error')
        else:
            log('Movie Scraping: OK', 'info')

        tools.setSetting('general.tempSilent', 'false')
    except:
        tools.setSetting('general.tempSilent', 'false')
        ScrapingException()
Example #21
0
# -*- coding: utf-8 -*-

import xbmc
from random import randint

from resources.lib.common import maintenance
from resources.lib.common import tools
from resources.lib.modules.trakt_sync.activities import TraktSyncDatabase

tools.log('##################  STARTING SERVICE  ######################')
monitor = xbmc.Monitor()

tools.setSetting('general.tempSilent', 'false')

tools.log('Performing initial background maintenance...')

if tools.getSetting('general.checkAddonUpdates') == 'true':
    maintenance.check_for_addon_update()

TraktSyncDatabase().sync_activities()

maintenance.run_maintenance()

tools.log('Initial maintenance cycle completed')

tools.log('#############  SERVICE ENTERED KEEP ALIVE  #################')

while not monitor.abortRequested():
    try:
        if monitor.waitForAbort(60 * randint(13, 17)):
            break
Example #22
0
    def auth(self):

        url = 'https://api.trakt.tv/oauth/device/code'
        postData = {'client_id': self.ClientID}
        response = requests.post(url, data=postData)
        if not response.ok:
            tools.showDialog.ok(tools.addonName, tools.lang(40113))
            return
        response = json.loads(response.text)
        try:
            user_code = response['user_code']
            device = response['device_code']
            interval = int(response['interval'])
            expiry = int(response['expires_in'])
        except:
            tools.showDialog.ok(tools.addonName, tools.lang(32032))
            return
        currentTime = 0
        tools.copy2clip(user_code)
        tools.progressDialog.create(
            tools.addonName + ': ' + tools.lang(32031),
            tools.lang(32024) +
            tools.colorString('https://trakt.tv/activate \n') +
            tools.lang(32025) + tools.colorString(user_code) + "\n" +
            tools.lang(32071))
        tools.progressDialog.update(100)
        while currentTime < (expiry - interval):
            if tools.progressDialog.iscanceled():
                tools.progressDialog.close()
                return
            progressPercent = int(100 - ((float(currentTime) / expiry) * 100))
            tools.progressDialog.update(progressPercent)
            sleep(interval)
            postData = {
                'code': device,
                'client_id': self.ClientID,
                'client_secret': self.ClientSecret
            }
            url = 'https://api.trakt.tv/oauth/device/token'
            response = requests.post(url, data=postData)

            if '200' in str(response):
                response = json.loads(response.text)
                tools.setSetting('trakt.auth', response['access_token'])
                tools.setSetting('trakt.refresh', response['refresh_token'])
                self.AccessToken = response['access_token']
                self.headers = {
                    'trakt-api-version': '2',
                    'trakt-api-key': self.ClientID,
                    'content-type': 'application/json'
                }

                if not self.AccessToken is '':
                    self.headers[
                        'Authorization'] = 'Bearer %s' % self.AccessToken
                username = self.get_username()
                tools.setSetting('trakt.username', username)
                tools.progressDialog.close()
                tools.showDialog.ok(tools.addonName,
                                    'Sucessfully authenticated with Trakt')

                # Synchronise Trakt Database with new user
                from resources.lib.modules.trakt_sync import activities
                database = activities.TraktSyncDatabase()
                if database.activites['trakt_username'] != username:
                    database.clear_user_information()
                    database.flush_activities(False)
                    database._build_sync_activities()
                    database.set_trakt_user(username)
                    tools.execute(
                        'RunPlugin("plugin://plugin.video.%s/?action=syncTraktActivities")'
                        % tools.addonName.lower())
                break
            if '400' in str(response):
                pass
            else:
                tools.progressDialog.close()
                tools.showDialog.ok(tools.addonName, tools.lang(32032))
                break
Example #23
0
 def store_user_info(self):
     user_information = self.get_json('user', apikey=self.apikey)
     if user_information is not None:
         tools.setSetting('alldebrid.username',
                          user_information['user']['username'])
Example #24
0
def dispatch(params):
    from resources.lib.common import tools
    from resources.lib.modules import database

    tools.SETTINGS_CACHE = {}

    try:

        url = params.get('url')

        action = params.get('action')

        page = params.get('page')

        actionArgs = params.get('actionArgs')

        pack_select = params.get('packSelect')

        source_select = params.get('source_select')

        seren_reload = True if params.get('seren_reload') == 'true' else False

        resume = params.get('resume')

        forceresumeoff = True if params.get(
            'forceresumeoff') == 'true' else False

        forceresumeon = True if params.get(
            'forceresumeon') == 'true' else False

        smartPlay = True if params.get('smartPlay') == 'true' else False

    except:

        print('Welcome to console mode')
        print('Command Help:')
        print('   - Menu Number: opens the relevant menu page')
        print('   - shell: opens a interactive python shell within Seren')
        print('   - action xxx: run a custom Seren URL argument')

        url = ''

        action = None

        page = ''

        actionArgs = ''

        pack_select = ''

        source_select = ''

        seren_reload = ''

        resume = None

        forceresumeoff = True if params.get(
            'forceresumeoff') == 'true' else False

        forceresumeon = True if params.get(
            'forceresumeon') == 'true' else False

        smartPlay = True if params.get('smartPlay') == 'true' else False

    tools.log('Seren, Running Path - Action: %s, actionArgs: %s' %
              (action, actionArgs))

    if action is None:
        from resources.lib.gui import homeMenu

        homeMenu.Menus().home()

    if action == 'smartPlay':
        from resources.lib.modules import smartPlay
        # if 'resume' not in actionArgs:
        #     actionArgs = json.loads(actionArgs)
        #     actionArgs['resume'] = sys.argv[3].split(':')[-1]
        #     actionArgs = tools.quote(json.dumps(actionArgs, sort_keys=True))
        smartPlay.SmartPlay(actionArgs).fill_playlist()

    if action == 'playbackResume':
        from resources.lib.modules import smartPlay
        smart = smartPlay.SmartPlay(actionArgs)
        smart.workaround()

    if action == 'moviesHome':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().discoverMovies()

    if action == 'moviesPopular':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesPopular(page)

    if action == 'moviesTrending':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesTrending(page)

    if action == 'moviesPlayed':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesPlayed(page)

    if action == 'moviesWatched':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesWatched(page)

    if action == 'moviesCollected':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesCollected(page)

    if action == 'moviesAnticipated':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesAnticipated(page)

    if action == 'moviesBoxOffice':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesBoxOffice()

    if action == 'moviesUpdated':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesUpdated(page)

    if action == 'moviesRecommended':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesRecommended()

    if action == 'moviesSearch':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesSearch(actionArgs)

    if action == 'moviesSearchResults':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesSearchResults(actionArgs)

    if action == 'moviesSearchHistory':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesSearchHistory()

    if action == 'myMovies':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().myMovies()

    if action == 'moviesMyCollection':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().myMovieCollection()

    if action == 'moviesMyWatchlist':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().myMovieWatchlist()

    if action == 'moviesRelated':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesRelated(actionArgs)

    if action == 'colorPicker':
        tools.colorPicker()

    if action == 'authTrakt':
        from resources.lib.indexers import trakt

        trakt.TraktAPI().auth()

    if action == 'revokeTrakt':
        from resources.lib.indexers import trakt

        trakt.TraktAPI().revokeAuth()

    if action == 'getSources':

        try:

            item_information = tools.get_item_information(actionArgs)
            #
            # This tomfoolery here is the new workaround for Seren to skip the building playlist window

            if tools.getSetting(
                    'smartplay.playlistcreate') == 'true' or smartPlay:

                if tools.playList.size() > 0:
                    playlist_uris = [
                        tools.playList[i].getPath()
                        for i in range(tools.playList.size())
                    ]
                else:
                    playlist_uris = []

                if ('showInfo' in item_information and tools.playList.size() == 0) \
                        or not any(sys.argv[2] in i for i in playlist_uris):

                    try:
                        name = item_information['info']['title']
                        item = tools.addDirectoryItem(
                            name,
                            'getSources',
                            item_information['info'],
                            item_information['art'],
                            item_information['cast'],
                            isFolder=False,
                            isPlayable=True,
                            actionArgs=actionArgs,
                            bulk_add=True,
                            set_ids=item_information['ids'])
                        tools.cancelPlayback()
                        tools.playList.add(url=sys.argv[0] + sys.argv[2],
                                           listitem=item[1])
                        tools.player().play(tools.playList)
                        return
                    except:
                        import traceback
                        traceback.print_exc()
                        return

            bookmark_style = tools.getSetting('general.bookmarkstyle')

            if tools.playList.size(
            ) == 1 and resume is not None and bookmark_style != '2' and not forceresumeoff:

                if bookmark_style == '0' and not forceresumeon:
                    import datetime
                    selection = tools.showDialog.contextmenu([
                        '{} {}'.format(
                            tools.lang(32092),
                            datetime.timedelta(seconds=int(resume))),
                        tools.lang(40350)
                    ])
                    if selection == -1:
                        tools.cancelPlayback()
                        sys.exit()
                    elif selection != 0:
                        resume = None
            else:
                resume = None

            # Assume if we couldn't get information using the normal method, that it's the legacy method
            if item_information is None:
                item_information = actionArgs

            if not tools.premium_check():
                tools.showDialog.ok(tools.addonName, tools.lang(40146),
                                    tools.lang(40147))
                return None

            if tools.playList.getposition() == 0 and tools.getSetting(
                    'general.scrapedisplay') == '0':
                display_background = True
            else:
                display_background = False

            from resources.lib.modules.skin_manager import SkinManager

            if display_background:
                from resources.lib.gui.windows.persistent_background import PersistentBackground
                background = PersistentBackground(
                    *SkinManager().confirm_skin_path(
                        'persistent_background.xml'),
                    actionArgs=actionArgs)
                background.setText(tools.lang(32045))
                background.show()

            from resources.lib.modules import getSources

            uncached_sources, source_results, args = database.get(
                getSources.getSourcesHelper,
                1,
                actionArgs,
                seren_reload=seren_reload,
                seren_sources=True)
            if len(source_results) <= 0:
                tools.showDialog.notification(tools.addonName,
                                              tools.lang(32047),
                                              time=5000)
                return

            if 'showInfo' in item_information:
                source_select_style = 'Episodes'
            else:
                source_select_style = 'Movie'

            if tools.getSetting(
                    'general.playstyle%s' %
                    source_select_style) == '1' or source_select == 'true':

                try:
                    background.setText(tools.lang(40135))
                except:
                    pass

                from resources.lib.modules import sourceSelect

                stream_link = sourceSelect.sourceSelect(
                    uncached_sources, source_results, actionArgs)

                if stream_link is None:
                    tools.showDialog.notification(tools.addonName,
                                                  tools.lang(32047),
                                                  time=5000)
                    raise Exception
                if not stream_link:
                    # user has backed out of source select, don't show no playable sources notification
                    raise Exception
            else:
                try:
                    background.setText(tools.lang(32046))
                except:
                    pass

                from resources.lib.modules import resolver

                resolver_window = resolver.Resolver(
                    *SkinManager().confirm_skin_path('resolver.xml'),
                    actionArgs=actionArgs)

                stream_link = database.get(resolver_window.doModal,
                                           1,
                                           source_results,
                                           args,
                                           pack_select,
                                           seren_reload=seren_reload)
                del resolver_window

                if stream_link is None:
                    tools.closeBusyDialog()
                    tools.showDialog.notification(tools.addonName,
                                                  tools.lang(32047),
                                                  time=5000)
                    raise Exception

            tools.showBusyDialog()
            try:
                background.close()
            except:
                pass
            try:
                del background
            except:
                pass

            from resources.lib.modules import player

            # if 'resume' not in actionArgs:
            #     actionArgs = json.loads(actionArgs)
            #     actionArgs['resume'] = sys.argv[3].split(':')[-1]
            #     actionArgs = json.dumps(actionArgs, sort_keys=True)

            player.serenPlayer().play_source(stream_link,
                                             actionArgs,
                                             resume_time=resume,
                                             params=params)

        except:
            import traceback
            traceback.print_exc()
            # Perform cleanup and make sure all open windows close and playlist is cleared
            try:
                tools.closeBusyDialog()
            except:
                pass
            try:
                background.close()
            except:
                pass
            try:
                del background
            except:
                pass
            try:
                resolver_window.close()
            except:
                pass
            try:
                del resolver_window
            except:
                pass
            try:
                tools.playList.clear()
            except:
                pass
            try:
                tools.closeOkDialog()
            except:
                pass
            try:
                tools.cancelPlayback()
            except:
                pass

    if action == 'preScrape':

        from resources.lib.modules.skin_manager import SkinManager

        try:
            item_information = tools.get_item_information(actionArgs)

            if 'showInfo' in item_information:
                source_select_style = 'Episodes'
            else:
                source_select_style = 'Movie'

            from resources.lib.modules import getSources

            uncached_sources, source_results, args = database.get(
                getSources.getSourcesHelper,
                1,
                actionArgs,
                seren_reload=seren_reload,
                seren_sources=True)

            if tools.getSetting('general.playstyle%s' %
                                source_select_style) == '0':
                from resources.lib.modules import resolver

                resolver_window = resolver.Resolver(
                    *SkinManager().confirm_skin_path('resolver.xml'),
                    actionArgs=actionArgs)
                database.get(resolver_window.doModal,
                             1,
                             source_results,
                             args,
                             pack_select,
                             seren_reload=seren_reload)

            tools.setSetting(id='general.tempSilent', value='false')
        except:
            tools.setSetting(id='general.tempSilent', value='false')
            import traceback

            traceback.print_exc()
            pass

        tools.log('Pre-scraping completed')

    if action == 'authRealDebrid':
        from resources.lib.debrid import real_debrid

        real_debrid.RealDebrid().auth()

    if action == 'showsHome':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().discoverShows()

    if action == 'myShows':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().myShows()

    if action == 'showsMyCollection':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().myShowCollection()

    if action == 'showsMyWatchlist':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().myShowWatchlist()

    if action == 'showsMyProgress':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().myProgress()

    if action == 'showsMyRecentEpisodes':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().myRecentEpisodes()

    if action == 'showsPopular':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsPopular(page)

    if action == 'showsRecommended':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsRecommended()

    if action == 'showsTrending':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsTrending(page)

    if action == 'showsPlayed':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsPlayed(page)

    if action == 'showsWatched':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsWatched(page)

    if action == 'showsCollected':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsCollected(page)

    if action == 'showsAnticipated':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsAnticipated(page)

    if action == 'showsUpdated':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsUpdated(page)

    if action == 'showsSearch':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsSearch(actionArgs)

    if action == 'showsSearchResults':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsSearchResults(actionArgs)

    if action == 'showsSearchHistory':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showSearchHistory()

    if action == 'showSeasons':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showSeasons(actionArgs)

    if action == 'seasonEpisodes':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().seasonEpisodes(actionArgs)

    if action == 'showsRelated':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsRelated(actionArgs)

    if action == 'showYears':
        from resources.lib.gui import tvshowMenus
        tvshowMenus.Menus().showYears(actionArgs, page)

    if action == 'searchMenu':
        from resources.lib.gui import homeMenu

        homeMenu.Menus().searchMenu()

    if action == 'toolsMenu':
        from resources.lib.gui import homeMenu

        homeMenu.Menus().toolsMenu()

    if action == 'clearCache':
        from resources.lib.common import tools

        tools.clearCache()

    if action == 'traktManager':
        from resources.lib.indexers import trakt

        trakt.TraktAPI().traktManager(actionArgs)

    if action == 'onDeckShows':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().onDeckShows()

    if action == 'onDeckMovies':
        from resources.lib.gui.movieMenus import Menus

        Menus().onDeckMovies()

    if action == 'cacheAssist':
        from resources.lib.modules import cacheAssist

        cacheAssist.CacheAssit(actionArgs)

    if action == 'tvGenres':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showGenres()

    if action == 'showGenresGet':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showGenreList(actionArgs, page)

    if action == 'movieGenres':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().movieGenres()

    if action == 'movieGenresGet':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().movieGenresList(actionArgs, page)

    if action == 'filePicker':
        from resources.lib.modules import smartPlay

        smartPlay.SmartPlay(actionArgs).torrent_file_picker()

    if action == 'shufflePlay':
        from resources.lib.modules import smartPlay

        try:
            smart = smartPlay.SmartPlay(actionArgs).shufflePlay()
        except:
            import traceback
            traceback.print_exc()
            pass

    if action == 'resetSilent':
        tools.setSetting('general.tempSilent', 'false')
        tools.showDialog.notification('{}: {}'.format(tools.addonName,
                                                      tools.lang(40296)),
                                      tools.lang(32048),
                                      time=5000)

    if action == 'clearTorrentCache':
        from resources.lib.modules import database

        database.torrent_cache_clear()

    if action == 'openSettings':
        tools.execute('Addon.OpenSettings(%s)' % tools.addonInfo('id'))

    if action == 'myTraktLists':
        from resources.lib.indexers import trakt

        trakt.TraktAPI().myTraktLists(actionArgs)

    if action == 'traktList':
        from resources.lib.indexers import trakt

        trakt.TraktAPI().getListItems(actionArgs, page)

    if action == 'nonActiveAssistClear':
        from resources.lib.gui import debridServices

        debridServices.Menus().assist_non_active_clear()

    if action == 'debridServices':
        from resources.lib.gui import debridServices

        debridServices.Menus().home()

    if action == 'cacheAssistStatus':
        from resources.lib.gui import debridServices

        debridServices.Menus().get_assist_torrents()

    if action == 'premiumizeTransfers':
        from resources.lib.gui import debridServices

        debridServices.Menus().list_premiumize_transfers()

    if action == 'showsNextUp':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().myNextUp()

    if action == 'runMaintenance':
        from resources.lib.common import maintenance

        maintenance.run_maintenance()

    if action == 'providerTools':
        from resources.lib.gui import homeMenu

        homeMenu.Menus().providerMenu()

    if action == 'adjustProviders':
        tools.log('adjustProviders endpoint has been deprecated')
        return
        # from resources.lib.modules import customProviders
        #
        # customProviders.providers().adjust_providers(actionArgs)

    if action == 'adjustPackage':
        tools.log('adjustPackage endpoint has been deprecated')
        return
        # DEPRECATED
        # from resources.lib.modules import customProviders
        #
        # customProviders.providers().adjust_providers(actionArgs, package_disable=True)

    if action == 'installProviders':
        from resources.lib.modules import customProviders

        customProviders.providers().install_package(actionArgs)

    if action == 'uninstallProviders':
        from resources.lib.modules import customProviders

        customProviders.providers().uninstall_package()

    if action == 'showsNew':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().newShows()

    if action == 'realdebridTransfers':
        from resources.lib.gui import debridServices

        debridServices.Menus().list_RD_transfers()

    if action == 'cleanInstall':
        from resources.lib.common import maintenance

        maintenance.wipe_install()

    if action == 'buildPlaylistWorkaround':
        from resources.lib.modules import smartPlay
        smartPlay.SmartPlay(actionArgs).resume_playback()

    if action == 'premiumizeCleanup':
        from resources.lib.common import maintenance

        maintenance.premiumize_transfer_cleanup()

    if action == 'test2':
        pass

    if action == 'manualProviderUpdate':
        from resources.lib.modules import customProviders

        customProviders.providers().manual_update()

    if action == 'clearSearchHistory':
        from resources.lib.modules import database

        database.clearSearchHistory()

    if action == 'externalProviderInstall':
        from resources.lib.modules import customProviders

        confirmation = tools.showDialog.yesno(tools.addonName,
                                              tools.lang(40117))
        if confirmation == 0:
            sys.exit()

        customProviders.providers().install_package(1, url=url)

    if action == 'externalProviderUninstall':
        from resources.lib.modules import customProviders

        confirmation = tools.showDialog.yesno(tools.addonName,
                                              tools.lang(40119) % url)
        if confirmation == 0:
            sys.exit()

        customProviders.providers().uninstall_package(package=url,
                                                      silent=False)

    if action == 'showsNetworks':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsNetworks()

    if action == 'showsNetworkShows':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsNetworkShows(actionArgs, page)

    if action == 'movieYears':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().movieYears()

    if action == 'movieYearsMovies':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().movieYearsMovies(actionArgs, page)

    if action == 'syncTraktActivities':
        from resources.lib.modules.trakt_sync.activities import TraktSyncDatabase
        TraktSyncDatabase().sync_activities()

    if action == 'traktSyncTools':
        from resources.lib.gui import homeMenu
        homeMenu.Menus().traktSyncTools()

    if action == 'flushTraktActivities':
        from resources.lib.modules import trakt_sync
        trakt_sync.TraktSyncDatabase().flush_activities()

    if action == 'flushTraktDBMeta':
        from resources.lib.modules import trakt_sync
        trakt_sync.TraktSyncDatabase().clear_all_meta()

    if action == 'myFiles':
        from resources.lib.gui import myFiles
        myFiles.Menus().home()

    if action == 'myFilesFolder':
        from resources.lib.gui import myFiles
        myFiles.Menus().myFilesFolder(actionArgs)

    if action == 'myFilesPlay':
        from resources.lib.gui import myFiles
        myFiles.Menus().myFilesPlay(actionArgs)

    if action == 'forceTraktSync':
        from resources.lib.modules import trakt_sync
        from resources.lib.modules.trakt_sync.activities import TraktSyncDatabase
        trakt_sync.TraktSyncDatabase().flush_activities()
        TraktSyncDatabase().sync_activities()

    if action == 'rebuildTraktDatabase':
        from resources.lib.modules.trakt_sync import TraktSyncDatabase
        TraktSyncDatabase().re_build_database()

    if action == 'myUpcomingEpisodes':
        from resources.lib.gui import tvshowMenus
        tvshowMenus.Menus().myUpcomingEpisodes()

    if action == 'myWatchedEpisodes':
        from resources.lib.gui import tvshowMenus
        tvshowMenus.Menus().myWatchedEpisodes(page)

    if action == 'myWatchedMovies':
        from resources.lib.gui import movieMenus
        movieMenus.Menus().myWatchedMovies(page)

    if action == 'showsByActor':
        from resources.lib.gui import tvshowMenus
        tvshowMenus.Menus().showsByActor(actionArgs)

    if action == 'movieByActor':
        from resources.lib.gui import movieMenus
        movieMenus.Menus().moviesByActor(actionArgs)

    if action == 'playFromRandomPoint':
        from resources.lib.modules import smartPlay
        smartPlay.SmartPlay(actionArgs).play_from_random_point()

    if action == 'refreshProviders':
        from resources.lib.modules.customProviders import providers
        providers().update_known_providers()

    if action == 'installSkin':
        from resources.lib.modules.skin_manager import SkinManager
        SkinManager().install_skin()

    if action == 'uninstallSkin':
        from resources.lib.modules.skin_manager import SkinManager
        SkinManager().uninstall_skin()

    if action == 'switchSkin':
        from resources.lib.modules.skin_manager import SkinManager
        SkinManager().switch_skin()

    if action == 'manageProviders':
        tools.showBusyDialog()
        from resources.lib.gui.windows.custom_providers import CustomProviders
        from resources.lib.modules.skin_manager import SkinManager
        CustomProviders(*SkinManager().confirm_skin_path(
            'custom_providers.xml')).doModal()

    if action == 'flatEpisodes':
        from resources.lib.gui.tvshowMenus import Menus
        Menus().flat_episode_list(actionArgs)

    if action == 'runPlayerDialogs':
        from resources.lib.modules.player import PlayerDialogs
        try:
            PlayerDialogs().display_dialog()
        except:
            import traceback
            traceback.print_exc()

    if action == 'authAllDebrid':
        from resources.lib.debrid.all_debrid import AllDebrid
        AllDebrid().auth()

    if action == 'checkSkinUpdates':
        from resources.lib.modules.skin_manager import SkinManager
        SkinManager().check_for_updates()

    if action == 'authPremiumize':
        from resources.lib.debrid.premiumize import Premiumize
        Premiumize().auth()
Example #25
0
if action == 'preScrape':
    tools.log('Started Pre-scraping')
    try:
        from resources.lib.modules import getSources

        source_results, args = database.get(getSources.Sources().doModal, 1,
                                            actionArgs)

        if tools.getSetting('general.playstyle') == '0':
            from resources.lib.modules import resolver

            stream_link = database.get(resolver.Resolver().doModal, 1,
                                       source_results, args, pack_select)

        tools.setSetting(id='general.tempSilent', value='false')
    except:
        tools.setSetting(id='general.tempSilent', value='false')
        import traceback

        traceback.print_exc()
        pass
    tools.log('Pre-scraping completed')

if action == 'authRealDebrid':
    from resources.lib.debrid import real_debrid

    real_debrid.RealDebrid().auth()

if action == 'showsHome':
    from resources.lib.gui import tvshowMenus
Example #26
0
def api(params):

    from resources.lib.common import tools
    from resources.lib.modules import database

    tools.SETTINGS_CACHE = {}

    try:

        url = params.get('url')

        action = params.get('action')

        page = params.get('page')

        actionArgs = params.get('actionArgs')

        pack_select = params.get('packSelect')

        source_select = params.get('source_select')

        seren_reload = params.get('seren_reload')

        if seren_reload == 'true':
            seren_reload = True

    except:

        print('Welcome to console mode')
        print('Command Help:')
        print('   - Menu Number: opens the relevant menu page')
        print('   - shell: opens a interactive python shell within Seren')
        print('   - action xxx: run a custom Seren URL argument')

        url = ''

        action = None

        page = ''

        actionArgs = ''

        pack_select = ''

        source_select = ''

        seren_reload = ''

    unit_tests = params.get('unit_tests', False)

    if unit_tests:
        tools.enable_unit_tests()

    tools.log('Seren, Running Path - Action: %s, actionArgs: %s' %
              (action, actionArgs))

    if action == None:
        from resources.lib.gui import homeMenu

        homeMenu.Menus().home()

    if action == 'smartPlay':
        from resources.lib.modules import smartPlay
        smartPlay.SmartPlay(actionArgs).fill_playlist()

    if action == 'playbackResume':
        from resources.lib.modules import smartPlay

        smart = smartPlay.SmartPlay(actionArgs)
        smart.workaround()

    if action == 'moviesHome':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().discoverMovies()

    if action == 'moviesPopular':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesPopular(page)

    if action == 'moviesTrending':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesTrending(page)

    if action == 'moviesPlayed':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesPlayed(page)

    if action == 'moviesWatched':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesWatched(page)

    if action == 'moviesCollected':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesCollected(page)

    if action == 'moviesAnticipated':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesAnticipated(page)

    if action == 'moviesBoxOffice':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesBoxOffice()

    if action == 'moviesUpdated':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesUpdated(page)

    if action == 'moviesRecommended':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesRecommended()

    if action == 'moviesSearch':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesSearch(actionArgs)

    if action == 'moviesSearchResults':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesSearchResults(actionArgs)

    if action == 'moviesSearchHistory':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesSearchHistory()

    if action == 'myMovies':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().myMovies()

    if action == 'moviesMyCollection':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().myMovieCollection()

    if action == 'moviesMyWatchlist':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().myMovieWatchlist()

    if action == 'moviesRelated':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().moviesRelated(actionArgs)

    if action == 'colorPicker':
        tools.colorPicker()

    if action == 'authTrakt':
        from resources.lib.indexers import trakt

        trakt.TraktAPI().auth()

    if action == 'revokeTrakt':
        from resources.lib.indexers import trakt

        trakt.TraktAPI().revokeAuth()

    if action == 'getSources':

        try:
            from resources.lib.gui.windows.persistent_background import PersistentBackground
            item_information = tools.get_item_information(actionArgs)

            # Assume if we couldn't get information using the normal method, that it's the legacy method
            if item_information is None:
                item_information = actionArgs

            if not tools.premium_check():
                tools.showDialog.ok(tools.addonName, tools.lang(40146),
                                    tools.lang(40147))
                return None

            if tools.playList.getposition() == 0 and tools.getSetting(
                    'general.scrapedisplay') == '0':
                display_background = True
            else:
                display_background = False

            if tools.getSetting('general.scrapedisplay') == '1':
                tools.closeBusyDialog()

            if display_background:
                background = PersistentBackground('persistent_background.xml',
                                                  tools.addonDir,
                                                  actionArgs=actionArgs)
                background.setText(tools.lang(32045))
                background.show()

            from resources.lib.modules import getSources

            uncached_sources, source_results, args = database.get(
                getSources.getSourcesHelper,
                1,
                actionArgs,
                seren_reload=seren_reload,
                seren_sources=True)
            if len(source_results) <= 0:
                tools.showDialog.notification(tools.addonName,
                                              tools.lang(32047),
                                              time=5000)
                return

            if 'showInfo' in item_information:
                source_select_style = 'Episodes'
            else:
                source_select_style = 'Movie'

            if tools.getSetting(
                    'general.playstyle%s' %
                    source_select_style) == '1' or source_select == 'true':
                try:
                    background.setText(tools.lang(40135))
                except:
                    pass

                from resources.lib.modules import sourceSelect

                stream_link = sourceSelect.sourceSelect(
                    uncached_sources, source_results, actionArgs)

                if stream_link is None:
                    tools.showDialog.notification(tools.addonName,
                                                  tools.lang(32047),
                                                  time=5000)
                    raise Exception
            else:
                try:
                    background.setText(tools.lang(32046))
                except:
                    pass

                from resources.lib.modules import resolver

                resolver_window = resolver.Resolver('resolver.xml',
                                                    tools.addonDir,
                                                    actionArgs=actionArgs)
                stream_link = database.get(resolver_window.doModal,
                                           1,
                                           source_results,
                                           args,
                                           pack_select,
                                           seren_reload=seren_reload)
                del resolver_window

                if stream_link is None:
                    tools.closeBusyDialog()
                    tools.showDialog.notification(tools.addonName,
                                                  tools.lang(32047),
                                                  time=5000)
                    raise Exception

            try:
                background.close()
            except:
                pass
            try:
                del background
            except:
                pass

            from resources.lib.modules import player

            player.serenPlayer().play_source(stream_link, actionArgs)

        except:
            # Perform cleanup and make sure all open windows close and playlist is cleared
            try:
                tools.closeBusyDialog()
            except:
                pass
            try:
                background.close()
            except:
                pass
            try:
                del background
            except:
                pass
            try:
                sources_window.close()
            except:
                pass
            try:
                del sources_window
            except:
                pass
            try:
                resolver_window.close()
            except:
                pass
            try:
                del resolver_window
            except:
                pass
            try:
                tools.playList.clear()
            except:
                pass
            try:
                tools.closeOkDialog()
            except:
                pass
            try:
                tools.cancelPlayback()
            except:
                pass

    if action == 'preScrape':
        try:
            item_information = tools.get_item_information(actionArgs)

            if 'showInfo' in item_information:
                source_select_style = 'Episodes'
            else:
                source_select_style = 'Movie'

            from resources.lib.modules import getSources

            uncached_sources, source_results, args = database.get(
                getSources.getSourcesHelper,
                1,
                actionArgs,
                seren_reload=seren_reload,
                seren_sources=True)

            if tools.getSetting('general.playstyle%s' %
                                source_select_style) == '0':
                from resources.lib.modules import resolver

                from resources.lib.modules import resolver

                resolver_window = resolver.Resolver('resolver.xml',
                                                    tools.addonDir,
                                                    actionArgs=actionArgs)
                database.get(resolver_window.doModal,
                             1,
                             source_results,
                             args,
                             pack_select,
                             seren_reload=seren_reload)

            tools.setSetting(id='general.tempSilent', value='false')
        except:
            tools.setSetting(id='general.tempSilent', value='false')
            import traceback

            traceback.print_exc()
            pass
        tools.log('Pre-scraping completed')

    if action == 'authRealDebrid':
        from resources.lib.debrid import real_debrid

        real_debrid.RealDebrid().auth()

    if action == 'showsHome':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().discoverShows()

    if action == 'myShows':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().myShows()

    if action == 'showsMyCollection':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().myShowCollection()

    if action == 'showsMyWatchlist':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().myShowWatchlist()

    if action == 'showsMyProgress':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().myProgress()

    if action == 'showsMyRecentEpisodes':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().myRecentEpisodes()

    if action == 'showsPopular':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsPopular(page)

    if action == 'showsRecommended':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsRecommended()

    if action == 'showsTrending':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsTrending(page)

    if action == 'showsPlayed':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsPlayed(page)

    if action == 'showsWatched':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsWatched(page)

    if action == 'showsCollected':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsCollected(page)

    if action == 'showsAnticipated':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsAnticipated(page)

    if action == 'showsUpdated':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsUpdated(page)

    if action == 'showsSearch':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsSearch(actionArgs)

    if action == 'showsSearchResults':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsSearchResults(actionArgs)

    if action == 'showsSearchHistory':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showSearchHistory()

    if action == 'showSeasons':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showSeasons(actionArgs)

    if action == 'seasonEpisodes':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().seasonEpisodes(actionArgs)

    if action == 'showsRelated':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsRelated(actionArgs)

    if action == 'showYears':
        from resources.lib.gui import tvshowMenus
        tvshowMenus.Menus().showYears(actionArgs, page)

    if action == 'searchMenu':
        from resources.lib.gui import homeMenu

        homeMenu.Menus().searchMenu()

    if action == 'toolsMenu':
        from resources.lib.gui import homeMenu

        homeMenu.Menus().toolsMenu()

    if action == 'clearCache':
        from resources.lib.common import tools

        tools.clearCache()

    if action == 'traktManager':
        from resources.lib.indexers import trakt

        trakt.TraktAPI().traktManager(actionArgs)

    if action == 'onDeckShows':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().onDeckShows()

    if action == 'onDeckMovies':
        from resources.lib.gui.movieMenus import Menus

        Menus().onDeckMovies()

    if action == 'cacheAssist':
        from resources.lib.modules import cacheAssist

        cacheAssist.CacheAssit(actionArgs)

    if action == 'tvGenres':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showGenres()

    if action == 'showGenresGet':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showGenreList(actionArgs, page)

    if action == 'movieGenres':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().movieGenres()

    if action == 'movieGenresGet':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().movieGenresList(actionArgs, page)

    if action == 'filePicker':
        from resources.lib.modules import smartPlay

        smartPlay.SmartPlay(actionArgs).torrent_file_picker()

    if action == 'shufflePlay':
        from resources.lib.modules import smartPlay

        try:
            smart = smartPlay.SmartPlay(actionArgs).shufflePlay()
        except:
            import traceback
            traceback.print_exc()
            pass

    if action == 'resetSilent':
        tools.setSetting('general.tempSilent', 'false')
        tools.showDialog.notification(tools.addonName + ": Silent scrape",
                                      tools.lang(32048),
                                      time=5000)

    if action == 'clearTorrentCache':
        from resources.lib.modules import database

        database.torrent_cache_clear()

    if action == 'openSettings':
        tools.execute('Addon.OpenSettings(%s)' % tools.addonInfo('id'))

    if action == 'myTraktLists':
        from resources.lib.indexers import trakt

        trakt.TraktAPI().myTraktLists(actionArgs)

    if action == 'traktList':
        from resources.lib.indexers import trakt

        trakt.TraktAPI().getListItems(actionArgs, page)

    if action == 'nonActiveAssistClear':
        from resources.lib.gui import debridServices

        debridServices.Menus().assist_non_active_clear()

    if action == 'debridServices':
        from resources.lib.gui import debridServices

        debridServices.Menus().home()

    if action == 'cacheAssistStatus':
        from resources.lib.gui import debridServices

        debridServices.Menus().get_assist_torrents()

    if action == 'premiumizeTransfers':
        from resources.lib.gui import debridServices

        debridServices.Menus().list_premiumize_transfers()

    if action == 'showsNextUp':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().myNextUp()

    if action == 'runMaintenance':
        from resources.lib.common import maintenance

        maintenance.run_maintenance()

    if action == 'providerTools':
        from resources.lib.gui import homeMenu

        homeMenu.Menus().providerMenu()

    if action == 'adjustProviders':
        from resources.lib.modules import customProviders

        customProviders.providers().adjust_providers(actionArgs)

    if action == 'adjustPackage':
        from resources.lib.modules import customProviders

        customProviders.providers().adjust_providers(actionArgs,
                                                     package_disable=True)

    if action == 'installProviders':
        from resources.lib.modules import customProviders

        customProviders.providers().install_package(actionArgs)

    if action == 'uninstallProviders':
        from resources.lib.modules import customProviders

        customProviders.providers().uninstall_package()

    if action == 'showsNew':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().newShows()

    if action == 'realdebridTransfers':
        from resources.lib.gui import debridServices

        debridServices.Menus().list_RD_transfers()

    if action == 'cleanInstall':
        from resources.lib.common import maintenance

        maintenance.wipe_install()

    if action == 'buildPlaylistWorkaround':

        from resources.lib.modules import smartPlay
        smartPlay.SmartPlay(actionArgs).resume_playback()

    if action == 'premiumizeCleanup':
        from resources.lib.common import maintenance

        maintenance.premiumize_transfer_cleanup()

    if action == 'test2':
        tools.log('Nope')

    if action == 'manualProviderUpdate':
        from resources.lib.modules import customProviders

        customProviders.providers().manual_update()

    if action == 'clearSearchHistory':
        from resources.lib.modules import database

        database.clearSearchHistory()
        tools.showDialog.ok(tools.addonName, 'Search History has been cleared')

    if action == 'externalProviderInstall':
        from resources.lib.modules import customProviders

        confirmation = tools.showDialog.yesno(tools.addonName,
                                              tools.lang(40117))
        if confirmation == 0:
            sys.exit()

        customProviders.providers().install_package(1, url=url)

    if action == 'externalProviderUninstall':
        from resources.lib.modules import customProviders

        confirmation = tools.showDialog.yesno(tools.addonName,
                                              tools.lang(40119) % url)
        if confirmation == 0:
            sys.exit()

        customProviders.providers().uninstall_package(package=url,
                                                      silent=False)

    if action == 'showsNetworks':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsNetworks()

    if action == 'showsNetworkShows':
        from resources.lib.gui import tvshowMenus

        tvshowMenus.Menus().showsNetworkShows(actionArgs, page)

    if action == 'movieYears':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().movieYears()

    if action == 'movieYearsMovies':
        from resources.lib.gui import movieMenus

        movieMenus.Menus().movieYearsMovies(actionArgs, page)

    if action == 'syncTraktActivities':
        from resources.lib.modules.trakt_sync.activities import TraktSyncDatabase
        TraktSyncDatabase().sync_activities()

    if action == 'traktSyncTools':
        from resources.lib.gui import homeMenu
        homeMenu.Menus().traktSyncTools()

    if action == 'flushTraktActivities':
        from resources.lib.modules import trakt_sync
        trakt_sync.TraktSyncDatabase().flush_activities()

    if action == 'flushTraktDBMeta':
        from resources.lib.modules import trakt_sync
        trakt_sync.TraktSyncDatabase().clear_all_meta()

    if action == 'myFiles':
        from resources.lib.gui import myFiles
        myFiles.Menus().home()

    if action == 'myFilesFolder':
        from resources.lib.gui import myFiles
        myFiles.Menus().myFilesFolder(actionArgs)

    if action == 'myFilesPlay':
        from resources.lib.gui import myFiles
        myFiles.Menus().myFilesPlay(actionArgs)

    if action == 'forceTraktSync':
        from resources.lib.modules import trakt_sync
        from resources.lib.modules.trakt_sync.activities import TraktSyncDatabase
        trakt_sync.TraktSyncDatabase().flush_activities()
        TraktSyncDatabase().sync_activities()

    if action == 'rebuildTraktDatabase':
        from resources.lib.modules.trakt_sync import TraktSyncDatabase
        TraktSyncDatabase().re_build_database()

    if action == 'myUpcomingEpisodes':
        from resources.lib.gui import tvshowMenus
        tvshowMenus.Menus().myUpcomingEpisodes()

    if action == 'showsByActor':
        from resources.lib.gui import tvshowMenus
        tvshowMenus.Menus().showsByActor(actionArgs)

    if action == 'movieByActor':
        from resources.lib.gui import movieMenus
        movieMenus.Menus().moviesByActor(actionArgs)

    if action == 'playFromRandomPoint':
        from resources.lib.modules import smartPlay
        smartPlay.SmartPlay(actionArgs).play_from_random_point()

    if action == 'refreshProviders':
        from resources.lib.modules.customProviders import providers
        providers().update_known_providers()

    if unit_tests:
        items = tools.xbmcplugin.DIRECTORY.items
        tools.xbmcplugin.DIRECTORY.items = []
        return items