Exemple #1
0
def build_next_episode_manager():
    from modules.nav_utils import add_dir
    from modules.indicators_bookmarks import get_watched_status_tvshow, get_watched_info_tv

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

    check_meta_database()
    clear_all_trakt_cache_data(confirm=False)
    sync_watched_trakt_to_fen()
    params = dict(parse_qsl(sys.argv[2].replace('?', '')))
    NEXT_EP_UNWATCHED = __addon__.getSetting('nextep.unwatched_colour')
    if not NEXT_EP_UNWATCHED or NEXT_EP_UNWATCHED == '':
        NEXT_EP_UNWATCHED = 'red'
    threads = []
    sorted_list = []
    action = params['action']
    if action == 'manage_unwatched':
        tmdb_list = [i['tmdb_id'] for i in get_unwatched_next_episodes()]
        heading = 'Select Show to remove from Fen Next Episode:'
    elif settings.watched_indicators() in (1, 2):
        from apis.trakt_api import trakt_get_next_episodes
        tmdb_list, exclude_list = trakt_get_next_episodes(include_hidden=True)
        heading = 'Select Show to Hide/Unhide from Trakt Progress:'
        action = 'trakt_and_fen'
    else:
        settings.check_database(WATCHED_DB)
        dbcon = database.connect(WATCHED_DB)
        dbcur = dbcon.cursor()
        dbcur.execute(
            '''SELECT media_id FROM watched_status WHERE db_type=? GROUP BY media_id''',
            ('episode', ))
        rows = dbcur.fetchall()
        tmdb_list = [row[0] for row in rows]
        exclude_list = check_for_next_episode_excludes()
        heading = 'Select Show to Include/Exclude in Fen Next Episode:'
    add_dir({'mode': 'nill'},
            '[I][COLOR=grey][B]INFO:[/B][/COLOR] [COLOR=grey2]%s[/COLOR][/I]' %
            heading,
            iconImage='settings.png')
    if not tmdb_list:
        from modules.nav_utils import notification
        return notification('No Shows Present', time=5000)
    meta_user_info = retrieve_user_info()
    window.setProperty('fen_fanart_error', 'true')
    for tmdb_id in tmdb_list:
        threads.append(Thread(target=_process, args=(tmdb_id, action)))
    [i.start() for i in threads]
    [i.join() for i in threads]
    sorted_items = sorted(sorted_list, key=lambda k: k['display'])
    watched_info, use_trakt = get_watched_info_tv()
    for i in sorted_items:
        try:
            cm = []
            meta = json.loads(i['meta'])
            playcount, overlay, total_watched, total_unwatched = get_watched_status_tvshow(
                watched_info, use_trakt, meta['tmdb_id'],
                meta.get('total_episodes'))
            meta.update({
                'playcount': playcount,
                'overlay': overlay,
                'total_watched': str(total_watched),
                'total_unwatched': str(total_unwatched)
            })
            url = build_url(i['url_params'])
            browse_url = build_url({
                'mode': 'build_season_list',
                'meta': i['meta']
            })
            cm.append(
                ("[B]Browse...[/B]", 'XBMC.Container.Update(%s)' % browse_url))
            listitem = xbmcgui.ListItem(i['display'])
            listitem.setProperty('watchedepisodes', str(total_watched))
            listitem.setProperty('unwatchedepisodes', str(total_unwatched))
            listitem.setProperty('totalepisodes', str(meta['total_episodes']))
            listitem.setProperty('totalseasons', str(meta['total_seasons']))
            listitem.addContextMenuItems(cm)
            listitem.setArt({
                'poster': meta['poster'],
                'fanart': meta['fanart'],
                'banner': meta['banner'],
                'clearart': meta['clearart'],
                'clearlogo': meta['clearlogo'],
                'landscape': meta['landscape']
            })
            listitem.setCast(meta['cast'])
            listitem.setInfo('video', remove_unwanted_info_keys(meta))
            xbmcplugin.addDirectoryItem(__handle__,
                                        url,
                                        listitem,
                                        isFolder=True)
        except:
            pass
    xbmcplugin.setContent(__handle__, 'tvshows')
    xbmcplugin.endOfDirectory(__handle__, cacheToDisc=False)
    setView('view.main', 'tvshows')
