Esempio n. 1
2
 def __get_token(self):
     pin = self.pin_edit_control.getText().strip()
     if pin:
         try:
             trakt_api = Trakt_API(use_https=use_https, timeout=trakt_timeout)
             result = trakt_api.get_token(pin=pin)
             _SALTS.set_setting('trakt_oauth_token', result['access_token'])
             _SALTS.set_setting('trakt_refresh_token', result['refresh_token'])
             return True
         except:
             return False
     return False
Esempio n. 2
0
 def __get_token(self):
     pin = self.pin_edit_control.getText().strip()
     if pin:
         try:
             trakt_api = Trakt_API(use_https=use_https, timeout=trakt_timeout)
             result = trakt_api.get_token(pin=pin)
             kodi.set_setting('trakt_oauth_token', result['access_token'])
             kodi.set_setting('trakt_refresh_token', result['refresh_token'])
             return True
         except:
             return False
     return False
Esempio n. 3
0
 def __get_token(self):
     pin = self.pin_edit_control.getText().strip()
     if pin:
         try:
             trakt_api = Trakt_API(use_https=use_https, timeout=trakt_timeout)
             result = trakt_api.get_token(pin=pin)
             kodi.set_setting('trakt_oauth_token', result['access_token'])
             kodi.set_setting('trakt_refresh_token', result['refresh_token'])
             profile = trakt_api.get_user_profile(cached=False)
             kodi.set_setting('trakt_user', '%s (%s)' % (profile['username'], profile['name']))
             return True
         except:
             return False
     return False
Esempio n. 4
0
def auth_trakt():
    start = time.time()
    use_https = kodi.get_setting('use_https') == 'true'
    trakt_timeout = int(kodi.get_setting('trakt_timeout'))
    trakt_api = Trakt_API(use_https=use_https, timeout=trakt_timeout)
    result = trakt_api.get_code()
    code, expires, interval = result['device_code'], result['expires_in'], result['interval']
    time_left = expires - int(time.time() - start)
    line1 = i18n('verification_url') % (result['verification_url'])
    line2 = i18n('prompt_code') % (result['user_code'])
    line3 = i18n('code_expires') % (time_left)
    with ProgressDialog(i18n('trakt_acct_auth'), line1=line1, line2=line2, line3=line3) as pd:
        pd.update(100)
        while time_left:
            for _ in range(INTERVALS):
                kodi.sleep(interval * 1000 / INTERVALS)
                if pd.is_canceled(): return

            try:
                result = trakt_api.get_device_token(code)
                break
            except urllib2.URLError as e:
                # authorization is pending; too fast
                if e.code in [400, 429]:
                    pass
                elif e.code == 418:
                    kodi.notify(msg=i18n('user_reject_auth'), duration=3000)
                    return
                elif e.code == 410:
                    break
                else:
                    raise
                
            time_left = expires - int(time.time() - start)
            progress = time_left * 100 / expires
            pd.update(progress, line3=i18n('code_expires') % (time_left))
        
    try:
        kodi.set_setting('trakt_oauth_token', result['access_token'])
        kodi.set_setting('trakt_refresh_token', result['refresh_token'])
        trakt_api = Trakt_API(result['access_token'], use_https=use_https, timeout=trakt_timeout)
        profile = trakt_api.get_user_profile(cached=False)
        kodi.set_setting('trakt_user', '%s (%s)' % (profile['username'], profile['name']))
        kodi.notify(msg=i18n('trakt_auth_complete'), duration=3000)
    except Exception as e:
        log_utils.log('Trakt Authorization Failed: %s' % (e), log_utils.LOGDEBUG)
Esempio n. 5
0
 def __get_token(self):
     pin = self.pin_edit_control.getText().strip()
     if pin:
         try:
             trakt_api = Trakt_API(use_https=use_https,
                                   timeout=trakt_timeout)
             result = trakt_api.get_token(pin=pin)
             kodi.set_setting('trakt_oauth_token',
                              result['access_token'])
             kodi.set_setting('trakt_refresh_token',
                              result['refresh_token'])
             profile = trakt_api.get_user_profile(cached=False)
             kodi.set_setting(
                 'trakt_user',
                 '%s (%s)' % (profile['username'], profile['name']))
             return True
         except:
             return False
     return False
