Ejemplo n.º 1
0
 def set_info(self, item_no, item):
     meta = tikimeta.tvshow_meta(self.id_type, item, self.meta_user_info)
     if not meta: return
     playcount, overlay, total_watched, total_unwatched = get_watched_status_tvshow(self.watched_info, self.use_trakt, meta['tmdb_id'], meta.get('total_episodes'))
     meta.update({'item_no': item_no, 'playcount': playcount, 'overlay': overlay,
                  'total_watched': str(total_watched), 'total_unwatched': str(total_unwatched)})
     if not 'rootname' in meta: meta['rootname'] = '{0} ({1})'.format(meta['title'], meta['year'])
     self.items.append(meta)
Ejemplo n.º 2
0
 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])
Ejemplo n.º 3
0
 def process_eps(item):
     results.append(
         build_episode(
             {
                 "season":
                 int(item['season']),
                 "episode":
                 int(item['episode']),
                 'order':
                 item['order'],
                 "meta":
                 tvshow_meta('tvdb_id', item['media_id'],
                             meta_user_info)
             }, watched_info, use_trakt, meta_user_info))
Ejemplo n.º 4
0
def make_fresh_tvshow_meta(id_type, media_id):
    def make_refresh_property():
        window.setProperty('fen_refresh_complete_%s' % media_id, 'true')
        return meta

    meta = tikimeta.tvshow_meta(id_type, media_id)
    if window.getProperty('fen_refresh_complete_%s' % media_id) == 'true':
        return meta
    if not meta.get('status', None) or meta.get('status') in ('Ended',
                                                              'Canceled',
                                                              'Pilot'):
        return make_refresh_property()
    if not meta.get('in_production', False): return make_refresh_property()
    if not meta.get('next_episode_to_air', None):
        return make_refresh_property()
    if meta.get('status') in ('Returning Series', 'In Production'):
        try:
            next_episode = meta['next_episode_to_air']
            next_airdate = next_episode.get('air_date', None)
            if not next_airdate: return make_refresh_property()
            d = next_airdate.split('-')
            next_episode_date = date(int(d[0]), int(d[1]), int(d[2]))
            current_adjusted_date = settings.adjusted_datetime()
            if current_adjusted_date > next_episode_date:
                from resources.lib.modules.nav_utils import refresh_cached_data
                if refresh_cached_data('tvshow',
                                       id_type,
                                       media_id,
                                       from_list=True):
                    meta = tikimeta.tvshow_meta(id_type, media_id)
                    return make_refresh_property()
            else:
                return make_refresh_property()
        except:
            make_refresh_property()
    else:
        return make_refresh_property()