Exemple #2
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
Exemple #3
0
 def _build(item):
     try:
         cm = []
         item_no = item['item_no']
         tmdb_id = item['tmdb_id']
         tvdb_id = item['tvdb_id']
         imdb_id = item['imdb_id']
         title = item['title']
         year = item['year']
         trailer = item['trailer']
         if not 'rootname' in item: item['rootname'] = '{0} ({1})'.format(title, year)
         meta_json = json.dumps(item)
         openinfo_params = {'mode': 'extended_info_open', 'db_type': 'tvshow', 'tmdb_id': tmdb_id}
         season_params = {'mode': 'build_season_list', 'meta': meta_json, 'tmdb_id': tmdb_id}
         all_episodes_params = {'mode': 'build_episode_list', 'tmdb_id': tmdb_id, 'season': 'all', 'meta': meta_json}
         browse_params = all_episodes_params if all_episodes else season_params
         url_params = openinfo_params if default_openinfo else all_episodes_params if all_episodes else season_params
         url = build_url(url_params)
         hide_recommended_params = {'mode': 'trakt.hide_recommendations', 'db_type': 'shows', 'imdb_id': imdb_id}
         playback_menu_params = {'mode': 'playback_menu', 'list_name': list_name}
         watched_params = {"mode": "mark_tv_show_as_watched_unwatched", "action": 'mark_as_watched', "title": title, "year": year, "media_id": tmdb_id, "imdb_id": imdb_id, "tvdb_id": tvdb_id, "meta_user_info": meta_user_info}
         unwatched_params = {"mode": "mark_tv_show_as_watched_unwatched", "action": 'mark_as_unwatched', "title": title, "year": year, "media_id": tmdb_id, "imdb_id": imdb_id, "tvdb_id": tvdb_id, "meta_user_info": meta_user_info}
         add_remove_params = {"mode": "build_add_to_remove_from_list", "media_type": "tvshow", "meta": meta_json, "orig_mode": self.action}
         sim_recom_params = {"mode": "similar_recommendations_choice", "db_type": "tv", 'sim_recom_name': item['rootname'] , "sim_recom_tmdb": tmdb_id, "meta_user_info": meta_user_info}
         (trailer_params, trailer_title) = ({'mode': 'play_trailer', 'url': trailer, 'all_trailers': json.dumps(item['all_trailers'])}, 'Choose Trailer') if (all_trailers and item.get('all_trailers', False)) else ({'mode': 'play_trailer', 'url': trailer}, 'Trailer')
         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)))
         if default_openinfo: cm.append(("[B]Browse...[/B]",'XBMC.Container.Update(%s)' % build_url(browse_params)))
         cm.append(("[B]Add/Remove[/B]", "XBMC.RunPlugin(%s)" % build_url(add_remove_params)))
         cm.append(("[B]Similar/Recommended[/B]", "XBMC.RunPlugin(%s)" % build_url(sim_recom_params)))
         if self.action in ('tmdb_tv_similar', 'tmdb_tv_recommendations'):
             sim_recom_title = 'Similar to' if self.action == 'tmdb_tv_similar' else 'Recommended based on'
             export_sim_recom_params = {'mode': 'navigator.adjust_main_lists', 'method': 'add_sim_recom_external', 'end_mode': 'build_tvshow_list',
                             'end_action': self.action, 'db_type': 'tvshow', 'sim_recom_name': '[B]TV Shows[/B] | %s %s' % (sim_recom_title, self.sim_recom_name),
                             'sim_recom_tmdb': self.sim_recom_tmdb}
             cm.append(("[B]Export %s List[/B]" % sim_recom_title.split(' ')[0], "XBMC.RunPlugin(%s)" % build_url(export_sim_recom_params)))
         if trailer: cm.append(("[B]%s[/B]" % trailer_title,"XBMC.RunPlugin(%s)" % build_url(trailer_params)))
         if self.action == 'trakt_recommendations': cm.append(("[B]Hide from Recommendations[/B]", "XBMC.RunPlugin(%s)" % build_url(hide_recommended_params)))
         cm.append(("[B]Extended Info[/B]", 'RunScript(script.extendedinfo,info=extendedtvinfo,id=%s)' % tmdb_id))
         cm.append(("[B]Exit TV Show List[/B]","XBMC.Container.Refresh(%s)" % build_url(exit_list_params)))
         listitem = xbmcgui.ListItem()
         listitem.setLabel(title)
         try:
             listitem.setProperties({'watchedepisodes': item['total_watched'], 'unwatchedepisodes': item['total_unwatched'],
                                     'totalepisodes': str(item['total_episodes']), 'totalseasons': str(item['total_seasons'])})
         except:
             listitem.setProperty('watchedepisodes', item['total_watched'])
             listitem.setProperty('unwatchedepisodes', item['total_unwatched'])
             listitem.setProperty('totalepisodes', str(item['total_episodes']))
             listitem.setProperty('totalseasons', str(item['total_seasons']))
         listitem.addContextMenuItems(cm)
         listitem.setCast(item['cast'])
         listitem.setUniqueIDs({'imdb': str(imdb_id), 'tmdb': str(tmdb_id), 'tvdb': str(tvdb_id)})
         listitem.setArt({'poster': item['poster'], 'fanart': item['fanart'], 'icon': item['poster'], 'banner': item['banner'], 'clearart': item['clearart'], 'clearlogo': item['clearlogo'], 'landscape': item['landscape']})
         listitem.setInfo('video', remove_unwanted_info_keys(item))
         if is_widget:
             listitem.setProperty("fen_widget", 'true')
         if use_threading: item_list.append({'list_item': (url, listitem, True), 'item_position': item_no})
         else: xbmcplugin.addDirectoryItem(__handle__, url, listitem, isFolder=True)
     except: pass
