示例#1
0
class Script(object):
    def __init__(self):
        self.params = {}
        for arg in [try_decode(arg) for arg in sys.argv[1:]]:
            if '=' in arg:
                key, value = arg.split('=', 1)
                self.params[key] = value.strip('\'').strip(
                    '"') if value else True
            else:
                self.params[arg] = True
        self.params = reconfigure_legacy_params(**self.params)

    routing_table = {
        'authenticate_trakt': lambda **kwargs: TraktAPI(force=True),
        'revoke_trakt': lambda **kwargs: TraktAPI().logout(),
        'split_value': lambda **kwargs: split_value(**kwargs),
        'kodi_setting': lambda **kwargs: kodi_setting(**kwargs),
        'sync_trakt': lambda **kwargs: sync_trakt(**kwargs),
        'manage_artwork': lambda **kwargs: manage_artwork(**kwargs),
        'refresh_details': lambda **kwargs: refresh_details(**kwargs),
        'related_lists': lambda **kwargs: related_lists(**kwargs),
        'user_list': lambda **kwargs: user_list(**kwargs),
        'like_list': lambda **kwargs: like_list(**kwargs),
        'delete_list': lambda **kwargs: delete_list(**kwargs),
        'rename_list': lambda **kwargs: rename_list(**kwargs),
        'blur_image': lambda **kwargs: blur_image(**kwargs),
        'image_colors': lambda **kwargs: image_colors(**kwargs),
        'monitor_userlist': lambda **kwargs: monitor_userlist(),
        'update_players': lambda **kwargs: update_players(),
        'set_defaultplayer': lambda **kwargs: set_defaultplayer(**kwargs),
        'configure_players': lambda **kwargs: configure_players(**kwargs),
        'library_autoupdate': lambda **kwargs: library_update(**kwargs),
        # 'play_season': lambda **kwargs: play_season(**kwargs),
        'play_media': lambda **kwargs: play_media(**kwargs),
        'run_plugin': lambda **kwargs: run_plugin(**kwargs),
        'log_request': lambda **kwargs: log_request(**kwargs),
        'play': lambda **kwargs: play_external(**kwargs),
        'add_path': lambda **kwargs: WindowManager(**kwargs).router(),
        'add_query': lambda **kwargs: WindowManager(**kwargs).router(),
        'close_dialog': lambda **kwargs: WindowManager(**kwargs).router(),
        'reset_path': lambda **kwargs: WindowManager(**kwargs).router(),
        'call_id': lambda **kwargs: WindowManager(**kwargs).router(),
        'call_path': lambda **kwargs: WindowManager(**kwargs).router(),
        'call_update': lambda **kwargs: WindowManager(**kwargs).router()
    }

    def router(self):
        if not self.params:
            return
        if self.params.get('restart_service'):
            # Only do the import here because this function only for debugging purposes
            from resources.lib.monitor.service import restart_service_monitor
            return restart_service_monitor()

        routes_available = set(self.routing_table.keys())
        params_given = set(self.params.keys())
        route_taken = set.intersection(routes_available, params_given).pop()
        kodi_log(['lib.script.router.Script - route_taken\t', route_taken], 0)
        return self.routing_table[route_taken](**self.params)
 def __init__(self):
     self.handle = int(sys.argv[1])
     self.paramstring = try_decode(sys.argv[2][1:])
     self.params = parse_paramstring(self.paramstring)
     self.parent_params = self.params
     # self.container_path = u'{}?{}'.format(sys.argv[0], self.paramstring)
     self.update_listing = False
     self.plugin_category = ''
     self.container_content = ''
     self.container_update = None
     self.container_refresh = False
     self.item_type = None
     self.kodi_db = None
     self.kodi_db_tv = {}
     self.library = None
     self.tmdb_cache_only = True
     self.tmdb_api = TMDb()
     self.trakt_watchedindicators = ADDON.getSettingBool('trakt_watchedindicators')
     self.trakt_api = TraktAPI()
     self.is_widget = True if self.params.pop('widget', '').lower() == 'true' else False
     self.hide_watched = ADDON.getSettingBool('widgets_hidewatched') if self.is_widget else False
     self.flatten_seasons = ADDON.getSettingBool('flatten_seasons')
     self.ftv_forced_lookup = self.params.pop('fanarttv', '').lower()
     self.ftv_api = FanartTV(cache_only=self.ftv_is_cache_only())
     self.filter_key = self.params.pop('filter_key', None)
     self.filter_value = split_items(self.params.pop('filter_value', None))[0]
     self.exclude_key = self.params.pop('exclude_key', None)
     self.exclude_value = split_items(self.params.pop('exclude_value', None))[0]
     self.pagination = self.pagination_is_allowed()
     self.params = reconfigure_legacy_params(**self.params)
