| """ |
| Music Playlist Manager - Main Program |
| """ |
|
|
| from library import MusicLibrary |
| from parameters import APP_TITLE, APP_VERSION |
|
|
| def create_sample_library(library): |
| """ |
| Create sample music library |
| """ |
| songs_data = [ |
| ("Bohemian Rhapsody", "Queen", "A Night at the Opera", 354, "Rock", 1975), |
| ("Imagine", "John Lennon", "Imagine", 183, "Pop", 1971), |
| ("Billie Jean", "Michael Jackson", "Thriller", 294, "Pop", 1982), |
| ("Smells Like Teen Spirit", "Nirvana", "Nevermind", 301, "Rock", 1991), |
| ("Sweet Child O' Mine", "Guns N' Roses", "Appetite for Destruction", 356, "Rock", 1987), |
| ("Hotel California", "Eagles", "Hotel California", 391, "Rock", 1977), |
| ("Stairway to Heaven", "Led Zeppelin", "Led Zeppelin IV", 482, "Rock", 1971), |
| ("Purple Rain", "Prince", "Purple Rain", 518, "R&B", 1984), |
| ("Like a Rolling Stone", "Bob Dylan", "Highway 61 Revisited", 369, "Rock", 1965), |
| ("What's Going On", "Marvin Gaye", "What's Going On", 232, "R&B", 1971) |
| ] |
| |
| for title, artist, album, duration, genre, year in songs_data: |
| song = library.add_song(title, artist, album) |
| song.set_duration(duration) |
| song.set_genre(genre) |
| song.set_year(year) |
| |
| |
| import random |
| plays = random.randint(5, 50) |
| for _ in range(plays): |
| song.play() |
| song.rate(random.randint(3, 5)) |
| |
| print(f"Added {len(songs_data)} songs to library") |
|
|
| def print_separator(char='=', length=70): |
| """ |
| Print separator line |
| """ |
| print(char * length) |
|
|
| def main(): |
| """ |
| Main program execution |
| """ |
| print_separator() |
| print(f"{APP_TITLE} v{APP_VERSION}") |
| print_separator() |
| print("") |
| |
| |
| library = MusicLibrary() |
| |
| |
| print("Building music library...") |
| create_sample_library(library) |
| print("") |
| |
| |
| stats = library.get_library_statistics() |
| print_separator() |
| print("Library Statistics") |
| print_separator() |
| print(f"Total Songs: {stats['total_songs']}") |
| print(f"Total Artists: {stats['total_artists']}") |
| print(f"Total Albums: {stats['total_albums']}") |
| print(f"Total Playlists: {stats['total_playlists']}") |
| print(f"Total Duration: {stats['total_duration_hours']:.2f} hours") |
| print(f"Total Plays: {stats['total_plays']}") |
| print("") |
| |
| |
| print_separator() |
| print("Song Library") |
| print_separator() |
| |
| for song in list(library.songs.values())[:5]: |
| print(f"{song.title} - {song.artist}") |
| print(f" Album: {song.album} ({song.year})") |
| print(f" Duration: {song.get_duration_string()}") |
| print(f" Genre: {song.genre}") |
| print(f" Plays: {song.play_count} | Rating: {song.rating}/5") |
| print("") |
| |
| |
| print_separator() |
| print("Creating Playlists") |
| print_separator() |
| |
| rock_playlist = library.create_playlist("Classic Rock Hits") |
| rock_playlist.set_description("Best rock songs from the 60s to 90s") |
| |
| |
| for song in library.get_songs_by_genre("Rock"): |
| rock_playlist.add_song(song.song_id) |
| |
| print(f"Created: {rock_playlist}") |
| print("") |
| |
| favorites_playlist = library.create_playlist("My Favorites") |
| |
| |
| top_songs = library.get_most_played_songs(5) |
| for song in top_songs: |
| favorites_playlist.add_song(song.song_id) |
| song.toggle_favorite() |
| |
| print(f"Created: {favorites_playlist}") |
| print("") |
| |
| |
| print_separator() |
| print("Playlists") |
| print_separator() |
| |
| for playlist in library.playlists.values(): |
| print(f"\n{playlist.name}") |
| print(f" Description: {playlist.description}") |
| print(f" Songs: {playlist.get_song_count()}") |
| print(f" Created: {playlist.created_date.strftime('%Y-%m-%d')}") |
| |
| |
| playlist_songs = library.get_playlist_songs(playlist.playlist_id) |
| if playlist_songs: |
| print(" Tracks:") |
| for i, song in enumerate(playlist_songs[:3], 1): |
| print(f" {i}. {song.title} - {song.artist}") |
| |
| print("") |
| |
| |
| print_separator() |
| print("Most Played Songs") |
| print_separator() |
| |
| most_played = library.get_most_played_songs(5) |
| for i, song in enumerate(most_played, 1): |
| print(f"{i}. {song.title} - {song.artist}") |
| print(f" Plays: {song.play_count} | Rating: {song.rating}/5") |
| |
| print("") |
| |
| |
| print_separator() |
| print("Search Results for 'Hotel'") |
| print_separator() |
| |
| results = library.search_songs("Hotel") |
| for song in results: |
| print(f" {song}") |
| |
| print("") |
|
|
| if __name__ == "__main__": |
| main() |
|
|