Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON 3 PROGRAM Metadata: Organizing Your iTunes Digitized music such as that m

ID: 3775508 • Letter: P

Question

PYTHON 3 PROGRAM

Metadata: Organizing Your iTunes

Digitized music such as that managed by iTunes has metadata such as the name, artist, and so on. Internally, iTunes uses the XML format to manage its metadata, and Python has modules to work with XML, but XML has more complexity than we can deal with in a problem (or even a few chapters). However, using copy-and-paste you can copy your iTunes metadata from the text “list” view of your playlist into your favorite text

editor such as TextEdit or WordPad. The result is a file that is tab separated, i.e., fields are separated by the tab character. Because the split() method can take an argument of what to split on, we can split the lines of your text file using line.split(" "). Remember that we can specify the tab character with " ".

What is an appropriate data structure? It is natural to organize music around the artist, and an artist’s name is immutable, so a dictionary is suggested with the artist as the key. The remaining metadata becomes the value of each record. You can read in your metatdata and place it in a dictionary.

Write a program that does the following: ((((((((((THIS IS THE QUESTION PYTHON 3 PROGRAM )))))))))))

(a) Reads the metadata from a file into a dictionary (b) Loops to repeatedly prompt for:

i. Name: list all songs by the specified artist. ii. Album: list all songs on the specified album.

iii. Genre: list all songs in a specified genre. iv. Add: add a song.

v. Delete: delete a specified song (specify its name). vi. Popular: find the artist with the most songs in your collection.

vii. Longest: find the longest song in your collection and prints its metadata.

Hint: To sort to find the most popular or longest, you need to convert your dictionary into a data structure that you can sort, such as a list or tuple. Remember that the Python sort will sort on the first item in each list (or tuple), so you will need to arrange your lists appropriately

Explanation / Answer

mp4_video_tags = MP4(mp4_file)

mp4_video_tags['nam'] = 'Video Name'
mp4_video_tags['alb'] = 'DVD-Name'
mp4_video_tags['gen'] = 'Video-Training'
mp4_video_tags['day'] = '2015'
mp4_video_tags['ART'] = 'Company'
mp4_video_tags['aART'] = 'Company'
mp4_video_tags['wrt'] = 'Company'
mp4_video_tags['cprt'] = 'Copyright (c) Company'
mp4_video_tags['desc'] = 'description'
mp4_video_tags['tvsh'] = 'DVD-Name'
mp4_video_tags['trkn'] = [(1, 18)]
mp4_video_tags['disk'] = [(1, 1)]
mp4_video_tags['stik'] = 10

mp4_video_tags.save()