Ejemplo n.º 1
0
 def _grab_meta(self):
     meta_user_info = metadata.retrieve_user_info()
     if self.vid_type == 'movie':
         self.meta = metadata.movie_meta('tmdb_id', self.tmdb_id,
                                         meta_user_info)
     else:
         self.meta = metadata.tvshow_meta('tmdb_id', self.tmdb_id,
                                          meta_user_info)
         episodes_data = metadata.season_episodes_meta(
             self.season, self.meta, meta_user_info)
         try:
             episode_data = [
                 i for i in episodes_data
                 if i['episode'] == int(self.episode)
             ][0]
             self.meta.update({
                 'vid_type': 'episode',
                 'season': episode_data['season'],
                 'episode': episode_data['episode'],
                 'premiered': episode_data['premiered'],
                 'ep_name': episode_data['title'],
                 'plot': episode_data['plot']
             })
         except:
             pass
Ejemplo n.º 2
0
 def set_meta(self, _id):
     meta = metadata.tvshow_meta(self.id_type, _id, self.meta_user_info)
     if not meta: return
     playcount, overlay, total_watched, total_unwatched = get_watched_status_tvshow(
         self.watched_info, string(meta['tmdb_id']),
         meta.get('total_aired_eps'))
     meta.update({'playcount': playcount, 'overlay': overlay})
     return meta, playcount, total_watched, total_unwatched
Ejemplo n.º 3
0
def mark_as_watched_unwatched_tvshow(params):
    action = params.get('action')
    tmdb_id = params.get('tmdb_id')
    try:
        tvdb_id = int(params.get('tvdb_id', '0'))
    except:
        tvdb_id = 0
    watched_indicators = settings.watched_indicators()
    kodi_utils.progressDialogBG.create(ls(32577), '')
    if watched_indicators == 1:
        if not trakt_watched_unwatched(action, 'shows', tmdb_id, tvdb_id):
            return kodi_utils.notification(32574)
        clear_trakt_collection_watchlist_data('watchlist', 'tvshow')
        data_base = TRAKT_DB
    else:
        data_base = WATCHED_DB
    title = params.get('title', '')
    year = params.get('year', '')
    meta_user_info = metadata.retrieve_user_info()
    adjust_hours = settings.date_offset()
    current_date = get_datetime()
    insert_list = []
    insert_append = insert_list.append
    meta = metadata.tvshow_meta('tmdb_id', tmdb_id, meta_user_info)
    season_data = meta['season_data']
    season_data = [i for i in season_data if i['season_number'] > 0]
    total = len(season_data)
    last_played = get_last_played_value(data_base)
    for count, item in enumerate(season_data, 1):
        season_number = item['season_number']
        ep_data = metadata.season_episodes_meta(season_number, meta,
                                                meta_user_info)
        for ep in ep_data:
            season_number = ep['season']
            ep_number = ep['episode']
            display = 'S%.2dE%.2d' % (int(season_number), int(ep_number))
            kodi_utils.progressDialogBG.update(
                int(float(count) / float(total) * 100), ls(32577),
                '%s' % display)
            episode_date, premiered = adjust_premiered_date(
                ep['premiered'], adjust_hours)
            if not episode_date or current_date < episode_date: continue
            insert_append(
                make_batch_insert(action, 'episode', tmdb_id, season_number,
                                  ep_number, last_played, title))
    batch_mark_as_watched_unwatched(insert_list, action, data_base)
    batch_erase_bookmark(insert_list, action, watched_indicators)
    kodi_utils.progressDialogBG.close()
    if settings.sync_kodi_library_watchstatus():
        batch_mark_kodi_library(action, insert_list, title, year)
    refresh_container()
