-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathapplemusic_xml_parser.py
75 lines (61 loc) · 1.57 KB
/
applemusic_xml_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import xml.etree.ElementTree as ET
# Setup tree and root to parse
print('Welcome to Music Move!\n')
tree = 0
root = 0
def set_file(playlist):
global tree
global root
tree = ET.parse(playlist + ".xml")
root = tree.getroot()
# Finds the name of the song
def get_song_name():
key1 = 'Name'
tags = root.iter()
songs = []
for node in tags:
if key1 == node.text:
next_node = next(tags)
songs.append(next_node.text)
del songs[-1] # Deletes PlayList name
return songs
# Removes Feature from song name
def remove_feat_from_song(songname):
result = []
for song in songname:
start = song.find('(')
if start != -1:
result.append(song[0:start])
else:
result.append(song)
return result
# Removes Feature from album name
def remove_feat_from_album(album_name1):
result = []
for song in album_name1:
start = song.find('(')
if start != -1:
result.append(song[0:start])
else:
result.append(song)
return result
# Finds the Artist of the song
def get_artist_name():
key2 = 'Artist'
tags = root.iter()
artists = []
for node in tags:
if key2 == node.text:
next_node = next(tags)
artists.append(next_node.text)
return artists
# Finds the album name
def get_album_name():
key3 = 'Album'
tags = root.iter()
songs = []
for node in tags:
if key3 == node.text:
next_node = next(tags)
songs.append(next_node.text)
return songs