-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaylist.cpp
66 lines (59 loc) · 1.81 KB
/
playlist.cpp
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
#include <string.h>
#include <stdlib.h>
#include "playlist.hpp"
playlist::playlist()
: id(-1)
{
}
playlist create_playlist_from_iTunes_node(const pugi::xml_node playlist_node,
std::vector<Song> songs)
{
playlist playlist;
for (pugi::xml_node key = playlist_node.child("key"); key;
key = key.next_sibling("key"))
{
const char* key_text = key.child_value();
if (strcmp(key_text, "Name") == 0)
{
pugi::xml_node value = key.next_sibling("string");
playlist.name = value.child_value();
}
else if (strcmp(key_text, "Playlist ID") == 0)
{
pugi::xml_node value = key.next_sibling("integer");
playlist.id = atoi(value.child_value());
}
else if (strcmp(key_text, "Playlist Persistent ID") == 0)
{
pugi::xml_node value = key.next_sibling("string");
playlist.persistent_id = value.child_value();
}
}
// iterate through each playlist item, and add the Song object
pugi::xml_node songs_array = playlist_node.child("array");
for (pugi::xml_node song = songs_array.child("dict"); song;
song = song.next_sibling("dict"))
{
// iterate through each playlist item node
for (pugi::xml_node key = song.child("key"); key;
key = key.next_sibling("key"))
{
const char* key_text = key.child_value();
if (strcmp(key_text, "Track ID") == 0)
{
pugi::xml_node value = key.next_sibling("integer");
int track_id = atoi(value.child_value());
// find the song which has the same id, and add it to the playlist
for (std::vector<Song>::size_type i = 0; i < songs.size(); i++)
{
if (songs[i].id == track_id)
{
playlist.songs.push_back(songs[i]);
break;
}
}
}
}
}
return playlist;
}