Пример #1
0
def get_search_term(params):
    kodi_utils.close_all_dialog()
    db_type = params.get('db_type', '')
    query = params.get('query')
    search_type = params.get('search_type', 'media_title')
    if not query:
        from urllib.parse import unquote
        query = kodi_utils.dialog.input('Fen')
        if not query: return
        query = unquote(query)
    if search_type == 'media_title':
        mode, action = ('build_movie_list',
                        'tmdb_movies_search') if db_type == 'movie' else (
                            'build_tvshow_list', 'tmdb_tv_search')
        url = {'mode': mode, 'action': action, 'query': query}
    elif search_type == 'imdb_keyword':
        url = {
            'mode': 'imdb_build_keyword_results',
            'db_type': db_type,
            'query': query
        }
    if kodi_utils.external_browse():
        return kodi_utils.execute_builtin('ActivateWindow(10025,%s,return)' %
                                          kodi_utils.build_url(url))
    return kodi_utils.execute_builtin('Container.Update(%s)' %
                                      kodi_utils.build_url(url))
Пример #2
0
def build_trakt_list(params):
	def _process_ids(item_position, item):
		item['media_id'] = trakt_api.get_trakt_movie_id(item['media_ids']) if item['media_type'] == 'movie' else trakt_api.get_trakt_tvshow_id(item['media_ids'])
		final_append((item_position, item))
	def _add_misc_dir(url_params, list_name=ls(32799), iconImage='item_next.png', isFolder=True):
		icon = kodi_utils.translate_path('special://home/addons/script.tikiart/resources/media/%s' % iconImage)
		listitem = make_listitem()
		listitem.setLabel(list_name)
		listitem.setArt({'icon': icon, 'poster': icon, 'thumb': icon, 'fanart': fanart, 'banner': icon})
		if url_params['mode'] == 'build_navigate_to_page':
			listitem.setProperty('SpecialSort', 'top')
			listitem.addContextMenuItems([(ls(32784),'RunPlugin(%s)' % build_url({'mode': 'toggle_jump_to'}))])
		else:
			listitem.setProperty('SpecialSort', 'bottom')
		kodi_utils.add_item(__handle__, build_url(url_params), listitem, isFolder)
	__handle__ = int(argv[1])
	is_widget = kodi_utils.external_browse()
	user, slug, list_type = params.get('user'), params.get('slug'), params.get('list_type')
	letter, page_no = params.get('new_letter', 'None'), int(params.get('new_page', '1'))
	original_list, final_list, final_listitems = [], [], []
	original_append, final_append = original_list.append, final_list.append
	result = trakt_api.get_trakt_list_contents(list_type, user, slug)
	for item in result:
		try:
			media_type = item['type']
			if not media_type in ('movie', 'show'): continue
			original_append({'media_type': media_type, 'title': item[media_type]['title'], 'media_ids': item[media_type]['ids']})
		except: pass
	if paginate():
		limit = page_limit()
		trakt_list, total_pages = paginate_list(original_list, page_no, letter, limit)
	else:
		trakt_list, total_pages = original_list, 1
	threads = list(make_thread_list_enumerate(_process_ids, trakt_list, Thread))
	[i.join() for i in threads]
	final_list.sort(key=lambda k: k[0])
	final_list = [i[1] for i in final_list]
	movie_list = [(i['media_id'], final_list.index(i), 'movie') for i in final_list if i['media_type'] == 'movie']
	tvshow_list = [(i['media_id'], final_list.index(i), 'tvshow') for i in final_list if i['media_type'] == 'show']
	content = 'movies' if len(movie_list) > len(tvshow_list) else 'tvshows'
	if total_pages > 2 and not is_widget:
		_add_misc_dir({'mode': 'build_navigate_to_page', 'db_type': 'Media', 'user': user, 'slug': slug, 'current_page': page_no, 'total_pages': total_pages,
						'transfer_mode': 'trakt.list.build_trakt_list'}, ls(32964), 'item_jump.png', False)
	if len(movie_list) > 0:
		movie_listitems = Movies({'list': [i[0] for i in movie_list]}).worker()
		final_listitems.extend([(i, x[1]) for i in movie_listitems for x in movie_list if [str(x[0]) == i[1].getUniqueID('tmdb') and x[2] == 'movie'][0]])
	if len(tvshow_list) > 0:
		tvshow_listitems = TVShows({'list': [i[0] for i in tvshow_list]}).worker()
		final_listitems.extend([(i, x[1]) for i in tvshow_listitems for x in tvshow_list if [str(x[0]) == i[1].getUniqueID('tmdb') and x[2] == 'tvshow'][0]])
	final_listitems.sort(key=lambda k: k[1])
	item_list = [i[0] for i in final_listitems]
	kodi_utils.add_items(__handle__, item_list)
	if total_pages > page_no: _add_misc_dir({'mode': 'trakt.list.build_trakt_list', 'user': user, 'slug': slug, 'new_page': str(page_no + 1), 'new_letter': letter})
	kodi_utils.set_content(__handle__, content)
	kodi_utils.end_directory(__handle__)
	if params.get('refreshed'): kodi_utils.sleep(1500)
	kodi_utils.set_view_mode('view.trakt_list', content)
