After the lab, you should be proficient at
You will want to copy the files from
/home/courses/cs111/handouts/lab10
.
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.
Review the PlayTime class inside of music.py
. This
class represents the length of a song or a music collection. You'll
need to use this class in your other classes. You can rename it and
add more methods if you want.
Data:
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 files (for each 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 object 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.
By default, check if the filename is in the "libraries" directory, i.e, the filename is "libraries/mytunes.library". Otherwise, add "libraries/" to the beginning of the filename.
minutes and seconds are two-digit numbers that may have a leading 0.
Separate from __str__ method. It's too hard/expensive to accumulate all of this into a string and return it.
Add a method that will print out the music collection, nicely formatted. Include the total number of songs and the length of the music collection.
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 for extra credit. The albums must be in the appropriate format.
Write a method to read in (import) an album. Store the songs in the music collection.
Note: You will append the "albums/" directory to the filename passed into the method (if it isn't already there) so that the user doesn't need to type that everytime.
albums
directory and be correctly
formatted.
Example Run:
Enter the name of the file: west.txt Reading album from albums/west.txt Successfully added 13 songs, totalling 00:51:17
You must print out similar output to above.
This method should do the opposite of your method that reads the library in. Whenever you read the number of songs, you write the number of songs.
Example Run (From UI):
What is the name of the file that you want to export the library to? mytunes.saved Saving library to file: libraries/mytunes.saved
Note: Your program should add the "libraries/" directory to the filename (if it's not already there) so that the user doesn't have to.
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
Best practices: Write the constructor and string representation/print method for each class. Then test them in a test function. Then, write another method and test it. Continue in this way.
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 "libraries/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.
Note: You could write this with a bunch of if statements. Or, you could create a list of valid options and check if the user's selection is in that list.
You can submit albums for the rest of the class to use for extra credit. The album must be in the specified format. You can submit up to 3 albums for extra credit, 4 points each.
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 1:20
p.m. on Friday.
Ask well before the deadline if you need help turning in your assignment!