Exemple #1
0
def find_by_album(name):
    music_list = import_music_library()
    album_name_found = ()
    for item in music_list:
        if name.lower() in item["album name"].lower():
            album_name_found = album_name_found + (item["album name"],)
    return album_name_found
Exemple #2
0
def convert_time_to_float():
    music_list = import_music_library()
    time_list = []
    for item in music_list:
        time = float(item["album time"].replace(":", "."))
        time_list.append(time)
    return time_list
Exemple #3
0
def find_youngest_album():
    from file_operations import import_music_library
    music_library = (import_music_library())
    import operator
    album_years = {}
    for music_dictionary in music_library:
        album_years[music_dictionary['album name']] = int(music_dictionary['year'])
    return(max(album_years.items(), key=operator.itemgetter(1))[0])
Exemple #4
0
def count_albums_by_genre():
    from file_operations import import_music_library
    music_library = (import_music_library())
    album_count_by_genres = {}
    for music_dictionary in music_library:
        if music_dictionary['genre'] not in album_count_by_genres.keys():
            album_count_by_genres[music_dictionary['genre']] = 1
        else:
            album_count_by_genres[music_dictionary['genre']] = int(album_count_by_genres[music_dictionary['genre']]) + 1
    return(album_count_by_genres)
Exemple #5
0
def edit_album(user_album_name):
    from file_operations import import_music_library
    music_library = import_music_library()

    for element in music_library:
        if element['album name'] == user_album_name:
            album_to_edit = element

    print('What do you want to change?: ')
    i = 1
    for element in album_to_edit.keys():
        print(f'{i}. {element.capitalize()}')
        i += 1
Exemple #6
0
def view_album_by_artist(_):
    music_library = (import_music_library())
    user_artist_name = input('Please enter an artist\'s name: ')
    album_by_given_artist = []
    for music_dictionary in music_library:
        if user_artist_name.lower() in (
                music_dictionary['artist name']).lower():
            album_found = music_dictionary['album name']
            album_by_given_artist.append(album_found)
        else:
            print('No such artist found')
            break
    return (tuple(album_by_given_artist))
Exemple #7
0
def suggestions_by_genre(genre):
    music_library = import_music_library()
    similar_genres = {
        'ancient': '',
        'hard rock': 'progressive rock,rock',
        'hip hop': '',
        'pop': '',
        'progressive rock': 'rock,hard rock',
        'rock': 'progressive rock,hard rock'
    }

    genres_to_suggest = similar_genres[genre].split(',')
    return [
        album for album in music_library if album.genre in genres_to_suggest
    ]
Exemple #8
0
def get_album_name_list():
    music_list = import_music_library()
    album_name_list = []
    for item in music_list:
        album_name_list.append(item["album name"])
    return album_name_list
Exemple #9
0
def view_album(id=None):
    music_library = import_music_library()
    if id is None:
        return music_library
    else:
        return music_library[int(id)]