Ejemplo n.º 4
0
def play_fetch_random(tmdb_id):
    meta_user_info = metadata.retrieve_user_info()
    meta = metadata.tvshow_meta('tmdb_id', tmdb_id, meta_user_info)
    adjust_hours = date_offset()
    current_date = get_datetime()
    episodes_data = metadata.all_episodes_meta(meta, meta_user_info)
    episodes_data = [
        i for i in episodes_data if not i['season'] == 0 and
        adjust_premiered_date(i['premiered'], adjust_hours)[0] <= current_date
    ]
    if not episodes_data: return {'pass': True}
    chosen_episode = choice(episodes_data)
    title = meta['title']
    season = int(chosen_episode['season'])
    episode = int(chosen_episode['episode'])
    query = title + ' S%.2dE%.2d' % (season, episode)
    display_name = '%s - %dx%.2d' % (title, season, episode)
    ep_name = chosen_episode['title']
    plot = chosen_episode['plot']
    try:
        premiered = adjust_premiered_date(chosen_episode['premiered'],
                                          adjust_hours)[1]
    except:
        premiered = chosen_episode['premiered']
    meta.update({
        'vid_type': 'episode',
        'rootname': display_name,
        'season': season,
        'episode': episode,
        'premiered': premiered,
        'ep_name': ep_name,
        'plot': plot,
        'random': 'true'
    })
    url_params = {
        'mode': 'play_media',
        'vid_type': 'episode',
        'tmdb_id': meta['tmdb_id'],
        'query': query,
        'tvshowtitle': meta['rootname'],
        'season': season,
        'episode': episode,
        'autoplay': 'True'
    }
    return execute_builtin('RunPlugin(%s)' % build_url(url_params))
