def music_add_artist_to_library(artist_name): import math library_folder = setup_library( plugin.get_setting(SETTING_MUSIC_LIBRARY_FOLDER, unicode)) album_results = lastfm.get_artist_top_albums(artist_name) total_albums = len(album_results) index = 0 pDialog = xbmcgui.DialogProgress() pDialog.create( '[COLOR yellow]chappaai[/COLOR]', _("{0} {1} {2}").format(_("Adding"), artist_name, _("to library"))) for album in album_results["album"]: album_name = to_utf8(album["name"]) percent_done = int(math.floor((float(index) / total_albums) * 100)) pDialog.update( percent_done, _("{0} {1} - {2} {3}").format(_("Adding"), artist_name, album_name, _("to library"))) track_results = lastfm.get_album_info(artist_name, album_name) for track in track_results["tracks"]["track"]: if pDialog.iscanceled(): pDialog.update(0) return track_name = to_utf8(track["name"]) add_music_to_library(library_folder, artist_name, album_name, track_name) index += 1 pDialog.update(0) scan_library(type="music")
def get_tvdb_id_from_name(name, lang): import_tvdb() search_results = tvdb.search(name, language=lang) if not search_results: dialogs.ok( _("Show not found"), "{0} {1} in tvdb".format(_("no show information found for"), to_utf8(name))) return items = [] for show in search_results: if "firstaired" in show: show["year"] = int(show['firstaired'].split("-")[0].strip()) else: show["year"] = 0 items.append(show) if len(items) > 1: selection = dialogs.select(_("Choose Show"), [ "{0} ({1})".format(to_utf8(s["seriesname"]), s["year"]) for s in items ]) else: selection = 0 if selection != -1: return items[selection]["id"]
def guide_tv_play_by_name_only(name, lang): tvdb_id = get_tvdb_id_from_name(name, lang) if tvdb_id: season = None episode = None show = tv_tvshow(tvdb_id) while season is None or episode is None: selection = dialogs.select(_("Choose season"), [item["label"] for item in show]) if selection != -1: season = show[selection]["info"]["season"] season = int(season) else: return items = [] episodes = tv_season(tvdb_id, season) for item in episodes: label = "S{0}E{1} - {2}".format(item["info"]["season"], item["info"]["episode"], to_utf8(item["info"]["title"])) if item["info"]["plot"] is not None: label += " - {0}".format(to_utf8(item["info"]["plot"])) items.append(label) selection = dialogs.select(_("Choose episode"), items) if selection != -1: episode = episodes[selection]["info"]["episode"] episode = int(episode) guide_tv_play(tvdb_id, season, episode, "default") if plugin.get_setting(SETTING_TV_PLAYED_BY_ADD, converter=bool) == True: tv_add_to_library(tvdb_id)
def people_list_show_people(id, source, fanart): items = [] try: if source == "imdb": people = trakt.get_show_people(id) else: xbmcgui.Dialog().ok("Error", "No cast info found") return plugin.finish(items=[]) except: xbmcgui.Dialog().ok("Error", "No cast info found") return plugin.finish(items=[]) if "cast" in people: for actor in people["cast"]: context_menu = [ ( "Convert to bob_xml", "RunPlugin({0})".format( plugin.url_for("bob_convert_person_to_xml", trakt_id=actor["person"]["ids"]["trakt"])) ) ] image = get_person_artwork(actor) label = "{0} ({1})".format(to_utf8(actor["person"]["name"]), to_utf8(actor["character"])) info = actor["person"]["biography"] items.append({'label': label, 'path': plugin.url_for("people_list_person_select", id=actor["person"]["ids"]["trakt"], name=to_utf8(actor["person"]["name"])), 'info': info, 'thumbnail': image, 'poster': image, 'context_menu': context_menu, 'icon': "DefaultVideo.png", 'properties': {'fanart_image': fanart}, }) return plugin.finish(items=items)
def get_movie_parameters(movie): parameters = {} parameters['date'] = movie['release_date'] parameters['year'] = parse_year(movie['release_date']) parameters['id'] = movie['id'] parameters['imdb'] = movie['imdb_id'] parameters['title'] = movie['title'] parameters['urltitle'] = urllib.quote(to_utf8(parameters['title'])) parameters['sorttitle'] = parameters['title'] articles = ['a ', 'A ', 'An ', 'an ', 'The ', 'the '] for article in articles: if to_utf8(parameters['title']).startswith(article): parameters['sorttitle'] = to_utf8(parameters['title']).replace(article,'') parameters['shorttitle'] = parameters['title'][1:-1] if "movie" in str(parameters['sorttitle']).lower(): parameters['sortesttitle'] = str(parameters['sorttitle']).lower().replace(' movie','') elif "movi" in str(parameters['sorttitle']).lower(): parameters['sortesttitle'] = str(parameters['sorttitle']).lower().replace(' movi','') else: parameters['sortesttitle'] = parameters['sorttitle'] parameters['original_title'] = movie['original_title'] parameters['name'] = u'%s (%s)' % (parameters['title'], parameters['year']) parameters['urlname'] = urllib.quote(to_utf8(parameters['name'])) # parameters['score'] = movie['vote_average'] # parameters['votes'] = movie['vote_count'] # parameters['runtime'] = movie['runtime'] # parameters['duration'] = int(movie['runtime']) * 60 # parameters['plot'] = movie['overview'] parameters['poster'] = "https://image.tmdb.org/t/p/original/" + str(movie['poster_path']) parameters['fanart'] = "https://image.tmdb.org/t/p/original/" + str(movie['backdrop_path']) # parameters['trailer'] = "plugin://script.extendedinfo/?info=playtrailer&id=" + str(movie['imdb_id']) return parameters
def get_episode_parameters(show, season, episode): import_tmdb() if season in show and episode in show[season]: season_obj = show[season] episode_obj = show[season][episode] else: return # Get parameters parameters = {'id': show['id'], 'season': season, 'episode': episode} show_info = get_tvshow_metadata_tvdb(show, banners=True) network = show.get('network', '') parameters['network'] = network if network: parameters['network_clean'] = re.sub("(\(.*?\))", "", network).strip() else: parameters['network_clean'] = network parameters['showname'] = show['seriesname'] parameters['clearname'] = re.sub("(\(.*?\))", "", show['seriesname']).strip() parameters['urlname'] = urllib.quote(to_utf8(parameters['clearname'])) articles = ['a ', 'A ', 'An ', 'an ', 'The ', 'the '] parameters['sortname'] = parameters['clearname'] for article in articles: if to_utf8(parameters['clearname']).startswith(article): parameters['sortname'] = to_utf8(parameters['clearname']).replace(article,'') parameters['shortname'] = parameters['clearname'][1:-1] try: parameters['absolute_number'] = int(episode_obj.get('absolute_number')) except: parameters['absolute_number'] = "na" parameters['title'] = episode_obj.get('episodename', str(episode)) parameters['urltitle'] = urllib.quote(to_utf8(parameters['title'])) parameters['firstaired'] = episode_obj.get('firstaired') parameters['year'] = show.get('year', 0) parameters['imdb'] = show.get('imdb_id', '') parameters['epid'] = episode_obj.get('id') # parameters['score'] = show['rating'] # parameters['vote_count'] = show['ratingcount'] # parameters['runtime'] = show['runtime'] # parameters['duration'] = int(show['runtime']) * 60 # parameters['plot'] = show['overview'] # parameters['banner'] = "http://thetvdb.com/banners/graphical/" + str(show['id']) + "-g2.jpg" parameters['poster'] = "http://thetvdb.com/banners/posters/" + str(show['id']) + "-2.jpg" parameters['fanart'] = "http://thetvdb.com/banners/fanart/original/" + str(show['id']) + "-2.jpg" parameters['thumbnail'] = "http://thetvdb.com/banners/episodes/" + str(show['id']) + "/" + str(parameters['epid']) + ".jpg" # parameters['trailer'] = "plugin://script.extendedinfo/?info=playtvtrailer&tvdb_id=" + str(show['id']) try: genre = [x for x in show['genre'].split('|') if not x == ''] except: genre = [] parameters['genre'] = " / ".join(genre) is_anime = False if parameters['absolute_number'] and parameters['absolute_number'] != '0' and "animation" in parameters['genre'].lower(): tmdb_results = tmdb.Find(show['id']).info(external_source="tvdb_id") or {} for tmdb_show in tmdb_results.get("tv_results", []): if "JP" in tmdb_show['origin_country']: is_anime = True if is_anime: parameters['name'] = u'{showname} {absolute_number}'.format(**parameters) else: parameters['name'] = u'{showname} S{season:02d}E{episode:02d}'.format(**parameters) return parameters
def tv_play_by_name_only(name, lang): tvdb_id = get_tvdb_id_from_name(name, lang) if tvdb_id: season = None episode = None show = tv_tvshow(tvdb_id) while season is None or episode is None: # don't exit completely if pressing back from episode selector selection = dialogs.select(_("Choose season"), [item["label"] for item in show]) if selection != -1: season = show[selection]["info"]["season"] season = int(season) else: return items = [] episodes = tv_season(tvdb_id, season) for item in episodes: label = "S{0}E{1} - {2}".format(item["info"]["season"], item["info"]["episode"], to_utf8(item["info"]["title"])) if item["info"]["plot"] is not None: label += " - {0}".format(to_utf8(item["info"]["plot"])) items.append(label) selection = dialogs.select(_("Choose episode"), items) if selection != -1: episode = episodes[selection]["info"]["episode"] episode = int(episode) tv_play(tvdb_id, season, episode, "default")
def music_add_artist_to_library(artist_name): import math library_folder = setup_library(plugin.get_setting(SETTING_MUSIC_LIBRARY_FOLDER)) album_results = lastfm.get_artist_top_albums(artist_name) total_albums = len(album_results) index = 0 pDialog = xbmcgui.DialogProgress() pDialog.create( "[COLOR ff0084ff]M[/COLOR]etalli[COLOR ff0084ff]Q[/COLOR]", _("{0} {1} {2}").format(_("Adding"), artist_name, _("to library")), ) for album in album_results["album"]: album_name = to_utf8(album["name"]) percent_done = int(math.floor((float(index) / total_albums) * 100)) pDialog.update( percent_done, _("{0} {1} - {2} {3}").format(_("Adding"), artist_name, album_name, _("to library")) ) track_results = lastfm.get_album_info(artist_name, album_name) for track in track_results["tracks"]["track"]: if pDialog.iscanceled(): pDialog.update(0) return track_name = to_utf8(track["name"]) add_music_to_library(library_folder, artist_name, album_name, track_name) index += 1 pDialog.update(0) scan_library(type="music")
def music_artist_tracks(artist_name, page): artist_name = to_utf8(artist_name) results = lastfm.get_artist_top_tracks(artist_name, page) items = [] for track in results["track"]: large_image = track["image"][-1]["#text"] track_name = to_utf8(track["name"]) context_menu = [ ( _("Context player"), "PlayMedia({0})".format( plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name, mode="context") ), ), ( _("Add to library"), "RunPlugin({0})".format( plugin.url_for("music_add_to_library", artist_name=artist_name, track_name=track_name) ), ), ( _("Musicvideo"), "PlayMedia({0})".format( plugin.url_for("music_play_video", artist_name=artist_name, track_name=track_name, mode="default") ), ), ] if plugin.get_setting(SETTING_PREFERRED_MUSIC_TYPE) == "audio": item = { "label": track_name, "path": plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name), "thumbnail": large_image, "icon": "DefaultMusic.png", "poster": large_image, "info_type": "music", "context_menu": context_menu, } else: item = { "label": track_name, "path": plugin.url_for("music_play_video", artist_name=artist_name, track_name=track_name), "thumbnail": large_image, "icon": "DefaultMusicVideo.png", "poster": large_image, "info_type": "music", "context_menu": context_menu, } items.append(item) if results["@attr"]["totalPages"] > page: items.append( { "label": _("Next >>"), "icon": get_icon_path("item_next"), "path": plugin.url_for(music_artist_tracks, artist_name=artist_name, page=int(page) + 1), } ) return items
def music_artist_album_tracks(artist_name, album_name): artist_name = to_utf8(artist_name) album_name = to_utf8(album_name) results = lastfm.get_album_info(artist_name, album_name) items = [] for track in results["tracks"]["track"]: track_name = to_utf8(track["name"]) track_number = track["@attr"]["rank"] image = results["image"][-1]["#text"] context_menu = [ ( _("Context player"), "PlayMedia({0})".format( plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name, mode="context") ), ), ( _("Add to library"), "RunPlugin({0})".format( plugin.url_for( "music_add_to_library", artist_name=artist_name, track_name=track_name, album_name=album_name ) ), ), ( _("Musicvideo"), "RunPlugin({0})".format( plugin.url_for("music_play_video", artist_name=artist_name, track_name=track_name, mode="default") ), ), ] if plugin.get_setting(SETTING_PREFERRED_MUSIC_TYPE) == "audio": item = { "label": "{0}. {1}".format(track_number, track_name), "path": plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name), "thumbnail": image, "icon": "DefaultMusic.png", "poster": image, "info_type": "music", "context_menu": context_menu, } else: item = { "label": "{0}. {1}".format(track_number, track_name), "path": plugin.url_for( "music_play_video", artist_name=artist_name, album_name=album_name, track_name=track_name ), "thumbnail": image, "icon": "DefaultMusicVideo.png", "poster": image, "info_type": "music", "context_menu": context_menu, } items.append(item) return items
def music_artist_albums(artist_name, page): artist_name = to_utf8(artist_name) results = lastfm.get_artist_top_albums(artist_name, page) items = [{ 'label': _("All Tracks"), 'path': plugin.url_for("music_artist_tracks", artist_name=artist_name), 'icon': get_icon_path("music") }] for album in results["album"]: album_name = to_utf8(album["name"]) image = album['image'][-1]['#text'] artist_album_name = to_utf8(album['artist']['name']) context_menu = [(_("Scan item to library"), "RunPlugin({0})".format( plugin.url_for("music_add_album_to_library", artist_name=artist_album_name, album_name=album_name)))] item = { 'thumbnail': image, 'label': "{0}".format(album_name), 'info': { 'title': album_name, 'artist': [artist_album_name], }, 'info_type': 'music', 'path': plugin.url_for("music_artist_album_tracks", artist_name=artist_name, album_name=album_name), 'context_menu': context_menu } items.append(item) if results["@attr"]["totalPages"] > page: next_page = int(page) + 1 items.append({ 'label': _("Next >>"), 'icon': get_icon_path("item_next"), 'path': plugin.url_for("music_artist_albums", artist_name=artist_name, page=next_page) }) if FORCE == True: plugin.set_view_mode(VIEW) return items else: return items
def music_search_album_term(term, page): search_results = lastfm.search_album(term, page) albums = search_results["albummatches"]["album"] items_per_page = search_results["opensearch:itemsPerPage"] start_index = search_results["opensearch:startIndex"] total_results = search_results["opensearch:totalResults"] items = [] for album in albums: large_image = album["image"][-1]["#text"] album_name = to_utf8(album["name"]) artist_name = to_utf8(album["artist"]) context_menu = [(_("Scan item to library"), "RunPlugin({0})".format( plugin.url_for("music_add_album_to_library", artist_name=artist_name, album_name=album_name)))] item = { 'label': "{0} - {1}".format(artist_name, album_name), 'path': plugin.url_for("music_artist_album_tracks", artist_name=artist_name, album_name=album_name), 'thumbnail': large_image, 'icon': "DefaultMusic.png", 'poster': large_image, 'info': { 'artist': artist_name, }, 'info_type': 'music', 'context_menu': context_menu } items.append(item) if start_index + items_per_page < total_results: items.append({ 'label': "{0} {1}".format(_("Next page"), " >>"), 'icon': get_icon_path("item_next"), 'path': plugin.url_for("music_search_album_term", term=term, page=int(page) + 1) }) if FORCE == True: plugin.set_view_mode(VIEW) return items else: return items
def music_top_tracks_by_country(country, page): results = lastfm.get_top_tracks_by_country(country, page) tracks = results["tracks"]["track"] items = [] for track in tracks: large_image = track["image"][-1]["#text"] track_name = to_utf8(track["name"]) artist_name = to_utf8(track["artist"]["name"]) context_menu = [ ("{0} {1}...".format(_("Select"), _("Stream").lower()), "PlayMedia({0})".format( plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name, mode='context'))), (_("Scan item to library"), "RunPlugin({0})".format( plugin.url_for("music_add_to_library", artist_name=artist_name, track_name=track_name))) #, # ( # _("Music video"), # "RunPlugin({0})".format(plugin.url_for("music_play_video", artist_name=artist_name, # track_name=track_name, mode='context')) # ) ] item = { 'label': "{0} - {1}".format(artist_name, track_name), 'path': plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name), 'thumbnail': large_image, 'icon': "DefaultMusic.png", 'poster': large_image, 'info': { 'artist': artist_name, }, 'info_type': 'music', 'context_menu': context_menu } items.append(item) if FORCE == True: plugin.set_view_mode(VIEW) return items else: return items
def music_artist_tracks(artist_name, page): artist_name = to_utf8(artist_name) results = lastfm.get_artist_top_tracks(artist_name, page) items = [] for track in results["track"]: large_image = track["image"][-1]["#text"] track_name = to_utf8(track["name"]) context_menu = [ ( _("Context player"), "PlayMedia({0})".format(plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name, mode='context')) ), ( _("Scan item to library"), "RunPlugin({0})".format(plugin.url_for("music_add_to_library", artist_name=artist_name, track_name=track_name)) ), ( _("Musicvideo"), "PlayMedia({0})".format(plugin.url_for("music_play_video", artist_name=artist_name, track_name=track_name, mode='default')) ) ] if plugin.get_setting(SETTING_PREFERRED_MUSIC_TYPE, unicode) == "audio": item = { 'label': track_name, 'path': plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name), 'thumbnail': large_image, 'icon': "DefaultMusic.png", 'poster': large_image, 'info_type': 'music', 'context_menu': context_menu, } else: item = { 'label': track_name, 'path': plugin.url_for("music_play_video", artist_name=artist_name, track_name=track_name), 'thumbnail': large_image, 'icon': "DefaultMusicVideo.png", 'poster': large_image, 'info_type': 'music', 'context_menu': context_menu, } items.append(item) if results["@attr"]["totalPages"] > page: items.append({ 'label': _("Next >>"), 'icon': get_icon_path("item_next"), 'path': plugin.url_for("music_artist_tracks", artist_name=artist_name, page=int(page) + 1) }) if FORCE == True: plugin.set_view_mode(VIEW); return items else: return items
def music_search_track_term(term, page): search_results = lastfm.search_track(term, page) tracks = search_results["trackmatches"]["track"] items_per_page = search_results["opensearch:itemsPerPage"] start_index = search_results["opensearch:startIndex"] total_results = search_results["opensearch:totalResults"] items = [] for track in tracks: large_image = track["image"][-1]["#text"] track_name = to_utf8(track["name"]) artist_name = to_utf8(track["artist"]) context_menu = [ ( _("Context player"), "PlayMedia({0})".format( plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name, mode="context") ), ), ( _("Add to library"), "RunPlugin({0})".format( plugin.url_for("music_add_to_library", artist_name=artist_name, track_name=track_name) ), ), ( _("Musicvideo"), "RunPlugin({0})".format( plugin.url_for("music_play_video", artist_name=artist_name, track_name=track_name, mode="context") ), ), ] item = { "label": "{0} - {1}".format(artist_name, track_name), "path": plugin.url_for(music_play_audio, artist_name=artist_name, track_name=track_name), "thumbnail": large_image, "icon": "DefaultMusic.png", "poster": large_image, "info": {"artist": artist_name}, "info_type": "music", "context_menu": context_menu, } items.append(item) if start_index + items_per_page < total_results: items.append( { "label": _("Next >>"), "icon": get_icon_path("item_next"), "path": plugin.url_for(music_search_track_term, term=term, page=int(page) + 1), } ) return items
def music_search_track_term(term, page): search_results = lastfm.search_track(term, page) tracks = search_results["trackmatches"]["track"] items_per_page = search_results["opensearch:itemsPerPage"] start_index = search_results["opensearch:startIndex"] total_results = search_results["opensearch:totalResults"] items = [] for track in tracks: large_image = track["image"][-1]["#text"] track_name = to_utf8(track["name"]) artist_name = to_utf8(track["artist"]) context_menu = [ ( "{0} {1} {2}...".format(_("Select"), _("Audio").lower(), _("Stream").lower()), "PlayMedia({0})".format(plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name, mode='context')) ), ( _("Scan item to library"), "RunPlugin({0})".format(plugin.url_for("music_add_to_library", artist_name=artist_name, track_name=track_name)) ), ( "{0} {1} {2}...".format(_("Select"), _("Video").lower(), _("Stream").lower()), "RunPlugin({0})".format(plugin.url_for("music_play_video", artist_name=artist_name, track_name=track_name, mode='context')) ) ] item = { 'label': "{0} - {1}".format(artist_name, track_name), 'path': plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name), 'thumbnail': large_image, 'icon': "DefaultMusic.png", 'poster': large_image, 'info': { 'artist': artist_name, }, 'info_type': 'music', 'context_menu': context_menu } items.append(item) if start_index + items_per_page < total_results: items.append({ 'label': _("Next >>"), 'icon': get_icon_path("item_next"), 'path': plugin.url_for("music_search_track_term", term=term, page=int(page) + 1) }) if FORCE == True: plugin.set_view_mode(VIEW); return items else: return items
def music_artist_album_tracks(artist_name, album_name): artist_name = to_utf8(artist_name) album_name = to_utf8(album_name) results = lastfm.get_album_info(artist_name, album_name) items = [] for track in results["tracks"]["track"]: track_name = to_utf8(track["name"]) track_number = track["@attr"]["rank"] image = results["image"][-1]["#text"] context_menu = [ ( "{0} {1} {2}...".format(_("Select"), _("Audio").lower(), _("Stream").lower()), "PlayMedia({0})".format(plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name, mode='context')) ), ( _("Scan item to library"), "RunPlugin({0})".format(plugin.url_for("music_add_to_library", artist_name=artist_name, track_name=track_name, album_name=album_name)) ), ( "{0} {1} {2}...".format(_("Select"), _("Video").lower(), _("Stream").lower()), "RunPlugin({0})".format(plugin.url_for("music_play_video", artist_name=artist_name, track_name=track_name, mode='default')) ) ] if plugin.get_setting(SETTING_PREFERRED_MUSIC_TYPE, unicode) == "audio": item = { 'label': "{0}. {1}".format(track_number, track_name), 'path': plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name), 'thumbnail': image, 'icon': "DefaultMusic.png", 'poster': image, 'info_type': 'music', 'context_menu': context_menu, } else: item = { 'label': "{0}. {1}".format(track_number, track_name), 'path': plugin.url_for("music_play_video", artist_name=artist_name, album_name=album_name, track_name=track_name), 'thumbnail': image, 'icon': "DefaultMusicVideo.png", 'poster': image, 'info_type': 'music', 'context_menu': context_menu, } items.append(item) if FORCE == True: plugin.set_view_mode(VIEW); return items else: return items
def lists_search_for_lists_term(term, page): lists, pages = trakt.search_for_list(term, page) page = int(page) pages = int(pages) items = [] for list in lists: if "list" in list: list_info = list["list"] else: continue name = list_info["name"] user = list_info["username"] slug = list_info["ids"]["slug"] total = list_info["item_count"] info = {} info['title'] = name if "description" in list_info: info["plot"] = list_info["description"] else: info["plot"] = _("No description available") if user != None and total != None and total != 0: items.append({ 'label': "{0} - {1} ({2})".format(to_utf8(name), to_utf8(user), total), 'path': plugin.url_for("lists_trakt_show_list", user=user, slug=slug), 'context_menu': [ ( _("Scan item to library"), "RunPlugin({0})".format(plugin.url_for("lists_trakt_add_all_to_library", user=user, slug=slug)) ), ( "{0} ({1})".format(_("Play"), _("Random").lower()), "RunPlugin({0})".format(plugin.url_for("lists_trakt_play_random", user=user, slug=slug)) ) ], 'info': info, 'icon': get_icon_path("traktlikedlists"), 'thumbnail': get_icon_path("traktlikedlists"), }) fanart = plugin.addon.getAddonInfo('fanart') for item in items: item['properties'] = {'fanart_image' : get_background_path()} if pages > page: items.append({ 'label': _("Next page").format() + " >> (%s/%s)" % (page + 1, pages), 'path': plugin.url_for("lists_search_for_lists_term", term = term, page=page + 1), 'icon': get_icon_path("item_next"), 'thumbnail': get_icon_path("item_next"), }) if FORCE == True: return plugin.finish(items=items, sort_methods=SORT, view_mode=VIEW) else: return plugin.finish(items=items, sort_methods=SORT)
def music_artist_album_tracks(artist_name, album_name): artist_name = to_utf8(artist_name) album_name = to_utf8(album_name) results = lastfm.get_album_info(artist_name, album_name) items = [] for track in results["tracks"]["track"]: track_name = to_utf8(track["name"]) track_number = track["@attr"]["rank"] image = results["image"][-1]["#text"] context_menu = [ ( _("Context player"), "PlayMedia({0})".format(plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name, mode='context')) ), ( _("Add to library"), "RunPlugin({0})".format(plugin.url_for("music_add_to_library", artist_name=artist_name, track_name=track_name, album_name=album_name)) ), ( _("Musicvideo"), "RunPlugin({0})".format(plugin.url_for("music_play_video", artist_name=artist_name, track_name=track_name, mode='default')) ) ] if plugin.get_setting(SETTING_PREFERRED_MUSIC_TYPE) == "audio": item = { 'label': "{0}. {1}".format(track_number, track_name), 'path': plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name), 'thumbnail': image, 'icon': "DefaultMusic.png", 'poster': image, 'info_type': 'music', 'context_menu': context_menu, } else: item = { 'label': "{0}. {1}".format(track_number, track_name), 'path': plugin.url_for("music_play_video", artist_name=artist_name, album_name=album_name, track_name=track_name), 'thumbnail': image, 'icon': "DefaultMusicVideo.png", 'poster': image, 'info_type': 'music', 'context_menu': context_menu, } items.append(item) return items
def lists_search_for_lists_term(term,page): lists, pages = trakt.search_for_list(term, page) page = int(page) pages = int(pages) items = [] for list in lists: if "list" in list: list_info = list["list"] else: continue name = list_info["name"] user = list_info["username"] slug = list_info["ids"]["slug"] info = {} info['title'] = name if "description" in list_info: info["plot"] = list_info["description"] else: info["plot"] = _("No description available") if user != None: items.append({ 'label': "{0} {1} {2}".format(to_utf8(name), _("by"), to_utf8(user)), 'path': plugin.url_for("lists_trakt_show_list", user=user, slug=slug), 'context_menu': [ ( _("Add list to library"), "RunPlugin({0})".format(plugin.url_for("lists_trakt_add_all_to_library", user=user, slug=slug)) ) ], 'info': info, 'icon': get_icon_path("traktlikedlists"), }) fanart = plugin.addon.getAddonInfo('fanart') for item in items: item['properties'] = {'fanart_image' : get_background_path()} if (len(items) < plugin.get_setting(SETTING_TRAKT_PER_PAGE, int) and pages > page): page = page + 1 results = lists_search_for_lists_term(term, page) return items + results if pages > page: items.append({ 'label': _("Next page").format() + " >> (%s/%s)" % (page + 1, pages), 'path': plugin.url_for("lists_search_for_lists_term", term = term, page=page + 1), 'icon': get_icon_path("traktlikedlists"), }) if FORCE == True: return plugin.finish(items=items, sort_methods=SORT, view_mode=VIEW) else: return plugin.finish(items=items, sort_methods=SORT)
def music_add_album_to_library(artist_name, album_name): library_folder = setup_library(plugin.get_setting(SETTING_MUSIC_LIBRARY_FOLDER, unicode)) results = lastfm.get_album_info(artist_name, album_name) for track in results["tracks"]["track"]: track_name = to_utf8(track["name"]) add_music_to_library(library_folder, artist_name, album_name, track_name) scan_library(type="music")
def music_top_artists_by_country(country, page): results = lastfm.get_top_artists_by_country(country, page) artists = results["topartists"]["artist"] items = [] for artist in artists: large_image = artist["image"][-1]["#text"] name = to_utf8(artist["name"]) context_menu = [ ( _("Add to library"), "RunPlugin({0})".format(plugin.url_for("music_add_artist_to_library", artist_name=name)), ) ] item = { "label": name, "path": plugin.url_for(music_artist_albums, artist_name=name), "thumbnail": large_image, "icon": "DefaultMusic.png", "poster": large_image, "info": {"artist": name}, "info_type": "music", "context_menu": context_menu, } items.append(item) return items
def music_top_artists(page): results = lastfm.get_top_artists(page) artists = results["artists"]["artist"] items = [] for artist in artists: large_image = artist["image"][-1]["#text"] name = to_utf8(artist["name"]) context_menu = [ ( _("Add to library"), "RunPlugin({0})".format(plugin.url_for("music_add_artist_to_library", artist_name=name)) ) ] item = { 'label': name, 'path': plugin.url_for(music_artist_albums, artist_name=name), 'thumbnail': large_image, 'icon': "DefaultMusic.png", 'poster': large_image, 'info': { 'artist': name, }, 'info_type': 'music', 'context_menu': context_menu } items.append(item) return items
def music_top_artists_by_country(country, page): results = lastfm.get_top_artists_by_country(country, page) artists = results["topartists"]["artist"] items = [] for artist in artists: large_image = artist["image"][-1]["#text"] name = to_utf8(artist["name"]) context_menu = [ ( _("Scan item to library"), "RunPlugin({0})".format(plugin.url_for("music_add_artist_to_library", artist_name=name)) ) ] item = { 'label': name, 'path': plugin.url_for("music_artist_albums", artist_name=name), 'thumbnail': large_image, 'icon': "DefaultMusic.png", 'poster': large_image, 'info': { 'artist': name, }, 'info_type': 'music', 'context_menu': context_menu } items.append(item) if FORCE == True: plugin.set_view_mode(VIEW); return items else: return items
def on_play_video(mode, players, params, trakt_ids=None): assert players # Cancel resolve action_cancel() # Get video link use_simple_selector = plugin.get_setting(SETTING_USE_SIMPLE_SELECTOR, converter=bool) is_extended = not (use_simple_selector or len(players) == 1) if not is_extended: xbmc.executebuiltin("ActivateWindow(busydialog)") try: selection = get_video_link(players, params, mode, use_simple_selector) finally: if not is_extended: xbmc.executebuiltin("Dialog.Close(busydialog)") if not selection: return # Get selection details link = selection["path"] action = selection.get("action", "") plugin.log.info("Playing url: %s" % to_utf8(link)) # Activate link if action == "ACTIVATE": action_activate(link) else: if trakt_ids: set_property("script.trakt.ids", json.dumps(trakt_ids)) return link return None
def batch_add_tvshows_to_library(library_folder, show): id = show['id'] showname = to_utf8(show['seriesname']) playlist_folder = plugin.get_setting(SETTING_TV_PLAYLIST_FOLDER, unicode) if not xbmcvfs.exists(playlist_folder): try: xbmcvfs.mkdir(playlist_folder) except: dialogs.notify(msg=_('Creation of [COLOR ff0084ff]M[/COLOR]etalli[COLOR ff0084ff]Q[/COLOR] Playlist Folder'), title=_('Failed'), delay=5000, image=get_icon_path("lists")) playlist_file = os.path.join(playlist_folder, id+".xsp") if not xbmcvfs.exists(playlist_file): playlist_file = xbmcvfs.File(playlist_file, 'w') content = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><smartplaylist type="tvshows"><name>%s</name><match>all</match><rule field="path" operator="contains"><value>%s%s</value></rule><rule field="playcount" operator="is"><value>0</value></rule><order direction="ascending">numepisodes</order></smartplaylist>' % (showname, plugin.get_setting(SETTING_TV_LIBRARY_FOLDER, unicode).replace('special://profile',''), str(id)) playlist_file.write(str(content)) playlist_file.close() show_folder = os.path.join(library_folder, str(id)+'/') if not xbmcvfs.exists(show_folder): try: xbmcvfs.mkdir(show_folder) except: pass player_filepath = os.path.join(show_folder, 'player.info') player_file = xbmcvfs.File(player_filepath, 'w') content = "default" player_file.write(content) player_file.close() nfo_filepath = os.path.join(show_folder, 'tvshow.nfo') if not xbmcvfs.exists(nfo_filepath): nfo_file = xbmcvfs.File(nfo_filepath, 'w') content = "http://thetvdb.com/index.php?tab=series&id=%s" % str(id) nfo_file.write(content) nfo_file.close() clean_needed = True return clean_needed
def music_add_album_to_library(artist_name, album_name): library_folder = setup_library(plugin.get_setting(SETTING_MUSIC_LIBRARY_FOLDER)) results = lastfm.get_album_info(artist_name, album_name) for track in results["tracks"]["track"]: track_name = to_utf8(track["name"]) add_music_to_library(library_folder, artist_name, album_name, track_name) scan_library(type="music")
def music_top_artists_by_country(country, page): results = lastfm.get_top_artists_by_country(country, page) artists = results["topartists"]["artist"] items = [] for artist in artists: large_image = artist["image"][-1]["#text"] name = to_utf8(artist["name"]) context_menu = [(_("Scan item to library"), "RunPlugin({0})".format( plugin.url_for("music_add_artist_to_library", artist_name=name)))] item = { 'label': name, 'path': plugin.url_for("music_artist_albums", artist_name=name), 'thumbnail': large_image, 'icon': "DefaultMusic.png", 'poster': large_image, 'info': { 'artist': name, }, 'info_type': 'music', 'context_menu': context_menu } items.append(item) if FORCE == True: plugin.set_view_mode(VIEW) return items else: return items
def movies_play_by_name(name, lang="en"): """ Activate tv search """ import_tmdb() from meta.utils.text import parse_year items = tmdb.Search().movie(query=name, language=lang, page=1)["results"] if not items: dialogs.ok( _("Movie not found"), "{0} {1}".format(_("No movie information found on TMDB for"), name)) return if len(items) > 1: selection = dialogs.select(_("Choose Movie"), [ "{0} ({1})".format(to_utf8(s["title"]), parse_year(s["release_date"])) for s in items ]) else: selection = 0 if selection != -1: id = items[selection]["id"] movies_play("tmdb", id, "default")
def on_play_video(mode, players, params, trakt_ids=None): assert players # Cancel resolve action_cancel() # Get video link use_simple_selector = plugin.get_setting(SETTING_USE_SIMPLE_SELECTOR, bool) is_extended = not (use_simple_selector or len(players) == 1) if not is_extended: xbmc.executebuiltin("ActivateWindow(busydialog)") try: selection = get_video_link(players, params, mode, use_simple_selector) finally: if not is_extended: xbmc.executebuiltin("Dialog.Close(busydialog)") if not selection: return # Get selection details link = selection['path'] action = selection.get('action', '') plugin.log.info('Playing url: %s' % to_utf8(link)) # Activate link if action == "ACTIVATE": action_activate(link) elif action == "RUN": action_run(link) elif action == "DEBLOCK": action_deblock(link) else: if trakt_ids: set_property('script.trakt.ids', json.dumps(trakt_ids)) return link return None
def guide_movies_play_by_name(name, lang="en"): import_tmdb() from meta.utils.text import parse_year items = tmdb.Search().movie(query=name, language=lang, page=1)["results"] if not items: return dialogs.ok( _("%s not found") % _("Movie"), "{0} {1}".format(_("No movie information found on TMDB for"), name)) if len(items) > 1: selection = dialogs.select( "{0}".format( _("Choose thumbnail").replace( _("Thumbnail").lower(), _("Movie").lower())), [ "{0} ({1})".format(to_utf8(s["title"]), parse_year(s["release_date"])) for s in items ]) else: selection = 0 if selection != -1: id = items[selection]["id"] guide_movies_play("tmdb", id, "default") if plugin.get_setting(SETTING_MOVIES_PLAYED_BY_ADD, bool) == True: movies_add_to_library("tmdb", id)
def live_search_term(term): """ Perform search of a specified <term>""" term = to_utf8(term) channels = get_channels() if term not in channels: channels.append(term) xbmc.executebuiltin("Container.Refresh") return live_play(term)
def call_trakt(path, params={}, data=None, is_delete=False, with_auth=True, pagination = False): params = dict([(k, to_utf8(v)) for k, v in params.items() if v]) headers = { 'Content-Type': 'application/json', 'trakt-api-version': '2', 'trakt-api-key': CLIENT_ID } def send_query(): if with_auth: try: expires_at = plugin.get_setting(SETTING_TRAKT_EXPIRES_AT, converter=int) if time.time() > expires_at: trakt_refresh_token() except: pass token = plugin.get_setting(SETTING_TRAKT_ACCESS_TOKEN) if token: headers['Authorization'] = 'Bearer ' + token if data is not None: assert not params return requests.post("{0}/{1}".format(API_ENDPOINT, path), json=data, headers=headers) elif is_delete: return requests.delete("{0}/{1}".format(API_ENDPOINT, path), headers=headers) else: return requests.get("{0}/{1}".format(API_ENDPOINT, path), params, headers=headers) def paginated_query(): page = 1 lists = [] while True: params['page'] = page results = send_query() if with_auth and results.status_code == 401 and dialogs.yesno(_("Authenticate Trakt"), _( "You must authenticate with Trakt. Do you want to authenticate now?")) and trakt_authenticate(): response = paginated_query() return response results.raise_for_status() results.encoding = 'utf-8' lists.extend(results.json()) if int(results.headers["X-Pagination-Page-Count"]) <= page: return lists page += 1 if pagination == False: response = send_query() if with_auth and response.status_code == 401 and dialogs.yesno(_("Authenticate Trakt"), _( "You must authenticate with Trakt. Do you want to authenticate now?")) and trakt_authenticate(): response = send_query() response.raise_for_status() response.encoding = 'utf-8' return response.json() else: response = paginated_query() return response
def get_trakt_episode_parameters(show, preason, prepisode): if "status_code" in str(prepisode): return None parameters = {'id': show['external_ids']['tvdb_id'], 'season': preason['season_number'], 'episode': prepisode['episode_number']} network = show['networks'][0]['name'] parameters['network'] = network if network: parameters['network_clean'] = re.sub("(\(.*?\))", "", network).strip() else: parameters['network_clean'] = network parameters['imdb'] = show['external_ids']['imdb_id'] parameters['tmdb'] = show['id'] parameters['showname'] = show['name'] parameters['clearname'] = re.sub("(\(.*?\))", "", show['name']).strip() parameters['urlname'] = urllib.quote(to_utf8(parameters['clearname'])) articles = ['a ', 'A ', 'An ', 'an ', 'The ', 'the '] parameters['sortname'] = to_utf8(parameters['clearname']) for article in articles: if to_utf8(parameters['clearname']).startswith(article): parameters['sortname'] = to_utf8(parameters['clearname']).replace(article,'') parameters['shortname'] = to_utf8(parameters['clearname'][1:-1]) parameters['absolute_number'] = "na" parameters['title'] = prepisode['name'] parameters['urltitle'] = urllib.quote(to_utf8(parameters['title'])) parameters['sorttitle'] = to_utf8(parameters['title']) articles = ['a ', 'A ', 'An ', 'an ', 'The ', 'the '] for article in articles: if to_utf8(parameters['title']).startswith(article): parameters['sorttitle'] = to_utf8(parameters['title']).replace(article,'') parameters['shorttitle'] = to_utf8(parameters['title'][1:-1]) parameters['firstaired'] = prepisode['air_date'] parameters['year'] = int(show['first_air_date'].split("-")[0].strip()) if parameters['firstaired']: parameters['epyear'] = int(parameters['firstaired'].split("-")[0].strip()) parameters['epmonth'] = int(parameters['firstaired'].split("-")[1].strip()) parameters['epday'] = int(parameters['firstaired'].split("-")[2].strip()) else: parameters["epyear"] = 1900 parameters["epmonth"] = 0 parameters["epday"] = 0 parameters['epid'] = prepisode['id'] if preason['episodes'][0] != None and preason['episodes'][0] != "" and preason['episodes'][0] != []: parameters['poster'] = u'%s%s' % ("http://image.tmdb.org/t/p/w500", preason['episodes'][0]['still_path']) elif show['poster_path'] != None and show['poster_path'] != "" and show['poster_path'] != []: parameters['poster'] = u'%s%s' % ("http://image.tmdb.org/t/p/w500", show['poster_path']) if show['backdrop_path'] != None and show['backdrop_path'] != "" and show['backdrop_path'] != []: parameters['fanart'] = u'%s%s' % ("http://image.tmdb.org/t/p/original", show['backdrop_path']) else: parameters['fanart'] = "" parameters['thumbnail'] = parameters['poster'] parameters['icon'] = parameters['poster'] try: genre = [x for x in show['genre'].split('|') if not x == ''] except: genre = [] parameters['genre'] = " / ".join(genre) if "JP" in show['origin_country']: is_anime = True else: is_anime = False if is_anime: parameters['name'] = u'{showname} {absolute_number}'.format(**parameters) else: parameters['name'] = u'{showname} S{season:02d}E{episode:02d}'.format(**parameters) parameters['now'] = datetime.datetime.now().strftime('%Y%m%d%H%M%S%f') return parameters
def music_artist_albums(artist_name, page): artist_name = to_utf8(artist_name) results = lastfm.get_artist_top_albums(artist_name, page) items = [ { 'label': _("All Tracks"), 'path': plugin.url_for("music_artist_tracks", artist_name=artist_name), 'icon': get_icon_path("music") } ] for album in results["album"]: album_name = to_utf8(album["name"]) image = album['image'][-1]['#text'] artist_album_name = to_utf8(album['artist']['name']) context_menu = [ ( _("Scan item to library"), "RunPlugin({0})".format(plugin.url_for("music_add_album_to_library", artist_name=artist_album_name, album_name=album_name)) ) ] item = { 'thumbnail': image, 'label': "{0}".format(album_name), 'info': { 'title': album_name, 'artist': [artist_album_name], }, 'info_type': 'music', 'path': plugin.url_for("music_artist_album_tracks", artist_name=artist_name, album_name=album_name), 'context_menu': context_menu } items.append(item) if results["@attr"]["totalPages"] > page: next_page = int(page) + 1 items.append({ 'label': _("Next >>"), 'icon': get_icon_path("item_next"), 'path': plugin.url_for("music_artist_albums", artist_name=artist_name, page=next_page) }) if FORCE == True: plugin.set_view_mode(VIEW); return items else: return items
def music_top_tracks_by_country(country, page): results = lastfm.get_top_tracks_by_country(country, page) tracks = results["tracks"]["track"] items = [] for track in tracks: large_image = track["image"][-1]["#text"] track_name = to_utf8(track["name"]) artist_name = to_utf8(track["artist"]["name"]) context_menu = [ ( "{0} {1}...".format(_("Select"), _("Stream").lower()), "PlayMedia({0})".format(plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name, mode='context')) ), ( _("Scan item to library"), "RunPlugin({0})".format(plugin.url_for("music_add_to_library", artist_name=artist_name, track_name=track_name)) )#, # ( # _("Music video"), # "RunPlugin({0})".format(plugin.url_for("music_play_video", artist_name=artist_name, # track_name=track_name, mode='context')) # ) ] item = { 'label': "{0} - {1}".format(artist_name, track_name), 'path': plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name), 'thumbnail': large_image, 'icon': "DefaultMusic.png", 'poster': large_image, 'info': { 'artist': artist_name, }, 'info_type': 'music', 'context_menu': context_menu } items.append(item) if FORCE == True: plugin.set_view_mode(VIEW); return items else: return items
def music_artist_albums(artist_name, page): artist_name = to_utf8(artist_name) results = lastfm.get_artist_top_albums(artist_name, page) items = [ { "label": _("All Tracks"), "path": plugin.url_for("music_artist_tracks", artist_name=artist_name), "icon": get_icon_path("music"), } ] for album in results["album"]: album_name = to_utf8(album["name"]) image = album["image"][-1]["#text"] artist_album_name = to_utf8(album["artist"]["name"]) context_menu = [ ( _("Add to library"), "RunPlugin({0})".format( plugin.url_for("music_add_album_to_library", artist_name=artist_album_name, album_name=album_name) ), ) ] item = { "thumbnail": image, "label": "{0}".format(album_name), "info": {"title": album_name, "artist": [artist_album_name]}, "info_type": "music", "path": plugin.url_for("music_artist_album_tracks", artist_name=artist_name, album_name=album_name), "context_menu": context_menu, } items.append(item) if results["@attr"]["totalPages"] > page: next_page = int(page) + 1 items.append( { "label": _("Next >>"), "icon": get_icon_path("item_next"), "path": plugin.url_for(music_artist_albums, artist_name=artist_name, page=next_page), } ) return items
def call_trakt(path, params={}, data=None, is_delete=False, with_auth=True, pagination = False, page = 1): params = dict([(k, to_utf8(v)) for k, v in params.items() if v]) headers = { 'Content-Type': 'application/json', 'trakt-api-version': '2', 'trakt-api-key': CLIENT_ID } def send_query(): if with_auth: try: expires_at = plugin.get_setting(SETTING_TRAKT_EXPIRES_AT, converter=int) if time.time() > expires_at: trakt_refresh_token() except: pass token = plugin.get_setting(SETTING_TRAKT_ACCESS_TOKEN) if token: headers['Authorization'] = 'Bearer ' + token if data is not None: assert not params return requests.post("{0}/{1}".format(API_ENDPOINT, path), json=data, headers=headers) elif is_delete: return requests.delete("{0}/{1}".format(API_ENDPOINT, path), headers=headers) else: return requests.get("{0}/{1}".format(API_ENDPOINT, path), params, headers=headers) def paginated_query(page): lists = [] params['page'] = page results = send_query() if with_auth and results.status_code == 401 and dialogs.yesno(_("Authenticate Trakt"), _( "You must authenticate with Trakt. Do you want to authenticate now?")) and trakt_authenticate(): response = paginated_query(1) return response results.raise_for_status() results.encoding = 'utf-8' lists.extend(results.json()) return lists, results.headers["X-Pagination-Page-Count"] if pagination == False: response = send_query() if with_auth and response.status_code == 401 and dialogs.yesno(_("Authenticate Trakt"), _( "You must authenticate with Trakt. Do you want to authenticate now?")) and trakt_authenticate(): response = send_query() response.raise_for_status() response.encoding = 'utf-8' return response.json() else: (response, numpages) = paginated_query(page) return response, numpages
def music_search_album_term(term, page): search_results = lastfm.search_album(term, page) albums = search_results["albummatches"]["album"] items_per_page = search_results["opensearch:itemsPerPage"] start_index = search_results["opensearch:startIndex"] total_results = search_results["opensearch:totalResults"] items = [] for album in albums: large_image = album["image"][-1]["#text"] album_name = to_utf8(album["name"]) artist_name = to_utf8(album["artist"]) context_menu = [ ( _("Scan item to library"), "RunPlugin({0})".format(plugin.url_for("music_add_album_to_library", artist_name=artist_name, album_name=album_name)) ) ] item = { 'label': "{0} - {1}".format(artist_name, album_name), 'path': plugin.url_for("music_artist_album_tracks", artist_name=artist_name, album_name=album_name), 'thumbnail': large_image, 'icon': "DefaultMusic.png", 'poster': large_image, 'info': { 'artist': artist_name, }, 'info_type': 'music', 'context_menu': context_menu } items.append(item) if start_index + items_per_page < total_results: items.append({ 'label': "{0} {1}".format(_("Next page"), " >>"), 'icon': get_icon_path("item_next"), 'path': plugin.url_for("music_search_album_term", term=term, page=int(page) + 1) }) if FORCE == True: plugin.set_view_mode(VIEW); return items else: return items
def music_top_tracks_by_country(country, page): results = lastfm.get_top_tracks_by_country(country, page) tracks = results["tracks"]["track"] items = [] for track in tracks: large_image = track["image"][-1]["#text"] track_name = to_utf8(track["name"]) artist_name = to_utf8(track["artist"]["name"]) context_menu = [ ( _("Context player"), "PlayMedia({0})".format( plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name, mode="context") ), ), ( _("Add to library"), "RunPlugin({0})".format( plugin.url_for("music_add_to_library", artist_name=artist_name, track_name=track_name) ), ) # , # ( # _("Musicvideo"), # "RunPlugin({0})".format(plugin.url_for("music_play_video", artist_name=artist_name, # track_name=track_name, mode='context')) # ) ] item = { "label": "{0} - {1}".format(artist_name, track_name), "path": plugin.url_for(music_play_audio, artist_name=artist_name, track_name=track_name), "thumbnail": large_image, "icon": "DefaultMusic.png", "poster": large_image, "info": {"artist": artist_name}, "info_type": "music", "context_menu": context_menu, } items.append(item) return items
def music_search_album_term(term, page): search_results = lastfm.search_album(term, page) albums = search_results["albummatches"]["album"] items_per_page = search_results["opensearch:itemsPerPage"] start_index = search_results["opensearch:startIndex"] total_results = search_results["opensearch:totalResults"] items = [] for album in albums: large_image = album["image"][-1]["#text"] album_name = to_utf8(album["name"]) artist_name = to_utf8(album["artist"]) context_menu = [ ( _("Add to library"), "RunPlugin({0})".format( plugin.url_for("music_add_album_to_library", artist_name=artist_name, album_name=album_name) ), ) ] item = { "label": "{0} - {1}".format(artist_name, album_name), "path": plugin.url_for(music_artist_album_tracks, artist_name=artist_name, album_name=album_name), "thumbnail": large_image, "icon": "DefaultMusic.png", "poster": large_image, "info": {"artist": artist_name}, "info_type": "music", "context_menu": context_menu, } items.append(item) if start_index + items_per_page < total_results: items.append( { "label": _("Next >>"), "icon": get_icon_path("item_next"), "path": plugin.url_for(music_search_album_term, term=term, page=int(page) + 1), } ) return items
def live(): """ Live TV directory """ items = [ { 'label': _("Search"), 'path': plugin.url_for(live_search), 'icon': get_icon_path("search"), }, ] channels = get_channels() if channels: items.append({ 'label': _("Clear channels"), 'path': plugin.url_for(clear_channels), #'icon': TODO, }) for (index, channel) in enumerate(channels): channel = to_utf8(channel) context_menu = [ ( _("Remove channel"), "RunPlugin({0})".format(plugin.url_for(remove_channel, channel=channel)) ) ] if index != 0: context_menu.append( ( _("Move up"), "RunPlugin({0})".format(plugin.url_for(move_channel_up, channel=channel)) ) ) if index != len(channels) - 1: context_menu.append( ( _("Move down"), "RunPlugin({0})".format(plugin.url_for(move_channel_down, channel=channel)) ) ) items.append({ 'label': channel, 'path': plugin.url_for(live_play, channel=channel), 'icon': "DefaultVideo.png", 'context_menu': context_menu, }) return items
def guide_movies_play_by_name(name, lang = "en"): import_tmdb() from meta.utils.text import parse_year items = tmdb.Search().movie(query=name, language=lang, page=1)["results"] if not items: return dialogs.ok(_("Movie not found"), "{0} {1}".format(_("No movie information found on TMDB for"), name)) if len(items) > 1: selection = dialogs.select(_("Choose Movie"), ["{0} ({1})".format( to_utf8(s["title"]), parse_year(s["release_date"])) for s in items]) else: selection = 0 if selection != -1: id = items[selection]["id"] guide_movies_play("tmdb", id, "default") if plugin.get_setting(SETTING_MOVIES_PLAYED_BY_ADD, converter=bool) == True: movies_add_to_library("tmdb", id)
def get_movie_parameters(movie): parameters = {} parameters['date'] = movie['release_date'] parameters['premiered'] = movie['release_date'] parameters['year'] = parse_year(movie['release_date']) parameters['released'] = movie['release_date'] parameters['id'] = movie['id'] parameters['imdb'] = movie['imdb_id'] parameters['title'] = movie['title'] parameters['urltitle'] = urllib.quote(to_utf8(parameters['title'])) parameters['sorttitle'] = to_utf8(parameters['title']) articles = ['a ', 'A ', 'An ', 'an ', 'The ', 'the '] for article in articles: if to_utf8(parameters['title']).startswith(article): parameters['sorttitle'] = to_utf8(parameters['title']).replace(article,'') parameters['shorttitle'] = to_utf8(parameters['title'][1:-1]) if "movie" in str(parameters['sorttitle']).lower(): parameters['sortesttitle'] = str(parameters['sorttitle']).lower().replace(' movie','') elif "movi" in str(parameters['sorttitle']).lower(): parameters['sortesttitle'] = str(parameters['sorttitle']).lower().replace(' movi','') else: parameters['sortesttitle'] = parameters['sorttitle'] parameters['original_title'] = movie['original_title'] parameters['name'] = u'%s (%s)' % (parameters['title'], parameters['year']) parameters['urlname'] = urllib.quote(to_utf8(parameters['name'])) parameters['released'] = movie['release_date'] parameters['rating'] = movie['vote_average'] genre = [x['name'] for x in movie['genres'] if not x == ''] studios = [x['name'] for x in movie['production_companies'] if not x == ''] parameters['studios'] = " / ".join(studios) parameters['genres'] = " / ".join(genre) if movie['runtime'] and movie['runtime'] != "" and movie['runtime'] != None: parameters['runtime'] = movie['runtime'] else: parameters['runtime'] = "0" parameters['duration'] = int(parameters['runtime']) * 60 parameters['plot'] = movie['overview'] parameters['tagline'] = movie['tagline'] parameters['rating'] = movie['vote_average'] parameters['poster'] = "https://image.tmdb.org/t/p/original/" + str(movie['poster_path']) parameters['fanart'] = "https://image.tmdb.org/t/p/original/" + str(movie['backdrop_path']) parameters['now'] = datetime.datetime.now().strftime('%Y%m%d%H%M%S%f') return parameters
def music_artist(name): name = to_utf8(name) items = [ { 'label': _("Tracks"), 'path': plugin.url_for("music_artist_tracks", artist_name=name), 'icon': get_icon_path("music") }, { 'label': _("Albums"), 'path': plugin.url_for("music_artist_albums", artist_name=name), 'icon': get_icon_path("music") }, ] return items
def music_artist(name): name = to_utf8(name) items = [ { 'label': _("Tracks"), 'path': plugin.url_for("music_artist_tracks", artist_name=name), 'icon': get_icon_path("music") }, { 'label': _("Albums"), 'path': plugin.url_for("music_artist_albums", artist_name=name), 'icon': get_icon_path("music") }, ] if FORCE == True: plugin.set_view_mode(VIEW); return items else: return items
def get_tvmaze_episode_parameters(show, preason, prepisode): if "status_code" in str(prepisode): return None parameters = {'id': show['externals']['thetvdb'], 'season': preason['number'], 'episode': prepisode['number']} network = show['network']['name'] parameters['network'] = network if network: parameters['network_clean'] = re.sub("(\(.*?\))", "", network).strip() else: parameters['network_clean'] = network parameters['imdb'] = show['externals']['imdb'] parameters['tvrage'] = show['externals']['tvrage'] parameters['showname'] = show['name'] parameters['clearname'] = re.sub("(\(.*?\))", "", show['name']).strip() parameters['urlname'] = urllib.quote(to_utf8(parameters['clearname'])) articles = ['a ', 'A ', 'An ', 'an ', 'The ', 'the '] parameters['sortname'] = to_utf8(parameters['clearname']) for article in articles: if to_utf8(parameters['clearname']).startswith(article): parameters['sortname'] = to_utf8(parameters['clearname']).replace(article,'') parameters['shortname'] = to_utf8(parameters['clearname'][1:-1]) parameters['absolute_number'] = "na" parameters['title'] = prepisode['name'] parameters['urltitle'] = urllib.quote(to_utf8(parameters['title'])) parameters['sorttitle'] = to_utf8(parameters['title']) articles = ['a ', 'A ', 'An ', 'an ', 'The ', 'the '] for article in articles: if to_utf8(parameters['title']).startswith(article): parameters['sorttitle'] = to_utf8(parameters['title']).replace(article,'') parameters['shorttitle'] = to_utf8(parameters['title'][1:-1]) parameters['firstaired'] = prepisode['airdate'] parameters['year'] = int(show['premiered'].split("-")[0].strip()) if parameters['firstaired']: parameters['epyear'] = int(parameters['firstaired'].split("-")[0].strip()) parameters['epmonth'] = int(parameters['firstaired'].split("-")[1].strip()) parameters['epday'] = int(parameters['firstaired'].split("-")[2].strip()) else: parameters["epyear"] = 1900 parameters["epmonth"] = 0 parameters["epday"] = 0 parameters['epid'] = prepisode['id'] if prepisode['image'] != None: parameters['poster'] = prepisode['image']['original'] elif preason['image'] != None: parameters['poster'] = preason['image']['original'] elif show['image'] != None: parameters['poster'] = show['image']['original'] parameters['fanart'] = "" parameters['thumbnail'] = parameters['poster'] parameters['icon'] = parameters['poster'] parameters['genre'] = show['type'] parameters['now'] = datetime.datetime.now().strftime('%Y%m%d%H%M%S%f') return parameters
def make_tvshow_item(info): tvdb_id = info['tvdb_id'] if xbmc.getCondVisibility("system.hasaddon(script.qlickplay)"): context_menu = [(_("Add to library"),"RunPlugin({0})".format(plugin.url_for("tv_add_to_library", id=tvdb_id))), (_("TV trailer"),"RunScript(script.qlickplay,info=playtvtrailer,tvdb_id={0})".format(tvdb_id)), (_("[COLOR ff0084ff]Q[/COLOR]lick[COLOR ff0084ff]P[/COLOR]lay"), "RunScript(script.qlickplay,info=tvinfo,tvdb_id={0})".format(tvdb_id)), (_("Recommended tv shows (TMDb)"),"ActivateWindow(10025,plugin://script.qlickplay/?info=similartvshows&tvdb_id={0})".format(tvdb_id))] elif xbmc.getCondVisibility("system.hasaddon(script.extendedinfo)"): context_menu = [(_("Add to library"),"RunPlugin({0})".format(plugin.url_for("tv_add_to_library", id=tvdb_id))), (_("TV trailer"),"RunScript(script.extendedinfo,info=playtvtrailer,tvdb_id={0})".format(tvdb_id)), (_("Extended TV show info"), "RunScript(script.extendedinfo,info=extendedtvinfo,tvdb_id={0})".format(tvdb_id)), (_("Recommended tv shows (TMDb)"),"ActivateWindow(10025,plugin://script.extendedinfo/?info=similartvshows&tvdb_id={0})".format(tvdb_id))] else: context_menu = [(_("Add to library"),"RunPlugin({0})".format(plugin.url_for("tv_add_to_library", id=tvdb_id)))] context_menu.append((_("Add to list"), "RunPlugin({0})".format(plugin.url_for("lists_add_show_to_list", src='tvdb', id=tvdb_id)))) context_menu.append((_("Show info"),'Action(Info)')) return {'label': to_utf8(info['title']), 'path': plugin.url_for("tv_tvshow", id=tvdb_id), 'context_menu': context_menu, 'thumbnail': info['poster'], 'icon': "DefaultVideo.png", 'poster': info['poster'], 'properties' : {'fanart_image' : info['fanart']}, 'info_type': 'video', 'stream_info': {'video': {}}, 'info': info}
def call_last_fm(params={}, data=None, result_format = "json"): params = dict([(k, to_utf8(v)) for k, v in params.items() if v]) params["api_key"] = API_KEY params["format"] = result_format def send_query(): if data is not None: assert not params return requests.post("{0}".format(API_ENDPOINT), json=data) else: return requests.get("{0}".format(API_ENDPOINT), params) response = send_query() response.raise_for_status() response.encoding = 'utf-8' if result_format == "json": return response.json() else: return response.text