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_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 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_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_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_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 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 get_albumId(self,album, artist): c.execute("SELECT * FROM album WHERE strAlbum = ? AND strArtists = ?", (album, artist)) row = c.fetchone() if row: return row[0] else: album_info = lastfm.get_album_info(artist, album) if "wiki" in album_info: review = album_info["wiki"]["content"] else: review = "" c.execute("INSERT INTO album (strAlbum,strArtists,strReleaseType, strReview) VALUES (?,?,?,?)", (album, artist, "album", review)) id = c.lastrowid conn.commit() return id
def add_music_to_library(library_folder, artist_name, album_name, track_name): # replace non valid path characters with _ safe_artist_name = to_utf8(re.sub('[^\w\-_\. ]', '_', artist_name)) safe_album_name = to_utf8(re.sub('[^\w\-_\. ]', '_', album_name)) safe_track_name = to_utf8(re.sub('[^\w\-_\. ]', '_', track_name)) changed = False artist_info = lastfm.get_artist_info(artist_name) album_info = lastfm.get_album_info(artist_name, album_name) # create nfo file artist_folder = os.path.join(library_folder, safe_artist_name) album_folder = os.path.join(artist_folder, safe_album_name) if not xbmcvfs.exists(artist_folder): xbmcvfs.mkdir(artist_folder) if not xbmcvfs.exists(album_folder): xbmcvfs.mkdir(album_folder) nfo_artist_path = os.path.join(artist_folder, "artist.nfo") nfo_album_path = os.path.join(album_folder, "album.nfo") track_info = lastfm.get_track_info(artist_name, track_name) track_number = "" if "album" in track_info: track_number = track_info["album"]["@attr"]["position"] if track_number != "" and track_number != None: full_track_name = track_number + ". " + safe_track_name else: full_track_name = safe_track_name else: full_track_name = safe_track_name nfo_track_path = os.path.join(album_folder, full_track_name + ".nfo") if not xbmcvfs.exists(nfo_artist_path): changed = True image = artist_info["image"][-1]["#text"] nfo_file = xbmcvfs.File(nfo_artist_path, 'w') content = "<artist>\n" \ " <name>{0}</name>\n" \ " <thumb>{1}</thumb>\n" \ "</artist>".format(artist_name, image) nfo_file.write(content) nfo_file.close() if not xbmcvfs.exists(nfo_album_path): changed = True image = album_info["image"][-1]["#text"] nfo_file = xbmcvfs.File(nfo_album_path, 'w') content = "<album>\n" \ " <title>{0}</title>\n" \ " <artist>{1}</artist>\n" \ " <thumb>{2}</thumb>\n" \ "</album>".format(album_name, artist_name, image) nfo_file.write(content) nfo_file.close() if not xbmcvfs.exists(nfo_track_path): changed = True track_info = lastfm.get_track_info(artist_name, track_name) track_number = "" if "album" in track_info: track_number = track_info["album"]["@attr"]["position"] nfo_file = xbmcvfs.File(nfo_track_path, 'w') content = "<musicvideo>\n" \ " <title>{0}</title>\n" \ " <artist>{1}</artist>\n" \ " <album>{2}</album>\n" \ " <track>{3}</track>\n" \ "</musicvideo>".format(to_utf8(track_name), artist_name, album_name, track_number) nfo_file.write(content) nfo_file.close() # create strm file strm_filepath = os.path.join(album_folder, full_track_name + ".strm") if not xbmcvfs.exists(strm_filepath): changed = True track_info = lastfm.get_track_info(artist_name, track_name) track_number = "" if "album" in track_info: track_number = track_info["album"]["@attr"]["position"] strm_filepath = os.path.join( album_folder, track_number + ". " + safe_track_name + ".strm") strm_file = xbmcvfs.File(strm_filepath, 'w') content = plugin.url_for("music_play", artist_name=artist_name, track_name=track_name, album_name=album_name, mode='library') strm_file.write(content) strm_file.close() # create thumbnails thumb_album_path = os.path.join(artist_folder, "folder.jpg") if not xbmcvfs.exists(thumb_album_path): changed = True r = requests.get(artist_info["image"][-1]["#text"], stream=True) if r.status_code == 200: try: with open(thumb_album_path, 'wb') as f: r.raw.decode_content = True shutil.copyfileobj(r.raw, f) except: pass thumb_album_path = os.path.join(album_folder, "folder.jpg") if not xbmcvfs.exists(thumb_album_path): changed = True try: r = requests.get(album_info["image"][-1]["#text"], stream=True) if r.status_code == 200: with open(thumb_album_path, 'wb') as f: r.raw.decode_content = True shutil.copyfileobj(r.raw, f) except: pass return changed
def add_music_to_library(library_folder, artist_name, album_name, track_name): # replace non valid path characters with _ safe_artist_name = to_utf8(re.sub('[^\w\-_\. ]', '_', artist_name)) safe_album_name = to_utf8(re.sub('[^\w\-_\. ]', '_', album_name)) safe_track_name = to_utf8(re.sub('[^\w\-_\. ]', '_', track_name)) changed = False artist_info = lastfm.get_artist_info(artist_name) album_info = lastfm.get_album_info(artist_name, album_name) # create nfo file artist_folder = os.path.join(library_folder, safe_artist_name) album_folder = os.path.join(artist_folder, safe_album_name) if not xbmcvfs.exists(artist_folder): xbmcvfs.mkdir(artist_folder) if not xbmcvfs.exists(album_folder): xbmcvfs.mkdir(album_folder) nfo_artist_path = os.path.join(artist_folder, "artist.nfo") nfo_album_path = os.path.join(album_folder, "album.nfo") track_info = lastfm.get_track_info(artist_name, track_name) track_number = "" if "album" in track_info: track_number = track_info["album"]["@attr"]["position"] if track_number != "" and track_number != None: full_track_name = track_number + ". " + safe_track_name else: full_track_name = safe_track_name else: full_track_name = safe_track_name nfo_track_path = os.path.join(album_folder, full_track_name + ".nfo") if not xbmcvfs.exists(nfo_artist_path): changed = True image = artist_info["image"][-1]["#text"] nfo_file = xbmcvfs.File(nfo_artist_path, 'w') content = "<artist>\n" \ " <name>{0}</name>\n" \ " <thumb>{1}</thumb>\n" \ "</artist>".format(artist_name, image) nfo_file.write(content) nfo_file.close() if not xbmcvfs.exists(nfo_album_path): changed = True image = album_info["image"][-1]["#text"] nfo_file = xbmcvfs.File(nfo_album_path, 'w') content = "<album>\n" \ " <title>{0}</title>\n" \ " <artist>{1}</artist>\n" \ " <thumb>{2}</thumb>\n" \ "</album>".format(album_name, artist_name, image) nfo_file.write(content) nfo_file.close() if not xbmcvfs.exists(nfo_track_path): changed = True track_info = lastfm.get_track_info(artist_name, track_name) track_number = "" if "album" in track_info: track_number = track_info["album"]["@attr"]["position"] nfo_file = xbmcvfs.File(nfo_track_path, 'w') content = "<musicvideo>\n" \ " <title>{0}</title>\n" \ " <artist>{1}</artist>\n" \ " <album>{2}</album>\n" \ " <track>{3}</track>\n" \ "</musicvideo>".format(to_utf8(track_name), artist_name, album_name, track_number) nfo_file.write(content) nfo_file.close() # create strm file strm_filepath = os.path.join(album_folder, full_track_name + ".strm") if not xbmcvfs.exists(strm_filepath): changed = True track_info = lastfm.get_track_info(artist_name, track_name) track_number = "" if "album" in track_info: track_number = track_info["album"]["@attr"]["position"] strm_filepath = os.path.join(album_folder, track_number + ". " + safe_track_name + ".strm") strm_file = xbmcvfs.File(strm_filepath, 'w') content = plugin.url_for("music_play", artist_name=artist_name, track_name=track_name, album_name=album_name, mode='library') strm_file.write(content) strm_file.close() # create thumbnails thumb_album_path = os.path.join(artist_folder, "folder.jpg") if not xbmcvfs.exists(thumb_album_path): changed = True r = requests.get(artist_info["image"][-1]["#text"], stream=True) if r.status_code == 200: try: with open(thumb_album_path, 'wb') as f: r.raw.decode_content = True shutil.copyfileobj(r.raw, f) except: pass thumb_album_path = os.path.join(album_folder, "folder.jpg") if not xbmcvfs.exists(thumb_album_path): changed = True try: r = requests.get(album_info["image"][-1]["#text"], stream=True) if r.status_code == 200: with open(thumb_album_path, 'wb') as f: r.raw.decode_content = True shutil.copyfileobj(r.raw, f) except: pass return changed