Exemplo n.º 1
0
def load_data():
    new_artist = None
    new_album = None
    artist_list = []

    with open("albums.txt", "r") as albums:
        for line in albums:
            artist_field, album_field, year_field, song_field = tuple(
                line.strip('\n').split('\t'))
            year_field = int(year_field)
            print(artist_field, album_field, year_field, song_field)

            if new_artist is None:
                new_artist = Artist(artist_field)
            elif new_artist.name != artist_field:
                new_artist.add_album(new_album)
                artist_list.append(new_artist)
                new_artist = Artist(artist_field)
                new_album = None

            if new_album is None:
                new_album = Album(album_field, year_field, new_artist)
            elif new_album.name != album_field:
                new_artist.add_album(new_album)
                new_album = Album(album_field, year_field, new_artist)

            new_song = Song(song_field, new_artist)
            new_album.add_song(new_song)

        if new_artist is not None:
            if new_album is not None:
                new_artist.add_album(new_album)
            artist_list.append(new_artist)

    return artist_list
 def setUpClass(cls) -> None:
     cls.artist1 = Artist('Steve', 'UK')
     cls.artist2 = Artist('John', 'USA')
     cls.album1 = Album('s_album1', 2019, cls.artist1)
     cls.album2 = Album('j_album1', 2017, cls.artist2)
     cls.song1 = Song('s_song', cls.artist1, 2018, 180, cls.album1)
     cls.song2 = Song('j_song', cls.artist2, 2017, 150, cls.album2)
 def test_adding_song_raises_error_when_artists_doesnt_match(self):
     a = Artist('Lana Del Ray', 'USA')
     a1 = Artist('Adele', 'UK')
     b = Album('Born to Die', 2012, 'alternative/indie', a)
     b1 = Album('21', 2011, 'pop/soul', a1)
     c = Song('Blue Jeans', a, 2012, 240, b)
     with self.assertRaises(WrongArtistError):
         b1.add_song(c)
Exemplo n.º 4
0
def get_covers(artist, pth, lastfm):

    for album in artist.albums:
        album = Album(album)
        if not image.is_fine(album.image):
            print parser.unescape(album.name)
            image.fix(album, pth, lastfm)
Exemplo n.º 5
0
 def test_add_song_works_correct(self):
     art1 = Artist("Mettalica", "USA")
     alb1 = Album('Death magnetic', 2008, 'Thrash metal', art1)
     song1 = Song('That Was Just Your Life', 2008, 426, art1, alb1)
     len_1 = len(alb1.songs)
     self.assertEqual(alb1.songs, [song1])
     song2 = Song('The End of the Line', 2008, 470, art1, alb1)
     len_2 = len(alb1.songs)
     self.assertEqual(len_1, len_2 - 1)
     song1 = Song('That Was Just Your Life', 2008, 426, art1, alb1)
     len_3 = len(alb1.songs)
     self.assertEqual(len_2, len_3)
Exemplo n.º 6
0
from classes import Artist, Album, Song

