Exemple #1
0
def split_values(song: Song, tag: SongTag):
    """Split the values in a tag on the given string in settings.

        Parameters
        ----------
        song : Song -
            Song to be edited\n
        tag : SongTag -
            Tag where data should be split
        """
    values_to_set: Union[List, List[str], List[List[str]]] = []
    values = tag.get_tag(song.id3)
    if values is None:
        return
    for value in values:
        if tag.value_length == 1:
            values_to_set = cast(List[str], values_to_set)
            value = cast(str, value)
            values_split = _split_value(value)
            values_to_set.extend(values_split)
        else:
            values_to_set = cast(List[List[str]], values_to_set)
            value = cast(List[str], value)
            role, person = value
            split_roles = _split_value(role)
            split_people = _split_value(person)
            for split_role in split_roles:
                for split_person in split_people:
                    values_to_set.append([split_role, split_person])
    tag.set_tag(song.id3, values_to_set)
    song.save()
Exemple #2
0
def remove_values(song: Song, tag: SongTag,
                  values_to_remove: Union[List[str], List[List[str]], None]):
    """Remove the given values from the tag for this song.

        Parameters
        ----------
        song : Song -
            Song to be edited\n
        tag : SongTag -
            Tag the values awill be removed from\n
        remove_values : Union[List[str], List[List[str]], None] -
            Values to be removed
        """
    if values_to_remove is None:
        return
    values = tag.get_tag(song.id3)
    if values is None:
        return
    values = values.copy()
    for value in values_to_remove:
        try:
            values.remove(value)  # type: ignore
        except ValueError:
            continue
    if len(values) > 0:
        tag.set_tag(song.id3, values)
    else:
        tag.remove_tag(song.id3)
    song.save()
Exemple #3
0
 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()
Exemple #4
0
def add_values(song: Song, tag: SongTag,
               new_values: Union[List[str], List[List[str]], None]):
    """Append values sent to the tag in the song.

        Parameters
        ----------
        song : Song -
            Song where the data should change\n
        tag : SongTag -
            The tag whose values should change\n
        new_values : Union[List[str], List[List[str]], None] -
            The values to be added
        """
    if new_values is None:
        add_tag(song, tag)
        return
    values = tag.get_tag(song.id3)
    if values is None:
        set_tag(song, tag, new_values)
        return
    values_copy = values.copy()
    for value in new_values:
        if value not in values:
            values_copy.append(value)  # type: ignore
    tag.set_tag(song.id3, values_copy)
    song.save()
Exemple #5
0
 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')
Exemple #6
0
 def post(self):
     jsn = self.request.get("json")
     try:
         data = json.loads(jsn)
         Song.new_from_dict(data)
     except ValueError as err:
         self.render("import.html", error=str(err))
     self.redirect("/")
Exemple #7
0
 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')
Exemple #8
0
 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')
Exemple #9
0
 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)
Exemple #10
0
def remove_tag(song: Song, tag: SongTag):
    """Remove all values a tag and then remove the tag from the song.

        Parameters
        ----------
        song : Song -
            Song that the tag should be removed from\n
        tag : SongTag -
            Tag that should be removed.
        """
    if tag.has_tag(song.id3):
        tag.remove_tag(song.id3)
        song.save()
Exemple #11
0
def add_tag(song: Song, tag: SongTag):
    """Add a non-existent tag to the tags in a song.

        Parameters
        ----------
        song : Song -
            Song that the tag should be added to\n
        tag : SongTag -
            Tag that should be added.
        """
    if not tag.has_tag(song.id3):
        tag.set_tag(song.id3, [])
        song.save()
Exemple #12
0
 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")
Exemple #13
0
    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")
Exemple #14
0
    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")
Exemple #15
0
 def get(self, song_id):
     if utils.is_number(song_id):
         song = Song.get_by_id(int(song_id))
     if song:
         self.render("recording.html", song=song)
     else:
         self.error(404)
Exemple #16
0
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.")
Exemple #17
0
 def get(self, song_id):
     if utils.is_number(song_id):
         song = Song.get_by_id(int(song_id))
     if song:
         self.render("song.html", song=song, recordings=song.get_recordings(), edit_lyrics=True)
     else:
         self.error(404)
Exemple #18
0
 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)
Exemple #19
0
 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)
Exemple #20
0
 def post(self, song_id):
     if utils.is_number(song_id):
         song = Song.get_by_id(int(song_id))
     if song:
         song.delete_self()
         self.redirect("/")
     else:
         self.error(404)
Exemple #21
0
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()
Exemple #22
0
 def post(self, song_id):
     if utils.is_number(song_id):
         song = Song.get_by_id(int(song_id))
     if song:
         lyrics = self.request.get("lyrics")
         song.set_lyrics(lyrics)
         self.redirect(song.get_url())
     else:
         self.error(404)