Ejemplo n.º 5
0
def process_eps(item, nextep_settings, nextep_display_settings, watched_info,
                use_trakt, meta_user_info):
    try:
        meta = tvshow_meta('tmdb_id', item['tmdb_id'], meta_user_info)
        include_unaired = nextep_settings['include_unaired']
        season = item['season']
        episode = item['episode']
        unwatched = item.get('unwatched', False)
        seasons_data = all_episodes_meta(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'] == season
        ][0]
        season = season if episode < curr_season_data[
            'episode_count'] else season + 1
        episode = episode + 1 if episode < curr_season_data[
            'episode_count'] else 1
        if settings.watched_indicators() in (1, 2):
            resformat = "%Y-%m-%dT%H:%M:%S.%fZ"
            curr_last_played = item.get('last_played',
                                        '2000-01-01T00:00:00.000Z')
        else:
            resformat = "%Y-%m-%d %H:%M:%S"
            curr_last_played = item.get('last_played', '2000-01-01 00:00:00')
        datetime_object = jsondate_to_datetime(curr_last_played, resformat)
        result.append(
            build_episode(
                {
                    "season": season,
                    "episode": episode,
                    "meta": meta,
                    "curr_last_played_parsed": datetime_object,
                    "action": "next_episode",
                    "unwatched": unwatched,
                    "nextep_display_settings": nextep_display_settings,
                    'include_unaired': include_unaired
                }, watched_info, use_trakt, meta_user_info))
    except:
        pass
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
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
Ejemplo n.º 8
0
def build_episode_list():
    UNAIRED_EPISODE_COLOUR = settings.unaired_episode_colour()
    if not UNAIRED_EPISODE_COLOUR or UNAIRED_EPISODE_COLOUR == '':
        UNAIRED_EPISODE_COLOUR = 'red'
    params = dict(parse_qsl(sys.argv[2].replace('?', '')))
    try:
        meta = json.loads(window.getProperty('fen_media_meta'))
    except:
        meta = tikimeta.tvshow_meta('tmdb_id', params.get('tmdb_id'))
    thumb_path = 'http://image.tmdb.org/t/p/original%s'
    cast = []
    infoLabels = tikimeta.season_episodes_meta(meta['tmdb_id'],
                                               params.get('season'))
    watched_indicators = settings.watched_indicators()
    try:
        for item in infoLabels['credits']['cast']:
            cast_thumb = "http://image.tmdb.org/t/p/original%s" % item[
                "profile_path"] if 'profile_path' in item else ''
            cast.append({
                "name": item["name"],
                "role": item["character"],
                "thumbnail": cast_thumb
            })
    except:
        pass
    for i in infoLabels['episodes']:
        try:
            cm = []
            guest_stars = get_guest_stars(i['guest_stars'])
            first_aired = i['air_date'] if 'air_date' in i else None
            writer = ', '.join(
                [c['name'] for c in i['crew'] if c['job'] == 'Writer'])
            director = ', '.join(
                [c['name'] for c in i['crew'] if c['job'] == 'Director'])
            thumb = thumb_path % i['still_path'] if i.get(
                'still_path', None) != None else meta['fanart']
            playcount, overlay = get_watched_status('episode', meta['tmdb_id'],
                                                    i['season_number'],
                                                    i['episode_number'])
            query = meta['title'] + ' S%.2dE%.2d' % (int(
                i['season_number']), int(i['episode_number']))
            display_name = '%s - %dx%.2d' % (meta['title'],
                                             int(i['season_number']),
                                             int(i['episode_number']))
            meta.update({
                'vid_type': 'episode',
                'rootname': display_name,
                'season': i['season_number'],
                'episode': i['episode_number'],
                'premiered': first_aired,
                'ep_name': i['name'],
                'plot': i['overview']
            })
            meta_json = json.dumps(meta)
            url_params = {
                'mode': 'play_media',
                'vid_type': 'episode',
                'tmdb_id': meta['tmdb_id'],
                'query': query,
                'tvshowtitle': meta['rootname'],
                'season': i['season_number'],
                'episode': i['episode_number'],
                'meta': meta_json
            }
            url = build_url(url_params)
            try:
                d = first_aired.split('-')
                episode_date = date(int(d[0]), int(d[1]), int(d[2]))
            except:
                episode_date = date(2000, 01,
                                    01) if i['season_number'] == 0 else None
            current_adjusted_date = settings.adjusted_datetime()
            display = '%dx%.2d - %s' % (i['season_number'],
                                        i['episode_number'], i['name'])
            cad = True
            if not episode_date or current_adjusted_date < episode_date:
                cad = False
                display = '[I][COLOR={}]{}[/COLOR][/I]'.format(
                    UNAIRED_EPISODE_COLOUR, display)
            listitem = xbmcgui.ListItem(display)
            listitem.setProperty(
                "resumetime",
                get_resumetime('episode', meta['tmdb_id'], i['season_number'],
                               i['episode_number']))
            (state, action) = ('Watched',
                               'mark_as_watched') if playcount == 0 else (
                                   'Unwatched', 'mark_as_unwatched')
            (state2,
             action2) = ('Watched',
                         'mark_as_watched') if state == 'Unwatched' else (
                             'Unwatched', 'mark_as_unwatched')
            playback_menu_params = {
                'mode': 'playback_menu',
                'suggestion': query
            }
            watched_title = 'Trakt' if watched_indicators in (1, 2) else "Fen"
            watched_unwatched_params = {
                "mode": "mark_episode_as_watched_unwatched",
                "action": action,
                "media_id": meta['tmdb_id'],
                "imdb_id": meta["imdb_id"],
                "tvdb_id": meta["tvdb_id"],
                "season": i['season_number'],
                "episode": i['episode_number'],
                "title": meta['title'],
                "year": meta['year']
            }
            if cad:
                cm.append(("[B]Mark %s %s[/B]" % (state, watched_title),
                           'XBMC.RunPlugin(%s)' %
                           build_url(watched_unwatched_params)))
            if cad and listitem.getProperty("resumetime") != '0.000000':
                cm.append(("[B]Mark %s %s[/B]" % (state2, watched_title),
                           'XBMC.RunPlugin(%s)' %
                           build_url({
                               "mode": "mark_episode_as_watched_unwatched",
                               "action": action2,
                               "media_id": meta['tmdb_id'],
                               "imdb_id": meta["imdb_id"],
                               "season": i['season_number'],
                               "episode": i['episode_number'],
                               "title": meta['title'],
                               "year": meta['year']
                           })))
            cm.append(("[B]Options[/B]",
                       'XBMC.RunPlugin(%s)' % build_url(playback_menu_params)))
            cm.append(
                ("[B]Extended Info[/B]",
                 'RunScript(script.extendedinfo,info=extendedtvinfo,id=%s)' %
                 meta['tmdb_id']))
            listitem.addContextMenuItems(cm)
            listitem.setArt({
                'poster': meta['poster'],
                'fanart': meta['fanart'],
                'thumb': thumb,
                'banner': meta['banner'],
                'clearlogo': meta['clearlogo'],
                'landscape': meta['landscape']
            })
            listitem.setCast(cast + guest_stars)
            listitem.setInfo(
                'video', {
                    'mediatype': 'episode',
                    'trailer': str(meta.get('trailer')),
                    'title': i['name'],
                    'tvshowtitle': meta.get('title'),
                    'size': '0',
                    'plot': i['overview'],
                    'premiered': first_aired,
                    'genre': meta.get('genre'),
                    'season': i['season_number'],
                    'episode': i['episode_number'],
                    'duration': meta.get('episode_run_time'),
                    'rating': i['vote_average'],
                    'votes': i['vote_count'],
                    'writer': writer,
                    'director': director,
                    'playcount': playcount,
                    'overlay': overlay
                })
            if not not_widget:
                listitem.setProperty("fen_widget", 'true')
                listitem.setProperty("fen_playcount", str(playcount))
            xbmcplugin.addDirectoryItem(__handle__,
                                        url,
                                        listitem,
                                        isFolder=False)
        except:
Ejemplo n.º 9
0
def build_season_list():
    params = dict(parse_qsl(sys.argv[2].replace('?', '')))
    meta = json.loads(
        params.get('meta')) if 'meta' in params else tikimeta.tvshow_meta(
            'tmdb_id', params.get('tmdb_id'))
    show_specials = settings.show_specials()
    use_season_title = settings.use_season_title()
    season_data = [i for i in meta['season_data'] if i['season_number'] > 0
                   ] if not show_specials else meta['season_data']
    watched_indicators = settings.watched_indicators()
    for item in season_data:
        try:
            cm = []
            plot = item['overview'] if item['overview'] != '' else meta['plot']
            title = item['name'] if use_season_title else 'Season %s' % str(
                item['season_number'])
            season_poster = "http://image.tmdb.org/t/p/original%s" % item[
                'poster_path'] if item['poster_path'] is not None else meta[
                    'poster']
            aired_episodes = aired_episode_number_season(
                meta, item['season_number'])
            playcount, overlay, watched, unwatched = get_watched_status_season(
                meta['tmdb_id'], item['season_number'], aired_episodes)
            watched_title = 'Trakt' if watched_indicators in (1, 2) else "Fen"
            watched_params = {
                "mode": "mark_season_as_watched_unwatched",
                "action": 'mark_as_watched',
                "title": meta['title'],
                "year": meta['year'],
                "media_id": meta['tmdb_id'],
                "imdb_id": meta["imdb_id"],
                "tvdb_id": meta["tvdb_id"],
                "season": item['season_number']
            }
            unwatched_params = {
                "mode": "mark_season_as_watched_unwatched",
                "action": 'mark_as_unwatched',
                "title": meta['title'],
                "year": meta['year'],
                "media_id": meta['tmdb_id'],
                "imdb_id": meta["imdb_id"],
                "tvdb_id": meta["tvdb_id"],
                "season": item['season_number']
            }
            playback_menu_params = {'mode': 'playback_menu'}
            cm.append(("[B]Mark Watched %s[/B]" % watched_title,
                       'XBMC.RunPlugin(%s)' % build_url(watched_params)))
            cm.append(("[B]Mark Unwatched %s[/B]" % watched_title,
                       'XBMC.RunPlugin(%s)' % build_url(unwatched_params)))
            cm.append(("[B]Options[/B]",
                       'XBMC.RunPlugin(%s)' % build_url(playback_menu_params)))
            cm.append(
                ("[B]Extended Info[/B]",
                 'RunScript(script.extendedinfo,info=extendedtvinfo,id=%s)' %
                 meta['tmdb_id']))
            url_params = {
                'mode': 'build_episode_list',
                'tmdb_id': meta['tmdb_id'],
                'season': str(item['season_number']),
                'season_id': item['id']
            }
            url = build_url(url_params)
            listitem = xbmcgui.ListItem(title)
            listitem.setProperty('watchedepisodes', str(watched))
            listitem.setProperty('unwatchedepisodes', str(unwatched))
            listitem.setProperty('totalepisodes', str(item['episode_count']))
            listitem.addContextMenuItems(cm)
            listitem.setArt({
                'poster': season_poster,
                'fanart': meta['fanart'],
                'banner': meta['banner'],
                'clearlogo': meta['clearlogo'],
                'landscape': meta['landscape']
            })
            listitem.setCast(meta['cast'])
            listitem.setInfo(
                'video', {
                    'mediatype': 'tvshow',
                    'trailer': str(meta['trailer']),
                    'title': meta.get('title'),
                    'size': '0',
                    'duration': meta.get('episode_run_time'),
                    'plot': plot,
                    'rating': meta.get('rating'),
                    'premiered': meta.get('premiered'),
                    'studio': meta.get('studio'),
                    'year': meta.get('year'),
                    'genre': meta.get('genre'),
                    'code': meta.get('imdb_id'),
                    'tvshowtitle': meta.get('title'),
                    'imdbnumber': meta.get('imdb_id'),
                    'votes': meta.get('votes'),
                    'episode': str(item['episode_count']),
                    'playcount': playcount,
                    'overlay': overlay
                })
            xbmcplugin.addDirectoryItem(__handle__,
                                        url,
                                        listitem,
                                        isFolder=True)
        except:
            pass
    xbmcplugin.setContent(__handle__, 'seasons')
    xbmcplugin.endOfDirectory(__handle__)
    setView('view.seasons')
    window.setProperty('fen_media_meta', json.dumps(meta))