Ejemplo n.º 5
0
def build_season_list(params):
    def _process():
        running_ep_count = total_aired_eps

        def _unaired_status():
            if episode_count == 0: return True
            season_date_start = adjust_premiered_date(air_date, 0)[0]
            if not season_date_start or current_date < season_date_start:
                return True
            return False

        for item in season_data:
            try:
                listitem = make_listitem()
                set_property = listitem.setProperty
                cm = []
                cm_append = cm.append
                item_get = item.get
                overview = item_get('overview')
                name = item_get('name')
                poster_path = item_get('poster_path')
                air_date = item_get('air_date')
                season_number = item_get('season_number')
                episode_count = item_get('episode_count')
                season_poster = 'https://image.tmdb.org/t/p/%s%s' % (
                    image_resolution,
                    poster_path) if poster_path is not None else show_poster
                if season_number == 0: unaired = False
                else:
                    unaired = _unaired_status()
                    if unaired:
                        if not show_unaired: return
                        episode_count = 0
                    else:
                        running_ep_count -= episode_count
                        if running_ep_count < 0:
                            episode_count = running_ep_count + episode_count
                try:
                    year = air_date.split('-')[0]
                except:
                    year = show_year
                plot = overview if overview != '' else show_plot
                title = name if use_season_title and name != '' else '%s %s' % (
                    season_str, string(season_number))
                if unaired: title = unaired_label % title
                playcount, overlay, watched, unwatched = get_watched_status_season(
                    watched_info, string(tmdb_id), season_number,
                    episode_count)
                url_params = build_url({
                    'mode': 'build_episode_list',
                    'tmdb_id': tmdb_id,
                    'season': season_number
                })
                extras_params = build_url({
                    'mode': 'extras_menu_choice',
                    'tmdb_id': tmdb_id,
                    'db_type': 'tvshow',
                    'is_widget': is_widget
                })
                options_params = build_url({
                    'mode': 'options_menu_choice',
                    'content': 'season',
                    'tmdb_id': tmdb_id
                })
                cm_append((extras_str, run_plugin % extras_params))
                cm_append((options_str, run_plugin % options_params))
                if not playcount:
                    watched_params = build_url({
                        'mode': 'mark_as_watched_unwatched_season',
                        'action': 'mark_as_watched',
                        'title': show_title,
                        'year': show_year,
                        'tmdb_id': tmdb_id,
                        'tvdb_id': tvdb_id,
                        'season': season_number
                    })
                    cm_append((watched_str % watched_title,
                               run_plugin % watched_params))
                if watched:
                    unwatched_params = build_url({
                        'mode': 'mark_as_watched_unwatched_season',
                        'action': 'mark_as_unwatched',
                        'title': show_title,
                        'year': show_year,
                        'tmdb_id': tmdb_id,
                        'tvdb_id': tvdb_id,
                        'season': season_number
                    })
                    cm_append((unwatched_str % watched_title,
                               run_plugin % unwatched_params))
                listitem.setLabel(title)
                listitem.setContentLookup(False)
                listitem.addContextMenuItems(cm)
                listitem.setArt({
                    'poster': season_poster,
                    'icon': season_poster,
                    'thumb': season_poster,
                    'fanart': fanart,
                    'banner': banner,
                    'clearart': clearart,
                    'clearlogo': clearlogo,
                    'landscape': landscape,
                    'tvshow.clearart': clearart,
                    'tvshow.clearlogo': clearlogo,
                    'tvshow.landscape': landscape,
                    'tvshow.banner': banner
                })
                listitem.setCast(cast)
                listitem.setUniqueIDs({
                    'imdb': imdb_id,
                    'tmdb': string(tmdb_id),
                    'tvdb': string(tvdb_id)
                })
                listitem.setInfo(
                    'video', {
                        'mediatype': 'season',
                        'trailer': trailer,
                        'title': title,
                        'size': '0',
                        'duration': episode_run_time,
                        'plot': plot,
                        'rating': rating,
                        'premiered': premiered,
                        'studio': studio,
                        'year': year,
                        'genre': genre,
                        'mpaa': mpaa,
                        'tvshowtitle': show_title,
                        'imdbnumber': imdb_id,
                        'votes': votes,
                        'season': season_number,
                        'playcount': playcount,
                        'overlay': overlay
                    })
                set_property('watchedepisodes', string(watched))
                set_property('unwatchedepisodes', string(unwatched))
                set_property('totalepisodes', string(episode_count))
                if is_widget:
                    set_property('fen_widget', 'true')
                    set_property('fen_playcount', string(playcount))
                    set_property('fen_extras_menu_params', extras_params)
                    set_property('fen_options_menu_params', options_params)
                else:
                    set_property('fen_widget', 'false')
                yield (url_params, listitem, True)
            except:
                pass

    __handle__ = int(argv[1])
    meta_user_info = metadata.retrieve_user_info()
    watched_indicators = settings.watched_indicators()
    watched_info = get_watched_info_tv(watched_indicators)
    show_unaired = settings.show_unaired()
    is_widget = kodi_utils.external_browse()
    current_date = get_datetime()
    image_resolution = meta_user_info['image_resolution']['poster']
    poster_main, poster_backup, fanart_main, fanart_backup = settings.get_art_provider(
    )
    meta = metadata.tvshow_meta('tmdb_id', params['tmdb_id'], meta_user_info)
    meta_get = meta.get
    season_data = meta_get('season_data')
    if not season_data: return
    tmdb_id, tvdb_id, imdb_id = meta_get('tmdb_id'), meta_get(
        'tvdb_id'), meta_get('imdb_id')
    show_title, show_year, show_plot, banner = meta_get('title'), meta_get(
        'year'), meta_get('plot'), meta_get('banner')
    show_poster = meta_get(poster_main) or meta_get(
        poster_backup) or poster_empty
    fanart = meta_get(fanart_main) or meta_get(fanart_backup) or fanart_empty
    clearlogo, clearart, landscape = meta_get('clearlogo'), meta_get(
        'clearart'), meta_get('landscape')
    cast, mpaa, votes = meta_get('cast'), meta_get('mpaa'), meta_get('votes')
    trailer, genre, studio = string(
        meta_get('trailer')), meta_get('genre'), meta_get('studio')
    episode_run_time, rating, premiered = meta_get(
        'episode_run_time'), meta_get('rating'), meta_get('premiered')
    total_seasons = meta_get('total_seasons')
    total_aired_eps = meta_get('total_aired_eps')
    if not settings.show_specials():
        season_data = [i for i in season_data if not i['season_number'] == 0]
    season_data.sort(key=lambda k: k['season_number'])
    use_season_title = settings.use_season_title()
    watched_title = 'Trakt' if watched_indicators == 1 else 'Fen'
    kodi_utils.add_items(__handle__, list(_process()))
    kodi_utils.set_content(__handle__, 'seasons')
    kodi_utils.end_directory(__handle__)
    kodi_utils.set_view_mode('view.seasons', 'seasons')
