Exemplo n.º 1
0
def build_in_progress_episode():
    from modules.indicators_bookmarks import get_watched_info_tv

    def process_eps(item):
        listitem = build_episode(
            {
                "season": int(item[1]),
                "episode": int(item[2]),
                "meta": tvshow_meta('tmdb_id', item[0], meta_user_info)
            }, watched_info, use_trakt, meta_user_info)['listitem']
        xbmcplugin.addDirectoryItem(__handle__,
                                    listitem[0],
                                    listitem[1],
                                    isFolder=listitem[2])

    check_meta_database()
    settings.check_database(WATCHED_DB)
    watched_info, use_trakt = get_watched_info_tv()
    meta_user_info = retrieve_user_info()
    window.clearProperty('fen_fanart_error')
    threads = []
    dbcon = database.connect(WATCHED_DB)
    dbcur = dbcon.cursor()
    dbcur.execute(
        '''SELECT media_id, season, episode FROM progress WHERE db_type=? ORDER BY rowid DESC''',
        ('episode', ))
    rows = dbcur.fetchall()
    for item in rows:
        threads.append(Thread(target=process_eps, args=(item, )))
    [i.start() for i in threads]
    [i.join() for i in threads]
    xbmcplugin.setContent(__handle__, 'episodes')
    xbmcplugin.endOfDirectory(__handle__)
    setView('view.episode_lists', 'episodes')
Exemplo n.º 2
0
 def __init__(self, _list=None, idtype=None, action=None):
     tikimeta.check_meta_database()
     clear_all_trakt_cache_data(confirm=False)
     sync_watched_trakt_to_fen()
     self.list = [] if not _list else _list
     self.items = []
     self.new_page = None
     self.total_pages = None
     self.id_type = 'tmdb_id' if not idtype else idtype
     self.action = action
     self.cache_page_string = self.action
Exemplo n.º 3
0
 def __init__(self,
              db_type=None,
              tmdb_id=None,
              action=None,
              orig_mode=None):
     tikimeta.check_meta_database()
     self.db_type = db_type
     self.tmdb_id = tmdb_id  #str
     self.action = action
     self.orig_mode = orig_mode
     self.meta_user_info = tikimeta.retrieve_user_info()
     if self.db_type:
         self.path = settings.movies_directory(
         ) if self.db_type == 'movie' else settings.tv_show_directory()
     self.add_release_date = settings.add_release_date()
     window.setProperty('fen_fanart_error', 'true')
Exemplo n.º 4
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.º 5
0
def nextep_playback_info(tmdb_id,
                         current_season,
                         current_episode,
                         from_library=None):
    def build_next_episode_play():
        ep_data = [
            i['episodes_data'] for i in seasons_data
            if i['season_number'] == season
        ][0]
        ep_data = [i for i in ep_data if i['airedEpisodeNumber'] == episode][0]
        airdate = ep_data['firstAired']
        d = airdate.split('-')
        episode_date = date(int(d[0]), int(d[1]), int(d[2]))
        if current_adjusted_date < episode_date: return {'pass': True}
        query = meta['title'] + ' S%.2dE%.2d' % (int(season), int(episode))
        display_name = '%s - %dx%.2d' % (meta['title'], int(season),
                                         int(episode))
        meta.update({
            'vid_type': 'episode',
            'rootname': display_name,
            "season": season,
            'ep_name': ep_data['episodeName'],
            "episode": episode,
            'premiered': airdate,
            'plot': ep_data['overview']
        })
        meta_json = json.dumps(meta)
        url_params = {
            'mode': 'play_media',
            'background': 'true',
            'vid_type': 'episode',
            'tmdb_id': meta['tmdb_id'],
            'query': query,
            'tvshowtitle': meta['rootname'],
            'season': season,
            'episode': episode,
            'meta': meta_json,
            'ep_name': ep_data['episodeName']
        }
        if from_library:
            url_params.update({'library': 'True', 'plot': ep_data['overview']})
        return build_url(url_params)

    check_meta_database()
    meta_user_info = retrieve_user_info()
    meta = tvshow_meta('tmdb_id', tmdb_id, meta_user_info)
    nextep_info = {'pass': True}
    try:
        current_adjusted_date = settings.adjusted_datetime()
        seasons_data = all_episodes_meta(tmdb_id, meta['tvdb_id'],
                                         meta['tvdb_summary']['airedSeasons'],
                                         meta['season_data'], meta_user_info)
        curr_season_data = [
            i for i in seasons_data if i['season_number'] == current_season
        ][0]
        season = current_season if current_episode < curr_season_data[
            'episode_count'] else current_season + 1
        episode = current_episode + 1 if current_episode < curr_season_data[
            'episode_count'] else 1
        nextep_info = {
            'season': season,
            'episode': episode,
            'url': build_next_episode_play()
        }
    except:
        pass
    return nextep_info