Ejemplo n.º 10
0
def set_bookmark_kodi_library(db_type,
                              tmdb_id,
                              curr_time,
                              season='',
                              episode=''):
    from tikimeta import movie_meta, tvshow_meta, retrieve_user_info
    meta_user_info = retrieve_user_info()
    window.setProperty('fen_fanart_error', 'true')
    try:
        info = movie_meta(
            'tmdb_id', tmdb_id,
            meta_user_info) if db_type == 'movie' else tvshow_meta(
                'tmdb_id', tmdb_id, meta_user_info)
        title = info['title']
        year = info['year']
        years = (str(year), str(int(year) + 1), str(int(year) - 1))
        if db_type == 'movie':
            r = xbmc.executeJSONRPC(
                '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties": ["title"]}, "id": 1}'
                % years)
        else:
            r = xbmc.executeJSONRPC(
                '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties": ["title"]}, "id": 1}'
                % years)
        r = to_utf8(r)
        r = json.loads(
            r)['result']['movies'] if db_type == 'movie' else json.loads(
                r)['result']['tvshows']
        if db_type == 'movie':
            r = [
                i for i in r
                if clean_file_name(title).lower() in clean_file_name(
                    to_utf8(i['title'])).lower()
            ]
        else:
            r = [
                i for i in r if clean_file_name(title).lower() in (
                    clean_file_name(to_utf8(i['title'])).lower(
                    ) if not ' (' in to_utf8(i['title']) else clean_file_name(
                        to_utf8(i['title'])).lower().split(' (')[0])
            ]
        if db_type == 'episode':
            r = xbmc.executeJSONRPC(
                '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "season", "operator": "is", "value": "%s"}, {"field": "episode", "operator": "is", "value": "%s"}]}, "properties": ["file"], "tvshowid": %s }, "id": 1}'
                % (str(season), str(episode), str(r['tvshowid'])))
            r = to_utf8(r)
            r = json.loads(r)['result']['episodes'][0]
        (method, id_name,
         library_id) = ('SetMovieDetails', 'movieid',
                        r['movieid']) if db_type == 'movie' else (
                            'SetEpisodeDetails', 'episodeid', r['episodeid'])
        query = {
            "jsonrpc": "2.0",
            "id": "setResumePoint",
            "method": "VideoLibrary." + method,
            "params": {
                id_name: library_id,
                "resume": {
                    "position": curr_time,
                }
            }
        }
        xbmc.executeJSONRPC(json.dumps(query))
    except:
        pass