if __name__ == '__main__':
    artist1 = Artist('Steve', 'UK')
    artist2 = Artist('John', 'USA')

    steve_album1 = Album('s_album1', 2019, 'Indie rock', artist1)
    john_album1 = Album('j_album1', 2018, 'Alternative rock', artist2)
    john_album2 = Album('j_album2', 2017, 'Heavy metal', artist2)

    steve_song1 = Song('s_song1', artist1, [artist2], 2019, 180, steve_album1)
    steve_song2 = Song('s_song2', artist1, [artist2], 2019, 220)
    john_song1 = Song('j_song1', artist2, [artist1], 2017, 150, john_album1)
    john_song2 = Song('j_song2', artist2, [artist1], 2018, 300, john_album2)
    john_song3 = Song('j_song3', artist2, [artist1], 2019, 180, john_album1)
    # Exception:
    steve_song3 = Song('s_song3', artist1, [artist2], 2019, 210, john_album1)

    # print(artist1.albums)
    # print(artist2.albums)
    # print(steve_album1.songs)
    # print(john_album1.songs)
    # print(artist1.songs)
    # print(artist2.songs)
    # print(john_album1.duration)
 def test_creating_song_adds_it_to_artists_songs_list(self):
     a = Artist('Ed Sheeran', 'UK')
     b = Album('Divide', 2017, 'pop', a)
     c = Song('Shape of You', a, 2017, 234, b)
     self.assertIn(c, a.songs)
 def test_repr_check(self):
     a = Artist('Ed Sheeran', 'UK')
     b = Album('Divide', 2017, 'pop', a)
     c = Song('Supermarket Flowers', a, 2017, 221, b)
     self.assertEqual(repr(c), c.name)
 def test_creating_song_adds_it_to_albums_songs_list(self):
     a = Artist('Ed Sheeran', 'UK')
     b = Album('Divide', 2017, 'pop', a)
     c = Song('New Man', a, 2017, 189, b)
     self.assertIn(c, b.songs)
 def setUpClass(cls) -> None:
     cls.artist1 = Artist('Steve', 'UK')
     cls.album1 = Album('s_album1', 2019, cls.artist1)
     cls.song1 = Song('s_song', cls.artist1, 2018, 180, cls.album1)
 def test_property_albums_number(self):
     self.album2 = Album('s_album2', 2018, self.artist1)
     self.assertEqual(self.artist1.albums_number, 2)
 def test_song_number_is_calculated_right(self):
     a = Artist('Ed Sheeran', 'UK')
     b = Album('Divide', 2017, 'pop', a)
     c = Song('Galway Girl', a, 2017, 248, b)
     d = Song('Castle on the Hill', a, 2017, 421, b)
     self.assertEqual(a.songs_number, 2)
 def test_albums_number_is_calculated_right(self):
     a = Artist('Panic At The Disco', 'USA')
     b = Album('Pray for the Wicked', 2018, 'rock/alternative', a)
     c = Album('Death of a Bachelor', 2016, 'rock/alternative', a)
     self.assertEqual(a.albums_number, 2)
Exemplo n.º 14
0
from classes import Artist, Album, Song

if __name__ == '__main__':
    a = Artist('Ed Sheeran', 'GB')
    s = Artist('Edn', 'GB')
    b = Album('Divide', 2015, 'pop', a)
    print(a.albums)
    print(a.songs)
    c = Song('Galway Girl', a, 2016, 150, b, 9)
    print(a.songs)

    print(c.duration)
Exemplo n.º 15
0
from classes import Artist, Album, Song
# import classes as clx

if __name__ == "__main__":
    art1 = Artist("Mettalica", "USA")
    alb1 = Album('Death magnetic', 2008, 'Thrash metal', art1)
    song1 = Song('That Was Just Your Life', 2008, 426, art1, alb1)
    song2 = Song('The End of the Line', 2008, 470,  art1, alb1)
    alb2 = Album('St. Anger', 2003, 'Thrash metal', art1)
    song3 = Song('Frantic', 2003, 348,  art1, alb2)
    art2 = Artist('Motorhead', "USA")
    song4 = Song('Enter Sandman', 1991, 330, art1)
    song4.add_artist(art2)

    print(art1.songs_number, alb1.duration,
          alb1.songs_number, art1.album_number,
          song4.features, art2.album_number)


