diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2017-06-14 20:24:58 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2017-06-14 20:24:58 +0000 |
| commit | b2576ddc181d3758e3a57d9cac871ee7d7e2ef06 (patch) | |
| tree | 1dfd6331a91f153d4a693a0aa32a774e2e53e2ea /src/plugins/PlayListFormats/xspf | |
| parent | 9e3bcc8653f5e0500e9d0e4ee0c953e8bbf4ea4c (diff) | |
| download | qmmp-b2576ddc181d3758e3a57d9cac871ee7d7e2ef06.tar.gz qmmp-b2576ddc181d3758e3a57d9cac871ee7d7e2ef06.tar.bz2 qmmp-b2576ddc181d3758e3a57d9cac871ee7d7e2ef06.zip | |
improved playlist formats support
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@7237 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/PlayListFormats/xspf')
| -rw-r--r-- | src/plugins/PlayListFormats/xspf/xspfplaylistformat.cpp | 67 | ||||
| -rw-r--r-- | src/plugins/PlayListFormats/xspf/xspfplaylistformat.h | 4 |
2 files changed, 52 insertions, 19 deletions
diff --git a/src/plugins/PlayListFormats/xspf/xspfplaylistformat.cpp b/src/plugins/PlayListFormats/xspf/xspfplaylistformat.cpp index d5ab21fb5..93d691d3c 100644 --- a/src/plugins/PlayListFormats/xspf/xspfplaylistformat.cpp +++ b/src/plugins/PlayListFormats/xspf/xspfplaylistformat.cpp @@ -37,11 +37,11 @@ const PlayListFormatProperties XSPFPlaylistFormat::XSPFPlaylistFormat::propertie return p; } -QStringList XSPFPlaylistFormat::decode(const QString & contents) +QList<PlayListTrack*> XSPFPlaylistFormat::decode(const QByteArray &contents) { - QStringList out; + QList<PlayListTrack*> out; QString currentTag; - QString contents_copy = contents; + QString contents_copy = QString::fromUtf8(contents); //remove control symbols to avoid xml errors for(int i = 0; i < contents_copy.size(); ++i) @@ -54,24 +54,47 @@ QStringList XSPFPlaylistFormat::decode(const QString & contents) } QXmlStreamReader xml(contents_copy); - while(!xml.atEnd()) + while(!xml.atEnd() || !xml.hasError()) { xml.readNext(); if (xml.isStartElement()) { currentTag = xml.name().toString(); - + if(currentTag == "track") + out << new PlayListTrack(); } else if (xml.isCharacters() && !xml.isWhitespace()) { - if (currentTag == "location") - { + if(out.isEmpty()) + continue; + if(currentTag == "location") + { QUrl url(xml.text().toString()); if (url.scheme() == "file") //remove scheme for local files only - out << QUrl::fromPercentEncoding(url.toString().toLatin1()).remove("file://"); + out.last()->insert(Qmmp::URL, QUrl::fromPercentEncoding(url.toString().toLatin1()).remove("file://")); else - out << QUrl::fromPercentEncoding(url.toString().toLatin1()); + out.last()->insert(Qmmp::URL, QUrl::fromPercentEncoding(url.toString().toLatin1())); + } + else if(currentTag == "title") + { + out.last()->insert(Qmmp::TITLE, xml.text().toString()); + } + else if(currentTag == "creator") + { + out.last()->insert(Qmmp::ARTIST, xml.text().toString()); + } + else if(currentTag == "annotation") + { + out.last()->insert(Qmmp::COMMENT, xml.text().toString()); + } + else if(currentTag == "album") + { + out.last()->insert(Qmmp::ALBUM, xml.text().toString()); + } + else if(currentTag == "meta" && xml.attributes().value("rel") == "year") + { + out.last()->insert(Qmmp::YEAR, xml.text().toString()); } else xml.skipCurrentElement(); @@ -88,10 +111,10 @@ QStringList XSPFPlaylistFormat::decode(const QString & contents) // Needs more work - it's better use libSpiff there and put it as plugin. -QString XSPFPlaylistFormat::encode(const QList<PlayListTrack*> & files, const QString &path) +QByteArray XSPFPlaylistFormat::encode(const QList<PlayListTrack*> &files, const QString &path) { - Q_UNUSED(path); - QString out; + QString xspfDir = QFileInfo(path).canonicalPath(); + QByteArray out; QXmlStreamWriter xml(&out); xml.setCodec("UTF-8"); xml.setAutoFormatting(true); @@ -103,16 +126,27 @@ QString XSPFPlaylistFormat::encode(const QList<PlayListTrack*> & files, const QS xml.writeStartElement("trackList"); int counter = 1; - foreach(PlayListTrack* f,files) + foreach(PlayListTrack* f, files) { xml.writeStartElement("track"); QString url; if (f->url().contains("://")) + { url = QUrl::toPercentEncoding(f->url(), ":/"); - else //append protocol - url = QUrl::toPercentEncoding(QString("file://") + - QFileInfo(f->url()).absoluteFilePath(), ":/"); + } + else if(f->url().startsWith(xspfDir)) //relative path + { + QString p = f->url(); + p.remove(0, xspfDir.size()); + if(p.startsWith("/")) + p.remove(0, 1); + url = QUrl::toPercentEncoding(p, ":/"); + } + else //absolute path + { + url = QUrl::toPercentEncoding(QLatin1String("file://") + f->url(), ":/"); + } xml.writeTextElement("location", url); xml.writeTextElement("title", f->value(Qmmp::TITLE)); @@ -133,7 +167,6 @@ QString XSPFPlaylistFormat::encode(const QList<PlayListTrack*> & files, const QS xml.writeEndElement(); //playlist xml.writeEndDocument(); return out; - } Q_EXPORT_PLUGIN2(xspfplaylistformat,XSPFPlaylistFormat) diff --git a/src/plugins/PlayListFormats/xspf/xspfplaylistformat.h b/src/plugins/PlayListFormats/xspf/xspfplaylistformat.h index d3b03d3ca..dbd1325d5 100644 --- a/src/plugins/PlayListFormats/xspf/xspfplaylistformat.h +++ b/src/plugins/PlayListFormats/xspf/xspfplaylistformat.h @@ -36,8 +36,8 @@ class XSPFPlaylistFormat : public QObject, public PlayListFormat Q_INTERFACES(PlayListFormat) public: const PlayListFormatProperties properties() const; - QStringList decode(const QString& contents); - QString encode(const QList<PlayListTrack*>& contents, const QString &path); + QList<PlayListTrack*> decode(const QByteArray &contents); + QByteArray encode(const QList<PlayListTrack*> &contents, const QString &path); }; #endif |