Ejemplo n.º 11
0
def mark_tv_show_as_watched_unwatched():
    from modules.next_episode import add_next_episode_unwatched
    params = dict(parse_qsl(sys.argv[2].replace('?', '')))
    action = 'mark_as_watched' if params.get(
        'action') == 'mark_as_watched' else 'mark_as_unwatched'
    media_id = params.get('media_id')
    tvdb_id = int(params.get('tvdb_id', '0'))
    imdb_id = params.get('imdb_id')
    watched_indicators = settings.watched_indicators()
    if watched_indicators in (1, 2):
        from apis.trakt_api import trakt_watched_unwatched
        trakt_watched_unwatched(action, 'shows', imdb_id, tvdb_id)
        clear_trakt_watched_data('tvshow')
        clear_trakt_collection_watchlist_data('watchlist', 'tvshow')
    if watched_indicators in (0, 1):
        import tikimeta
        bg_dialog = xbmcgui.DialogProgressBG()
        bg_dialog.create('Please Wait', '')
        title = params.get('title', '')
        year = params.get('year', '')
        try:
            meta_user_info = json.loads(params.get('meta_user_info', ))
        except:
            meta_user_info = tikimeta.retrieve_user_info()
        se_list = []
        count = 1
        meta = tikimeta.tvshow_meta('tmdb_id', media_id, meta_user_info)
        season_data = tikimeta.all_episodes_meta(
            media_id, tvdb_id, meta['tvdb_summary']['airedSeasons'],
            meta['season_data'], meta_user_info)
        total = sum([
            i['episode_count'] for i in season_data if i['season_number'] > 0
        ])
        for item in season_data:
            season_number = item['season_number']
            if season_number <= 0: continue
            ep_data = tikimeta.season_episodes_meta(
                media_id, tvdb_id, season_number,
                meta['tvdb_summary']['airedSeasons'], meta['season_data'],
                meta_user_info)
            for ep in ep_data:
                season_number = ep['season']
                ep_number = ep['episode']
                season_ep = '%.2d<>%.2d' % (int(season_number), int(ep_number))
                display = 'Updating - S%.2dE%.2d' % (int(season_number),
                                                     int(ep_number))
                bg_dialog.update(int(float(count) / float(total) * 100),
                                 'Please Wait', '%s' % display)
                count += 1
                try:
                    first_aired = ep['premiered']
                    d = first_aired.split('-')
                    episode_date = date(int(d[0]), int(d[1]), int(d[2]))
                except:
                    episode_date = date(2100, 10, 24)
                if not settings.adjusted_datetime() > episode_date: continue
                mark_as_watched_unwatched('episode', media_id, action,
                                          season_number, ep_number, title)
                se_list.append(season_ep)
        bg_dialog.close()
    if action == 'mark_as_watched':
        add_next_episode_unwatched('remove', media_id, silent=True)
    if settings.sync_kodi_library_watchstatus():
        from modules.kodi_library import get_library_video, batch_mark_episodes_as_watched_unwatched_kodi_library
        in_library = get_library_video('tvshow', title, year)
        if not in_library:
            refresh_container()
            return
        if not in_library: return
        from modules.nav_utils import notification
        notification('Browse back to Kodi Home Screen!!', time=7000)
        xbmc.sleep(8500)
        ep_dict = {
            'action': action,
            'tvshowid': in_library['tvshowid'],
            'season_ep_list': se_list
        }
        if batch_mark_episodes_as_watched_unwatched_kodi_library(
                in_library, ep_dict):
            notification('Kodi Library Sync Complete', time=5000)
    refresh_container()