Exemplo n.º 16
0
def get_albums():

    #creates flickr object
    flickrObj = flickrapi.FlickrAPI(key, secret, format="json")
    photolist = get_ids()  #list of ids returned from the search on flickr
    albumlist = {}  # {album id: album object}

    #loops through all the photos in the search
    for pid in photolist:
        '''
        #for i in range(0,1):
        pid = photolist[i]
        '''

        all_contexts = json.loads(
            flickrObj.photos.getAllContexts(photo_id=pid).decode(
                encoding='utf-8'))

        #list of all set ids
        if 'set' in all_contexts:  #all_contexts["set"] == True
            sets = all_contexts["set"]

            #loops through all the sets that the photo is in
            for i in sets:
                set_id = i["id"]
                #if the album has not already been processed
                if not (set_id in albumlist):
                    #gets the userid for the owner of the album
                    user = json.loads(
                        flickrObj.photos.getInfo(photo_id=pid).decode(
                            encoding='utf-8'))['photo']['owner']['nsid']
                    #gets list of pictuers in the album
                    photosets = json.loads(
                        flickrObj.photosets.getPhotos(
                            photoset_id=set_id,
                            user_id=user).decode(encoding='utf-8'))
                    #creates album object we are analyzing and sets the album id, album url, and album name
                    newalbum = Album(set_id, user_id=user)
                    add_album_url(newalbum)
                    add_album_name(newalbum)

                    #initializes minimum and maximum posted/taken time
                    first_posted = json.loads(
                        flickrObj.photos.getInfo(
                            photo_id=photosets['photoset']['photo'][0]['id']).
                        decode(encoding='utf-8'))['photo']['dates']['posted']
                    first_taken = json.loads(
                        flickrObj.photos.getInfo(
                            photo_id=photosets['photoset']['photo'][0]['id']).
                        decode(encoding='utf-8'))['photo']['dates']['taken']
                    #converts the text time into unix timestamp
                    mint = int(
                        datetime.strptime(first_taken,
                                          '%Y-%m-%d %H:%M:%S').strftime("%s"))
                    maxt = int(
                        datetime.strptime(first_taken,
                                          '%Y-%m-%d %H:%M:%S').strftime("%s"))
                    minp = int(first_posted)
                    maxp = int(first_posted)

                    #counter in loop which counts number of pictures in album
                    album_size = 0
                    #number of pictures of species of interest in the album
                    num_species = 0

                    #loops through each picture in the photoset creatingi a photo class object for each image
                    for j in photosets['photoset']['photo']:

                        newphoto = Photo(photoId=j['id'])
                        add_photo_url(newphoto)
                        add_photo_description(newphoto)
                        #add_photo_location(newphoto)
                        '''
                            NEED TO BE DONE:
                            make photo_list a list of photo objects (appending newphoto ) instead of a
                            list of photo ids, which it currently is
                            
                            see: line 177
                            '''
                        taken = json.loads(
                            flickrObj.photos.getInfo(photo_id=j['id']).decode(
                                encoding='utf-8'))['photo']['dates']['taken']
                        #converts the text time into unix timestamp
                        taken = int(
                            datetime.strptime(
                                taken, '%Y-%m-%d %H:%M:%S').strftime("%s"))
                        posted = int(
                            json.loads(
                                flickrObj.photos.getInfo(
                                    photo_id=j['id']).decode(encoding='utf-8'))
                            ['photo']['dates']['posted'])

                        #resets the max/min time if its later/earlier respectively
                        if taken < mint:
                            mint = taken
                        if taken > maxt:
                            maxt = taken
                        if posted < minp:
                            minp = posted
                        if posted > maxp:
                            maxp = posted
                        #adds the photo to the photolist attribute of the album object
                        newalbum.photo_list.append(j['id'])

                        album_size += 1

                        #checks to see if picture has tag of species of interest and updates the count
                        if j['id'] in photolist:
                            num_species += 1

                #calculates the time range the album has for taken/posted
                newalbum.time_range_posted = int(maxp) - int(minp)
                newalbum.time_range_taken = int(maxt) - int(mint)
                #updates album size
                newalbum.size = album_size
                #calculates species of interest ratio to total number of photos in album
                newalbum.species_ratio = float(num_species) / float(album_size)

                #adds the album to the albumlist
                albumlist[newalbum.sid] = newalbum

    return albumlist