Esempio n. 6
0
def auth_trakt():
    start = time.time()
    use_https = kodi.get_setting('use_https') == 'true'
    trakt_timeout = int(kodi.get_setting('trakt_timeout'))
    trakt_api = Trakt_API(use_https=use_https, timeout=trakt_timeout)
    result = trakt_api.get_code()
    code, expires, interval = result['device_code'], result[
        'expires_in'], result['interval']
    time_left = expires - int(time.time() - start)
    line1 = i18n('verification_url') % (result['verification_url'])
    line2 = i18n('prompt_code') % (result['user_code'])
    line3 = i18n('code_expires') % (time_left)
    with ProgressDialog(i18n('trakt_acct_auth'),
                        line1=line1,
                        line2=line2,
                        line3=line3) as pd:
        pd.update(100)
        while time_left:
            for _ in range(INTERVALS):
                kodi.sleep(interval * 1000 / INTERVALS)
                if pd.is_canceled(): return

            try:
                result = trakt_api.get_device_token(code)
                break
            except urllib2.URLError as e:
                # authorization is pending; too fast
                if e.code in [400, 429]:
                    pass
                elif e.code == 418:
                    kodi.notify(msg=i18n('user_reject_auth'), duration=3000)
                    return
                elif e.code == 410:
                    break
                else:
                    raise

            time_left = expires - int(time.time() - start)
            progress = time_left * 100 / expires
            pd.update(progress, line3=i18n('code_expires') % (time_left))

    try:
        kodi.set_setting('trakt_oauth_token', result['access_token'])
        kodi.set_setting('trakt_refresh_token', result['refresh_token'])
        trakt_api = Trakt_API(result['access_token'],
                              use_https=use_https,
                              timeout=trakt_timeout)
        profile = trakt_api.get_user_profile(cached=False)
        kodi.set_setting('trakt_user',
                         '%s (%s)' % (profile['username'], profile['name']))
        kodi.notify(msg=i18n('trakt_auth_complete'), duration=3000)
    except Exception as e:
        log_utils.log('Trakt Authorization Failed: %s' % (e),
                      log_utils.LOGDEBUG)
def make_list_dict():
    slug = kodi.get_setting('default_slug')
    token = kodi.get_setting('trakt_oauth_token')
    list_data = {}
    if token and slug:
        try:
            trakt_api = Trakt_API(token, kodi.get_setting('use_https') == 'true', timeout=int(kodi.get_setting('trakt_timeout')))
            if slug == WATCHLIST_SLUG:
                trakt_list = trakt_api.show_watchlist(SECTIONS.MOVIES)
            else:
                trakt_list = trakt_api.show_list(slug, SECTIONS.MOVIES)
        except (TransientTraktError, TraktAuthError) as e:
            logger.log(str(e), log_utils.LOGERROR)
            kodi.notify(msg=str(e), duration=5000)
            trakt_list = []
                
        for movie in trakt_list:
            key = movie['title'].upper()
            list_data[key] = list_data.get(key, set())
            if movie['year'] is not None:
                new_set = set([movie['year'] - 1, movie['year'], movie['year'] + 1])
                list_data[key].update(new_set)
    logger.log('List Dict: %s: %s' % (slug, list_data))
    return list_data
def make_list_dict():
    slug = kodi.get_setting('default_slug')
    token = kodi.get_setting('trakt_oauth_token')
    list_data = {}
    if token and slug:
        try:
            trakt_api = Trakt_API(token, kodi.get_setting('use_https') == 'true', timeout=int(kodi.get_setting('trakt_timeout')))
            if slug == WATCHLIST_SLUG:
                trakt_list = trakt_api.show_watchlist(SECTIONS.MOVIES)
            else:
                trakt_list = trakt_api.show_list(slug, SECTIONS.MOVIES)
        except (TransientTraktError, TraktAuthError) as e:
            log_utils.log(str(e), log_utils.LOGERROR)
            kodi.notify(msg=str(e), duration=5000)
            trakt_list = []
                
        for movie in trakt_list:
            key = movie['title'].upper()
            list_data[key] = list_data.get(key, set())
            if movie['year'] is not None:
                new_set = set([movie['year'] - 1, movie['year'], movie['year'] + 1])
                list_data[key].update(new_set)
    log_utils.log('List Dict: %s: %s' % (slug, list_data))
    return list_data
