Пример #1
0
def get_in_progress_tvshows(dummy_arg, page_no, letter):
    def _process(item):
        tmdb_id = item['media_id']
        meta = metadata.tvshow_meta('tmdb_id', tmdb_id, meta_user_info)
        watched_status = get_watched_status_tvshow(watched_info, tmdb_id,
                                                   meta.get('total_aired_eps'))
        if watched_status[0] == 0: append(item)

    check_trakt_refresh()
    duplicates = set()
    data = []
    append = data.append
    watched_indicators = settings.watched_indicators()
    paginate = settings.paginate()
    limit = settings.page_limit()
    meta_user_info = metadata.retrieve_user_info()
    watched_info = get_watched_info_tv(watched_indicators)
    prelim_data = [{
        'media_id': i[0],
        'title': i[3]
    } for i in watched_info
                   if not (i[0] in duplicates or duplicates.add(i[0]))]
    threads = list(make_thread_list(_process, prelim_data, Thread))
    [i.join() for i in threads]
    original_list = sort_for_article(data, 'title', settings.ignore_articles())
    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
Пример #2
0
def retrieve_favourites(db_type, page_no, letter):
	paginate = settings.paginate()
	limit = settings.page_limit()
	data = Favourites({}).get_favourites(db_type)
	data = sort_for_article(data, 'title', settings.ignore_articles())
	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
Пример #3
0
def build_trakt_list(params):
	def _process_ids(item_position, item):
		item['media_id'] = trakt_api.get_trakt_movie_id(item['media_ids']) if item['media_type'] == 'movie' else trakt_api.get_trakt_tvshow_id(item['media_ids'])
		final_append((item_position, item))
	def _add_misc_dir(url_params, list_name=ls(32799), iconImage='item_next.png', isFolder=True):
		icon = kodi_utils.translate_path('special://home/addons/script.tikiart/resources/media/%s' % iconImage)
		listitem = make_listitem()
		listitem.setLabel(list_name)
		listitem.setArt({'icon': icon, 'poster': icon, 'thumb': icon, 'fanart': fanart, 'banner': icon})
		if url_params['mode'] == 'build_navigate_to_page':
			listitem.setProperty('SpecialSort', 'top')
			listitem.addContextMenuItems([(ls(32784),'RunPlugin(%s)' % build_url({'mode': 'toggle_jump_to'}))])
		else:
			listitem.setProperty('SpecialSort', 'bottom')
		kodi_utils.add_item(__handle__, build_url(url_params), listitem, isFolder)
	__handle__ = int(argv[1])
	is_widget = kodi_utils.external_browse()
	user, slug, list_type = params.get('user'), params.get('slug'), params.get('list_type')
	letter, page_no = params.get('new_letter', 'None'), int(params.get('new_page', '1'))
	original_list, final_list, final_listitems = [], [], []
	original_append, final_append = original_list.append, final_list.append
	result = trakt_api.get_trakt_list_contents(list_type, user, slug)
	for item in result:
		try:
			media_type = item['type']
			if not media_type in ('movie', 'show'): continue
			original_append({'media_type': media_type, 'title': item[media_type]['title'], 'media_ids': item[media_type]['ids']})
		except: pass
	if paginate():
		limit = page_limit()
		trakt_list, total_pages = paginate_list(original_list, page_no, letter, limit)
	else:
		trakt_list, total_pages = original_list, 1
	threads = list(make_thread_list_enumerate(_process_ids, trakt_list, Thread))
	[i.join() for i in threads]
	final_list.sort(key=lambda k: k[0])
	final_list = [i[1] for i in final_list]
	movie_list = [(i['media_id'], final_list.index(i), 'movie') for i in final_list if i['media_type'] == 'movie']
	tvshow_list = [(i['media_id'], final_list.index(i), 'tvshow') for i in final_list if i['media_type'] == 'show']
	content = 'movies' if len(movie_list) > len(tvshow_list) else 'tvshows'
	if total_pages > 2 and not is_widget:
		_add_misc_dir({'mode': 'build_navigate_to_page', 'db_type': 'Media', 'user': user, 'slug': slug, 'current_page': page_no, 'total_pages': total_pages,
						'transfer_mode': 'trakt.list.build_trakt_list'}, ls(32964), 'item_jump.png', False)
	if len(movie_list) > 0:
		movie_listitems = Movies({'list': [i[0] for i in movie_list]}).worker()
		final_listitems.extend([(i, x[1]) for i in movie_listitems for x in movie_list if [str(x[0]) == i[1].getUniqueID('tmdb') and x[2] == 'movie'][0]])
	if len(tvshow_list) > 0:
		tvshow_listitems = TVShows({'list': [i[0] for i in tvshow_list]}).worker()
		final_listitems.extend([(i, x[1]) for i in tvshow_listitems for x in tvshow_list if [str(x[0]) == i[1].getUniqueID('tmdb') and x[2] == 'tvshow'][0]])
	final_listitems.sort(key=lambda k: k[1])
	item_list = [i[0] for i in final_listitems]
	kodi_utils.add_items(__handle__, item_list)
	if total_pages > page_no: _add_misc_dir({'mode': 'trakt.list.build_trakt_list', 'user': user, 'slug': slug, 'new_page': str(page_no + 1), 'new_letter': letter})
	kodi_utils.set_content(__handle__, content)
	kodi_utils.end_directory(__handle__)
	if params.get('refreshed'): kodi_utils.sleep(1500)
	kodi_utils.set_view_mode('view.trakt_list', content)
