Esempio n. 1
0
 def __init__(self, date, moment, artistFromName, albumFromName,
              songFromName, artistToName, albumToName, songToName,
              isRootNode, isAlbum, isSong, repetitions, device, isStreaming,
              isFirstTimeListening, notes):
     self.date = date
     self.moment = moment
     self.artistFrom = Artist(artistFromName)
     self.artistTo = Artist(artistToName)
     self.albumFrom = Album(albumFromName)
     self.albumTo = Album(albumToName)
     self.songFrom = Song(songFromName)
     self.songTo = Song(songToName)
     if (isRootNode == 'Y'):
         self.isRootNode = True
     else:
         self.isRootNode = False
     if (isAlbum == 'A'):
         self.isAlbum = True
         self.isSong = False
     elif (isSong == "S"):
         self.isAlbum = False
         self.isSong = True
     if (isStreaming == 'Y'):
         self.isStreaming = True
     else:
         self.isStreaming = False
     if (isFirstTimeListening == 'Y'):
         self.isFirstTimeListening = True
     else:
         self.isFirstTimeListening = False
     self.notes = notes
Esempio n. 2
0
def main():
    set_from_db.get_songs_from_file()
    set_from_db.get_users_from_file()
    # Users.initiate_users()
    # SongsList.initiate_songs()
    Users.add_user("eytan", "123")

    e = Users.get_user("eytan")

    e.change_password("123", "456")

    e.add_playlist("lala")
    e.add_playlist("lala2")

    p = e.get_playlist("lala")

    s1 = Song("hamilton", 2010, "rap", "lin manuel miranda")
    s2 = Song("hamilton_1", 2010, "rap", "lin manuel miranda")
    SongsList.add_song(s1)
    SongsList.add_song(s2)
    e.add_song_to_playlist("lala", "hamilton")
    e.add_song_to_playlist("lala", "hamilton_1")
    e.add_song_to_playlist("lala2", "hamilton_1")

    set_from_db.write_users_to_file()
    set_from_db.write_songs_to_file()
    print("h")
Esempio n. 3
0
 def test_total_length(self):
     test_playlist = Playlist("chalgata")
     song1 = Song("s", "s", "s", 1, 2, 3)
     song2 = Song("a", "s", "s", 1, 3, 4)
     test_playlist.add_song(song1)
     test_playlist.add_song(song2)
     self.assertEqual(test_playlist.songs, [song1, song2])
     self.assertEqual(test_playlist.total_length(), 5)
Esempio n. 4
0
    def test_add_songs(self):
        songs = [Song("Odin1", "Mar", "The sons of Odin_01", "2:78"),
                 Song("Odin2", "Manomar", "The", "1:2:44"),
                 Song("Odin3", "Manomar", "The sons ", "2:44"),
                 Song("Odin90", "Manomar", "Theof Odi n_04", "2:44")]

        self.pl.add_songs(songs)
        self.pl.pprint_playlist()
Esempio n. 5
0
def get_songs_from_source(songs):
    SongsList.initiate_songs()

    for current in songs:
        song = Song(current['title'], current['year'], current['genre'],
                    current['performer'])
        song.rating = current['rating']
        SongsList.add_song(song)
Esempio n. 6
0
 def test_remove_songs(self):
     test_playlist = Playlist("chalgata")
     song1 = Song("s", "s", "s", 1, 2, 3)
     test_playlist.add_song(song1)
     self.assertEqual(test_playlist.songs, [song1])
     test_playlist.remove_song(song1)
     self.assertEqual(test_playlist.songs, [])
Esempio n. 7
0
class testSong(unittest.TestCase):
    def setUp(self):
        self.s = Song('fj', 'xhch', 'drdy', '4:09')
        self.s2 = Song('fj', 'xhch', 'drdy', '1:04:09')
        self.s3 = Song('fj', 'xhch', 'drdy', '2:25:09')

    def test_lenght(self):
        self.assertEqual(self.s.lenght(seconds=True), 249)

    def test_lenght2(self):
        self.assertEqual(self.s2.lenght(minutes=True), 64)

    def test_lenght3(self):
        self.assertEqual(self.s3.lenght(hours=True), 2)

    def test_lenght4(self):
        self.assertEqual(self.s.lenght(), '2')
Esempio n. 8
0
 def test_song_constructor(self):
     new_song = Song("Fuel", "Metallica", "Reload", 5, 277, 320)
     self.assertEqual(new_song.title, "Fuel")
     self.assertEqual(new_song.artist, "Metallica")
     self.assertEqual(new_song.album, "Reload")
     self.assertEqual(new_song.rating, 5)
     self.assertEqual(new_song.length, 277)
     self.assertEqual(new_song.bitrate, 320)
Esempio n. 9
0
def parse_song_data(data):
    """
    Convert song data from dictionaries to the Song class.
    """
    parsed_song_data = {}

    for song_name in data:  #View each song
        songdict = data[song_name]  #Get that song's dictionary

        song = Song(songdict)  #Use dictionary to create Song object
        parsed_song_data[song_name] = song  #Add song object

    return parsed_song_data  #Return song object