Esempio n. 9
0
ICON_PATH = os.path.join(kodi.get_path(), 'icon.png')
SORT_FIELDS = [
    (SORT_LIST[int(kodi.get_setting('sort1_field'))], SORT_SIGNS[kodi.get_setting('sort1_order')]),
    (SORT_LIST[int(kodi.get_setting('sort2_field'))], SORT_SIGNS[kodi.get_setting('sort2_order')]),
    (SORT_LIST[int(kodi.get_setting('sort3_field'))], SORT_SIGNS[kodi.get_setting('sort3_order')]),
    (SORT_LIST[int(kodi.get_setting('sort4_field'))], SORT_SIGNS[kodi.get_setting('sort4_order')]),
    (SORT_LIST[int(kodi.get_setting('sort5_field'))], SORT_SIGNS[kodi.get_setting('sort5_order')]),
    (SORT_LIST[int(kodi.get_setting('sort6_field'))], SORT_SIGNS[kodi.get_setting('sort6_order')])]

last_check = datetime.datetime.fromtimestamp(0)

TOKEN = kodi.get_setting('trakt_oauth_token')
use_https = kodi.get_setting('use_https') == 'true'
trakt_timeout = int(kodi.get_setting('trakt_timeout'))
list_size = int(kodi.get_setting('list_size'))
trakt_api = Trakt_API(TOKEN, use_https, list_size, trakt_timeout)
db_connection = DB_Connection()

THEME_LIST = ['Shine', 'Luna_Blue', 'Iconic', 'Simple', 'SALTy', 'SALTy (Blended)', 'SALTy (Blue)', 'SALTy (Frog)', 'SALTy (Green)',
              'SALTy (Macaw)', 'SALTier (Green)', 'SALTier (Orange)', 'SALTier (Red)', 'IGDB', 'Simply Elegant', 'IGDB Redux']
THEME = THEME_LIST[int(kodi.get_setting('theme'))]
if xbmc.getCondVisibility('System.HasAddon(script.salts.themepak)'):
    themepak_path = xbmcaddon.Addon('script.salts.themepak').getAddonInfo('path')
else:
    themepak_path = kodi.get_path()
THEME_PATH = os.path.join(themepak_path, 'art', 'themes', THEME)
PLACE_POSTER = os.path.join(kodi.get_path(), 'resources', 'place_poster.png')

def art(name):
    path = os.path.join(THEME_PATH, name)
    if not xbmcvfs.exists(path):
Esempio n. 10
0
if P_MODE == P_MODES.THREADS:
    import threading
    from Queue import Queue, Empty
elif P_MODE == P_MODES.PROCESSES:
    try:
        import multiprocessing
        from multiprocessing import Queue
        from Queue import Empty
    except ImportError:
        import threading
        from Queue import Queue, Empty
        P_MODE = P_MODES.THREADS
        builtin = 'XBMC.Notification(%s,Process Mode not supported on this platform falling back to Thread Mode, 7500, %s)'
        xbmc.executebuiltin(builtin % (ADDON.get_name(), ICON_PATH))

trakt_api = Trakt_API(username, password, token, use_https, list_size,
                      trakt_timeout)
db_connection = DB_Connection()

THEME_LIST = ['Shine', 'Luna_Blue', 'Iconic']
THEME = THEME_LIST[int(ADDON.get_setting('theme'))]
if xbmc.getCondVisibility('System.HasAddon(script.salts.themepak)'):
    themepak_path = xbmcaddon.Addon('script.salts.themepak').getAddonInfo(
        'path')
else:
    themepak_path = ADDON.get_path()
THEME_PATH = os.path.join(themepak_path, 'art', 'themes', THEME)


def art(name):
    return os.path.join(THEME_PATH, name)
Esempio n. 11
0
if P_MODE == P_MODES.THREADS:
    import threading
    from Queue import Queue, Empty
elif P_MODE == P_MODES.PROCESSES:
    try:
        import multiprocessing
        from multiprocessing import Queue
        from Queue import Empty
    except ImportError:
        import threading
        from Queue import Queue, Empty
        P_MODE = P_MODES.THREADS
        builtin = 'XBMC.Notification(%s,Process Mode not supported on this platform falling back to Thread Mode, 7500, %s)'
        xbmc.executebuiltin(builtin % (ADDON.get_name(), ICON_PATH))

trakt_api = Trakt_API(username, password, use_https, trakt_timeout)
db_connection = DB_Connection()

THEME_LIST = ['Shine', 'Luna_Blue', 'Iconic']
THEME = THEME_LIST[int(ADDON.get_setting('theme'))]
if xbmc.getCondVisibility('System.HasAddon(script.salts.themepak)'):
    themepak_path = xbmcaddon.Addon('script.salts.themepak').getAddonInfo(
        'path')
else:
    themepak_path = ADDON.get_path()
THEME_PATH = os.path.join(themepak_path, 'art', 'themes', THEME)


def art(name):
    return os.path.join(THEME_PATH, name)