32
SongList XSPFParser::Load(QIODevice *device, const QString& playlist_path, const QDir&) const {
33
SongList XSPFParser::Load(QIODevice *device, const QString& playlist_path,
34
const QDir& dir) const {
35
37
QXmlStreamReader reader(device);
50
Song XSPFParser::ParseTrack(QXmlStreamReader* reader) const {
52
QString title, artist, album;
52
Song XSPFParser::ParseTrack(QXmlStreamReader* reader, const QDir& dir) const {
53
QString title, artist, album, location;
53
54
qint64 nanosec = -1;
54
56
while (!reader->atEnd()) {
55
57
QXmlStreamReader::TokenType type = reader->readNext();
57
59
case QXmlStreamReader::StartElement: {
58
60
QStringRef name = reader->name();
59
61
if (name == "location") {
60
QUrl url(reader->readElementText());
61
if (url.scheme() == "file") {
62
QString filename = url.toLocalFile();
63
if (!QFile::exists(filename)) {
67
// Load the song from the library if it's there.
68
Song library_song = LoadLibrarySong(filename);
69
if (library_song.is_valid())
72
song.InitFromFile(filename, -1);
75
song.set_filename(url.toString());
76
song.set_filetype(Song::Type_Stream);
62
location = reader->readElementText();
78
63
} else if (name == "title") {
79
64
title = reader->readElementText();
80
65
} else if (name == "creator") {
82
67
} else if (name == "album") {
83
68
album = reader->readElementText();
84
69
} else if (name == "duration") { // in milliseconds.
85
const QString& duration = reader->readElementText();
70
const QString duration = reader->readElementText();
87
72
nanosec = duration.toInt(&ok) * kNsecPerMsec;
98
83
case QXmlStreamReader::EndElement: {
99
84
if (reader->name() == "track") {
100
song.Init(title, artist, album, nanosec);
108
// At least make an effort if we never find a </track>.
109
song.Init(title, artist, album, nanosec);
94
Song song = LoadSong(location, 0, dir);
96
// Override metadata with what was in the playlist
97
song.set_title(title);
98
song.set_artist(artist);
99
song.set_album(album);
100
song.set_length_nanosec(nanosec);
120
111
StreamElement tracklist("trackList", &writer);
121
112
foreach (const Song& song, songs) {
122
113
StreamElement track("track", &writer);
123
writer.writeTextElement("location", MakeUrl(song.filename()));
114
writer.writeTextElement("location", song.url().toString());
124
115
writer.writeTextElement("title", song.title());
125
116
if (!song.artist().isEmpty()) {
126
117
writer.writeTextElement("creator", song.artist());
136
127
// Ignore images that are in our resource bundle.
137
128
if (!art.startsWith(":") && !art.isEmpty()) {
138
129
// Convert local files to URLs.
130
if (!art.contains("://")) {
131
art = QUrl::fromLocalFile(art).toString();
140
133
writer.writeTextElement("image", art);