def handle_tmdb_images(results): images = [] for item in results: artwork = get_image_urls(poster=item.get('file_path')) image = { 'aspectratio': item['aspect_ratio'], 'vote_average': Utils.fetch(item, 'vote_average'), 'iso_639_1': Utils.fetch(item, 'iso_639_1') } image.update(artwork) images.append(image) return images
def handle_tmdb_seasons(results): listitems = [] for season in results: season_number = str(Utils.fetch(season, 'season_number')) artwork = get_image_urls(poster=season.get('poster_path')) title = 'Specials' if season_number == '0' else u'Season %s' % season_number listitem = { 'media_type': 'season', 'title': title, 'season': season_number, 'air_date': Utils.fetch(season, 'air_date'), 'year': Utils.get_year(Utils.fetch(season, 'air_date')), 'id': Utils.fetch(season, 'id') } listitem.update(artwork) listitems.append(listitem) return listitems
def play_episode_choose_player(self): if self.dbid and int(self.dbid) > 0: dbid = self.dbid url = '' PLAYER.play_from_button(url, listitem=None, window=self, type='episodeid', dbid=dbid) else: url = 'plugin://plugin.video.chappaai/tv/play_choose_player/%s/%s/%s/False' % (Utils.fetch(TheMovieDB.get_tvshow_ids(self.tvshow_id), 'tvdb_id'), self.info['season'], self.info['episode']) xbmc.executebuiltin('RunPlugin(%s)' % url)
def handle_tmdb_tagged_images(results): images = [] for item in results: artwork = get_image_urls(poster=item.get('file_path')) image = { 'aspectratio': item['aspect_ratio'], 'vote_average': Utils.fetch(item, 'vote_average'), 'iso_639_1': Utils.fetch(item, 'iso_639_1'), 'title': Utils.fetch(item['media'], 'title'), 'mediaposter': 'https://image.tmdb.org/t/p/w500' + Utils.fetch(item['media'], 'poster_path') } image.update(artwork) images.append(image) return images
def handle_tmdb_videos(results): listitems = [] for item in results: image = 'https://i.ytimg.com/vi/%s/0.jpg' % Utils.fetch(item, 'key') listitem = { 'thumb': image, 'title': Utils.fetch(item, 'name'), 'iso_639_1': Utils.fetch(item, 'iso_639_1'), 'type': Utils.fetch(item, 'type'), 'key': Utils.fetch(item, 'key'), 'youtube_id': Utils.fetch(item, 'key'), 'site': Utils.fetch(item, 'site'), 'id': Utils.fetch(item, 'id'), 'size': Utils.fetch(item, 'size') } listitems.append(listitem) return listitems
def get_imdb_id_from_movie_id(movie_id=None, cache_time=14): if not movie_id: return None session_str = '' response = get_tmdb_data( 'movie/%s?&language=%s,null,%s&%s' % (movie_id, xbmcaddon.Addon().getSetting('LanguageID'), xbmcaddon.Addon().getSetting('LanguageID'), session_str), cache_time) if not response: return False imdb_id = Utils.fetch(response, 'imdb_id') return imdb_id
def get_tvshow_ids(tvshow_id=None, cache_time=14): if not tvshow_id: return None session_str = '' response = get_tmdb_data( 'tv/%s?append_to_response=external_ids&language=%s&include_image_language=en,null,%s&%s' % (tvshow_id, xbmcaddon.Addon().getSetting('LanguageID'), xbmcaddon.Addon().getSetting('LanguageID'), session_str), cache_time) if not response: return False external_ids = Utils.fetch(response, 'external_ids') return external_ids
def get_keywords(movie_id): response = get_tmdb_data( 'movie/%s?append_to_response=alternative_titles,credits,images,keywords,releases,videos,translations,similar,reviews,rating&include_image_language=en,null,%s&language=%s&' % (movie_id, xbmcaddon.Addon().getSetting('LanguageID'), xbmcaddon.Addon().getSetting('LanguageID')), 30) keywords = [] if 'keywords' in response: for keyword in response['keywords']['keywords']: keyword_dict = { 'id': Utils.fetch(keyword, 'id'), 'name': keyword['name'] } keywords.append(keyword_dict) return keywords
def play_episode_choose_player(self): Utils.show_busy() # window_id = xbmcgui.getCurrentWindowDialogId() # xbmc.log(str(window_id)+'===>OPENINFO', level=xbmc.LOGNOTICE) url = 'plugin://plugin.video.openmeta/tv/play_choose_player/%s/%s/%s/False' % (Utils.fetch(TheMovieDB.get_tvshow_ids(self.tvshow_id), 'tvdb_id'), self.info['season'], self.info['episode']) # PLAYER.play_from_button(url, listitem=None, window=self, type='episodeid', dbid=dbid) # xbmc.executebuiltin('Dialog.Close(%s, true)' % window_id) # xbmc.executebuiltin('RunPlugin(%s)' % url) if self.dbid and int(self.dbid) > 0: dbid = self.dbid # url = '' PLAYER.play_from_button(url, listitem=None, window=self, type='episodeid', dbid=dbid) # else: # url = 'plugin://plugin.video.openmeta/tv/play_choose_player/%s/%s/%s/False' % (Utils.fetch(TheMovieDB.get_tvshow_ids(self.tvshow_id), 'tvdb_id'), self.info['season'], self.info['episode']) PLAYER.play_from_button(url, listitem=None, window=self, type='episodeid', dbid=0)
def play_episode(self): if self.dbid: dbid = self.dbid url = '' else: dbid = 0 url = 'plugin://plugin.video.openmeta/tv/play/%s/%s/%s' % ( Utils.fetch( TheMovieDB.get_tvshow_ids(self.tvshow_id), 'tvdb_id'), self.info['season'], self.info['episode']) PLAYER.play_from_button(url, listitem=None, window=self, type='episodeid', dbid=dbid)
def handle_tmdb_tvshows(results, local_first=True, sortkey='year'): tvshows = [] response = get_tmdb_data( 'genre/tv/list?language=%s&' % xbmcaddon.Addon().getSetting('LanguageID'), 30) id_list = [item['id'] for item in response['genres']] label_list = [item['name'] for item in response['genres']] for tv in results: tmdb_id = Utils.fetch(tv, 'id') artwork = get_image_urls(poster=tv.get('poster_path'), fanart=tv.get('backdrop_path')) if 'genre_ids' in tv: genre_list = [ label_list[id_list.index(genre_id)] for genre_id in tv['genre_ids'] if genre_id in id_list ] genres = ' / '.join(genre_list) else: genres = '' duration = '' if 'episode_run_time' in tv: if len(tv['episode_run_time']) > 1: duration = '%i - %i' % (min( tv['episode_run_time']), max(tv['episode_run_time'])) elif len(tv['episode_run_time']) == 1: duration = '%i' % tv['episode_run_time'][0] newtv = { 'title': Utils.fetch(tv, 'name'), 'TVShowTitle': Utils.fetch(tv, 'name'), 'OriginalTitle': Utils.fetch(tv, 'original_name'), 'duration': duration, 'id': tmdb_id, 'genre': genres, 'country': Utils.fetch(tv, 'original_language'), 'Popularity': Utils.fetch(tv, 'popularity'), 'credit_id': Utils.fetch(tv, 'credit_id'), 'Plot': Utils.fetch(tv, 'overview'), 'Trailer': 'plugin://script.extendedinfo?info=tvtrailer&&id=%s' % tmdb_id, 'year': Utils.get_year(Utils.fetch(tv, 'first_air_date')), 'media_type': 'tv', 'character': Utils.fetch(tv, 'character'), 'path': 'plugin://script.extendedinfo?info=extendedtvinfo&&id=%s' % tmdb_id, 'Rating': Utils.fetch(tv, 'vote_average'), 'User_Rating': str(Utils.fetch(tv, 'rating')), 'Votes': Utils.fetch(tv, 'vote_count'), 'TotalEpisodes': Utils.fetch(tv, 'number_of_episodes'), 'TotalSeasons': Utils.fetch(tv, 'number_of_seasons'), 'Release_Date': Utils.fetch(tv, 'first_air_date'), 'Premiered': Utils.fetch(tv, 'first_air_date') } newtv.update(artwork) date = Utils.fetch(tv, 'first_air_date') tvshows.append(newtv) tvshows = local_db.merge_with_local_tvshow_info(tvshows, local_first, sortkey) return tvshows
def context_menu(self): if self.listitem.getProperty( 'dbid') and self.listitem.getProperty('dbid') != 0: dbid = self.listitem.getProperty('dbid') else: dbid = 0 item_id = self.listitem.getProperty('id') if self.type == 'tv': imdb_id = Utils.fetch(TheMovieDB.get_tvshow_ids(item_id), 'imdb_id') tvdb_id = Utils.fetch(TheMovieDB.get_tvshow_ids(item_id), 'tvdb_id') elif self.type == "episode": tvdb_id = self.listitem.getProperty("tvdb_id") imdb_id = self.listitem.getProperty("imdb_id") else: imdb_id = TheMovieDB.get_imdb_id_from_movie_id(item_id) if self.listitem.getProperty('TVShowTitle'): listitems = ['Play first episode'] else: listitems = ['Play'] if self.listitem.getProperty('dbid'): listitems += ['Remove from library'] else: listitems += ['Add to library'] listitems += ['Trailer'] if self.type == "tv": listitems += ['Rate TV show'] elif self.type == "episode": listitems += ['Library: all tvshows'] else: listitems += ['Rate movie'] listitems += [LANG(14076)] if self.type == "tv" or self.type == "episode": if self.listitem.getProperty("dbid"): listitems = [LANG(208)] if not self.type == "tv" or self.type == "episode": listitems += ['Add to list'] if self.mode == "list": listitems += ['Remove from list'] if self.type == "movie" and xbmc.getCondVisibility( "system.hasaddon(plugin.video.couchpotato_manager)"): listitems += ['Add to CouchPotato'] if xbmc.getCondVisibility( "system.hasaddon(plugin.video.trakt_list_manager)"): listitems += ['Visit : [COLOR skyblue]%s[/COLOR]'] if self.type == "tv" and xbmc.getCondVisibility( "system.hasaddon(plugin.video.sickrage)"): listitems += ['Add to SickBeard'] if self.trakt_account and (self.type == 'movie' or self.type == 'tv'): listitems += ['Trakt Manager'] selection = xbmcgui.Dialog().select(heading='Choose option', list=listitems) if selection != -1 and listitems[selection] == 'Trakt Manager': name = self.listitem.getProperty("title") if self.type == "movie": content = "movie" else: content = "tvshow" xbmc.executebuiltin( "RunScript(script.extendedinfo,info=traktManager,name=%s,tmdb=%s,content=%s)" % (name, item_id, content)) elif selection == 0: if self.listitem.getProperty('TVShowTitle'): url = 'plugin://plugin.video.chappaai/tv/play/%s/1/1' % tvdb_id PLAYER.play_from_button(url, listitem=None, window=self, dbid=0) else: if self.listitem.getProperty('dbid'): dbid = self.listitem.getProperty('dbid') url = '' else: dbid = 0 url = 'plugin://plugin.video.chappaai/movies/play/tmdb/%s' % item_id PLAYER.play_from_button(url, listitem=None, window=self, type='movieid', dbid=dbid) if selection == 1: if self.listitem.getProperty('TVShowTitle'): TVLibrary = xbmcaddon.Addon( 'plugin.video.chappaai').getSetting( 'tv_library_folder') if self.listitem.getProperty('dbid'): Utils.get_kodi_json(method='VideoLibrary.RemoveTVShow', params='{"tvshowid": %s}' % dbid) if os.path.exists( xbmc.translatePath('%s%s/' % (TVLibrary, tvdb_id))): shutil.rmtree( xbmc.translatePath('%s%s/' % (TVLibrary, tvdb_id))) Utils.after_add(type='tv') Utils.notify( header='[B]%s[/B]' % self.listitem.getProperty('TVShowTitle'), message='Removed from library', icon=self.listitem.getProperty('poster'), time=5000, sound=False) xbmc.sleep(250) self.update(force_update=True) self.getControl(500).selectItem(self.position) else: if xbmcgui.Dialog().yesno( 'Wraith', 'Add [B]%s[/B] to library?' % self.listitem.getProperty('TVShowTitle')): xbmc.executebuiltin( 'RunPlugin(plugin://plugin.video.chappaai/tv/add_to_library/%s)' % tvdb_id) Utils.after_add(type='tv') Utils.notify( header='[B]%s[/B] added to library' % self.listitem.getProperty('TVShowTitle'), message='Exit & re-enter to refresh', icon=self.listitem.getProperty('poster'), time=5000, sound=False) else: if self.listitem.getProperty('dbid'): if xbmcgui.Dialog().yesno( 'Wraith', 'Remove [B]%s[/B] from library?' % self.listitem.getProperty('title')): Utils.get_kodi_json( method='VideoLibrary.RemoveMovie', params='{"movieid": %s}' % dbid) MovieLibrary = xbmcaddon.Addon( 'plugin.video.chappaai').getSetting( 'movies_library_folder') if os.path.exists( xbmc.translatePath( '%s%s/' % (MovieLibrary, imdb_id))): shutil.rmtree( xbmc.translatePath( '%s%s/' % (MovieLibrary, imdb_id))) Utils.after_add(type='movie') Utils.notify( header='[B]%s[/B]' % self.listitem.getProperty('title'), message='Removed from library', icon=self.listitem.getProperty('poster'), time=5000, sound=False) xbmc.sleep(250) self.update(force_update=True) self.getControl(500).selectItem(self.position) else: if xbmcgui.Dialog().yesno( 'Wraith', 'Add [B]%s[/B] to library?' % self.listitem.getProperty('title')): xbmc.executebuiltin( 'RunPlugin(plugin://plugin.video.chappaai/movies/add_to_library/tmdb/%s)' % item_id) Utils.after_add(type='movie') Utils.notify( header='[B]%s[/B] added to library' % self.listitem.getProperty('title'), message='Exit & re-enter to refresh', icon=self.listitem.getProperty('poster'), time=5000, sound=False) if selection == 2: if self.listitem.getProperty('TVShowTitle'): url = 'plugin://script.extendedinfo?info=playtvtrailer&&id=' + item_id else: url = 'plugin://script.extendedinfo?info=playtrailer&&id=' + item_id PLAYER.play(url, listitem=None, window=self)
def extended_episode_info(tvshow_id, season, episode, cache_time=7): if not tvshow_id or not episode: return None if not season: season = 0 session_str = '' tvshow = get_tmdb_data( 'tv/%s?append_to_response=alternative_titles,content_ratings,credits,external_ids,images,keywords,rating,similar,translations,videos&language=%s&include_image_language=en,null,%s&%s' % (tvshow_id, xbmcaddon.Addon().getSetting('LanguageID'), xbmcaddon.Addon().getSetting('LanguageID'), session_str), 99999) response = get_tmdb_data( 'tv/%s/season/%s/episode/%s?append_to_response=credits,external_ids,images,rating,videos&language=%s&include_image_language=en,null,%s&%s&' % (tvshow_id, season, episode, xbmcaddon.Addon().getSetting('LanguageID'), xbmcaddon.Addon().getSetting('LanguageID'), session_str), cache_time) tmdb_id = Utils.fetch(tvshow, 'id') TVShowTitle = Utils.fetch(tvshow, 'name') external_ids = Utils.fetch(tvshow, 'external_ids') year = Utils.get_year(Utils.fetch(tvshow, 'first_air_date')), if external_ids: imdb_id = Utils.fetch(external_ids, 'imdb_id') freebase_id = Utils.fetch(external_ids, 'freebase_id') tvdb_id = Utils.fetch(external_ids, 'tvdb_id') tvrage_id = Utils.fetch(external_ids, 'tvrage_id') videos = handle_tmdb_videos( response['videos']['results']) if 'videos' in response else [] try: actors = handle_tmdb_people(response['credits']['cast']) except: actors = [] try: crew = handle_tmdb_people(response['credits']['crew']) except: crew = [] try: guest_stars = handle_tmdb_people(response['credits']['guest_stars']) except: guest_stars = [] try: images = handle_tmdb_images(response['images']['stills']) except: images = [] answer = { 'SeasonDescription': Utils.clean_text(response['overview']), 'Plot': Utils.clean_text(response['overview']), 'TVShowTitle': TVShowTitle, 'tvshow_id': tmdb_id, 'tvdb_id': tvdb_id, 'actors': actors, 'path': 'plugin://script.extendedinfo?info=extendedepisodeinfo&tvshow_id=%s&season=%s&episode=%s' % (tvshow_id, season, episode), 'crew': crew, 'guest_stars': guest_stars, 'videos': videos, 'images': images } return (handle_tmdb_episodes([response])[0], answer)
def extended_season_info(tvshow_id, season_number): if not tvshow_id or not season_number: return None session_str = '' tvshow = get_tmdb_data( 'tv/%s?append_to_response=alternative_titles,content_ratings,credits,external_ids,images,keywords,rating,similar,translations,videos&language=%s&include_image_language=en,null,%s&%s' % (tvshow_id, xbmcaddon.Addon().getSetting('LanguageID'), xbmcaddon.Addon().getSetting('LanguageID'), session_str), 99999) response = get_tmdb_data( 'tv/%s/season/%s?append_to_response=videos,images,external_ids,credits&language=%s&include_image_language=en,null,%s&' % (tvshow_id, season_number, xbmcaddon.Addon().getSetting('LanguageID'), xbmcaddon.Addon().getSetting('LanguageID')), 7) dbid = Utils.fetch(tvshow, 'dbid') tmdb_id = Utils.fetch(tvshow, 'id') external_ids = Utils.fetch(tvshow, 'external_ids') year = Utils.get_year(Utils.fetch(tvshow, 'first_air_date')) if external_ids: imdb_id = Utils.fetch(external_ids, 'imdb_id') freebase_id = Utils.fetch(external_ids, 'freebase_id') tvdb_id = Utils.fetch(external_ids, 'tvdb_id') tvrage_id = Utils.fetch(external_ids, 'tvrage_id') if not response: Utils.notify('Could not find season info') return None if response.get('name', False): title = response['name'] else: title = 'Specials' if season_number == '0' else u'Season %s' % season_number season = { 'SeasonDescription': Utils.clean_text(response['overview']), 'Plot': Utils.clean_text(response['overview']), 'TVShowTitle': Utils.fetch(tvshow, 'name'), 'title': title, 'dbid': dbid, 'imdb_id': imdb_id, 'tmdb_id': tmdb_id, 'tvdb_id': tvdb_id, 'tvrage_id': tvrage_id, 'year': year, 'season': season_number, 'path': 'plugin://script.extendedinfo?info=seasoninfo&tvshow=%s&season=%s' % (Utils.fetch(tvshow, 'name'), season_number), 'release_date': response['air_date'], 'AirDate': response['air_date'] } artwork = get_image_urls(poster=response.get('poster_path')) season.update(artwork) videos = handle_tmdb_videos( response['videos']['results']) if 'videos' in response else [] listitems = { 'actors': handle_tmdb_people(response['credits']['cast']), 'crew': handle_tmdb_people(response['credits']['crew']), 'videos': videos, 'episodes': handle_tmdb_episodes(response['episodes']), 'images': handle_tmdb_images(response['images']['posters']) } return (season, listitems)
def extended_tvshow_info(tvshow_id=None, cache_time=7, dbid=None): if not tvshow_id: return None session_str = '' response = get_tmdb_data( 'tv/%s?append_to_response=alternative_titles,content_ratings,credits,external_ids,images,keywords,rating,similar,translations,videos&language=%s&include_image_language=en,null,%s&%s' % (tvshow_id, xbmcaddon.Addon().getSetting('LanguageID'), xbmcaddon.Addon().getSetting('LanguageID'), session_str), cache_time) if not response: return False videos = handle_tmdb_videos( response['videos']['results']) if 'videos' in response else [] tmdb_id = Utils.fetch(response, 'id') external_ids = Utils.fetch(response, 'external_ids') if external_ids: imdb_id = Utils.fetch(external_ids, 'imdb_id') freebase_id = Utils.fetch(external_ids, 'freebase_id') tvdb_id = Utils.fetch(external_ids, 'tvdb_id') tvrage_id = Utils.fetch(external_ids, 'tvrage_id') artwork = get_image_urls(poster=response.get('poster_path'), fanart=response.get('backdrop_path')) if len(response.get('episode_run_time', -1)) > 1: duration = '%i - %i' % (min( response['episode_run_time']), max(response['episode_run_time'])) elif len(response.get('episode_run_time', -1)) == 1: duration = '%i' % response['episode_run_time'][0] else: duration = '' us_cert = Utils.dictfind(response['content_ratings']['results'], 'iso_3166_1', 'US') if us_cert: mpaa = us_cert['rating'] elif response['content_ratings']['results']: mpaa = response['content_ratings']['results'][0]['rating'] else: mpaa = '' genres = [item['name'] for item in response['genres']] tvshow = { 'title': Utils.fetch(response, 'name'), 'TVShowTitle': Utils.fetch(response, 'name'), 'OriginalTitle': Utils.fetch(response, 'original_name'), 'duration': duration, 'duration(h)': Utils.format_time(duration, 'h'), 'duration(m)': Utils.format_time(duration, 'm'), 'id': tmdb_id, 'tmdb_id': tmdb_id, 'imdb_id': imdb_id, 'freebase_id': freebase_id, 'tvdb_id': tvdb_id, 'tvrage_id': tvrage_id, 'mpaa': mpaa, 'genre': ' / '.join(genres), 'credit_id': Utils.fetch(response, 'credit_id'), 'Plot': Utils.clean_text(Utils.fetch(response, 'overview')), 'year': Utils.get_year(Utils.fetch(response, 'first_air_date')), 'media_type': 'tv', 'Popularity': Utils.fetch(response, 'popularity'), 'Rating': Utils.fetch(response, 'vote_average'), 'country': Utils.fetch(response, 'original_language'), 'User_Rating': str(Utils.fetch(response, 'rating')), 'Votes': Utils.fetch(response, 'vote_count'), 'Status': translate_status(Utils.fetch(response, 'status')), 'path': 'plugin://script.extendedinfo?info=extendedtvinfo&&id=%s' % tvshow_id, 'trailer': 'plugin://script.extendedinfo?info=playtvtrailer&&id=%s' % tvshow_id, 'ShowType': Utils.fetch(response, 'type'), 'homepage': Utils.fetch(response, 'homepage'), 'last_air_date': Utils.fetch(response, 'last_air_date'), 'first_air_date': Utils.fetch(response, 'first_air_date'), 'TotalEpisodes': Utils.fetch(response, 'number_of_episodes'), 'TotalSeasons': Utils.fetch(response, 'number_of_seasons'), 'in_production': Utils.fetch(response, 'in_production'), 'Release_Date': Utils.fetch(response, 'first_air_date'), 'Premiered': Utils.fetch(response, 'first_air_date') } tvshow.update(artwork) if dbid: local_item = local_db.get_tvshow_from_db(dbid) tvshow.update(local_item) else: tvshow = local_db.merge_with_local_tvshow_info([tvshow])[0] tvshow['Rating'] = Utils.fetch(response, 'vote_average') listitems = { 'actors': handle_tmdb_people(response['credits']['cast']), 'similar': handle_tmdb_tvshows(response['similar']['results']), 'studios': handle_tmdb_misc(response['production_companies']), 'networks': handle_tmdb_misc(response['networks']), 'certifications': handle_tmdb_misc(response['content_ratings']['results']), 'crew': handle_tmdb_people(response['credits']['crew']), 'genres': handle_tmdb_misc(response['genres']), 'keywords': handle_tmdb_misc(response['keywords']['results']), 'videos': videos, 'seasons': handle_tmdb_seasons(response['seasons']), 'images': handle_tmdb_images(response['images']['posters']), 'backdrops': handle_tmdb_images(response['images']['backdrops']) } return (tvshow, listitems)
def extended_movie_info(movie_id=None, dbid=None, cache_time=14): if not movie_id: return None session_str = '' response = get_tmdb_data( 'movie/%s?append_to_response=alternative_titles,credits,images,keywords,releases,videos,translations,similar,reviews,rating&include_image_language=en,null,%s&language=%s&%s' % (movie_id, xbmcaddon.Addon().getSetting('LanguageID'), xbmcaddon.Addon().getSetting('LanguageID'), session_str), cache_time) if not response: Utils.notify('Could not get movie information', sound=False) return {} mpaa = '' set_name = '' set_id = '' genres = [i['name'] for i in response['genres']] Studio = [i['name'] for i in response['production_companies']] authors = [ i['name'] for i in response['credits']['crew'] if i['department'] == 'Writing' ] directors = [ i['name'] for i in response['credits']['crew'] if i['department'] == 'Directing' ] us_cert = Utils.dictfind(response['releases']['countries'], 'iso_3166_1', 'US') if us_cert: mpaa = us_cert['certification'] elif response['releases']['countries']: mpaa = response['releases']['countries'][0]['certification'] movie_set = Utils.fetch(response, 'belongs_to_collection') if movie_set: set_name = Utils.fetch(movie_set, 'name') set_id = Utils.fetch(movie_set, 'id') artwork = get_image_urls(poster=response.get('poster_path'), fanart=response.get('backdrop_path')) movie = { 'title': Utils.fetch(response, 'title'), 'Label': Utils.fetch(response, 'title'), 'Tagline': Utils.fetch(response, 'tagline'), 'duration': Utils.fetch(response, 'runtime'), 'duration(h)': Utils.format_time(Utils.fetch(response, 'runtime'), 'h'), 'duration(m)': Utils.format_time(Utils.fetch(response, 'runtime'), 'm'), 'duration(hm)': Utils.format_time(Utils.fetch(response, 'runtime')), 'mpaa': mpaa, 'Director': ' / '.join(directors), 'writer': ' / '.join(authors), 'Budget': Utils.millify(Utils.fetch(response, 'budget')), 'Revenue': Utils.millify(Utils.fetch(response, 'revenue')), 'Homepage': Utils.fetch(response, 'homepage'), 'Set': set_name, 'SetId': set_id, 'id': Utils.fetch(response, 'id'), 'tmdb_id': Utils.fetch(response, 'id'), 'imdb_id': Utils.fetch(response, 'imdb_id'), 'Plot': Utils.clean_text(Utils.fetch(response, 'overview')), 'OriginalTitle': Utils.fetch(response, 'original_title'), 'Country': Utils.fetch(response, 'original_language'), 'genre': ' / '.join(genres), 'Rating': Utils.fetch(response, 'vote_average'), 'Votes': Utils.fetch(response, 'vote_count'), 'Adult': str(Utils.fetch(response, 'adult')), 'Popularity': Utils.fetch(response, 'popularity'), 'Status': translate_status(Utils.fetch(response, 'status')), 'release_date': Utils.fetch(response, 'release_date'), 'Premiered': Utils.fetch(response, 'release_date'), 'Studio': ' / '.join(Studio), 'year': Utils.get_year(Utils.fetch(response, 'release_date')), 'path': 'plugin://script.extendedinfo?info=extendedinfo&&id=%s' % movie_id, 'trailer': 'plugin://script.extendedinfo?info=playtrailer&&id=%s' % movie_id } movie.update(artwork) videos = handle_tmdb_videos( response['videos']['results']) if 'videos' in response else [] if dbid: local_item = local_db.get_movie_from_db(dbid) movie.update(local_item) else: movie = local_db.merge_with_local_movie_info([movie])[0] movie['Rating'] = Utils.fetch(response, 'vote_average') listitems = { 'actors': handle_tmdb_people(response['credits']['cast']), 'similar': handle_tmdb_movies(response['similar']['results']), 'studios': handle_tmdb_misc(response['production_companies']), 'releases': handle_tmdb_misc(response['releases']['countries']), 'crew': handle_tmdb_people(response['credits']['crew']), 'genres': handle_tmdb_misc(response['genres']), 'keywords': handle_tmdb_misc(response['keywords']['keywords']), 'reviews': handle_tmdb_misc(response['reviews']['results']), 'videos': videos, 'images': handle_tmdb_images(response['images']['posters']), 'backdrops': handle_tmdb_images(response['images']['backdrops']) } return (movie, listitems)
def handle_tmdb_movies(results=[], local_first=True, sortkey='year'): response = get_tmdb_data( 'genre/movie/list?language=%s&' % xbmcaddon.Addon().getSetting('LanguageID'), 30) id_list = [item['id'] for item in response['genres']] label_list = [item['name'] for item in response['genres']] movies = [] for movie in results: if 'genre_ids' in movie: genre_list = [ label_list[id_list.index(genre_id)] for genre_id in movie['genre_ids'] if genre_id in id_list ] genres = ' / '.join(genre_list) else: genres = '' tmdb_id = str(Utils.fetch(movie, 'id')) artwork = get_image_urls(poster=movie.get('poster_path'), fanart=movie.get('backdrop_path')) trailer = 'plugin://script.extendedinfo?info=playtrailer&&id=' + tmdb_id path = 'plugin://script.extendedinfo?info=extendedinfo&&id=' + tmdb_id listitem = { 'title': Utils.fetch(movie, 'title'), 'Label': Utils.fetch(movie, 'title'), 'OriginalTitle': Utils.fetch(movie, 'original_title'), 'id': tmdb_id, 'path': path, 'media_type': 'movie', 'country': Utils.fetch(movie, 'original_language'), 'plot': Utils.fetch(movie, 'overview'), 'Trailer': trailer, 'Popularity': Utils.fetch(movie, 'popularity'), 'Rating': Utils.fetch(movie, 'vote_average'), 'credit_id': Utils.fetch(movie, 'credit_id'), 'character': Utils.fetch(movie, 'character'), 'job': Utils.fetch(movie, 'job'), 'department': Utils.fetch(movie, 'department'), 'Votes': Utils.fetch(movie, 'vote_count'), 'User_Rating': Utils.fetch(movie, 'rating'), 'year': Utils.get_year(Utils.fetch(movie, 'release_date')), 'genre': genres, 'Premiered': Utils.fetch(movie, 'release_date') } listitem.update(artwork) date = Utils.fetch(movie, 'release_date') movies.append(listitem) movies = local_db.merge_with_local_movie_info(movies, local_first, sortkey) return movies
def context_menu(self): if self.listitem.getProperty( 'dbid') and self.listitem.getProperty('dbid') != 0: dbid = self.listitem.getProperty('dbid') else: dbid = 0 item_id = self.listitem.getProperty('id') if self.type == 'tv': imdb_id = Utils.fetch(TheMovieDB.get_tvshow_ids(item_id), 'imdb_id') tvdb_id = Utils.fetch(TheMovieDB.get_tvshow_ids(item_id), 'tvdb_id') else: imdb_id = TheMovieDB.get_imdb_id_from_movie_id(item_id) if self.listitem.getProperty('TVShowTitle'): listitems = ['Play first episode'] else: listitems = ['Play'] if self.listitem.getProperty('dbid'): listitems += ['Remove from library'] else: listitems += ['Add to library'] listitems += ['Trailer'] selection = xbmcgui.Dialog().select(heading='Choose option', list=listitems) if selection == 0: if self.listitem.getProperty('TVShowTitle'): url = 'plugin://plugin.video.openmeta/tv/play/%s/1/1' % tvdb_id PLAYER.play_from_button(url, listitem=None, window=self, dbid=0) else: if self.listitem.getProperty('dbid'): dbid = self.listitem.getProperty('dbid') url = '' else: dbid = 0 url = 'plugin://plugin.video.openmeta/movies/play/tmdb/%s' % item_id PLAYER.play_from_button(url, listitem=None, window=self, type='movieid', dbid=dbid) if selection == 1: if self.listitem.getProperty('TVShowTitle'): TVLibrary = xbmcaddon.Addon( 'plugin.video.openmeta').getSetting( 'tv_library_folder') if self.listitem.getProperty('dbid'): Utils.get_kodi_json(method='VideoLibrary.RemoveTVShow', params='{"tvshowid": %s}' % dbid) if os.path.exists( xbmc.translatePath('%s%s/' % (TVLibrary, tvdb_id))): shutil.rmtree( xbmc.translatePath('%s%s/' % (TVLibrary, tvdb_id))) Utils.after_add(type='tv') Utils.notify( header='[B]%s[/B]' % self.listitem.getProperty('TVShowTitle'), message='Removed from library', icon=self.listitem.getProperty('poster'), time=5000, sound=False) xbmc.sleep(250) self.update(force_update=True) self.getControl(500).selectItem(self.position) else: if xbmcgui.Dialog().yesno( 'OpenInfo', 'Add [B]%s[/B] to library?' % self.listitem.getProperty('TVShowTitle')): xbmc.executebuiltin( 'RunPlugin(plugin://plugin.video.openmeta/tv/add_to_library/%s)' % tvdb_id) Utils.after_add(type='tv') Utils.notify( header='[B]%s[/B] added to library' % self.listitem.getProperty('TVShowTitle'), message='Exit & re-enter to refresh', icon=self.listitem.getProperty('poster'), time=5000, sound=False) else: if self.listitem.getProperty('dbid'): if xbmcgui.Dialog().yesno( 'OpenInfo', 'Remove [B]%s[/B] from library?' % self.listitem.getProperty('title')): Utils.get_kodi_json( method='VideoLibrary.RemoveMovie', params='{"movieid": %s}' % dbid) MovieLibrary = xbmcaddon.Addon( 'plugin.video.openmeta').getSetting( 'movies_library_folder') if os.path.exists( xbmc.translatePath( '%s%s/' % (MovieLibrary, imdb_id))): shutil.rmtree( xbmc.translatePath( '%s%s/' % (MovieLibrary, imdb_id))) Utils.after_add(type='movie') Utils.notify( header='[B]%s[/B]' % self.listitem.getProperty('title'), message='Removed from library', icon=self.listitem.getProperty('poster'), time=5000, sound=False) xbmc.sleep(250) self.update(force_update=True) self.getControl(500).selectItem(self.position) else: if xbmcgui.Dialog().yesno( 'OpenInfo', 'Add [B]%s[/B] to library?' % self.listitem.getProperty('title')): xbmc.executebuiltin( 'RunPlugin(plugin://plugin.video.openmeta/movies/add_to_library/tmdb/%s)' % item_id) Utils.after_add(type='movie') Utils.notify( header='[B]%s[/B] added to library' % self.listitem.getProperty('title'), message='Exit & re-enter to refresh', icon=self.listitem.getProperty('poster'), time=5000, sound=False) if selection == 2: if self.listitem.getProperty('TVShowTitle'): url = 'plugin://script.extendedinfo?info=playtvtrailer&&id=' + item_id else: url = 'plugin://script.extendedinfo?info=playtrailer&&id=' + item_id PLAYER.play(url, listitem=None, window=self)
def handle_tmdb_episodes(results): listitems = [] for item in results: title = Utils.clean_text(Utils.fetch(item, 'name')) if not title: title = '%s %s' % ('Episode', Utils.fetch(item, 'episode_number')) try: artwork = get_image_urls(still=item.get('still_path')) except: artwork = [] listitem = { 'media_type': 'episode', 'title': title, 'release_date': Utils.fetch(item, 'air_date'), 'episode': Utils.fetch(item, 'episode_number'), 'production_code': Utils.fetch(item, 'production_code'), 'season': Utils.fetch(item, 'season_number'), 'Rating': round(float(Utils.fetch(item, 'vote_average')), 1), 'Votes': Utils.fetch(item, 'vote_count'), 'Plot': Utils.fetch(item, 'overview'), 'id': Utils.fetch(item, 'id'), 'Description': Utils.clean_text(Utils.fetch(item, 'overview')) } listitem.update(artwork) date = Utils.fetch(item, 'air_date') listitems.append(listitem) return listitems
def handle_tmdb_people(results): people = [] for person in results: artwork = get_image_urls(profile=person.get('profile_path')) also_known_as = ' / '.join(Utils.fetch(person, 'also_known_as')) newperson = { 'adult': str(Utils.fetch(person, 'adult')), 'name': person['name'], 'title': person['name'], 'also_known_as': also_known_as, 'alsoknownas': also_known_as, 'biography': Utils.clean_text(Utils.fetch(person, 'biography')), 'birthday': Utils.fetch(person, 'birthday'), 'age': Utils.calculate_age(Utils.fetch(person, 'birthday'), Utils.fetch(person, 'deathday')), 'character': Utils.fetch(person, 'character'), 'department': Utils.fetch(person, 'department'), 'job': Utils.fetch(person, 'job'), 'media_type': 'person', 'id': str(person['id']), 'cast_id': str(Utils.fetch(person, 'cast_id')), 'credit_id': str(Utils.fetch(person, 'credit_id')), 'path': 'plugin://script.extendedinfo?info=extendedactorinfo&&id=' + str(person['id']), 'deathday': Utils.fetch(person, 'deathday'), 'place_of_birth': Utils.fetch(person, 'place_of_birth'), 'placeofbirth': Utils.fetch(person, 'place_of_birth'), 'homepage': Utils.fetch(person, 'homepage') } newperson.update(artwork) people.append(newperson) return people
def handle_tmdb_misc(results): listitems = [] for item in results: artwork = get_image_urls(poster=item.get('poster_path')) listitem = { 'title': Utils.clean_text(Utils.fetch(item, 'name')), 'certification': Utils.fetch(item, 'certification') + Utils.fetch(item, 'rating'), 'item_count': Utils.fetch(item, 'item_count'), 'release_date': Utils.fetch(item, 'release_date'), 'path': 'plugin://script.extendedinfo?info=listmovies&---id=%s' % Utils.fetch(item, 'id'), 'year': Utils.get_year(Utils.fetch(item, 'release_date')), 'iso_3166_1': Utils.fetch(item, 'iso_3166_1').lower(), 'author': Utils.fetch(item, 'author'), 'content': Utils.clean_text(Utils.fetch(item, 'content')), 'id': Utils.fetch(item, 'id'), 'url': Utils.fetch(item, 'url'), 'Description': Utils.clean_text(Utils.fetch(item, 'description')) } listitem.update(artwork) listitems.append(listitem) return listitems