Exemplo n.º 1
0
def retrieve_kodi_library(db_type, page_no, letter):
    from modules.utils import title_key, to_utf8
    from modules.nav_utils import paginate_list
    from settings import paginate, page_limit
    paginate = paginate()
    limit = page_limit()
    if db_type in ('movie', 'movies'):
        db_type = 'movies'
        JSON_req = '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", \
        "params": {"properties": ["title", "imdbnumber"]},"id": "1"}'

    elif db_type in ('tvshow', 'tvshows'):
        db_type = 'tvshows'
        JSON_req = '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTvShows", \
        "params": {"properties": ["title","imdbnumber","uniqueid"]}, "id": "1"}'

    r = xbmc.executeJSONRPC(JSON_req)
    r = to_utf8(json.loads(r)['result'][db_type])
    r = sorted(r, key=lambda k: title_key(k['title']))
    original_list = [{
        'title': i.get('title', None),
        'media_id': i.get('imdbnumber', None)
    } for i in r] if db_type == 'movies' else [{
        'title':
        i.get('title', None),
        'media_id':
        i['uniqueid']['tvdb'] if 'uniqueid' in i and 'tvdb' in i['uniqueid']
        else i['imdbnumber'] if i['imdbnumber'].startswith("tt") else None
    } for i in r]
    if paginate:
        final_list, total_pages = paginate_list(original_list, page_no, letter,
                                                limit)
    else:
        final_list, total_pages = original_list, 1
    return final_list, total_pages
Exemplo n.º 2
0
def retrieve_subscriptions(db_type, page_no, letter):
    from modules.nav_utils import paginate_list
    from modules.utils import title_key
    paginate = settings.paginate()
    limit = settings.page_limit()
    data = Subscriptions(db_type).get_subscriptions()
    original_list = sorted(data, key=lambda k: title_key(k['title']))
    if paginate:
        final_list, total_pages = paginate_list(original_list, page_no, letter,
                                                limit)
    else:
        final_list, total_pages = original_list, 1
    return final_list, total_pages
Exemplo n.º 3
0
def in_progress_tvshow(db_type, page_no, letter):
    from modules.utils import title_key
    from modules.nav_utils import paginate_list
    paginate = settings.paginate()
    limit = settings.page_limit()
    check_meta_database()
    if settings.watched_indicators() in (1, 2):
        from apis.trakt_api import trakt_indicators_tv
        items = trakt_indicators_tv()
        data = [(i[0], i[3]) for i in items if i[1] > len(i[2])]
    else:
        from modules.indicators_bookmarks import get_watched_status_tvshow, get_watched_info_tv

        def _process(item):
            meta = tvshow_meta('tmdb_id', item[0], meta_user_info)
            watched_status = get_watched_status_tvshow(
                watched_info, use_trakt, meta['tmdb_id'],
                meta.get('total_episodes'))
            if not watched_status[0] == 1: data.append(item)

        data = []
        threads = []
        settings.check_database(WATCHED_DB)
        dbcon = database.connect(WATCHED_DB)
        dbcur = dbcon.cursor()
        dbcur.execute(
            '''SELECT media_id, title, last_played FROM watched_status WHERE db_type=? ORDER BY rowid DESC''',
            ('episode', ))
        rows1 = dbcur.fetchall()
        in_progress_result = list(set([i for i in rows1]))
        watched_info, use_trakt = get_watched_info_tv()
        meta_user_info = retrieve_user_info()
        window.setProperty('fen_fanart_error', 'true')
        for item in in_progress_result:
            threads.append(Thread(target=_process, args=(item, )))
        [i.start() for i in threads]
        [i.join() for i in threads]
    data = sorted(data, key=lambda k: title_key(k[1]))
    original_list = [{'media_id': i[0]} for i in data]
    if paginate:
        final_list, total_pages = paginate_list(original_list, page_no, letter,
                                                limit)
    else:
        final_list, total_pages = original_list, 1
    return final_list, total_pages
Exemplo n.º 4
0
def retrieve_favourites(db_type, page_no, letter):
    from modules.nav_utils import paginate_list
    from modules.utils import title_key
    from modules.settings import paginate, page_limit
    paginate = paginate()
    limit = page_limit()
    data = Favourites().get_favourites(db_type)
    data = sorted(data, key=lambda k: title_key(k['title']))
    original_list = [{
        'media_id': i['tmdb_id'],
        'title': i['title']
    } for i in data]
    if paginate:
        final_list, total_pages = paginate_list(original_list, page_no, letter,
                                                limit)
    else:
        final_list, total_pages = original_list, 1
    return final_list, total_pages