Exemplo n.º 17
0
def get_album_details(set_id, user):
    # gets list of pictuers in the album

    try: photosets = json.loads(
        flickrObj.photosets.getPhotos(photoset_id=set_id, user_id=user).decode(encoding='utf-8'))
    except:
        time.sleep(5)
        photosets = json.loads(flickrObj.photosets.getPhotos(photoset_id=set_id, user_id=user).decode(encoding='utf-8'))
    # creates album object we are analyzing and sets the album id, album url, and album name
    newalbum = Album(set_id, user_id=user)
    add_album_url(newalbum)
    albumName = photosets['photoset']['title']
    newalbum.name = albumName

    # initializes minimum and maximum posted/taken time

    """first_posted = json.loads(
        flickrObj.photos.getInfo(photo_id=photosets['photoset']['photo'][0]['id']).decode(
            encoding='utf-8'))['photo']['dates']['posted']
    first_taken = json.loads(
        flickrObj.photos.getInfo(photo_id=photosets['photoset']['photo'][0]['id']).decode(
            encoding='utf-8'))['photo']['dates']['taken']"""
    # converts the text time into unix timestamp
    mint = 1577840461  # 01/01/2020
    maxt = 915152461  # 01/01/1990
    minp = 1577840461
    maxp = 915152461

    # counter in loop which counts number of pictures in album
    album_size = 0
    # number of pictures of species of interest in the album
    num_species = 0
    count1 = 1
    # loops through each picture in the photoset creatingi a photo class object for each image
    if len(photosets['photoset']['photo']) >=500 :
        print(photosets['photoset']["total"])
        count1+=1
    count = 1
    # if photosets['photoset']['pages'] > 1:
    #     for page in range(0,photosets['photoset']['pages']):
    #         photosets1 = json.loads(
    #             flickrObj.photosets.getPhotos(photoset_id=set_id, user_id=user,page = page+1).decode(encoding='utf-8'))
    #         for j in photosets1['photoset']['photo']:
    #             start = time.time()
    #             # print( str(count) + " " + j['id'])
    #             count += 1
    #             try:
    #                 photoInfo = json.loads(flickrObj.photos.getInfo(photo_id=j['id']).decode(encoding='utf-8'))
    #             except:
    #                 time.sleep(10)
    #                 photoInfo = json.loads(flickrObj.photos.getInfo(photo_id=j['id']).decode(encoding='utf-8'))
    #             if "photo" not in photoInfo:
    #                 continue
    #             newphoto = Photo(photo_info=photoInfo)
    #             newphoto.albumId = set_id
    #             # add_photo_url(newphoto)
    #             newphoto.url = photoInfo['photo']['urls']['url'][0]['_content']
    #             newphoto.photo_description = photoInfo['photo']['description']['_content']
    #             if "location" in photoInfo["photo"]:
    #                 photolocation = photoInfo['photo']['location']
    #                 newphoto.photoLocationX = float(photolocation['latitude'])
    #                 newphoto.photoLocationY = float(photolocation['longitude'])
    #                 newphoto.location = (newphoto.photoLocationX, newphoto.photoLocationY)
    #             else:
    #                 newphoto.location = 0;
    #
    #             # add_photo_description(newphoto)
    #             # add_photo_location(newphoto)
    #
    #             '''
    #                 NEED TO BE DONE:
    #                 make photo_list a list of photo objects (appending newphoto ) instead of a
    #                 list of photo ids, which it currently is
    #
    #                 see: line 177
    #                 '''
    #
    #             taken = photoInfo['photo']['dates']['taken']
    #             # converts the text time into unix timestamp
    #             taken = datetime.strptime(taken, '%Y-%m-%d %H:%M:%S')
    #             # print(type(taken))
    #             taken = int(time.mktime(taken.timetuple()))
    #             posted = int(photoInfo['photo']['dates']['posted'])
    #             # posted = int(time.mktime(datetime.strptime(posted, '%Y-%m-%d %H:%M:%S').timetuple()))
    #             # resets the max/min time if its later/earlier respectively
    #             if taken < mint:
    #                 mint = taken
    #             if taken > maxt:
    #                 maxt = taken
    #             if posted < minp:
    #                 minp = posted
    #             if posted > maxp:
    #                 maxp = posted
    #             # adds the photo to the photolist attribute of the album object
    #             newalbum.photo_list[j['id']] = newphoto
    #
    #             album_size += 1
    #             stop = time.time()
    #             duration = stop - start
    #             # checks to see if picture has tag of species of interest and updates the count
    #             # if j['id'] in photolist :
    #             #    num_species+=1
    #             newalbum.time_range_posted = int(maxp) - int(minp)
    #             newalbum.time_range_taken = int(maxt) - int(mint)
    #             # updates album size
    #             newalbum.size = album_size
    #             # calculates species of interest ratio to total number of photos in album
    #             # newalbum.species_ratio = float(num_species)/float(album_size)

    return newalbum
Exemplo n.º 18
0
 def test_creating_album_adds_it_to_artists_albums_list(self):
     a = Artist('Lana Del Ray', 'USA')
     b = Album('Born to Die', 2012, 'alternative/indie', a)
     self.assertIn(b, a.albums)
Exemplo n.º 19
0
 def song_number_is_calculated_right(self):
     a = Artist('Lana Del Ray', 'USA')
     b = Album('Born to Die', 2012, 'alternative/indie', a)
     c = Song('Blue Jeans', a, 2012, 240, b)
     d = Song('Born to Die', a, 2012, 320, b)
     self.assertEqual(b.songs_number, 2)
Exemplo n.º 20
0
 def test_duration_is_calculated_right(self):
     a = Artist('Lana Del Ray', 'USA')
     b = Album('Born to Die', 2012, 'alternative/indie', a)
     c = Song('Blue Jeans', a, 2012, 240, b)
     d = Song('Born to Die', a, 2012, 320, b)
     self.assertEqual(b.duration, c.duration + d.duration)