Ejemplo n.º 6
0
 def build_content(tmdb_id):
     try:
         cm = []
         listitem = make_listitem()
         set_property = listitem.setProperty
         cm_append = cm.append
         meta = tvshow_meta('tmdb_id', tmdb_id, meta_user_info)
         meta_get = meta.get
         total_aired_eps = meta_get('total_aired_eps')
         total_seasons = meta_get('total_seasons')
         title = meta_get('title')
         playcount, overlay, total_watched, total_unwatched = get_watched_status_tvshow(
             watched_info, tmdb_id, total_aired_eps)
         meta.update({'playcount': playcount, 'overlay': overlay})
         if tmdb_id in exclude_list:
             color, action, status, sort_value = 'red', 'unhide', excluded_str, 1
         else:
             color, action, status, sort_value = 'green', 'hide', included_str, 0
         display = '[COLOR=%s][%s][/COLOR] %s' % (color, status, title)
         extras_params = {
             'mode': 'extras_menu_choice',
             'tmdb_id': tmdb_id,
             'db_type': 'tvshow',
             'is_widget': 'False'
         }
         url_params = {
             'mode': 'hide_unhide_trakt_items',
             'action': action,
             'media_type': 'shows',
             'media_id': meta_get('imdb_id'),
             'section': 'progress_watched'
         }
         url = build_url(url_params)
         if show_all_episodes:
             if all_episodes == 1 and total_seasons > 1:
                 browse_params = {
                     'mode': 'build_season_list',
                     'tmdb_id': tmdb_id
                 }
             else:
                 browse_params = {
                     'mode': 'build_episode_list',
                     'tmdb_id': tmdb_id,
                     'season': 'all'
                 }
         else:
             browse_params = {
                 'mode': 'build_season_list',
                 'tmdb_id': tmdb_id
             }
         cm_append((extras_str, 'RunPlugin(%s)' % build_url(extras_params)))
         cm_append((browse_str,
                    'Container.Update(%s)' % build_url(browse_params)))
         listitem.setLabel(display)
         set_property('watchedepisodes', str(total_watched))
         set_property('unwatchedepisodes', str(total_unwatched))
         set_property('totalepisodes', str(total_aired_eps))
         set_property('totalseasons', str(total_seasons))
         listitem.addContextMenuItems(cm)
         listitem.setArt({
             'poster': meta_get('poster'),
             'fanart': meta_get('fanart'),
             'banner': meta_get('banner'),
             'clearart': meta_get('clearart'),
             'clearlogo': meta_get('clearlogo'),
             'landscape': meta_get('landscape')
         })
         listitem.setCast(meta['cast'])
         listitem.setInfo('video', remove_meta_keys(meta, dict_removals))
         append({
             'listitem': (url, listitem, False),
             'sort_value': sort_value,
             'sort_title': title
         })
     except:
         pass
Ejemplo n.º 7
0
 def _process(item):
     tmdb_id = item['media_id']
     meta = metadata.tvshow_meta('tmdb_id', tmdb_id, meta_user_info)
     watched_status = get_watched_status_tvshow(
         watched_info, tmdb_id, meta.get('total_aired_eps'))
     if watched_status[0] == 1: append(item)
