Exemplo n.º 1
0
 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
Exemplo n.º 2
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()
Exemplo n.º 3
0
def make_day(date, use_words=True):
    from datetime import datetime, timedelta
    import time
    from resources.lib.modules.settings import adjusted_datetime, nextep_airdate_format
    try: date = datetime.strptime(date, '%Y-%m-%d')
    except TypeError: date = datetime(*(time.strptime(date, '%Y-%m-%d')[0:6]))
    date = date + timedelta(days=1)
    today = adjusted_datetime(dt=True)
    day_diff = (date - today).days
    date_format = nextep_airdate_format()
    fallback_format = '%Y-%m-%d'
    try: day = date.strftime(date_format)
    except ValueError: day = date.strftime(fallback_format)
    if use_words:
        if day_diff == -1:
            day = 'YESTERDAY'
        elif day_diff == 0:
            day = 'TODAY'
        elif day_diff == 1:
            day = 'TOMORROW'
        elif day_diff > 1 and day_diff < 7:
            date = date - timedelta(days=1)
            day = date.strftime('%A').upper()
    return day
Exemplo n.º 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:
Exemplo n.º 5
0
def mark_tv_show_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'
    media_id = params.get('media_id')
    tvdb_id = int(params.get('tvdb_id', '0'))
    imdb_id = params.get('imdb_id')
    from_search = params.get('from_search', 'false')
    watched_indicators = settings.watched_indicators()
    if watched_indicators in (1, 2):
        from resources.lib.modules.trakt import trakt_watched_unwatched
        trakt_watched_unwatched(action, 'shows', imdb_id, tvdb_id)
        clear_trakt_watched_data('tvshow', imdb_id)
    if watched_indicators in (0, 1):
        import tikimeta
        from resources.lib.indexers.tvshows import make_fresh_tvshow_meta
        title = params.get('title', '')
        year = params.get('year', '')
        bg_dialog = xbmcgui.DialogProgressBG()
        bg_dialog.create('Please Wait', '')
        se_list = []
        count = 1
        s_data = make_fresh_tvshow_meta('tmdb_id', media_id)
        season_data = s_data['season_data']
        total = sum([
            i['episode_count'] for i in season_data if i['season_number'] > 0
        ])
        for item in season_data:
            season_number = int(item['season_number'])
            if season_number <= 0: continue
            season_id = item['id']
            infoLabels = tikimeta.season_episodes_meta(media_id, season_number)
            ep_data = infoLabels['episodes']
            for item in ep_data:
                season_number = item['season_number']
                ep_number = item['episode_number']
                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 = 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
                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:
            refresh_container(from_search)
            return
        from resources.lib.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(from_search)
Exemplo n.º 6
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()