示例#3
0
def get_userlist(user_slug=None, list_slug=None, confirm=True, busy_spinner=True):
    with busy_dialog(is_enabled=busy_spinner):
        request = TraktAPI().get_response_json('users', user_slug, 'lists', list_slug, 'items')
    if not request:
        return
    if confirm:
        d_head = ADDON.getLocalizedString(32125)
        i_check_limits = check_overlimit(request)
        if i_check_limits:
            # List over limit so inform user that it is too large to add
            d_body = [
                ADDON.getLocalizedString(32168).format(list_slug, user_slug),
                ADDON.getLocalizedString(32170).format(i_check_limits.get('show'), i_check_limits.get('movie')),
                '',
                ADDON.getLocalizedString(32164).format(LIBRARY_ADD_LIMIT_TVSHOWS, LIBRARY_ADD_LIMIT_MOVIES)]
            xbmcgui.Dialog().ok(d_head, '\n'.join(d_body))
            return
        elif isinstance(confirm, bool) or len(request) > confirm:
            # List is within limits so ask for confirmation before adding it
            d_body = [
                ADDON.getLocalizedString(32168).format(list_slug, user_slug),
                ADDON.getLocalizedString(32171).format(len(request)) if len(request) > 20 else '',
                '',
                ADDON.getLocalizedString(32126)]
            if not xbmcgui.Dialog().yesno(d_head, '\n'.join(d_body)):
                return
    return request
示例#4
0
def log_request(**kwargs):
    with busy_dialog():
        kwargs['response'] = None
        if not kwargs.get('url'):
            kwargs['url'] = xbmcgui.Dialog().input('URL')
        if not kwargs['url']:
            return
        if kwargs.get('log_request').lower() == 'trakt':
            kwargs['response'] = TraktAPI().get_response_json(kwargs['url'])
        else:
            kwargs['response'] = TMDb().get_response_json(kwargs['url'])
        if not kwargs['response']:
            xbmcgui.Dialog().ok(kwargs['log_request'].capitalize(),
                                u'{}\nNo Response!'.format(kwargs['url']))
            return
        filename = validify_filename(u'{}_{}.json'.format(
            kwargs['log_request'], kwargs['url']))
        dumps_to_file(kwargs, 'log_request', filename)
        xbmcgui.Dialog().ok(
            kwargs['log_request'].capitalize(),
            u'[B]{}[/B]\n\n{}\n{}\n{}'.format(
                kwargs['url'],
                xbmc.translatePath('special://profile/addon_data/'),
                'plugin.video.themoviedb.helper/log_request', filename))
        xbmcgui.Dialog().textviewer(filename,
                                    dumps(kwargs['response'], indent=2))
示例#5
0
def delete_list(delete_list, **kwargs):
    if not xbmcgui.Dialog().yesno(
            ADDON.getLocalizedString(32358),
            ADDON.getLocalizedString(32357).format(delete_list)):
        return
    TraktAPI().delete_response('users/me/lists', delete_list)
    container_refresh()
示例#6
0
 def __init__(self, trakt_type, unique_id, season=None, episode=None, id_type=None):
     self.trakt_type = trakt_type
     self.unique_id = unique_id
     self.season = try_int(season) if season is not None else None
     self.episode = try_int(episode) if episode is not None else None
     self.id_type = id_type
     self.trakt_api = TraktAPI()
示例#7
0
def monitor_userlist():
    # Build list choices
    with busy_dialog():
        user_lists = []
        user_lists += TraktAPI().get_list_of_lists(
            'users/me/lists', authorize=True, next_page=False) or []
        user_lists += TraktAPI().get_list_of_lists(
            'users/likes/lists', authorize=True, next_page=False) or []
        saved_lists = _get_monitor_userlists()
        dialog_list = [i['label'] for i in user_lists]
        preselected = [
            x for x, i in enumerate(user_lists)
            if (i.get('params', {}).get('list_slug'),
                i.get('params', {}).get('user_slug')) in saved_lists
        ]

    # Ask user to choose lists
    indices = xbmcgui.Dialog().multiselect(ADDON.getLocalizedString(32312),
                                           dialog_list,
                                           preselect=preselected)
    if indices is None:
        return

    # Build the new settings and check that lists aren't over limit
    added_lists, added_users = [], []
    for x in indices:
        list_slug = user_lists[x].get('params', {}).get('list_slug')
        user_slug = user_lists[x].get('params', {}).get('user_slug')
        if get_userlist(user_slug, list_slug, confirm=50):
            added_lists.append(list_slug)
            added_users.append(user_slug)

    # Set the added lists to our settings
    if not added_lists or not added_users:
        return
    added_lists = ' | '.join(added_lists)
    added_users = ' | '.join(added_users)
    ADDON.setSettingString('monitor_userlist', added_lists)
    ADDON.setSettingString('monitor_userslug', added_users)

    # Update library?
    if xbmcgui.Dialog().yesno(xbmc.getLocalizedString(653),
                              ADDON.getLocalizedString(32132)):
        library_autoupdate(list_slugs=added_lists,
                           user_slugs=added_users,
                           busy_spinner=True)