Exemple #4
0
 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
Exemple #5
0
 def _process(item):
     try:
         cm = []
         poster = item['poster']
         if use_animated:
             if item.get('gif_poster', False):
                 item['use_animated_poster'] = True
                 poster = item['gif_poster']
         item_no = item['item_no']
         meta_json = json.dumps(item)
         rootname = item['rootname']
         tmdb_id = item['tmdb_id']
         imdb_id = item['imdb_id']
         title = item['title']
         trailer = item['trailer']
         playcount = item['playcount']
         resumetime = get_resumetime('movie', tmdb_id)
         default_openinfo_params = {
             'mode': 'extended_info_open',
             'db_type': 'movie',
             'tmdb_id': tmdb_id
         }
         play_params = {
             'mode': 'play_media',
             'vid_type': 'movie',
             'query': rootname,
             'tmdb_id': tmdb_id,
             'meta': meta_json
         }
         url_params = default_openinfo_params if default_openinfo else play_params
         url = build_url(url_params)
         playback_params = {
             'mode': 'playback_menu',
             'suggestion': rootname,
             'list_name': list_name,
             'play_params': json.dumps(url_params)
         }
         hide_recommended_params = {
             'mode': 'trakt.hide_recommendations',
             'db_type': 'movies',
             'imdb_id': imdb_id
         }
         (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')
         watched_unwatched_params = {
             "mode": "mark_movie_as_watched_unwatched",
             "action": action,
             "media_id": tmdb_id,
             "meta_user_info": meta_user_info,
             "title": title,
             "year": item['year']
         }
         add_remove_params = {
             "mode": "build_add_to_remove_from_list",
             "media_type": "movie",
             "meta": meta_json,
             "orig_mode": self.action
         }
         sim_recom_params = {
             "mode": "similar_recommendations_choice",
             "db_type": "movies",
             'sim_recom_name': rootname,
             "sim_recom_tmdb": tmdb_id,
             "meta_user_info": meta_user_info
         }
         (trailer_params, trailer_title) = (
             {
                 'mode': 'play_trailer',
                 'url': trailer,
                 'all_trailers': json.dumps(item['all_trailers'])
             }, 'Choose Trailer') if (all_trailers and item.get(
                 'all_trailers', False)) else ({
                     'mode': 'play_trailer',
                     'url': trailer
                 }, 'Trailer')
         cm.append(("[B]Mark %s %s[/B]" % (state, watched_title),
                    "XBMC.RunPlugin(%s)" %
                    build_url(watched_unwatched_params)))
         cm.append(("[B]Options[/B]",
                    "XBMC.RunPlugin(%s)" % build_url(playback_params)))
         if default_openinfo:
             cm.append(("[B]Sources Search...[/B]",
                        'XBMC.RunPlugin(%s)' % build_url(play_params)))
         cm.append(
             ("[B]Add/Remove[/B]",
              "XBMC.RunPlugin(%s)" % build_url(add_remove_params)))
         cm.append(("[B]Similar/Recommended[/B]",
                    "XBMC.RunPlugin(%s)" % build_url(sim_recom_params)))
         if self.action in ('tmdb_movies_similar',
                            'tmdb_movies_recommendations'):
             sim_recom_title = 'Similar to' if self.action == 'tmdb_movies_similar' else 'Recommended based on'
             export_sim_recom_params = {
                 'mode':
                 'navigator.adjust_main_lists',
                 'method':
                 'add_sim_recom_external',
                 'end_mode':
                 'build_movie_list',
                 'end_action':
                 self.action,
                 'db_type':
                 'movie',
                 'sim_recom_name':
                 '[B]Movies[/B] | %s %s' %
                 (sim_recom_title, self.sim_recom_name),
                 'sim_recom_tmdb':
                 self.sim_recom_tmdb
             }
             cm.append(
                 ("[B]Export %s List[/B]" %
                  sim_recom_title.split(' ')[0], "XBMC.RunPlugin(%s)" %
                  build_url(export_sim_recom_params)))
         if trailer:
             cm.append(
                 ("[B]%s[/B]" % trailer_title,
                  "XBMC.RunPlugin(%s)" % build_url(trailer_params)))
         if resumetime != '0':
             cm.append(
                 ("[B]Clear Progress[/B]",
                  'XBMC.RunPlugin(%s)' % build_url({
                      "mode": "watched_unwatched_erase_bookmark",
                      "db_type": "movie",
                      "media_id": tmdb_id,
                      "refresh": "true"
                  })))
         if self.action == 'trakt_recommendations':
             cm.append(("[B]Hide from Recommendations[/B]",
                        "XBMC.RunPlugin(%s)" %
                        build_url(hide_recommended_params)))
         cm.append(("[B]Read Reviews[/B]",
                    "XBMC.RunPlugin(%s)" % build_url({
                        'mode': 'movie_reviews',
                        'rootname': rootname,
                        'tmdb_id': tmdb_id,
                        'poster': poster
                    })))
         cm.append(
             ("[B]Extended Info[/B]",
              'RunScript(script.extendedinfo,info=extendedinfo,id=%s)' %
              tmdb_id))
         cm.append(
             ("[B]Exit Movie List[/B]", "XBMC.Container.Refresh(%s)" %
              build_url(exit_list_params)))
         listitem = xbmcgui.ListItem(title)
         listitem.setProperty("resumetime", resumetime)
         listitem.addContextMenuItems(cm)
         listitem.setCast(item['cast'])
         listitem.setUniqueIDs({
             'imdb': str(imdb_id),
             'tmdb': str(tmdb_id)
         })
         listitem.setArt({
             'poster': poster,
             'fanart': item['fanart'],
             'icon': poster,
             'banner': item['banner'],
             'clearart': item['clearart'],
             'clearlogo': item['clearlogo'],
             'landscape': item['landscape'],
             'discart': item['discart']
         })
         listitem.setInfo('Video', remove_unwanted_info_keys(item))
         if is_widget:
             listitem.setProperty('fen_playback_menu_params',
                                  json.dumps(playback_params))
             listitem.setProperty('fen_widget', 'true')
             listitem.setProperty('fen_playcount', str(playcount))
         if use_threading:
             item_list.append({
                 'list_item': (url, listitem, False),
                 'item_position': item_no
             })
         else:
             xbmcplugin.addDirectoryItem(__handle__,
                                         url,
                                         listitem,
                                         isFolder=False)
     except:
         pass