Ejemplo n.º 12
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
Ejemplo n.º 13
0
def build_episode_list():
    def _build(item):
        try:
            cm = []
            season = item['season']
            episode = item['episode']
            ep_name = item['title']
            premiered = item['premiered']
            playcount, overlay = get_watched_status(watched_info, use_trakt, 'episode', tmdb_id, season, episode)
            resumetime = get_resumetime('episode', tmdb_id, season, episode)
            query = title + ' S%.2dE%.2d' % (int(season), int(episode))
            display_name = '%s - %dx%.2d' % (title, season, episode)
            thumb = item['thumb'] if 'episodes' in item['thumb'] else fanart
            meta.update({'vid_type': 'episode', 'rootname': display_name, 'season': season,
                        'episode': episode, 'premiered': premiered, 'ep_name': ep_name,
                        'plot': item['plot']})
            item.update({'trailer': trailer, 'tvshowtitle': title,
                        'genre': genre, 'duration': duration, 'mpaa': mpaa,
                        'studio': studio, 'playcount': playcount, 'overlay': overlay})
            meta_json = json.dumps(meta)
            url_params = {'mode': 'play_media', 'vid_type': 'episode', 'tmdb_id': tmdb_id,
                        'query': query, 'tvshowtitle': meta['rootname'], 'season': season,
                        'episode': episode, 'meta': meta_json}
            url = build_url(url_params)
            try:
                d = premiered.split('-')
                episode_date = date(int(d[0]), int(d[1]), int(d[2]))
            except: episode_date = date(2000,1,1) if season == 0 else None
            unaired = False
            display = ep_name
            if not episode_date or current_adjusted_date < episode_date:
                unaired = True
                display = '[I][COLOR %s]%s[/COLOR][/I]' % (UNAIRED_EPISODE_COLOUR, ep_name)
                item['title'] = display
            item['sortseason'] = season
            item['sortepisode'] = episode
            (state, action) = ('Watched', 'mark_as_watched') if playcount == 0 else ('Unwatched', 'mark_as_unwatched')
            playback_menu_params = {'mode': 'playback_menu', 'suggestion': query, 'play_params': json.dumps(url_params)}
            if not unaired:
                watched_unwatched_params = {"mode": "mark_episode_as_watched_unwatched", "action": action, "media_id": tmdb_id, "imdb_id": imdb_id, "tvdb_id": tvdb_id, "season": season, "episode": episode,  "title": title, "year": year}
                cm.append(("[B]Mark %s %s[/B]" % (state, watched_title),'RunPlugin(%s)' % build_url(watched_unwatched_params)))
            cm.append(("[B]Options[/B]",'RunPlugin(%s)' % build_url(playback_menu_params)))
            if not unaired and resumetime != '0': cm.append(("[B]Clear Progress[/B]", 'RunPlugin(%s)' % build_url({"mode": "watched_unwatched_erase_bookmark", "db_type": "episode", "media_id": tmdb_id, "season": season, "episode": episode, "refresh": "true"})))
            cm.append(("[B]Extended Info[/B]", 'RunScript(script.extendedinfo,info=extendedtvinfo,id=%s)' % tmdb_id))
            listitem = xbmcgui.ListItem()
            listitem.setLabel(display)
            listitem.setProperty("resumetime", resumetime)
            listitem.addContextMenuItems(cm)
            listitem.setArt({'poster': show_poster, 'fanart': fanart, 'thumb': thumb, 'banner': banner, 'clearart': clearart, 'clearlogo': clearlogo, 'landscape': landscape})
            listitem.setCast(cast)
            listitem.setUniqueIDs({'imdb': str(imdb_id), 'tmdb': str(tmdb_id), 'tvdb': str(tvdb_id)})
            listitem.setInfo('video', remove_unwanted_info_keys(item))
            if is_widget:
                try:
                    listitem.setProperties({'fen_widget': 'true', 'fen_playcount': str(playcount), 'fen_playback_menu_params': json.dumps(playback_menu_params)})
                except:
                    listitem.setProperty("fen_widget", 'true')
                    listitem.setProperty("fen_playcount", str(playcount))
                    listitem.setProperty("fen_playback_menu_params", json.dumps(playback_menu_params))
            if use_threading: item_list.append((url, listitem, False))
            else: xbmcplugin.addDirectoryItem(__handle__, url, listitem, isFolder=False)
        except: pass
    UNAIRED_EPISODE_COLOUR = settings.unaired_episode_colour()
    if not UNAIRED_EPISODE_COLOUR or UNAIRED_EPISODE_COLOUR == '': UNAIRED_EPISODE_COLOUR = 'red'
    params = dict(parse_qsl(sys.argv[2].replace('?','')))
    meta_user_info = tikimeta.retrieve_user_info()
    all_episodes = True if params.get('season') == 'all' else False
    if all_episodes:
        if 'meta' in params:
            meta = json.loads(params.get('meta'))
        else:
            window.clearProperty('fen_fanart_error')
            meta = tikimeta.tvshow_meta('tmdb_id', params.get('tmdb_id'), meta_user_info)
    else:
        try:
            meta = json.loads(window.getProperty('fen_media_meta'))
        except:
            window.clearProperty('fen_fanart_error')
            meta = tikimeta.tvshow_meta('tmdb_id', params.get('tmdb_id'), meta_user_info)
    tmdb_id = meta['tmdb_id']
    tvdb_id = meta['tvdb_id']
    imdb_id = meta['imdb_id']
    title = meta['title']
    year = meta['year']
    rootname = meta['rootname']
    show_poster = meta['poster']
    fanart = meta['fanart']
    banner = meta['banner']
    clearlogo = meta['clearlogo']
    clearart = meta['clearart']
    landscape = meta['landscape']
    cast = meta['cast']
    mpaa = meta['mpaa']
    duration = meta.get('duration')
    trailer = str(meta['trailer'])
    genre = meta.get('genre')
    studio = meta.get('studio')
    watched_indicators = settings.watched_indicators()
    current_adjusted_date = settings.adjusted_datetime()
    watched_title = 'Trakt' if watched_indicators in (1, 2) else "Fen"
    episodes_data = tikimeta.season_episodes_meta(tmdb_id, tvdb_id, params.get('season'), meta['tvdb_summary']['airedSeasons'], meta['season_data'], meta_user_info, all_episodes)
    if all_episodes:
        if not settings.show_specials(): episodes_data = [i for i in episodes_data if not i['season'] == 0]
    episodes_data = sorted(episodes_data, key=lambda i: i['episode'])
    watched_info, use_trakt = get_watched_info_tv()
    use_threading = settings.thread_main_menus()
    if use_threading:
        item_list = []
        threads = []
        for item in episodes_data: threads.append(Thread(target=_build, args=(item,)))
        [i.start() for i in threads]
        [i.join() for i in threads]
        xbmcplugin.addDirectoryItems(__handle__, item_list)
    else:
        for item in episodes_data: _build(item)
    xbmcplugin.setContent(__handle__, 'episodes')
    xbmcplugin.addSortMethod(__handle__, xbmcplugin.SORT_METHOD_EPISODE)
    xbmcplugin.endOfDirectory(__handle__)
    setView('view.episodes', 'episodes')
