def test_if_next_song_shuffle_next_song(self): p = Playlist(name='carl cox', repeat=False, shuffle=True) exc = None k = [Song(title = 'Odin', artist = 'ManOWar',album = 'The Sons Of Odin', lenght = '3:44'),Song(title = 'Odin', artist = 'ManOWar',album = 'The Sons Of Azis', lenght = '5:44'),\ Song(title = 'Ledena Kralica', artist = 'Azis', album = 'Lubov', lenght = '5:24')] p.add_song(k) p.next_song()
def test_if_total_length_return_the_same(self): p = Playlist(name='carl cox') exc = None k = [Song(title = 'Odin', artist = 'ManOWar',album = 'The Sons Of Odin', lenght = '3:44'),Song(title = 'Odin', artist = 'ManOWar',album = 'The Sons Of Azis', lenght = '5:44'),\ Song(title = 'Odin', artist = 'ManOWar',album = 'The Sons Of Odin', lenght = '3:44')] p.add_song(k) res = p.total_length() self.assertEqual(res, '0:9:28')
def test_if_all_are_played_with_repeat_True(self): p = Playlist(name='carl cox', repeat=True, shuffle=False) exc = None k = [Song(title = 'Odin', artist = 'ManOWar',album = 'The Sons Of Odin', lenght = '3:44'),Song(title = 'Odin', artist = 'ManOWar',album = 'The Sons Of Azis', lenght = '5:44'),\ Song(title = 'Ledena Kralica', artist = 'Azis', album = 'Lubov', lenght = '5:24')] p.add_song(k) p.played = [Song(title = 'Odin', artist = 'ManOWar',album = 'The Sons Of Odin', lenght = '3:44'),Song(title = 'Odin', artist = 'ManOWar',album = 'The Sons Of Azis', lenght = '5:44'),\ Song(title = 'Ledena Kralica', artist = 'Azis', album = 'Lubov', lenght = '5:24')] self.assertNotEqual(p.next_song(), 'The Playlist is over')
def test_if_eq_returns_right(self): s1 = Song(title='Odin', artist='ManOWar', album='The Sons Of Odin', lenght='3:44') s2 = Song(title='Odin2', artist='ManOWar2', album='The Sons Of Odin2', lenght='3:44') self.assertFalse(s1 == s2)
def setUp(self): self.song = Song(title="Why", artist="BTR", album="Why", length="1:04:44") self.same_as_song = Song(title="Why", artist="BTR", album="Why", length="1:04:44") self.other_song = Song(title="Kukavica", artist="Ceca", album="Best From Ceca", length="3:54")
def setUp(self): self.track_1 = Song(title="Why", artist="BTR", album="Why", length="04:44") self.track_2 = Song(title="Forgotten gentleness", artist="BTR", album="Why", length="03:44") self.track_3 = Song(title="Kukavica", artist="Ceca", album="Best From Ceca", length="3:54") self.my_playlist = Playlist(name="bg rock")
def test_add_and_remove_songs(self): self.my_playlist.add_song(self.track_1) self.my_playlist.add_song(self.track_2) with self.subTest("Test adding songs one by one"): self.assertEqual(self.my_playlist.songs_list, [self.track_1, self.track_2]) self.my_playlist.remove_song(self.track_1) with self.subTest("Test removing song"): self.assertEqual(self.my_playlist.songs_list, [self.track_2]) self.my_playlist.add_songs([self.track_1]) with self.subTest("Test adding list of songs"): self.assertEqual(self.my_playlist.songs_list, [self.track_2, self.track_1]) with self.subTest("Test total duration of playlist for a few minutes"): self.assertEqual(self.my_playlist.total_length(), "0:08:28") self.track_3 = Song(title="The old collection", artist="BTR", album="Why", length="1:22:50") self.my_playlist.add_song(self.track_3) with self.subTest("Test total duration of playlist for longet period"): self.assertEqual(self.my_playlist.total_length(), "1:31:18")
async def addToQueue(ctx, arg1, arg2, arg3, arg4, reverse): queue = queues.getQueueObject(ctx.guild.id) voiceChannel = ctx.author.voice.channel if voiceChannel != None: try: song = Song(dirs=dirs, searchTerm=arg1, reverse=reverse, speed=arg2, reverb=arg3, overdrive=arg4) await song.processSong() queue.addToQueue(song) if not queue.playing: await playMusic(ctx) else: await ctx.send(f'queued -> {song}') except Exception as e: await ctx.send(traceback.format_exc()) print(traceback.format_exc()) else: await ctx.send(str(ctx.author.name) + "is not in a channel.")
def test_if_remove_song_works(self): p = Playlist(name='carl cox') exc = None k = [Song(title = 'Odin', artist = 'ManOWar',album = 'The Sons Of Odin', lenght = '3:44'),Song(title = 'Odin', artist = 'ManOWar',album = 'The Sons Of Azis', lenght = '5:44'),\ Song(title = 'Odin', artist = 'ManOWar',album = 'The Sons Of Odin', lenght = '3:44')] p.add_song(k) m = [ Song(title='Odin', artist='ManOWar', album='The Sons Of Odin', lenght='3:44'), Song(title='Odin', artist='ManOWar', album='The Sons Of Azis', lenght='5:44') ] p.remove_song(m)
def test_if_artist_return_the_same(self): p = Playlist(name='carl cox') exc = None k = [ Song(title='Odin', artist='ManOWar', album='The Sons Of Odin', lenght='3:44'), Song(title='Odin', artist='ManOWar', album='The Sons Of Azis', lenght='5:44') ] p.add_song(k) d = {'ManOWar': 2} res = p.artist() self.assertEqual(res, d)
def main(): song_1 = Song("Let it go") song_2 = Song("maldita primavera") song_3 = Song("El psichosochal") song_4 = Song("una cancion satanica") song_group_1 = SongGroup() song_group_1.add(song_1) song_group_1.add(song_2) song_group_2 = SongGroup() song_group_2.add(song_3) song_group_2.add(song_4) song_group_1.add(song_group_2) song_group_1.operation()
def test_if_str_return_the_same(self): s = Song(title='Odin', artist='ManOWar', album='The Sons Of Odin', lenght='3:44') result = str(s) expected = 'ManOWar - Odin from The Sons Of Odin - 3:44' self.assertEqual(result, expected)
def test_if_lenght_return_as_expected(self): s1 = Song(title='Odin', artist='ManOWar', album='The Sons Of Odin', lenght='3:44') self.assertEqual(s1.lenght(seconds=True), '44') self.assertEqual(s1.lenght(minutes=True), '3') self.assertEqual(s1.lenght(hours=True), '0') self.assertEqual(s1.lenght(), '3:44')
def test_if_all_input_is_string(self): exc = None try: s = Song(title='odin', artist=321, album='The Sons Of Odin', lenght='3:44') except Exception as err: exc = err self.assertIsNotNone(exc) self.assertEqual(str(exc), 'Elements need to be string')
def test_if_lenght_is_in_right_should_raise_error(self): exc = None try: s = Song(title='odin', artist='ManOWar', album='The Sons Of Odin', lenght='344') except Exception as err: exc = err self.assertIsNotNone(exc) self.assertEqual(str(exc), 'Lenght need to have atleast one ":"')
def songs_from_db(cursor): statement = "SELECT name, artist, lyrics from songs;" results = cursor.execute(statement).fetchall() if not results: print("query for songs failed") return None songs = [] for name, artist, lyrics in results: song = Song(artist, name, lyrics) songs.append(song) return songs
def test_if_remvoe_song_is_in_our_list_returns_error_if_not(self): p = Playlist(name='carl cox') exc = None k = [Song(title = 'Odin', artist = 'ManOWar',album = 'The Sons Of Odin', lenght = '3:44'),Song(title = 'Odin', artist = 'ManOWar',album = 'The Sons Of Azis', lenght = '5:44'),\ Song(title = 'Odin', artist = 'ManOWar',album = 'The Sons Of Odin', lenght = '3:44')] p.add_song(k) m = [ Song(title='Odin', artist='ManOWar', album='The Sons Of Odin', lenght='3:44'), Song(title='Odin3', artist='ManOWar', album='The Sons Of Azis', lenght='5:44') ] try: p.remove_song(m) except Exception as err: exc = err self.assertRaises(KeyError)
def generate_mp3(song_name): song_obj = MP3(song_name, ID3=EasyID3) seconds = int(song_obj.info.length) hours = seconds / 3600 seconds %= 3600 minutes = seconds / 60 seconds %= 60 length = "{}:{}:{}".format(hours, minutes, seconds) return Song(artist=song_obj['artist'][0], title=song_obj['title'][0], album=song_obj['album'][0], length=length)
def main(): s = Song(title="Odin", artist="Manowar", album="The Sons of Odin", lenght="3:44") print(str(s)) print(s.lenght(seconds=True)) print(s.lenght(minutes=True)) print(s.lenght(hours=True)) print(s.lenght()) code_songs = Playlist(name="Code", repeat=True, shuffle=False) s1 = Song(title="Doko Doko", artist="Kondio", album="Cherno", lenght="2:34") s2 = Song(title="Churuliike", artist="Azis", album="Guchek", lenght="6:13") s3 = Song(title="Leden kralica", artist="Azis", album="jik - tak", lenght="2:55") entry = [s,s1,s2,s3] code_songs.add_song(entry) for el in code_songs.d: print(el) code_songs.remove_song([s]) for el in code_songs.d: print(el) print(code_songs.artist()) print(code_songs.next_song()) print(code_songs.next_song())
def load_from_dict(cls, dict_data): list_songs = [] for song in dict_data['songs_list']: list_songs.append( Song(artist=song['artist'], title=song['title'], album=song['album'], length=song['length'])) new_playlist = cls(dict_data['name'], repeat=dict_data['repeat'], shuffle=dict_data['shuffle']) new_playlist.add_songs(list_songs[:]) return new_playlist
def scrape_albums(artist, cursor): res = [] count = 0 artist_name = artist.get_song_page_name() for album in artist.get_album_infos(): album = Album(artist.artist_name, album) res.append(album) print(f'{album.title} [{len(album.songs)}]') for song_name in album.songs: count = count + 1 if _song_exists(song_name, artist_name, cursor): print(f' ↛ {song_name} [skip]') else: song = Song(artist_name, song_name) _insert_song(song, album, cursor) return res, count
def add_files(self, files: List[str]): """Add files to the song model. Parameters ---------- files : List[str] - List of mp3 file locations to be added. """ if files: self.set_files_state(True) util_f.refresh_widget(self.filesTableView) start_time = time.time() progress_dialog = QProgressDialog("Adding Files...", "Cancel", 0, len(files), parent=self, flags=Qt.WindowFlags()) progress_dialog.setModal(True) progress_dialog.setMinimumDuration(2) progress_dialog.setWindowTitle("Add Files") for index, file in enumerate(files): progress_dialog.setValue(index) self.songs_model.songs.append(Song(file)) self.songs_model.layoutChanged.emit() time_taken_seconds = time.time() - start_time time_taken = util_f.format_time( datetime.timedelta(seconds=time_taken_seconds)) estimated_time = (time_taken_seconds / (index + 1)) * len(files) eta_delta = util_f.format_time( datetime.timedelta(seconds=estimated_time)) label_text = (f"{index}/{len(files)}\n" f"Time Taken: {time_taken}\n" f"ETA: {eta_delta}") progress_dialog.setLabelText(label_text) if progress_dialog.wasCanceled(): break progress_dialog.setValue(len(files)) util_f.update_table_view(self.filesTableView)
song_key = str(input('Recommended key to play the visual pattern: ')) if song_notation in [InputModes.ENGLISH, InputModes.DOREMI, InputModes.JIANPU, InputModes.ENGLISHCHORDS]: try: note_shift = int(7 * eval(input('Shift song by how many octaves? (-n ; +n): ').strip())) except (NameError, SyntaxError): note_shift = 0 else: note_shift = 0 # print('Your key is: '+song_key) # print('Your key in English is: '+myparser.english_note_name(song_key)) english_song_key = myparser.english_note_name(song_key) # Parses song line by line mysong = Song(english_song_key) # The song key must be in English format for song_line in song_lines: instrument_line = myparser.parse_line(song_line, song_key, note_shift) # The song key must be in the original format mysong.add_line(instrument_line) print('============================================================') error_ratio = mysong.get_num_broken() / max(1, mysong.get_num_instruments()) if error_ratio == 0: print('Song successfully read with no errors!') elif error_ratio < 0.05: print('Song successfully read with few errors!') else: print('**WARNING**: Your song contains many errors. Please check the following:' '\n- All your notes are within octaves 4 and 6. If not, try again with an octave shift.' '\n- Your song is free of typos. Please check this website for full instructions: '
def __init__(self): self.state = GameState.RUNNING self.difficulty = Difficulty(0, 0) self.song = Song('Free playing', [], 200)
def test_if_add_song_works(self): p = Playlist(name='123') k = [Song(title = 'Odin', artist = 'ManOWar',album = 'The Sons Of Odin', lenght = '3:44'),Song(title = 'Odin', artist = 'ManOWar',album = 'The Sons Of Azis', lenght = '5:44'),\ Song(title = 'Odin', artist = 'ManOWar',album = 'The Sons Of Odin', lenght = '3:44')] p.add_song(k)
def recommend_songs(liked_idxs, disliked_idxs, show=False): k = KMeansHelper() model = k.get_model() data = pd.read_csv("data/combined.csv") # Finding the liked songs using array of indices liked_songs = data.iloc[liked_idxs] disliked_songs = data.iloc[disliked_idxs] if len(disliked_idxs) > 0: largest_difference = calculate_largest_differnce( liked_songs, disliked_songs) else: largest_difference = "tempo" avg_attr = liked_songs[largest_difference].mean() cluster = model.predict([ liked_songs.drop( [ "song_name", "song_popularity", "song_duration_ms", "key", "loudness", "audio_mode", "tempo", "time_signature", "playlist", "album_names", "artist_name", ], axis=1, ).mean() ])[0] combined_data = data combined_data["cluster"] = model.labels_ recommended_cluster = combined_data[combined_data.cluster == cluster] recommended_cluster = recommended_cluster.drop(index=list(liked_idxs + disliked_idxs), errors="ignore") recommended_songs = recommended_cluster.iloc[( recommended_cluster[largest_difference] - avg_attr).abs().argsort().head(10)] plot1 = plot(largest_difference, liked_songs, disliked_songs, recommended_songs, show) plot2 = plot_trend(largest_difference, liked_songs, disliked_songs, recommended_songs, show) liked_idxs = [] for idx, song in recommended_songs.iterrows(): s = Song( idx, song.loc["song_name"], song.loc["song_popularity"], song.loc["artist_name"], song.loc["album_names"], ) liked_idxs.append(s) return [liked_idxs, plot1, plot2]