Пример #3
0
def get_episode_info():
	meta_user_info = metadata.retrieve_user_info()
	watched_indicators = settings.watched_indicators()
	watched_info = indicators.get_watched_info_tv(watched_indicators)
	show_unaired = settings.show_unaired()
	thumb_fanart = settings.thumb_fanart()
	is_widget = kodi_utils.external_browse()
	current_date = get_datetime()
	adjust_hours = settings.date_offset()
	bookmarks = indicators.get_bookmarks('episode', watched_indicators)
	return meta_user_info, watched_indicators, watched_info, show_unaired, thumb_fanart, is_widget, current_date, adjust_hours, bookmarks
Пример #4
0
 def worker(self):
     if self.is_widget == 'unchecked':
         self.is_widget = kodi_utils.external_browse()
     if not self.exit_list_params:
         self.exit_list_params = kodi_utils.get_infolabel(
             'Container.FolderPath')
     self.get_info()
     self.watched_title = 'Trakt' if self.watched_indicators == 1 else 'Fen'
     self.poster_main, self.poster_backup, self.fanart_main, self.fanart_backup = settings.get_art_provider(
     )
     self.append = self.items.append
     threads = list(
         make_thread_list_enumerate(self.build_movie_content, self.list,
                                    Thread))
     [i.join() for i in threads]
     self.items.sort(key=lambda k: int(k[1].getProperty('fen_sort_order')))
     return self.items
