예제 #1
0
 def build_next_episode_play():
     infoLabels = season_episodes_meta(tmdb_id, season)
     ep_data = infoLabels['episodes']
     ep_data = [i for i in ep_data if int(i['season_number']) == int(season) and int(i['episode_number']) == int(episode)][0]
     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['name'],
                 "episode": episode, 'premiered': ep_data['air_date'], '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['name']}
     if from_library: url_params.update({'library': 'True', 'plot': ep_data['overview']})
     return build_url(url_params)
예제 #2
0
 def create_tvshow_strm_files(self):
     from datetime import date
     from resources.lib.modules.utils import to_utf8
     from resources.lib.modules.kodi_library import get_library_video
     skip_duplicates = settings.skip_duplicates()
     season_data = [
         i for i in self.meta['season_data'] if int(i['season_number']) > 0
     ]
     for i in season_data:
         infoLabels = tikimeta.season_episodes_meta(self.tmdb_id,
                                                    i['season_number'])
         ep_data = infoLabels['episodes']
         for item in ep_data:
             in_library = get_library_video(
                 'episode', self.title, self.year, item['season_number'],
                 item['episode_number']) if skip_duplicates else None
             if not in_library:
                 first_aired = item[
                     'air_date'] if 'air_date' in item else None
                 try:
                     d = first_aired.split('-')
                     episode_date = date(int(d[0]), int(d[1]), int(d[2]))
                 except:
                     episode_date = date(2100, 10, 24)
                 if date.today() > episode_date:
                     display = "%s S%.2dE%.2d" % (
                         self.title, int(item['season_number']),
                         int(item['episode_number']))
                     season_path = os.path.join(
                         self.folder,
                         'Season ' + str(item['season_number']))
                     self.make_folder(season_path)
                     stream_file = os.path.join(season_path,
                                                str(display) + '.strm')
                     params = to_utf8({
                         'mode': 'play_media',
                         'library': 'True',
                         'query': self.title,
                         'year': self.year,
                         'plot': item['overview'],
                         'poster': self.meta['poster'],
                         'season': item['season_number'],
                         'episode': item['episode_number'],
                         'ep_name': item['name'],
                         'premiered': item['air_date'],
                         'tmdb_id': self.tmdb_id,
                         'vid_type': 'episode'
                     })
                     self.make_stream(stream_file, params)