Exemplo n.º 5
0
 def media_results(self, media_type, page_no, letter):
     from indexers.movies import Movies
     from indexers.tvshows import TVShows
     from modules.nav_utils import paginate_list, cached_page
     from modules.utils import title_key
     def _add_misc_dir(url_params, list_name='Next Page >>', info='Navigate to Next Page...', iconImage='item_next.png'):
         listitem = xbmcgui.ListItem(list_name, iconImage=os.path.join(icon_directory, iconImage))
         listitem.setArt({'fanart': __addon__.getAddonInfo('fanart')})
         listitem.setInfo('video', {'title': list_name, 'plot': info})
         if url_params['mode'] == 'build_navigate_to_page': listitem.addContextMenuItems([("[B]Switch Jump To Action[/B]","XBMC.RunPlugin(%s)" % build_url({'mode': 'toggle_jump_to'}))])
         xbmcplugin.addDirectoryItem(handle=__handle__, url=build_url(url_params), listitem=listitem, isFolder=True)
     not_widget = xbmc.getInfoLabel('Container.PluginName')
     cache_page = settings.cache_page()
     cache_page_string = 'people_search_%s_%s' % (media_type, self.actor_id)
     limit = 20
     if cache_page:
         if not 'new_page' in params:
             silent = False if not_widget else True
             retrieved_page = cached_page(cache_page_string, silent=silent)
             if retrieved_page: page_no = retrieved_page
     try:
         builder = Movies if media_type == 'movies' else TVShows
         function = TMDb.tmdb_movies_actor_roles if media_type == 'movies' else TMDb.tmdb_tv_actor_roles
         content = 'movies' if media_type == 'movies' else 'tvshows'
         key = 'title' if media_type == 'movies' else 'name'
         result = function(self.actor_id)
         data = sorted(result, key=lambda k: title_key(k[key]))
         original_list = [{'media_id': i['id'], 'title': i[key]} for i in data]
         paginated_list, total_pages = paginate_list(original_list, page_no, letter, limit)
         media_list = [i['media_id'] for i in paginated_list]
         if total_pages > 2 and not_widget: _add_misc_dir({'mode': 'build_navigate_to_page', 'db_type': 'Media', 'media_type': media_type, 'actor_id': self.actor_id, 'actor_name': self.actor_name, 'actor_image': self.actor_image, 'current_page': page_no, 'total_pages': total_pages, 'transfer_mode': 'people_search.media_results'}, 'Jump To...', 'Jump To a Certain Page/Letter...', 'item_jump.png')
         builder(media_list, action='people_search_%s' % media_type).worker()
         if total_pages > page_no: _add_misc_dir({'mode': 'people_search.media_results', 'media_type': media_type, 'actor_id': self.actor_id, 'actor_name': self.actor_name, 'actor_image': self.actor_image, 'new_page': str(page_no + 1), 'new_letter': letter})
         if cache_page: cached_page(cache_page_string, page_no=page_no)
         xbmcplugin.setContent(__handle__, content)
         xbmcplugin.endOfDirectory(__handle__)
         setView('view.%s' % content, content)
     except: notification('No Results', 3000)
Exemplo n.º 6
0
 def func(function):
     if nextep_settings['sort_key'] == 'name': return title_key(function)
     else: return function
Exemplo n.º 7
0
def build_next_episode_manager(params):
    def build_content(tmdb_id):
        try:
            cm = []
            listitem = make_listitem()
            set_property = listitem.setProperty
            cm_append = cm.append
            meta = tvshow_meta('tmdb_id', tmdb_id, meta_user_info)
            meta_get = meta.get
            total_aired_eps = meta_get('total_aired_eps')
            total_seasons = meta_get('total_seasons')
            title = meta_get('title')
            playcount, overlay, total_watched, total_unwatched = get_watched_status_tvshow(
                watched_info, tmdb_id, total_aired_eps)
            meta.update({'playcount': playcount, 'overlay': overlay})
            if tmdb_id in exclude_list:
                color, action, status, sort_value = 'red', 'unhide', excluded_str, 1
            else:
                color, action, status, sort_value = 'green', 'hide', included_str, 0
            display = '[COLOR=%s][%s][/COLOR] %s' % (color, status, title)
            extras_params = {
                'mode': 'extras_menu_choice',
                'tmdb_id': tmdb_id,
                'db_type': 'tvshow',
                'is_widget': 'False'
            }
            url_params = {
                'mode': 'hide_unhide_trakt_items',
                'action': action,
                'media_type': 'shows',
                'media_id': meta_get('imdb_id'),
                'section': 'progress_watched'
            }
            url = build_url(url_params)
            if show_all_episodes:
                if all_episodes == 1 and total_seasons > 1:
                    browse_params = {
                        'mode': 'build_season_list',
                        'tmdb_id': tmdb_id
                    }
                else:
                    browse_params = {
                        'mode': 'build_episode_list',
                        'tmdb_id': tmdb_id,
                        'season': 'all'
                    }
            else:
                browse_params = {
                    'mode': 'build_season_list',
                    'tmdb_id': tmdb_id
                }
            cm_append((extras_str, 'RunPlugin(%s)' % build_url(extras_params)))
            cm_append((browse_str,
                       'Container.Update(%s)' % build_url(browse_params)))
            listitem.setLabel(display)
            set_property('watchedepisodes', str(total_watched))
            set_property('unwatchedepisodes', str(total_unwatched))
            set_property('totalepisodes', str(total_aired_eps))
            set_property('totalseasons', str(total_seasons))
            listitem.addContextMenuItems(cm)
            listitem.setArt({
                'poster': meta_get('poster'),
                'fanart': meta_get('fanart'),
                'banner': meta_get('banner'),
                'clearart': meta_get('clearart'),
                'clearlogo': meta_get('clearlogo'),
                'landscape': meta_get('landscape')
            })
            listitem.setCast(meta['cast'])
            listitem.setInfo('video', remove_meta_keys(meta, dict_removals))
            append({
                'listitem': (url, listitem, False),
                'sort_value': sort_value,
                'sort_title': title
            })
        except:
            pass

    __handle__ = int(argv[1])
    list_items = []
    append = list_items.append
    meta_user_info, watched_indicators, watched_info, all_episodes, include_year_in_title, open_extras = get_tvshow_info(
    )
    ep_list = get_next_episodes(watched_info)
    tmdb_list = [i['tmdb_id'] for i in ep_list]
    try:
        exclude_list = trakt_get_hidden_items('progress_watched')
    except:
        exclude_list = []
    show_all_episodes = True if all_episodes in (1, 2) else False
    threads = list(make_thread_list(build_content, tmdb_list, Thread))
    [i.join() for i in threads]
    item_list = sorted(
        list_items,
        key=lambda k:
        (k['sort_value'], title_key(k['sort_title'], ignore_articles())),
        reverse=False)
    item_list = [i['listitem'] for i in item_list]
    kodi_utils.add_dir({'mode': 'nill'},
                       '[I][COLOR=grey2]%s[/COLOR][/I]' % heading.upper(),
                       __handle__,
                       iconImage='settings.png',
                       isFolder=False)
    kodi_utils.add_items(__handle__, item_list)
    kodi_utils.set_content(__handle__, 'tvshows')
    kodi_utils.end_directory(__handle__, cacheToDisc=False)
    kodi_utils.set_view_mode('view.main', 'tvshows')
    kodi_utils.focus_index(1)