Пример #4
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
Пример #5
0
def trakt_watchlist(db_type, page_no, letter):
    string_insert = 'movie' if db_type in ('movie', 'movies') else 'tvshow'
    original_list = trakt_fetch_collection_watchlist('watchlist', db_type)
    if settings.paginate():
        limit = settings.page_limit()
        final_list, total_pages = paginate_list(original_list, page_no, letter,
                                                limit)
    else:
        final_list, total_pages = original_list, 1
    for item in final_list:
        item['media_id'] = get_trakt_movie_id(
            item['media_ids']) if db_type == 'movies' else get_trakt_tvshow_id(
                item['media_ids'])
    return final_list, total_pages
Пример #6
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
Пример #7
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
Пример #8
0
def in_progress_movie(db_type, page_no, letter):
    from modules.nav_utils import paginate_list
    paginate = settings.paginate()
    limit = settings.page_limit()
    settings.check_database(WATCHED_DB)
    dbcon = database.connect(WATCHED_DB)
    dbcur = dbcon.cursor()
    dbcur.execute(
        '''SELECT media_id FROM progress WHERE db_type=? ORDER BY rowid DESC''',
        ('movie', ))
    rows = dbcur.fetchall()
    data = [i[0] for i in rows if not i[0] == '']
    original_list = [{'media_id': i} 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
Пример #9
0
def get_in_progress_movies(dummy_arg, page_no, letter):
    check_trakt_refresh()
    watched_indicators = settings.watched_indicators()
    paginate = settings.paginate()
    limit = settings.page_limit()
    if watched_indicators == 1: database_file = TRAKT_DB
    else: database_file = WATCHED_DB
    dbcon = database.connect(database_file)
    dbcur = dbcon.cursor()
    dbcur.execute(
        '''SELECT media_id FROM progress WHERE db_type=? ORDER BY rowid DESC''',
        ('movie', ))
    rows = dbcur.fetchall()
    data = reversed([i[0] for i in rows if not i[0] == ''])
    original_list = [{'media_id': i} 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
Пример #10
0
def get_watched_items(db_type, page_no, letter):
    paginate = settings.paginate()
    limit = settings.page_limit()
    watched_indicators = settings.watched_indicators()
    if db_type == 'tvshow':
        from threading import Thread
        from modules.utils import make_thread_list

        def _process(item):
            tmdb_id = item['media_id']
            meta = metadata.tvshow_meta('tmdb_id', tmdb_id, meta_user_info)
            watched_status = get_watched_status_tvshow(
                watched_info, tmdb_id, meta.get('total_aired_eps'))
            if watched_status[0] == 1: append(item)

        meta_user_info = metadata.retrieve_user_info()
        watched_info = get_watched_info_tv(watched_indicators)
        duplicates = set()
        data = []
        append = data.append
        prelim_data = [{
            'media_id': i[0],
            'title': i[3]
        } for i in watched_info
                       if not (i[0] in duplicates or duplicates.add(i[0]))]
        threads = list(make_thread_list(_process, prelim_data, Thread))
        [i.join() for i in threads]
        original_list = sort_for_article(data, 'title',
                                         settings.ignore_articles())
    else:
        watched_info = get_watched_info_movie(watched_indicators)
        data = [{'media_id': i[0], 'title': i[1]} for i in watched_info]
        original_list = sort_for_article(data, 'title',
                                         settings.ignore_articles())
    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
Пример #11
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