示例#8
0
 def __init__(self):
     self.properties = set()
     self.index_properties = set()
     self.trakt_api = TraktAPI()
     self.tmdb_api = TMDb()
     self.fanarttv = FanartTV()
     self.omdb_api = OMDb() if ADDON.getSettingString('omdb_apikey') else None
     self.imdb_top250 = {}
     self.property_prefix = 'ListItem'
示例#9
0
def rename_list(rename_list, **kwargs):
    name = xbmcgui.Dialog().input(ADDON.getLocalizedString(32359))
    if not name:
        return
    TraktAPI().post_response('users/me/lists',
                             rename_list,
                             postdata={'name': name},
                             response_method='put')
    container_refresh()
示例#10
0
def get_external_ids(li, season=None, episode=None):
    trakt_api = TraktAPI()
    unique_id, trakt_type = None, None
    if li.infolabels.get('mediatype') == 'movie':
        unique_id = li.unique_ids.get('tmdb')
        trakt_type = 'movie'
    elif li.infolabels.get('mediatype') == 'tvshow':
        unique_id = li.unique_ids.get('tmdb')
        trakt_type = 'show'
    elif li.infolabels.get('mediatype') in ['season', 'episode']:
        unique_id = li.unique_ids.get('tvshow.tmdb')
        trakt_type = 'show'
    if not unique_id or not trakt_type:
        return
    trakt_slug = trakt_api.get_id(id_type='tmdb',
                                  unique_id=unique_id,
                                  trakt_type=trakt_type,
                                  output_type='slug')
    if not trakt_slug:
        return
    details = trakt_api.get_details(trakt_type, trakt_slug, extended=None)
    if not details:
        return
    if li.infolabels.get('mediatype') in ['movie', 'tvshow', 'season']:
        return {
            'unique_ids': {
                'tmdb': unique_id,
                'tvdb': details.get('ids', {}).get('tvdb'),
                'imdb': details.get('ids', {}).get('imdb'),
                'slug': details.get('ids', {}).get('slug'),
                'trakt': details.get('ids', {}).get('trakt')
            }
        }
    episode_details = trakt_api.get_details(trakt_type,
                                            trakt_slug,
                                            season=season
                                            or li.infolabels.get('season'),
                                            episode=episode
                                            or li.infolabels.get('episode'),
                                            extended=None)
    if episode_details:
        return {
            'unique_ids': {
                'tvshow.tmdb': unique_id,
                'tvshow.tvdb': details.get('ids', {}).get('tvdb'),
                'tvshow.imdb': details.get('ids', {}).get('imdb'),
                'tvshow.slug': details.get('ids', {}).get('slug'),
                'tvshow.trakt': details.get('ids', {}).get('trakt'),
                'tvdb': episode_details.get('ids', {}).get('tvdb'),
                'tmdb': episode_details.get('ids', {}).get('tmdb'),
                'imdb': episode_details.get('ids', {}).get('imdb'),
                'slug': episode_details.get('ids', {}).get('slug'),
                'trakt': episode_details.get('ids', {}).get('trakt')
            }
        }
示例#11
0
def like_list(like_list, user_slug=None, delete=False, **kwargs):
    user_slug = user_slug or 'me'
    if not user_slug or not like_list:
        return
    TraktAPI().like_userlist(user_slug=user_slug,
                             list_slug=like_list,
                             confirmation=True,
                             delete=delete)
    if not delete:
        return
    container_refresh()
def like_list(like_list, user_slug=None, delete=False, **kwargs):
    user_slug = user_slug or 'me'
    if not user_slug or not like_list:
        return
    TraktAPI().like_userlist(user_slug=user_slug,
                             list_slug=like_list,
                             confirmation=True,
                             delete=delete)
    if not delete:
        return
    xbmc.executebuiltin('Container.Refresh')
    xbmc.executebuiltin(
        'UpdateLibrary(video,/fake/path/to/force/refresh/on/home)')
示例#13
0
 def __init__(self, items, **kwargs):
     set_kwargattr(self, kwargs)
     self._trakt = TraktAPI()
     self.build_menu(items)