Exemplo n.º 1
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))
Exemplo n.º 2
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()
Exemplo n.º 3
0
 def get_expiry_hours(self):
     try:
         current_date = get_datetime()
         if self.db_type == 'movie':
             premiered = jsondate_to_datetime(self.premiered,
                                              '%Y-%m-%d',
                                              remove_time=True)
             difference = (current_date - premiered).days
             if difference == 0: self.single_expiry = int(24 * 0.125)
             elif difference <= 10: self.single_expiry = 24 * 1
             elif difference <= 14: self.single_expiry = 24 * 3
             elif difference <= 180: self.single_expiry = 24 * 180
             else: self.single_expiry = 24 * 365
         else:
             extra_info = self.meta['extra_info']
             ended = extra_info['status'].lower() in ('ended', 'canceled')
             premiered = adjust_premiered_date(self.premiered,
                                               date_offset())[0]
             difference = (current_date - premiered).days
             last_episode_to_air = jsondate_to_datetime(
                 extra_info['last_episode_to_air']['air_date'],
                 '%Y-%m-%d',
                 remove_time=True)
             last_ep_difference = (current_date - last_episode_to_air).days
             if ended:
                 if last_ep_difference <= 30: recently_ended = True
                 else: recently_ended = False
             if not ended or recently_ended:
                 if difference == 0: self.single_expiry = int(24 * 0.125)
                 elif difference <= 3: self.single_expiry = 24 * 1
                 elif difference <= 7: self.single_expiry = 24 * 3
                 elif difference <= 14: self.single_expiry = 24 * 14
                 elif difference <= 28: self.single_expiry = 24 * 180
                 else: self.single_expiry = 24 * 365
                 if self.meta[
                         'total_seasons'] == self.season and last_ep_difference <= 21:
                     self.season_expiry = 24 * 10
                 else:
                     self.season_expiry = 24 * 365
                 self.show_expiry = 24 * 10
             else:
                 self.single_expiry = 24 * 365
                 self.season_expiry = 24 * 365
                 self.show_expiry = 24 * 365
     except:
         self.single_expiry, self.season_expiry, self.show_expiry = 24, 336, 336
Exemplo n.º 4
0
def pack_enable_check(meta, season, episode):
    try:
        extra_info = meta['extra_info']
        status = extra_info['status'].lower()
        if status in ('ended', 'canceled'): return True, True
        from metadata import season_episodes_meta, retrieve_user_info
        from modules.utils import adjust_premiered_date, get_datetime
        adjust_hours = date_offset()
        current_date = get_datetime()
        meta_user_info = retrieve_user_info()
        episodes_data = season_episodes_meta(season, meta, meta_user_info)
        unaired_episodes = [
            adjust_premiered_date(i['premiered'], adjust_hours)[0]
            for i in episodes_data
        ]
        if None in unaired_episodes or any(i > current_date
                                           for i in unaired_episodes):
            return False, False
        else:
            return True, False
    except:
        pass
    return False, False
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
	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
Exemplo n.º 7
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