Ejemplo n.º 14
0
def build_season_list():
    def _build(item, item_position=None):
        try:
            cm = []
            overview = item['overview']
            name = item['name']
            poster_path = item['poster_path']
            season_number = item['season_number']
            episode_count = item['episode_count']
            plot = overview if overview != '' else show_plot
            title = name if use_season_title and name != '' else 'Season %s' % str(season_number)
            season_poster = poster_path if poster_path is not None else show_poster
            playcount, overlay, watched, unwatched = get_watched_status_season(watched_info, use_trakt, tmdb_id, season_number, episode_count)
            watched_params = {"mode": "mark_season_as_watched_unwatched", "action": 'mark_as_watched', "title": show_title, "year": show_year, "media_id": tmdb_id, "imdb_id": imdb_id, "tvdb_id": tvdb_id, "season": season_number, "meta_user_info": meta_user_info}
            unwatched_params = {"mode": "mark_season_as_watched_unwatched", "action": 'mark_as_unwatched', "title": show_title, "year": show_year, "media_id": tmdb_id, "imdb_id": imdb_id, "tvdb_id": tvdb_id, "season": season_number, "meta_user_info": meta_user_info}
            playback_menu_params = {'mode': 'playback_menu'}
            cm.append(("[B]Mark Watched %s[/B]" % watched_title,'XBMC.RunPlugin(%s)' % build_url(watched_params)))
            cm.append(("[B]Mark Unwatched %s[/B]" % watched_title,'XBMC.RunPlugin(%s)' % build_url(unwatched_params)))
            cm.append(("[B]Options[/B]",'XBMC.RunPlugin(%s)' % build_url(playback_menu_params)))
            cm.append(("[B]Extended Info[/B]", 'RunScript(script.extendedinfo,info=extendedtvinfo,id=%s)' % tmdb_id))
            url_params = {'mode': 'build_episode_list', 'tmdb_id': tmdb_id, 'season': season_number}
            url = build_url(url_params)
            listitem = xbmcgui.ListItem()
            listitem.setLabel(title)
            try:
                listitem.setProperties({'watchedepisodes': str(watched), 'unwatchedepisodes': str(unwatched), 'totalepisodes': str(episode_count)})
            except:
                listitem.setProperty('watchedepisodes', str(watched))
                listitem.setProperty('unwatchedepisodes', str(unwatched))
                listitem.setProperty('totalepisodes', str(episode_count))
            listitem.addContextMenuItems(cm)
            listitem.setArt({'poster': season_poster, 'fanart': fanart, 'banner': banner, 'clearart': clearart, 'clearlogo': clearlogo, 'landscape': landscape})
            listitem.setCast(cast)
            listitem.setUniqueIDs({'imdb': str(imdb_id), 'tmdb': str(tmdb_id), 'tvdb': str(tvdb_id)})
            listitem.setInfo(
                'video', {'mediatype': 'tvshow', 'trailer': trailer,
                    'title': show_title, 'size': '0', 'duration': episode_run_time, 'plot': plot,
                    'rating': rating, 'premiered': premiered, 'studio': studio,
                    'year': show_year,'genre': genre, 'mpaa': mpaa,
                    'tvshowtitle': show_title, 'imdbnumber': imdb_id,'votes': votes,
                    'episode': str(episode_count),'playcount': playcount, 'overlay': overlay})
            if use_threading: item_list.append({'list_item': (url, listitem, True), 'item_position': item_position})
            else: xbmcplugin.addDirectoryItem(__handle__, url, listitem, isFolder=True)
        except: pass
    params = dict(parse_qsl(sys.argv[2].replace('?','')))
    meta_user_info = tikimeta.retrieve_user_info()
    if 'meta' in params:
        meta = json.loads(params.get('meta'))
    else:
        window.clearProperty('fen_fanart_error')
        meta = tikimeta.tvshow_meta('tmdb_id', params.get('tmdb_id'), meta_user_info)
    season_data = tikimeta.all_episodes_meta(meta['tmdb_id'], meta['tvdb_id'], meta['tvdb_summary']['airedSeasons'], meta['season_data'], meta_user_info)
    if not season_data: return
    meta_user_info = json.dumps(meta_user_info)
    tmdb_id = meta['tmdb_id']
    tvdb_id = meta['tvdb_id']
    imdb_id = meta['imdb_id']
    show_title = meta['title']
    show_year = meta['year']
    show_poster = meta['poster']
    show_plot = meta['plot']
    fanart = meta['fanart']
    banner = meta['banner']
    clearlogo = meta['clearlogo']
    clearart = meta['clearart']
    landscape = meta['landscape']
    cast = meta['cast']
    mpaa = meta['mpaa']
    trailer = str(meta['trailer'])
    episode_run_time = meta.get('episode_run_time')
    rating = meta.get('rating')
    premiered = meta.get('premiered')
    studio = meta.get('studio')
    genre = meta.get('genre')
    votes = meta.get('votes')
    if not settings.show_specials(): season_data = [i for i in season_data if not i['season_number'] == 0]
    season_data = sorted(season_data, key=lambda i: i['season_number'])
    use_season_title = settings.use_season_title()
    watched_indicators = settings.watched_indicators()
    watched_title = 'Trakt' if watched_indicators in (1, 2) else "Fen"
    use_threading = settings.thread_main_menus()
    watched_info, use_trakt = get_watched_info_tv()
    if use_threading:
        item_list = []
        threads = []
        for item_position, item in enumerate(season_data): threads.append(Thread(target=_build, args=(item, item_position)))
        [i.start() for i in threads]
        [i.join() for i in threads]
        item_list.sort(key=lambda k: k['item_position'])
        xbmcplugin.addDirectoryItems(__handle__, [i['list_item'] for i in item_list])
    else:
        for item in season_data: _build(item)
    xbmcplugin.setContent(__handle__, 'seasons')
    xbmcplugin.endOfDirectory(__handle__)
    setView('view.seasons', 'seasons')
    window.setProperty('fen_media_meta', json.dumps(meta))