Exemplo n.º 6
0
def build_next_episode():
    from modules.indicators_bookmarks import get_watched_info_tv
    check_meta_database()
    clear_all_trakt_cache_data(confirm=False)
    sync_watched_trakt_to_fen()
    try:
        threads = []
        seen = set()
        ep_list = []
        nextep_settings = settings.nextep_content_settings()
        nextep_display_settings = settings.nextep_display_settings()
        watched_info, use_trakt = get_watched_info_tv()
        meta_user_info = retrieve_user_info()
        cache_to_disk = nextep_settings['cache_to_disk']
        nextep_display_settings['cache_to_disk'] = cache_to_disk
        window.setProperty('fen_fanart_error', 'true')
        if nextep_settings['include_unwatched']:
            for i in get_unwatched_next_episodes():
                ep_list.append(i)
        if settings.watched_indicators() in (1, 2):
            from apis.trakt_api import trakt_get_next_episodes
            ep_list += trakt_get_next_episodes()
        else:
            settings.check_database(WATCHED_DB)
            dbcon = database.connect(WATCHED_DB)
            dbcur = dbcon.cursor()
            dbcur.execute(
                '''SELECT media_id, season, episode, last_played FROM watched_status WHERE db_type=?''',
                ('episode', ))
            rows = dbcur.fetchall()
            rows = sorted(rows, key=lambda x: (x[0], x[1], x[2]), reverse=True)
            [
                ep_list.append({
                    "tmdb_id": a,
                    "season": int(b),
                    "episode": int(c),
                    "last_played": d
                }) for a, b, c, d in rows if not (a in seen or seen.add(a))
            ]
            ep_list = [
                x for x in ep_list
                if x['tmdb_id'] not in check_for_next_episode_excludes()
            ]
        ep_list = [i for i in ep_list if not i['tmdb_id'] == None]
        for item in ep_list:
            threads.append(
                Thread(target=process_eps,
                       args=(item, nextep_settings, nextep_display_settings,
                             watched_info, use_trakt, meta_user_info)))
        [i.start() for i in threads]
        [i.join() for i in threads]
        r = [i for i in result if i is not None]
        r = sort_next_eps(r, nextep_settings)
        item_list = [i['listitem'] for i in r]
        for i in item_list:
            xbmcplugin.addDirectoryItem(__handle__, i[0], i[1], i[2])
        xbmcplugin.setContent(__handle__, 'episodes')
        xbmcplugin.endOfDirectory(__handle__, cacheToDisc=cache_to_disk)
        setView('view.episode_lists', 'episodes')
    except:
        from modules.nav_utils import notification
        notification('Error getting Next Episode Info', time=3500)
        pass