Ejemplo n.º 8
0
def build_episode_list(params):
	def _process():
		for item in episodes_data:
			try:
				cm = []
				listitem = make_listitem()
				set_property = listitem.setProperty
				cm_append = cm.append
				item_get = item.get
				season = item_get('season')
				episode = item_get('episode')
				ep_name = item_get('title')
				premiered = item_get('premiered')
				all_cast = cast + item_get('guest_stars', [])
				episode_date, premiered = adjust_premiered_date(premiered, adjust_hours)
				playcount, overlay = get_watched_status(watched_info, string(tmdb_id), season, episode)
				resumetime = get_resumetime(bookmarks, tmdb_id, season, episode)
				thumb = item_get('thumb', None) or fanart
				if thumb_fanart: background = thumb
				else: background = fanart
				item.update({'trailer': trailer, 'tvshowtitle': title, 'premiered': premiered, 'genre': genre, 'duration': duration, 'mpaa': mpaa, 'studio': studio,
							'playcount': playcount, 'overlay': overlay})
				extras_params = build_url({'mode': 'extras_menu_choice', 'tmdb_id': tmdb_id, 'db_type': 'tvshow', 'is_widget': is_widget})
				options_params = build_url({'mode': 'options_menu_choice', 'content': 'episode', 'tmdb_id': tmdb_id, 'season': season, 'episode': episode})
				url_params = build_url({'mode': 'play_media', 'vid_type': 'episode', 'tmdb_id': tmdb_id, 'season': season, 'episode': episode})
				display = ep_name
				unaired = False
				if not episode_date or current_date < episode_date:
					if not show_unaired: continue
					if season != 0:
						unaired = True
						display = unaired_label % ep_name
						item['title'] = display
				cm_append((extras_str, run_plugin % extras_params))
				cm_append((options_str, run_plugin % options_params))
				clearprog_params, unwatched_params, watched_params = '', '', ''
				if not unaired:
					if resumetime != '0':
						clearprog_params = build_url({'mode': 'watched_unwatched_erase_bookmark', 'db_type': 'episode', 'tmdb_id': tmdb_id,
													'season': season, 'episode': episode, 'refresh': 'true'})
						cm_append((clearprog_str, run_plugin % clearprog_params))
						set_property('fen_in_progress', 'true')
					if playcount:
						unwatched_params = build_url({'mode': 'mark_as_watched_unwatched_episode', 'action': 'mark_as_unwatched', 'tmdb_id': tmdb_id,
													'tvdb_id': tvdb_id, 'season': season, 'episode': episode,  'title': title, 'year': year})
						cm_append((unwatched_str % watched_title, run_plugin % unwatched_params))
					else:
						watched_params = build_url({'mode': 'mark_as_watched_unwatched_episode', 'action': 'mark_as_watched', 'tmdb_id': tmdb_id,
													'tvdb_id': tvdb_id, 'season': season, 'episode': episode,  'title': title, 'year': year})
						cm_append((watched_str % watched_title, run_plugin % watched_params))
				listitem.setLabel(display)
				listitem.setContentLookup(False)
				listitem.addContextMenuItems(cm)
				listitem.setArt({'poster': show_poster, 'fanart': background, 'thumb': thumb, 'icon':thumb, 'banner': banner, 'clearart': clearart, 'clearlogo': clearlogo,
								'landscape': thumb, 'tvshow.clearart': clearart, 'tvshow.clearlogo': clearlogo, 'tvshow.landscape': thumb, 'tvshow.banner': banner})
				listitem.setCast(all_cast)
				listitem.setUniqueIDs({'imdb': imdb_id, 'tmdb': string(tmdb_id), 'tvdb': string(tvdb_id)})
				listitem.setInfo('video', remove_meta_keys(item, dict_removals))
				set_property('resumetime', resumetime)
				if is_widget:
					set_property('fen_widget', 'true')
					set_property('fen_playcount', string(playcount))
					set_property('fen_options_menu_params', options_params)
					set_property('fen_extras_menu_params', extras_params)
					set_property('fen_unwatched_params', unwatched_params)
					set_property('fen_watched_params', watched_params)
					set_property('fen_clearprog_params', clearprog_params)
				else: set_property('fen_widget', 'false')
				yield (url_params, listitem, False)
			except: pass
	__handle__ = int(argv[1])
	item_list = []
	append = item_list.append
	meta_user_info, watched_indicators, watched_info, show_unaired, thumb_fanart, is_widget, current_date, adjust_hours, bookmarks = get_episode_info()
	poster_main, poster_backup, fanart_main, fanart_backup = settings.get_art_provider()
	all_episodes = True if params.get('season') == 'all' else False
	meta = metadata.tvshow_meta('tmdb_id', params.get('tmdb_id'), meta_user_info)
	meta_get = meta.get
	tmdb_id, tvdb_id, imdb_id = meta_get('tmdb_id'), meta_get('tvdb_id'), meta_get('imdb_id')
	title, year, rootname, banner = meta_get('title'), meta_get('year'), meta_get('rootname'), meta_get('banner')
	show_poster = meta_get(poster_main) or meta_get(poster_backup) or poster_empty
	fanart = meta_get(fanart_main) or meta_get(fanart_backup) or fanart_empty
	clearlogo, clearart, landscape = meta_get('clearlogo'), meta_get('clearart'), meta_get('landscape')
	cast, mpaa, duration = meta_get('cast'), meta_get('mpaa'), meta_get('duration')
	trailer, genre, studio = string(meta_get('trailer')), meta_get('genre'), meta_get('studio')
	tvshow_plot = meta_get('plot')
	get_resumetime = indicators.get_resumetime
	get_watched_status = indicators.get_watched_status_episode
	watched_title = 'Trakt' if watched_indicators == 1 else 'Fen'
	if all_episodes:
		episodes_data = metadata.all_episodes_meta(meta, meta_user_info)
		if not settings.show_specials(): episodes_data = [i for i in episodes_data if not i['season'] == 0]
	else: episodes_data = metadata.season_episodes_meta(params['season'], meta, meta_user_info)
	kodi_utils.add_items(__handle__, list(_process()))
	kodi_utils.set_content(__handle__, 'episodes')
	kodi_utils.set_sort_method(__handle__, 'episodes')
	kodi_utils.end_directory(__handle__)
	kodi_utils.set_view_mode('view.episodes', 'episodes')