Ejemplo n.º 15
0
 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)
Ejemplo n.º 16
0
 def playback_prep(self, vid_type, tmdb_id, query, tvshowtitle=None, season=None, episode=None, ep_name=None, plot=None, meta=None, from_library=False, background='false'):
     self.background = True if background == 'true' else False
     self.from_library = from_library
     self.widget = False if 'plugin' in xbmc.getInfoLabel('Container.PluginName') else True
     self.action = 'XBMC.Container.Update(%s)' if not self.widget else 'XBMC.RunPlugin(%s)'
     self.use_dialog = True if self.from_library or self.widget else settings.use_dialog()
     self.autoplay = settings.auto_play()
     self.prefer_hevc = settings.prefer_hevc()
     self.check_library = settings.check_library()
     self.check_downloads = settings.check_downloads()
     self.include_prerelease_results = settings.include_prerelease_results()
     self.include_uncached_results = settings.include_uncached_results()
     self.meta = json.loads(meta) if meta else tikimeta.movie_meta('tmdb_id', tmdb_id) if vid_type == "movie" else tikimeta.tvshow_meta('tmdb_id', tmdb_id)
     self.vid_type = vid_type
     self.tmdb_id = tmdb_id
     self.season = int(season) if season else ''
     self.episode = int(episode) if episode else ''
     display_name = clean_file_name(urllib.unquote(query)) if vid_type == 'movie' else '%s - %dx%.2d' % (self.meta['title'], self.season, self.episode)
     if from_library: self.meta.update({'plot': plot, 'from_library': from_library, 'ep_name': ep_name})
     self.meta.update({'query': query, 'vid_type': self.vid_type, 'media_id': self.tmdb_id,
         'rootname': display_name, 'tvshowtitle': self.meta['title'], 'season': self.season,
         'episode': self.episode, 'background': self.background})
     self.search_info = self._search_info()
     self._clear_sources()
     window.setProperty('fen_media_meta', json.dumps(self.meta))
     self.get_sources()