예제 #3
0
def build_episode(item):
    from resources.lib.modules.utils import make_day

    def check_for_unaired():
        try:
            d = first_aired.split('-')
            episode_date = date(int(d[0]), int(d[1]), int(d[2]))
        except:
            episode_date = None
        current_adjusted_date = settings.adjusted_datetime()
        unaired = False
        if not episode_date or current_adjusted_date < episode_date:
            unaired = True
        return unaired

    def build_display():
        if display_info:
            display_first_aired = make_day(first_aired)
            airdate = '[[COLOR=%s]%s[/COLOR]] ' % (
                display_info['airdate_colour'],
                display_first_aired) if display_info['include_airdate'] else ''
            highlight_color = display_info['unwatched_colour'] if item.get(
                'unwatched',
                False) else display_info['unaired_colour'] if unaired else ''
            italics_open, italics_close = ('[I]',
                                           '[/I]') if highlight_color else ('',
                                                                            '')
            episode_info = '%s[COLOR=%s]%dx%.2d - %s[/COLOR]%s' % (
                italics_open, highlight_color, info['season_number'],
                info['episode_number'], info['name'], italics_close)
            display = '%s%s: %s' % (airdate, meta['title'], episode_info)
            tvshow_display = display if display_info[
                'force_display'] else meta['title']
        else:
            display = '%s: %dx%.2d - %s' % (meta['title'].upper(
            ), info['season_number'], info['episode_number'], info['name'])
            tvshow_display = meta['title']
        return display, tvshow_display

    try:
        display_info = item.get('ne_display', None)
        thumb_path = 'http://image.tmdb.org/t/p/original%s'
        cm = []
        watched_indicators = settings.watched_indicators()
        action = item.get('action', '')
        meta = item['meta']
        info = [
            i for i in tikimeta.season_episodes_meta(
                meta['tmdb_id'], item['season'])['episodes']
            if i['episode_number'] == item['episode']
        ][0]
        first_aired = info['air_date']
        unaired = check_for_unaired()
        if unaired and not item.get('include_unaired', False): return
        guest_stars = get_guest_stars(info['guest_stars'])
        writer = ', '.join(
            [i['name'] for i in info['crew'] if i['job'] == 'Writer'])
        director = ', '.join(
            [i['name'] for i in info['crew'] if i['job'] == 'Director'])
        thumb = thumb_path % info['still_path'] if info.get(
            'still_path', None) != None else meta['fanart']
        playcount, overlay = get_watched_status('episode', meta['tmdb_id'],
                                                info['season_number'],
                                                info['episode_number'])
        query = meta['title'] + ' S%.2dE%.2d' % (info['season_number'],
                                                 info['episode_number'])
        display, tvshow_display = build_display()
        listitem = xbmcgui.ListItem(display)
        listitem.setProperty(
            "resumetime",
            get_resumetime('episode', meta['tmdb_id'], info['season_number'],
                           info['episode_number']))
        rootname = '{0} ({1})'.format(meta['title'], meta['year'])
        meta.update({
            'vid_type': 'episode',
            'rootname': rootname,
            'season': info['season_number'],
            'episode': info['episode_number'],
            'premiered': first_aired,
            'ep_name': info['name'],
            'plot': info['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': info['season_number'],
            'episode': info['episode_number'],
            'meta': meta_json
        }
        url = build_url(url_params)
        browse_url = build_url({
            'mode': 'build_season_list',
            'meta': meta_json
        })
        playback_menu_params = {'mode': 'playback_menu', 'suggestion': query}
        watched_title = 'Trakt' if watched_indicators in (1, 2) else "Fen"
        watched_params = {
            "mode": "mark_episode_as_watched_unwatched",
            "action": "mark_as_watched",
            "media_id": meta['tmdb_id'],
            "imdb_id": meta["imdb_id"],
            "tvdb_id": meta["tvdb_id"],
            "season": info['season_number'],
            "episode": info['episode_number'],
            "title": meta['title'],
            "year": meta['year']
        }
        if action == 'next_episode':
            nextep_manage_params = {"mode": "next_episode_context_choice"}
        cm.append(("[B]Mark Watched %s[/B]" % watched_title,
                   'XBMC.RunPlugin(%s)' % build_url(watched_params)))
        if listitem.getProperty("resumetime") != '0.000000':
            cm.append(("[B]Mark Unwatched %s[/B]" % watched_title,
                       'XBMC.RunPlugin(%s)' %
                       build_url({
                           "mode": "mark_episode_as_watched_unwatched",
                           "action": "mark_as_unwatched",
                           "media_id": meta['tmdb_id'],
                           "imdb_id": meta["imdb_id"],
                           "season": info['season_number'],
                           "episode": info['episode_number'],
                           "title": meta['title'],
                           "year": meta['year']
                       })))
        if action == 'next_episode':
            cm.append(("[B]Next Episode Manager[/B]",
                       'XBMC.RunPlugin(%s)' % build_url(nextep_manage_params)))
            cm.append(("[B]Refresh List[/B]", 'XBMC.Container.Refresh()'))
        cm.append(
            ("[B]Browse...[/B]", 'XBMC.Container.Update(%s)' % browse_url))
        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.setArt({
            'poster': meta['poster'],
            'fanart': meta['fanart'],
            'thumb': thumb,
            'banner': meta['banner'],
            'clearlogo': meta['clearlogo'],
            'landscape': meta['landscape']
        })
        listitem.addContextMenuItems(cm)
        listitem.setCast(meta['cast'] + guest_stars)
        listitem.setInfo(
            'video', {
                'mediatype': 'episode',
                'trailer': str(meta.get('trailer')),
                'title': info['name'],
                'tvshowtitle': tvshow_display,
                'size': '0',
                'plot': info['overview'],
                'premiered': first_aired,
                'writer': writer,
                'director': director,
                'season': info['season_number'],
                'genre': meta.get('genre'),
                'episode': info['episode_number'],
                'rating': info['vote_average'],
                'votes': info['vote_count'],
                'duration': meta.get('episode_run_time'),
                'playcount': playcount,
                'overlay': overlay
            })
        if not not_widget:
            listitem.setProperty("fen_widget", 'true')
            listitem.setProperty("fen_playcount", str(playcount))
        return {
            'listitem': (url, listitem, False),
            'curr_last_played_parsed': item.get('curr_last_played_parsed', ''),
            'order': item.get('order', ''),
            'name': query,
            'first_aired': first_aired
        }
    except:
        pass
예제 #4
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:
예제 #5
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()
예제 #6
0
def build_episode(item, watched_info, use_trakt, meta_user_info):
    from modules.utils import make_day
    def check_for_unaired():
        if item.get('ignore_unaired', False): return False
        try:
            d = first_aired.split('-')
            episode_date = date(int(d[0]), int(d[1]), int(d[2]))
        except: episode_date = None
        current_adjusted_date = settings.adjusted_datetime()
        unaired = False
        if not episode_date or current_adjusted_date < episode_date:
            unaired = True
        return unaired
    def build_display():
        if nextep_info:
            display_first_aired = make_day(first_aired)
            airdate = '[[COLOR %s]%s[/COLOR]] ' % (nextep_info['airdate_colour'], display_first_aired) if nextep_info['include_airdate'] else ''
            highlight_color = nextep_info['unwatched_colour'] if item.get('unwatched', False) else nextep_info['unaired_colour'] if unaired else ''
            italics_open, italics_close = ('[I]', '[/I]') if highlight_color else ('', '')
            if highlight_color: episode_info = '%s[COLOR %s]%dx%.2d - %s[/COLOR]%s' % (italics_open, highlight_color, info['season'], info['episode'], info['title'], italics_close)
            else: episode_info = '%s%dx%.2d - %s%s' % (italics_open, info['season'], info['episode'], info['title'], italics_close)
            display = '%s%s: %s' % (airdate, title, episode_info)
        elif trakt_calendar:
            display_first_aired = make_day(first_aired)
            display = '[%s] %s: %dx%.2d - %s' % (display_first_aired, title.upper(), info['season'], info['episode'], info['title'])
            if unaired:
                UNAIRED_EPISODE_COLOUR = settings.unaired_episode_colour()
                if not UNAIRED_EPISODE_COLOUR or UNAIRED_EPISODE_COLOUR == '': UNAIRED_EPISODE_COLOUR = 'red'
                displays = display.split(']')
                display = '[COLOR %s]' % UNAIRED_EPISODE_COLOUR + displays[0] + '][/COLOR]' + displays[1]
        else:
            UNAIRED_EPISODE_COLOUR = settings.unaired_episode_colour()
            if not UNAIRED_EPISODE_COLOUR or UNAIRED_EPISODE_COLOUR == '': UNAIRED_EPISODE_COLOUR = 'red'
            color_tags = ('[COLOR %s]' % UNAIRED_EPISODE_COLOUR, '[/COLOR]') if unaired else ('', '')
            display = '%s: %s%dx%.2d - %s%s' % (title.upper(), color_tags[0], info['season'], info['episode'], info['title'], color_tags[1])
        return display
    try:
        cm = []
        nextep_info = item.get('nextep_display_settings', None)
        trakt_calendar = item.get('trakt_calendar', False)
        watched_indicators = settings.watched_indicators()
        action = item.get('action', '')
        meta = item['meta']
        tmdb_id = meta['tmdb_id']
        tvdb_id = meta['tvdb_id']
        imdb_id = meta["imdb_id"]
        title = meta['title']
        year = meta['year']
        episodes_data = tikimeta.season_episodes_meta(tmdb_id, tvdb_id, item['season'], meta['tvdb_summary']['airedSeasons'], meta['season_data'], meta_user_info)
        info = [i for i in episodes_data if i['episode'] == item['episode']][0]
        first_aired = info['premiered']
        season = info['season']
        episode = info['episode']
        unaired = check_for_unaired()
        if unaired and not item.get('include_unaired', False): return
        thumb = info['thumb'] if 'episodes' in info['thumb'] else meta['fanart']
        playcount, overlay = get_watched_status(watched_info, use_trakt, 'episode', tmdb_id, season, episode)
        resumetime = get_resumetime('episode', tmdb_id, season, episode)
        info.update({'trailer': str(meta.get('trailer')), 'tvshowtitle': title,
                    'genre': meta.get('genre'), 'duration': meta.get('duration'), 'mpaa': meta.get('mpaa'),
                    'studio': meta.get('studio'), 'playcount': playcount, 'overlay': overlay})
        query = title + ' S%.2dE%.2d' % (season, episode)
        display = build_display()
        rootname = '{0} ({1})'.format(title, year)
        meta.update({'vid_type': 'episode', 'rootname': rootname, 'season': season,
                    'episode': episode, 'premiered': first_aired, 'ep_name': info['title'],
                    'plot': info['plot']})
        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)
        browse_url = build_url({'mode': 'build_season_list', 'meta': meta_json})
        playback_menu_params = {'mode': 'playback_menu', 'suggestion': query, 'play_params': json.dumps(url_params)}
        (wstate, waction) = ('Watched', 'mark_as_watched') if playcount == 0 else ('Unwatched', 'mark_as_unwatched')
        watched_title = 'Trakt' if watched_indicators in (1, 2) else "Fen"
        watched_params = {"mode": "mark_episode_as_watched_unwatched", "action": waction, "media_id": tmdb_id, "imdb_id": imdb_id, "tvdb_id": tvdb_id, "season": season, "episode": episode,  "title": title, "year": year}
        if action == 'next_episode': nextep_manage_params = {"mode": "next_episode_context_choice"}
        if not unaired: cm.append(("[B]Mark %s %s[/B]" % (wstate, watched_title),'RunPlugin(%s)' % build_url(watched_params)))
        cm.append(("[B]Options[/B]",'RunPlugin(%s)' % build_url(playback_menu_params)))
        if action == 'next_episode':
            cm.append(("[B]Next Episode Manager[/B]",'RunPlugin(%s)'% build_url(nextep_manage_params)))
            if nextep_info['cache_to_disk']: cm.append(("[B]Refresh...[/B]",'Container.Refresh()'))
        cm.append(("[B]Browse...[/B]",'Container.Update(%s)' % browse_url))
        cm.append(("[B]Extended Info[/B]", 'RunScript(script.extendedinfo,info=extendedtvinfo,id=%s)' % tmdb_id))
        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"})))
        listitem = xbmcgui.ListItem()
        listitem.setLabel(display)
        listitem.setProperty("resumetime", resumetime)
        listitem.setArt({'poster': meta['poster'], 'fanart': meta['fanart'], 'thumb':thumb, 'banner': meta['banner'], 'clearart': meta['clearart'], 'clearlogo': meta['clearlogo'], 'landscape': meta['landscape']})
        listitem.addContextMenuItems(cm)
        listitem.setCast(meta['cast'])
        listitem.setUniqueIDs({'imdb': str(imdb_id), 'tmdb': str(tmdb_id), 'tvdb': str(tvdb_id)})
        info['title'] = display
        listitem.setInfo('video', remove_unwanted_info_keys(info))
        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))
        return {'listitem': (url, listitem, False), 'curr_last_played_parsed': item.get('curr_last_played_parsed', ''), 'label': display, 'order': item.get('order', ''), 'name': query, 'first_aired': first_aired}
    except: pass