Ejemplo n.º 9
0
	def _process(item_position, ep_data):
		try:
			cm = []
			listitem = make_listitem()
			set_property = listitem.setProperty
			cm_append = cm.append
			ep_data_get = ep_data.get
			if list_type_starts_with('trakt_'): tmdb_id = get_trakt_tvshow_id(ep_data_get('ids'))
			else: tmdb_id = ep_data_get('tmdb_id')
			if not tmdb_id: return
			meta = metadata.tvshow_meta('tmdb_id', tmdb_id, meta_user_info)
			meta_get = meta.get
			tmdb_id, tvdb_id, imdb_id = meta_get('tmdb_id'), meta_get('tvdb_id'), meta_get('imdb_id')
			title, year, rootname, banner = meta_get('title'), meta_get('year'), meta_get('rootname'), meta_get('banner')
			show_poster = meta_get(poster_main) or meta_get(poster_backup) or poster_empty
			fanart = meta_get(fanart_main) or meta_get(fanart_backup) or fanart_empty
			clearlogo, clearart, landscape = meta_get('clearlogo'), meta_get('clearart'), meta_get('landscape')
			cast, mpaa, duration = meta_get('cast'), meta_get('mpaa'), meta_get('duration')
			trailer, genre, studio = string(meta_get('trailer')), meta_get('genre'), meta_get('studio')
			tvshow_plot = meta_get('plot')
			orig_season = ep_data_get('season')
			orig_episode = ep_data_get('episode')
			if list_type_starts_with('next_episode'):
				season_data = meta_get('season_data')
				curr_season_data = [i for i in season_data if i['season_number'] == orig_season][0]
				orig_season = orig_season if orig_episode < curr_season_data['episode_count'] else orig_season + 1
				orig_episode = orig_episode + 1 if orig_episode < curr_season_data['episode_count'] else 1
			episodes_data = metadata.season_episodes_meta(orig_season, meta, meta_user_info)
			try: item = [i for i in episodes_data if i['episode'] == orig_episode][0]
			except: return
			item_get = item.get
			season = item_get('season')
			episode = item_get('episode')
			ep_name = item_get('title')
			orig_premiered = item_get('premiered')
			all_cast = cast + item_get('guest_stars', [])
			episode_date, premiered = adjust_premiered_date(orig_premiered, adjust_hours)
			if not episode_date or current_date < episode_date:
				if list_type_starts_with('next_episode'):
					if not include_unaired: return
					if not date_difference(current_date, episode_date, 7): return
				elif not show_unaired: return
				unaired = True
				set_property('fen_unaired', 'true')
			else:
				unaired = False
				set_property('fen_unaired', 'false')
			playcount, overlay = get_watched_status(watched_info, string(tmdb_id), season, episode)
			resumetime = get_resumetime(bookmarks, tmdb_id, season, episode)
			if display_title == 0: title_string = '%s: ' % title
			else: title_string = ''
			if display_title in (0,1): seas_ep = '%dx%.2d - ' % (season, episode)
			else: seas_ep = ''
			if list_type_starts_with('next_episode'):
				unwatched = ep_data_get('unwatched', False)
				if episode_date: display_premiered = make_day(current_date, episode_date, date_format)
				else: display_premiered == 'UNKNOWN'
				airdate = '[[COLOR magenta]%s[/COLOR]] ' % display_premiered if include_airdate else ''
				highlight_color = unwatched_color if unwatched else unaired_color if unaired else ''
				italics_open, italics_close = ('[I]', '[/I]') if highlight_color else ('', '')
				if highlight_color: episode_info = '%s[COLOR %s]%s %s[/COLOR]%s' % (italics_open, highlight_color, seas_ep, ep_name, italics_close)
				else: episode_info = '%s%s%s%s' % (italics_open, seas_ep, ep_name, italics_close)
				display = '%s%s%s' % (airdate, upper(title_string), episode_info)
			elif list_type == 'trakt_calendar':
				if episode_date: display_premiered = make_day(current_date, episode_date, date_format)
				else: display_premiered == 'UNKNOWN'
				display = '[%s]%s%s%s' % (display_premiered, upper(title_string), seas_ep, item_get('title'))
				if unaired:
					displays = display.split(']')
					display = '[COLOR red]' + displays[0] + '][/COLOR]' + displays[1]
			else:
				color_tags = ('[COLOR red]', '[/COLOR]') if unaired else ('', '')
				display = '%s%s%s%s%s' % (upper(title_string), color_tags[0], seas_ep, ep_name, color_tags[1])
			thumb = item_get('thumb', None) or fanart
			if thumb_fanart: background = thumb
			else: background = fanart
			item.update({'trailer': trailer, 'tvshowtitle': title, 'premiered': premiered, 'genre': genre, 'duration': duration,
						'mpaa': mpaa, 'studio': studio, 'playcount': playcount, 'overlay': overlay, 'title': display})
			extras_params = build_url({'mode': 'extras_menu_choice', 'tmdb_id': tmdb_id, 'db_type': 'tvshow', 'is_widget': is_widget})
			options_params = build_url({'mode': 'options_menu_choice', 'content': 'episode', 'tmdb_id': tmdb_id, 'season': season, 'episode': episode})
			url_params = build_url({'mode': 'play_media', 'vid_type': 'episode', 'tmdb_id': tmdb_id, 'season': season, 'episode': episode})
			if show_all_episodes:
				if all_episodes == 1 and meta_get('total_seasons') > 1: browse_params = build_url({'mode': 'build_season_list', 'tmdb_id': tmdb_id})
				else: browse_params = build_url({'mode': 'build_episode_list', 'tmdb_id': tmdb_id, 'season': 'all'})
			else: browse_params = build_url({'mode': 'build_season_list', 'tmdb_id': tmdb_id})
			cm_append((extras_str, run_plugin % extras_params))
			cm_append((options_str, run_plugin % options_params))
			cm_append((browse_str, container_update % browse_params))
			clearprog_params, unwatched_params, watched_params = '', '', ''
			if not unaired:
				if resumetime != '0':
					clearprog_params = build_url({'mode': 'watched_unwatched_erase_bookmark', 'db_type': 'episode', 'tmdb_id': tmdb_id,
												'season': season, 'episode': episode, 'refresh': 'true'})
					cm_append((clearprog_str, run_plugin % clearprog_params))
					set_property('fen_in_progress', 'true')
				if playcount:
					unwatched_params = build_url({'mode': 'mark_as_watched_unwatched_episode', 'action': 'mark_as_unwatched', 'tmdb_id': tmdb_id,
												'tvdb_id': tvdb_id, 'season': season, 'episode': episode,  'title': title, 'year': year})
					cm_append((unwatched_str % watched_title, run_plugin % unwatched_params))
				else:
					watched_params = build_url({'mode': 'mark_as_watched_unwatched_episode', 'action': 'mark_as_watched', 'tmdb_id': tmdb_id,
												'tvdb_id': tvdb_id, 'season': season, 'episode': episode,  'title': title, 'year': year})
					cm_append((watched_str % watched_title, run_plugin % watched_params))
			if list_type == 'next_episode_trakt': cm_append((ls(32599), container_update % build_url({'mode': 'build_next_episode_manager'})))
			listitem.setLabel(display)
			listitem.setContentLookup(False)
			listitem.addContextMenuItems(cm)
			listitem.setArt({'poster': show_poster, 'fanart': background, 'thumb': thumb, 'icon':thumb, 'banner': banner, 'clearart': clearart, 'clearlogo': clearlogo,
							'landscape': thumb, 'tvshow.clearart': clearart, 'tvshow.clearlogo': clearlogo, 'tvshow.landscape': thumb, 'tvshow.banner': banner})
			listitem.setCast(all_cast)
			listitem.setUniqueIDs({'imdb': imdb_id, 'tmdb': string(tmdb_id), 'tvdb': string(tvdb_id)})
			listitem.setInfo('video', remove_meta_keys(item, dict_removals))
			set_property('resumetime', resumetime)
			set_property('fen_name', '%s - %.2dx%.2d' % (title, season, episode))
			if list_type_starts_with('next_episode'):
				last_played = ep_data_get('last_played', resinsert)
				set_property('fen_last_played', last_played)
				set_property('fen_first_aired', premiered)
			else: set_property('fen_sort_order', string(item_position))
			if is_widget:
				set_property('fen_widget', 'true')
				set_property('fen_playcount', string(playcount))
				set_property('fen_browse_params', browse_params)
				set_property('fen_options_menu_params', options_params)
				set_property('fen_extras_menu_params', extras_params)
				set_property('fen_unwatched_params', unwatched_params)
				set_property('fen_watched_params', watched_params)
				set_property('fen_clearprog_params', clearprog_params)
			else: set_property('fen_widget', 'false')
			append((url_params, listitem, False))
		except: pass
Ejemplo n.º 10
0
def set_bookmark_kodi_library(db_type,
                              tmdb_id,
                              curr_time,
                              total_time,
                              season='',
                              episode=''):
    meta_user_info = retrieve_user_info()
    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 = execute_JSON(
                '{"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 = execute_JSON(
                '{"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()
            ][0]
        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])
            ][0]
        if db_type == 'episode':
            r = execute_JSON(
                '{"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,
                    "total": total_time
                }
            }
        }
        execute_JSON(json.dumps(query))
    except:
        pass