Esempio n. 10
0
    def generate_palylist(self):
        folder_name = (re.findall('\w+', self.path)).pop()
        playlist = Playlist(folder_name, True, True)

        files = self.get_music_files()
        for f in files:
            file_path = '{}/{}'.format(self.path, f)
            tags = ID3(file_path)
            audio = MP3(file_path)
            lenght = '{:0.2f}'.format(audio.info.length / 60)
            song = Song(tags['TIT2'], tags['TCOM'], tags['TALB'], '3.35')
            playlist.songs.append(song)

        return playlist
Esempio n. 11
0
def albumCreation(artistID, albumID, songID, songSP, allAlbums, allSongs, isTo,
                  device, repetitions, albumOrSong, isFirstTimeListening):
    '''This function creates an album Object, looks (on Discogs) for the tracklist and then updates Song details (duration, date, Number of repetitions etc...)
    returns: album, AllSongs'''

    logging.info('     Creating a tracklist for \'' +
                 str(ID_album_dict[albumID]) + '\'')
    logging.info('     Updating \'allSongs\' collection...')

    trackList = []
    album = Album(None, None, None, None, None, None)

    if (ID_album_dict[albumID] == '//'):

        songSP = sp.track(songID)
        song = Song(songSP['id'], songSP['name'], songSP['duration_ms'], 0, 0)

        trackList.append(song)
        allSongs[songID] = song
    else:
        albumSP = sp.album(albumID)
        trackListSP = sp.album_tracks(albumID)
        logging.info('         Tracks in this album:\n')
        for songSP in trackListSP[
                'items']:  #creating a tracklist from the info retrieved from spotify
            song = Song(songSP['id'], songSP['name'], songSP['duration_ms'], 0,
                        0)
            trackList.append(song)
            logging.info('             -->' + songSP['name'])
            allSongs[songSP['id']] = song
        logging.info('\n')
        logging.info('     Creating album object for \'' +
                     str(ID_album_dict[albumID]) + '\'')
        album = Album(albumSP['id'], albumSP['name'], albumSP['release_date'],
                      albumSP['release_date_precision'],
                      albumSP['label'], albumSP['popularity'], trackList, None,
                      len(trackList), isFirstTimeListening
                      )  #Creating an album object with all the tracks
        album.setDuration()  #calculating the total duration of the album

    if (isTo == True and albumOrSong == 'S'):
        song = allSongs[songID]
        song.updateRepetitions(device, repetitions)
    else:
        logging.info(
            '         Im not updating \'PlayCount\' for this specific song: isTo = '
            + str(isTo) + ', albumOrSong = ' + str(albumOrSong))

    if (isTo == True and albumOrSong == 'A'):
        album.updateRepetitions(device, repetitions)
    else:
        logging.info(
            '         Im not updating \'PlayCount\' for this specific album: isTo = '
            + str(isTo) + ', albumOrSong = ' + str(albumOrSong))

    return (album, allSongs)
Esempio n. 12
0
def add_song():
    song_title = request.json.get("song_title")
    song_genre = request.json.get("song_genre")
    song_year = request.json.get("song_year")
    song_performer = request.json.get("song_performer")

    valid = valid_parameters(song_title=song_title,
                             song_genre=song_genre,
                             song_year=song_year,
                             song_performer=song_performer)

    if valid != True:
        return valid

    s = Song(song_title, song_year, song_genre, song_performer)
    add_song = SongsList.add_song(s)

    if add_song is None:
        return {"error": "this song already exist in the collection"}

    set_from_db.write_songs_to_file()

    return {"message": "OK", "data": song_title}
Esempio n. 13
0
from song_class import Song
import serializers as ser

if __name__ == '__main__':
    song = Song(1, 'Basket Case', 'Green Day')
    print('song:\n', song)
    serializer = ser.ObjectSerializer()
    product = serialzier.serialize(song, 'JSON')
    print('product (JSON):\n', product)
Esempio n. 14
0
 def test_show_artists(self):
     test_playlist = Playlist("chalgata")
     song1 = Song("s", "s", "s", 1, 2, 3)
     test_playlist.add_song(song1)
     self.assertEqual(test_playlist.show_artists(), ["s"])
Esempio n. 15
0
 def test_bitrate(self):
     test_playlist = Playlist("chalgata")
     song1 = Song("s", "s", "s", 1, 2, 3)
     test_playlist.add_song(song1)
     test_playlist.remove_bad_quality(4)
     self.assertEqual(test_playlist.songs, [])
Esempio n. 16
0
 def test_disrated(self):
     test_playlist = Playlist("chalgata")
     song1 = Song("s", "s", "s", 1, 2, 3)
     test_playlist.add_song(song1)
     test_playlist.remove_disrated(2)
     self.assertEqual(test_playlist.songs, [])
Esempio n. 17
0
 def setUp(self):
     self.pl = Playlist("My_list", repeat=True, shuffle=True)
     self.pl.add_song(Song("Odin1", "Manomar", "The sons of Odin_01", "2:44"))
     self.pl.add_song(Song("Odin2", "Manomar", "The sons of Odin_02", "2:44"))
     self.pl.add_song(Song("Odin3", "Manomar", "The sons of Odin_03", "2:44"))
     self.pl.add_song(Song("Odin4", "Manomar", "The sons of Odin_04", "2:44"))
Esempio n. 18
0
 def setUp(self):
     self.s = Song('fj', 'xhch', 'drdy', '4:09')
     self.s2 = Song('fj', 'xhch', 'drdy', '1:04:09')
     self.s3 = Song('fj', 'xhch', 'drdy', '2:25:09')