def grabSongsDetailFromPage(url): print("requests:" + url) page = requests.get(url) tree = html.fromstring(page.content) textContacts = tree.xpath('//div[@class="textcontact-music"]') songs = [] for detail in textContacts: title, artist, album, record, category, genre = "", "", "", "", "", "" for a in detail: href = a.get("href") if href is not None and ".html" in href: if "artist" in href: artist = a.text elif "album" in href: album = a.text elif "recording" in href: record = a.text elif "category" in href: category = a.text elif "genre" in href: genre = a.text else: title = a.text songs.append(Song(title, artist, album, record, category, genre)) return songs
def add_new_song(song_name): song_featured_artist = input('Enter song artist: ') song_released_date = input('Enter song released date: ') song_duration = input('Enter song duration: ') song_band_name_1 = input('Enter song band name 1: ') song_band_name_2 = input('Enter song band name 2: ') bands_name = [song_band_name_1, song_band_name_2] song_type = input('Enter song type(Single/In Album): ') song_genre = input('Enter song genre: ') song_lyrics = input('Enter song lyrics: ') song_playlist = input('Enter song playlist name: ') new_song = None if song_type == 'Single' or song_type == 'single': new_song = Song(song_name, song_featured_artist, bands_name, song_playlist, song_type, song_released_date, song_genre, song_lyrics, song_duration) else: song_album_title = input('Enter song album title: ') new_song = InAlbum(song_name, song_featured_artist, song_album_title, bands_name, song_playlist, song_type, song_released_date, song_genre, song_lyrics, song_duration) result = song_controller.add_song(new_song) if result == 'error': 'Error: Please enter a valid song features.' view_library()
def save_song_to_db(song, db): """ Save song in database """ try: cursor = db.cursor() song_name = song.name artists = song.artists lyrics = song.lyrics album_name = song.album source = song.source poster_url = song.image_link mp3_links = song.mp3_links release_date = song.released_date youtube_id = song.youtube_id genres = song.genres album_id = None artist_ids = [] if album_name is not None: album_id = Album(album_name).insert(cursor).id for artist in (artists or [{'name': None, type: None}]): artist_id = Artist(artist['name'], artist['type']) \ .insert(cursor).id if artist['type'] == 'singer': artist_ids.append(artist_id) song_id = Song(song_name, lyrics, album_id, poster_url, release_date, youtube_id, artist_ids=artist_ids).insert(cursor).id for artist_id in artist_ids: SongArtist(song_id, artist_id).insert(cursor) if genres: for genre in genres: genre_id = Genre(genre).insert(cursor).id SongGenre(song_id, genre_id).insert(cursor) for quality in mp3_links: url = mp3_links.get(quality) Mp3s(song_id, url, source, quality).insert(cursor) db.commit() except IOError as error: print("Error while inserting new song", error)
def save_rankings_to_db(ranking, app): """ Save ranking in song_rankings table """ db = get_db(app) try: cursor = db.cursor() for rank in ranking: song_name = rank.name artist_name = rank.artist youtube_id = rank.youtube_id source = rank.source song_rank = rank.ranking week = rank.week genre = rank.genre artist_ids = [] for artist in artist_name: artist_id = Artist(artist, 'singer') \ .insert(cursor).id artist_ids.append(artist_id) song_id = Song(song_name, None, None, None, None, youtube_id, artist_ids=artist_ids).insert(cursor).id genre_id = Genre(genre).insert(cursor).id SongGenre(song_id, genre_id).insert(cursor) for artist_id in artist_ids: SongArtist(song_id, artist_id).insert(cursor) SongRankings( song_id, artist_id, source, song_rank, week, ).insert(cursor) except IOError as error: print('Error while inserting new ranking ', error) finally: db.commit() db.close()
def map_result_set_to_list_of_objects(self, result_set): list_of_songs = [] for row in result_set: type_of_my_song = row[6] name = row[0] featured_artist = row[1] if row[2] == None: album_title = '' else: album_title = row[2] bands_name = ['', ''] if row[3] == None: if row[4] == None: bands_name = ['', ''] elif row[4] == None: bands_name = [row[3], ''] else: bands_name = [row[3], row[4]] if row[5] == None: playlist_name = '' else: playlist_name = row[5] song_type = row[6] released_date = row[7] genre = row[8] if row[9] == None: lyrics = '' else: lyrics = row[9] duration = row[10] if type_of_my_song == 'Single' or type_of_my_song == 'single': """ my_song = Song(row[0], row[1], [row[3], row[4]], row[5], row[6], row[7], row[8], row[9], row[10])""" my_song = Song(name, featured_artist, bands_name, playlist_name, song_type, released_date, genre, lyrics, duration) else: my_song = InAlbum(name, featured_artist, album_title, bands_name, playlist_name, song_type, released_date, genre, lyrics, duration) list_of_songs.append(my_song) return list_of_songs
def get_song(self, song_name): connection = sqlite3.connect("musicly.db") cur = connection.cursor() row = None try: connection.row_factory = sqlite3.Row sqlStatement = 'SELECT * FROM SONG WHERE NAME=?' cur.execute(sqlStatement, (song_name, )) row = cur.fetchone() except Exception as ex: print("There Is An Exception.") connection.close() # return SongController.map_to_song_object(row) my_song = None type_of_my_song = row[6] if type_of_my_song == 'Single': my_song = Song(row[0], row[1], [row[3], row[4]], row[5], row[6], row[7], row[8], row[9], row[10]) else: my_song = InAlbum(row[0], row[1], row[2], [row[3], row[4]], row[5], row[6], row[7], row[8], row[9], row[10]) return my_song
elif "recording" in href: record = a.text elif "category" in href: category = a.text elif "genre" in href: genre = a.text else: title = a.text songs.append(Song(title, artist, album, record, category, genre)) return songs if __name__ == "__main__": with open("songsList2.csv", 'w', newline='', encoding='utf-8') as csv_file: wr = csv.writer(csv_file, delimiter=',', quoting=csv.QUOTE_ALL) songs = [ Song("title", "artist", "album", "record", "category", "genre") ] # songs = grabSongsDetailFromPage("https://musicstation.kapook.com/genre.html?v=%E0%B8%A5%E0%B8%B9%E0%B8%81%E0%B8%97%E0%B8%B8%E0%B9%88%E0%B8%87-%E0%B9%80%E0%B8%9E%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%8A%E0%B8%B5%E0%B8%A7%E0%B8%B4%E0%B8%95&page=1") # print(songs) for page in range(1, 109): songs += grabSongsDetailFromPage( "https://musicstation.kapook.com/genre.html?v=%E0%B8%A5%E0%B8%B9%E0%B8%81%E0%B8%97%E0%B8%B8%E0%B9%88%E0%B8%87-%E0%B9%80%E0%B8%9E%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%8A%E0%B8%B5%E0%B8%A7%E0%B8%B4%E0%B8%95&page=" + page.__str__()) for page in range(1, 386): songs += grabSongsDetailFromPage( "https://musicstation.kapook.com/genre.html?v=%E0%B9%84%E0%B8%97%E0%B8%A2&page=" + page.__str__()) for cdr in songs: wr.writerow(cdr.getDetailCSV())
music_wavs[key] = file if found: print('Found', file_name) print('Parsing character and song data') characters = {} for index, character_data in enumerate( song_pack_data['offline_song_pack_list']): character = Character(character_data) character.number = index + 1 for song_data in character_data['song_info_list']: song = Song(song_data, character.id) if config['rename_aesir'] and song.artist == 'Æsir': song.artist = config['rename_aesir_to'] character.songs.append(song) characters[character.id] = character for expansion_pack in expansion_pack_data['ExpansionPackList']: pack_info = ExpansionPackInfo(expansion_pack) for song_data in expansion_pack['SongInfoList']: song = Song(song_data) if config['rename_aesir'] and song.artist == 'Æsir': song.artist = config['rename_aesir_to'] song.expansion_pack_info = pack_info characters[song.character_id].songs.append(song)