def download_custom_songs(): custom_songs = [] print( "Enter a blank line at any time when you are done entering data..." ) while True: print("\nEnter the info for the song you want to download:") title = str(input("Enter the title of the song: ")) if title is "": break artist = str(input("Enter the artist of the song: ")) if artist is "": break album = str(input("Enter the album the song is from: ")) if album is "": break time = str(input("Enter the time of the song (eg. 3:18): ")) if time is "": break custom_songs.append({ "title": title.strip(), "artist": artist.strip(), "album": album.strip(), "time": Util.time_in_seconds(time.strip()) }) Controller._download(custom_songs, "Custom")
def get_playlist(self): # Retrieve HTML source if it has not been retrieved already if not self.html_src: source = self.retrieve_html_source() else: source = self.html_src #split to find the playlist name name_source = source.split(r'<h1 class="main">')[1] name_source = name_source.split('</span>')[0] playlist_name = re.findall(r'\">(.*)</a>', name_source)[0] # Remove everything before the playlist section songs_source = source.split("<tbody data-bind=\"foreach: tracks\"")[1] # Divide up into songs songs = songs_source.split("</tr>") # Create a array of dictionaries of all the songs songs_dict = [] for song in songs: try: title = re.findall(r'<td.*>(.*)<\/div>', song, re.S)[0] artist = re.findall(r'spotify:artist:.*>(.*)<\/a>', song)[0] album = re.findall(r'spotify:album.*>(.*)<\/a>', song)[0] song_time = re.findall(r'tl-time\">([\w|:]*)<\/td>', song, re.S)[0] title = re.sub(r" - \w* Edit", "", title, re.IGNORECASE) title = re.sub(r" -.*Version.*", "", title, re.IGNORECASE) title = re.sub(r" -.*Remaster(ed)?.*", "", title, re.IGNORECASE) title = re.sub(r" \(Remaster(ed)?\) *", "", title, re.IGNORECASE) title = re.sub(r" -.*Anniversary Mix.*", "", title, re.IGNORECASE) song_dict = { 'title': Util.html_to_ascii(title), 'artist': Util.html_to_ascii(artist), 'album': Util.html_to_ascii(album), 'time': Util.time_in_seconds(song_time), } songs_dict.append(song_dict) except IndexError: pass return [playlist_name, songs_dict]