After the lab, you should be proficient at
You will want to copy the files from
/home/courses/cs111/handouts/lab10
.
Review the PlayTime class inside of music.py
. You'll
need to use this class in your program. You can rename it and add
more methods if you want.
Problem: Create MyTunes, a program to manage your music collection. Your music collection is a set of songs. You will keep track of songs and allow users to add to their music collection.
Organization: The classes should be in one module. The driver program will import the music classes.
The following summarizes the classes and their data and functionality. The longer descriptions for some methods are after the summaries.
number_of_songs artist1_name album1_name song1_name song1_minutes:seconds artist2_name album2_name song2_name song2_minutes:seconds ...
Note that this format requires reading files differently from how we have typically read in files in this class. (Line-by-line) How will you read in files with this format?
Example collection files can be found in libraries and the handouts directory for lab10. Feel free to share your library files with the class by emailing me with them, and I can post them.
You should use a Song class to maintain information about the song, such as the album, artist, name, and length of the song. You will add each song to the MusicLibrary's list of songs.
Example Run:
Title Artist Album Length ---------------------------------------------------------------------------------------- Burned Better Than Ezra Before the Robots 00:03:41 Daylight Better Than Ezra Before the Robots 00:03:54 ---------------------------------------------------------------------------------------- Total: 2 songs Playtime: 00:07:35
artist_name album_name number_of_songs song1_name minutes:seconds song2_name minutes:seconds ...The directory albums contains some example album files. Feel free to submit your own albums to share with the class.
Write a method to read in (import) an album. Store the songs in the music collection.
Example Run:
Enter the name of the file: albums/west.txt Reading album from albums/west.txt Successfully added 13 songs, totalling 00:51:17
Note: Before your program exits, you should also write your
collection to a file, specifically the
default mytunes.library
file or the one specified on
the command line.
Example Run:
What is the name of the file that you want to export the library to? mytunes.saved Saving library to file: mytunes.saved
Example Run:
Title Artist Album Length ---------------------------------------------------------------------------------------- A Lifetime Better Than Ezra Before the Robots 00:03:29 A Southern Thang Better Than Ezra Before the Robots 00:04:03 American Dream Better Than Ezra Before the Robots 00:03:41 Breathless Better Than Ezra Before the Robots 00:03:36 Burned Better Than Ezra Before the Robots 00:03:41 Burned Better Than Ezra Before the Robots 00:03:43 Daylight Better Than Ezra Before the Robots 00:03:54 Daylight Better Than Ezra Before the Robots 00:03:55 Hollow Better Than Ezra Before the Robots 00:03:31 It's Only Natural Better Than Ezra Before the Robots 00:04:17 Juicy Better Than Ezra Before the Robots 00:03:55 Our Finest Year Better Than Ezra Before the Robots 00:04:23 Our Last Night Better Than Ezra Before the Robots 00:04:13 Overcome Better Than Ezra Before the Robots 00:05:23 Special Better Than Ezra Before the Robots 00:04:05 ---------------------------------------------------------------------------------------- Total: 15 songs Playtime: 00:59:49
Write your program so that it will allow the user to enter the name of the collection file as a command-line argument. The program will attempt to read that file to initialize the music collection. If you do not give a command-line argument, the program will attempt to read the default "mytunes.library".
Your user menu should allow the user to execute each of the following options:
Example user menu:
Select one of the following options: (V)iew the library (I)mport songs into the library (S)ort the library E(X)port the library to a file (Q)uit the program Which option do you want?
Allow the user to enter lower case or capital letters for options. For example, either "V" or "v" is a valid choice for viewing the library.
try/except
statement to
catch and handle the exception so that the program doesn't just exit.
(You do not need to reprompt for the filename in the handling code;
just give a useful error message.)
turnin
directory.
(Review the UNIX handout if you don't
remember how to do that.)
printLab.sh
command to create a file to
print out. You should probably print from the labs
directory. You may get a warning about the directory containing
subdirectories. As long as you don't get an
enscript
error about unknown special escape, you
should be okay.
gv
command, such as gv lab10.ps
Print the file using the lpr
command
introduced in the first lab.
Labs are due at the beginning of Friday's class. You should hand
in the printed copy at the beginning of class, and the electronic
version should be in the turnin
directory before 2:25
p.m. on Friday.
Ask well before the deadline if you need help turning in your assignment!