Exemple #23
0
def set_tag(song: Song, tag: SongTag,
            new_values: Union[List[str], List[List[str]], None]):
    """Sets the values of the given tag to the values sent.

        Parameters
        ----------
        song : Song -
            Song where the tag should be set\n
        tag : SongTag -
            Tag that should be set\n
        new_values : Union[List[str], List[List[str]], None] -
            Values that should be set.
        """
    if new_values is None:
        add_tag(song, tag)
        return
    tag.set_tag(song.id3, new_values)
    song.save()
Exemple #24
0
    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)
Exemple #25
0
 def post(self):
     title = self.request.get("title")
     audiolink = self.request.get("audiolink")
     performer = self.request.get("performer")
     if title:
         s = Song.new_song(title, audiolink, performer)
         self.redirect("/song/%s" % str(s.key().id()))
     else:
         error = u"Название не может быть пустым!"
         self.render("newsong.html", title=title, audiolink=audiolink, performer=performer, error=error)
Exemple #26
0
def replace_values(song: Song, tag: SongTag, new_values: Union[List[List[str]],
                                                               None]):
    """Replace the values in the given tag if they match the strings in
        new values.

        Parameters
        ----------
        song : Song -
            Song to be edited\n
        tag : SongTag -
            Tag being edited\n
        new_values : Union[List[List[str]], None] -
            Values to change
        """
    if not new_values:
        return
    new_values = cast(List[List[str]], new_values)
    values = tag.get_tag(song.id3)
    if values is None:
        return
    values_copy = np.array(values)
    if tag.value_length == 1:
        values = cast(List[str], values)
        for index, item in enumerate(values):
            _replace_value(values_copy=values_copy,
                           new_values=new_values,
                           tag_length=tag.value_length,
                           item_index=index,
                           item=item)
    elif tag.value_length == 2:
        values = cast(List[List[str]], values)
        for index_of_pair, pair in enumerate(values):
            for index_in_pair, pair_item in enumerate(pair):
                _replace_value(values_copy=values_copy,
                               new_values=new_values,
                               tag_length=tag.value_length,
                               index_of_pair=index_of_pair,
                               pair=pair,
                               item_index=index_in_pair,
                               item=pair_item)
    values_copy = values_copy.tolist()
    tag.set_tag(song.id3, values_copy)
    song.save()
Exemple #27
0
    def get(self, song_id, rec_id):
        if utils.is_number(song_id):
            song = Song.get_by_id(int(song_id))
        if song and utils.is_number(rec_id):
            rec = Recording.get_by_id(int(rec_id), parent=song.key())

        if song and rec:
            self.render("recording.html", song=song, audiolink=rec.audiolink, performer=rec.performer)
        else:
            self.error(404)
Exemple #28
0
    def post(self, song_id, rec_id):
        if utils.is_number(song_id):
            song = Song.get_by_id(int(song_id))
        if song and utils.is_number(rec_id):
            rec = Recording.get_by_id(int(rec_id), parent=song.key())

        if song and rec:
            rec.delete_self()
            self.redirect(song.get_url())
        else:
            self.error(404)
Exemple #29
0
 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')
Exemple #30
0
 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 ":"')
Exemple #31
0
 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)
Exemple #32
0
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
Exemple #33
0
def remove_duplicates(song: Song, tag: SongTag):
    """Remove duplicate values from a specific tag.

        Parameters
        ----------
        song : Song -
            Song to be edited\n
        tag : SongTag -
            Tag to be edited
        """
    values = tag.get_tag(song.id3)
    if values is None:
        return
    values = tuple(
        tuple(value)  # type: ignore
        if isinstance(value, list) else value for value in values)
    new_list = [
        list(value) if isinstance(value, tuple) else value
        for value in list(OrderedDict.fromkeys((values)))
    ]
    tag.set_tag(song.id3, new_list)
    song.save()
    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)
Exemple #35
0
    def post(self, song_id):
        if utils.is_number(song_id):
            song = Song.get_by_id(int(song_id))
        if not song:
            self.error(404)

        audiolink = self.request.get("audiolink")
        performer = self.request.get("performer")
        if audiolink:
            song.add_recording(audiolink, performer)
            self.redirect("/song/%s" % str(song.key().id()))
        else:
            error = u"Линк не может быть пустым"
            self.render("recording.html", song=song, audiolink=audiolink, performer=performer, error=error)
Exemple #36
0
    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
Exemple #37
0
    def post(self, song_id, rec_id):
        if utils.is_number(song_id):
            song = Song.get_by_id(int(song_id))
        if song and utils.is_number(rec_id):
            rec = Recording.get_by_id(int(rec_id), parent=song.key())

        audiolink = self.request.get("audiolink")
        performer = self.request.get("performer")
        if audiolink:
            rec.update(audiolink, performer)
            self.redirect("/song/" + str(song.key().id()))
        else:
            error = u"Линк не может быть пустым"
            self.render("recording.html", song=song, audiolink=audiolink, performer=performer, error=error)
Exemple #38
0
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
Exemple #39
0
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 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)
Exemple #41
0
 def get(self):
     self.render("main.html", songs=Song.all_songs())
Exemple #42
0
 def get(self):
     songs = Song.all_songs()
     self.response.out.write(json.dumps([s.as_dict() for s in songs]))