예제 #7
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')
예제 #8
0
def mark_season_as_watched_unwatched():
    from resources.lib.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'
    season = int(params.get('season'))
    title = params.get('title')
    year = params.get('year')
    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 season == 0:
        from resources.lib.modules.nav_utils import notification
        notification(
            'Specials cannot be marked as %s' %
            ('Watched' if action == 'mark_as_watched' else 'Unwatched'),
            time=5000)
        return
    if watched_indicators in (1, 2):
        from resources.lib.modules.trakt import trakt_watched_unwatched
        trakt_watched_unwatched(action, 'season', imdb_id, tvdb_id, season)
        clear_trakt_watched_data('tvshow', imdb_id)
    if watched_indicators in (0, 1):
        import tikimeta
        bg_dialog = xbmcgui.DialogProgressBG()
        bg_dialog.create('Please Wait', '')
        infoLabels = tikimeta.season_episodes_meta(media_id, season)
        ep_data = infoLabels['episodes']
        count = 1
        se_list = []
        for item in ep_data:
            season_number = item['season_number']
            ep_number = item['episode_number']
            season_ep = '%.2d<>%.2d' % (season_number, ep_number)
            display = 'Updating - S%.2dE%.2d' % (season_number, ep_number)
            try:
                first_aired = item['air_date']
                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
            display = 'Updating - S%.2dE%.2d' % (season_number, ep_number)
            bg_dialog.update(int(float(count) / float(len(ep_data)) * 100),
                             'Please Wait', '%s' % display)
            count += 1
            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 resources.lib.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:
            xbmc.executebuiltin("Container.Refresh")
            return
        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):
            from resources.lib.modules.nav_utils import notification
            notification('Kodi Library Sync Complete', time=5000)
    refresh_container()