Exemplo n.º 8
0
def get_watched_items(db_type, page_no, letter):
    from modules.nav_utils import paginate_list
    from modules.utils import title_key, to_utf8
    watched_indicators = settings.watched_indicators()
    paginate = settings.paginate()
    limit = settings.page_limit()
    if db_type == 'tvshow':
        if watched_indicators in (1, 2):
            from apis.trakt_api import trakt_indicators_tv
            data = trakt_indicators_tv()
            data = sorted(data, key=lambda tup: title_key(tup[3]))
            original_list = [{
                'media_id': i[0],
                'title': i[3]
            } for i in data if i[1] == len(i[2])]
        else:
            import tikimeta
            meta_user_info = tikimeta.retrieve_user_info()
            settings.check_database(WATCHED_DB)
            dbcon = database.connect(WATCHED_DB)
            dbcur = dbcon.cursor()
            dbcur.execute(
                "SELECT media_id, title FROM watched_status WHERE db_type = ?",
                ('episode', ))
            rows = dbcur.fetchall()
            dbcon.close()
            watched_list = list(set(to_utf8([(i[0], i[1]) for i in rows])))
            watched_info, use_trakt = get_watched_info_tv()
            data = []
            for item in watched_list:
                meta = tikimeta.tvshow_meta('tmdb_id', item[0], meta_user_info)
                watched = get_watched_status_tvshow(watched_info, use_trakt,
                                                    item[0],
                                                    meta.get('total_episodes'))
                if watched[0] == 1: data.append(item)
                else: pass
            data = sorted(data, key=lambda tup: title_key(tup[1]))
            original_list = [{'media_id': i[0], 'title': i[1]} for i in data]
    else:
        if watched_indicators in (1, 2):
            from apis.trakt_api import trakt_indicators_movies
            data = trakt_indicators_movies()
            data = sorted(data, key=lambda tup: title_key(tup[1]))
            original_list = [{'media_id': i[0], 'title': i[1]} for i in data]

        else:
            settings.check_database(WATCHED_DB)
            dbcon = database.connect(WATCHED_DB)
            dbcur = dbcon.cursor()
            dbcur.execute(
                "SELECT media_id, title FROM watched_status WHERE db_type = ?",
                (db_type, ))
            rows = dbcur.fetchall()
            dbcon.close()
            data = to_utf8([(i[0], i[1]) for i in rows])
            data = sorted(data, key=lambda tup: title_key(tup[1]))
            original_list = [{'media_id': i[0], 'title': i[1]} for i in data]
    if paginate:
        final_list, total_pages = paginate_list(original_list, page_no, letter,
                                                limit)
    else:
        final_list, total_pages = original_list, 1
    return final_list, total_pages
Exemplo n.º 9
0
			def func(function):
				if sort_key == 'fen_name': return title_key(function, ignore_articles)
				elif sort_key == 'fen_last_played': return jsondate_to_datetime(function, resformat)
				else: return function