Пример #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')
Пример #6
0
 def fetch_list(self):
     try:
         params_get = self.params.get
         self.is_widget = kodi_utils.external_browse()
         self.exit_list_params = params_get(
             'exit_list_params',
             None) or kodi_utils.get_infolabel('Container.FolderPath')
         self.handle = int(argv[1])
         content_type = 'tvshows'
         mode = params_get('mode')
         try:
             page_no = int(params_get('new_page', '1'))
         except ValueError:
             page_no = params_get('new_page')
         letter = params_get('new_letter', 'None')
         list_append = self.list.append
         if self.action in personal:
             if self.action == 'favourites_tvshows':
                 var_module, import_function = 'modules.favourites', 'retrieve_favourites'
             elif self.action == 'in_progress_tvshows':
                 var_module, import_function = 'modules.watched_status', 'get_in_progress_tvshows'
             else:
                 var_module, import_function = 'modules.watched_status', 'get_watched_items'
         else:
             var_module, import_function = 'apis.%s_api' % self.action.split(
                 '_')[0], self.action
         try:
             function = manual_function_import(var_module, import_function)
         except:
             pass
         if self.action in tmdb_main:
             data = function(page_no)
             for item in data['results']:
                 list_append(item['id'])
             self.new_page = {
                 'new_page':
                 string(
                     (data['page'] if 'tmdb' in self.action else page_no) +
                     1)
             }
         elif self.action in trakt_main:
             data = function(page_no)
             for item in data:
                 list_append(get_trakt_tvshow_id(item['show']['ids']))
             self.new_page = {
                 'new_page':
                 string(
                     (data['page'] if 'tmdb' in self.action else page_no) +
                     1)
             }
         elif self.action in trakt_personal:
             data, total_pages = function('shows', page_no, letter)
             self.list = [i['media_id'] for i in data]
             if total_pages > 2: self.total_pages = total_pages
             try:
                 if total_pages > page_no:
                     self.new_page = {
                         'new_page': string(page_no + 1),
                         'new_letter': letter
                     }
             except:
                 pass
         elif self.action in imdb_personal:
             self.id_type = 'imdb_id'
             list_id = params_get('list_id', None)
             data, next_page = function('tvshow', list_id, page_no)
             self.list = [i['imdb_id'] for i in data]
             if next_page:
                 self.new_page = {
                     'list_id': list_id,
                     'new_page': string(page_no + 1),
                     'new_letter': letter
                 }
         elif self.action in personal:
             data, total_pages = function('tvshow', page_no, letter)
             self.list = [i['media_id'] for i in data]
             if total_pages > 2: self.total_pages = total_pages
             if total_pages > page_no:
                 self.new_page = {
                     'new_page': string(page_no + 1),
                     'new_letter': letter
                 }
         elif self.action in similar:
             tmdb_id = self.params['tmdb_id']
             data = function(tmdb_id, page_no)
             self.list = [i['id'] for i in data['results']]
             if data['page'] < data['total_pages']:
                 self.new_page = {
                     'new_page': string(data['page'] + 1),
                     'tmdb_id': tmdb_id
                 }
         elif self.action in tmdb_special:
             key = tmdb_special_key_dict[self.action]
             function_var = params_get(key, None)
             if not function_var: return
             data = function(function_var, page_no)
             self.list = [i['id'] for i in data['results']]
             if data['page'] < data['total_pages']:
                 self.new_page = {
                     'new_page': string(data['page'] + 1),
                     key: function_var
                 }
         elif self.action == 'tmdb_tv_discover':
             from indexers.discover import set_history
             name = self.params['name']
             query = self.params['query']
             if page_no == 1: set_history('tvshow', name, query)
             data = function(query, page_no)
             for item in data['results']:
                 list_append(item['id'])
             if data['page'] < data['total_pages']:
                 self.new_page = {
                     'query': query,
                     'name': name,
                     'new_page': string(data['page'] + 1)
                 }
         elif self.action == 'trakt_tv_mosts':
             for item in function(self.params['period'],
                                  self.params['duration'], page_no):
                 list_append((get_trakt_tvshow_id(item['show']['ids'])))
             self.new_page = {
                 'period': self.params['period'],
                 'duration': self.params['duration'],
                 'new_page': string(page_no + 1)
             }
         elif self.action == 'trakt_tv_related':
             imdb_id = params_get('imdb_id')
             data, total_pages = function(imdb_id, page_no)
             for item in data:
                 list_append(get_trakt_tvshow_id(item['ids']))
             if total_pages > page_no:
                 self.new_page = {
                     'new_page': string(page_no + 1),
                     'imdb_id': imdb_id,
                     'imdb_id': params_get('imdb_id')
                 }
         elif self.action == 'tmdb_tv_genres':
             genre_id = self.params[
                 'genre_id'] if 'genre_id' in self.params else self.multiselect_genres(
                     params_get('genre_list'))
             if not genre_id: return
             data = function(genre_id, page_no)
             self.list = [i['id'] for i in data['results']]
             if data['page'] < data['total_pages']:
                 self.new_page = {
                     'new_page': string(data['page'] + 1),
                     'genre_id': genre_id
                 }
         elif self.action == 'trakt_tv_certifications':
             for item in function(self.params['certification'], page_no):
                 list_append((get_trakt_tvshow_id(item['show']['ids'])))
             self.new_page = {
                 'new_page': string(page_no + 1),
                 'certification': self.params['certification']
             }
         elif self.action == 'trakt_recommendations':
             for item in function('shows'):
                 list_append(get_trakt_tvshow_id(item['ids']))
         elif self.action == 'tmdb_tv_search':
             query = self.params['query']
             data = function(query, page_no)
             total_pages = data['total_pages']
             if total_pages > page_no:
                 self.new_page = {
                     'new_page': string(page_no + 1),
                     'query': query
                 }
             self.list = [i['id'] for i in data['results']]
         elif self.action == 'trakt_tv_search':
             query = self.params['query']
             data, total_pages = function(query, page_no, letter)
             for item in data:
                 list_append(get_trakt_tvshow_id(item['show']['ids']))
             if total_pages > page_no:
                 self.new_page = {
                     'new_page': string(page_no + 1),
                     'new_letter': letter,
                     'query': query
                 }
         if self.total_pages and not self.is_widget:
             url_params = {
                 'mode': 'build_navigate_to_page',
                 'db_type': 'TV Shows',
                 'current_page': page_no,
                 'total_pages': self.total_pages,
                 'transfer_mode': mode,
                 'transfer_action': self.action,
                 'query': params_get('search_name', ''),
                 'actor_id': params_get('actor_id', '')
             }
             self.add_dir(url_params, jumpto_str, item_jump, False)
         kodi_utils.add_items(self.handle, self.worker())
         if self.new_page:
             self.new_page.update({
                 'mode': mode,
                 'action': self.action,
                 'exit_list_params': self.exit_list_params
             })
             self.add_dir(self.new_page)
     except:
         pass
     kodi_utils.set_content(self.handle, content_type)
     kodi_utils.end_directory(self.handle)
     kodi_utils.set_view_mode('view.tvshows', content_type)