Exemplo n.º 7
0
def build_next_episode_manager():
    from modules.nav_utils import add_dir
    from modules.indicators_bookmarks import get_watched_status_tvshow, get_watched_info_tv

    def _process(tmdb_id, action):
        try:
            meta = tvshow_meta('tmdb_id', tmdb_id, meta_user_info)
            title = meta['title']
            if action == 'manage_unwatched':
                action, display = 'remove', '[COLOR=%s][UNWATCHED][/COLOR] %s' % (
                    NEXT_EP_UNWATCHED, title)
                url_params = {
                    'mode': 'add_next_episode_unwatched',
                    'action': 'remove',
                    'tmdb_id': tmdb_id,
                    'title': title
                }
            elif action == 'trakt_and_fen':
                action, display = 'unhide' if tmdb_id in exclude_list else 'hide', '[COLOR=red][EXCLUDED][/COLOR] %s' % title if tmdb_id in exclude_list else '[COLOR=green][INCLUDED][/COLOR] %s' % title
                url_params = {
                    "mode": "hide_unhide_trakt_items",
                    "action": action,
                    "media_type": "shows",
                    "media_id": meta['imdb_id'],
                    "section": "progress_watched"
                }
            else:
                action, display = 'remove' if tmdb_id in exclude_list else 'add', '[COLOR=red][EXCLUDED][/COLOR] %s' % title if tmdb_id in exclude_list else '[COLOR=green][INCLUDED][/COLOR] %s' % title
                url_params = {
                    'mode': 'add_to_remove_from_next_episode_excludes',
                    'action': action,
                    'title': title,
                    'media_id': tmdb_id
                }
            sorted_list.append({
                'tmdb_id': tmdb_id,
                'display': display,
                'url_params': url_params,
                'meta': json.dumps(meta)
            })
        except:
            pass

    check_meta_database()
    clear_all_trakt_cache_data(confirm=False)
    sync_watched_trakt_to_fen()
    params = dict(parse_qsl(sys.argv[2].replace('?', '')))
    NEXT_EP_UNWATCHED = __addon__.getSetting('nextep.unwatched_colour')
    if not NEXT_EP_UNWATCHED or NEXT_EP_UNWATCHED == '':
        NEXT_EP_UNWATCHED = 'red'
    threads = []
    sorted_list = []
    action = params['action']
    if action == 'manage_unwatched':
        tmdb_list = [i['tmdb_id'] for i in get_unwatched_next_episodes()]
        heading = 'Select Show to remove from Fen Next Episode:'
    elif settings.watched_indicators() in (1, 2):
        from apis.trakt_api import trakt_get_next_episodes
        tmdb_list, exclude_list = trakt_get_next_episodes(include_hidden=True)
        heading = 'Select Show to Hide/Unhide from Trakt Progress:'
        action = 'trakt_and_fen'
    else:
        settings.check_database(WATCHED_DB)
        dbcon = database.connect(WATCHED_DB)
        dbcur = dbcon.cursor()
        dbcur.execute(
            '''SELECT media_id FROM watched_status WHERE db_type=? GROUP BY media_id''',
            ('episode', ))
        rows = dbcur.fetchall()
        tmdb_list = [row[0] for row in rows]
        exclude_list = check_for_next_episode_excludes()
        heading = 'Select Show to Include/Exclude in Fen Next Episode:'
    add_dir({'mode': 'nill'},
            '[I][COLOR=grey][B]INFO:[/B][/COLOR] [COLOR=grey2]%s[/COLOR][/I]' %
            heading,
            iconImage='settings.png')
    if not tmdb_list:
        from modules.nav_utils import notification
        return notification('No Shows Present', time=5000)
    meta_user_info = retrieve_user_info()
    window.setProperty('fen_fanart_error', 'true')
    for tmdb_id in tmdb_list:
        threads.append(Thread(target=_process, args=(tmdb_id, action)))
    [i.start() for i in threads]
    [i.join() for i in threads]
    sorted_items = sorted(sorted_list, key=lambda k: k['display'])
    watched_info, use_trakt = get_watched_info_tv()
    for i in sorted_items:
        try:
            cm = []
            meta = json.loads(i['meta'])
            playcount, overlay, total_watched, total_unwatched = get_watched_status_tvshow(
                watched_info, use_trakt, meta['tmdb_id'],
                meta.get('total_episodes'))
            meta.update({
                'playcount': playcount,
                'overlay': overlay,
                'total_watched': str(total_watched),
                'total_unwatched': str(total_unwatched)
            })
            url = build_url(i['url_params'])
            browse_url = build_url({
                'mode': 'build_season_list',
                'meta': i['meta']
            })
            cm.append(
                ("[B]Browse...[/B]", 'XBMC.Container.Update(%s)' % browse_url))
            listitem = xbmcgui.ListItem(i['display'])
            listitem.setProperty('watchedepisodes', str(total_watched))
            listitem.setProperty('unwatchedepisodes', str(total_unwatched))
            listitem.setProperty('totalepisodes', str(meta['total_episodes']))
            listitem.setProperty('totalseasons', str(meta['total_seasons']))
            listitem.addContextMenuItems(cm)
            listitem.setArt({
                'poster': meta['poster'],
                'fanart': meta['fanart'],
                'banner': meta['banner'],
                'clearart': meta['clearart'],
                'clearlogo': meta['clearlogo'],
                'landscape': meta['landscape']
            })
            listitem.setCast(meta['cast'])
            listitem.setInfo('video', remove_unwanted_info_keys(meta))
            xbmcplugin.addDirectoryItem(__handle__,
                                        url,
                                        listitem,
                                        isFolder=True)
        except:
            pass
    xbmcplugin.setContent(__handle__, 'tvshows')
    xbmcplugin.endOfDirectory(__handle__, cacheToDisc=False)
    setView('view.main', 'tvshows')