1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-07 17:42:35 +02:00

Handle namespaces in xspf files

This commit is contained in:
Alastair Porter 2011-03-06 22:21:32 -05:00
parent eec2c3a9bf
commit 5b87f97320
2 changed files with 36 additions and 13 deletions

View File

@ -76,36 +76,57 @@ XSPFLoader::gotBody()
qDebug() << Q_FUNC_INFO;
QDomDocument xmldoc;
xmldoc.setContent( m_body );
bool namespaceProcessing = true;
xmldoc.setContent( m_body, namespaceProcessing );
QDomElement docElement( xmldoc.documentElement() );
QString origTitle;
origTitle = docElement.firstChildElement( "title" ).text();
m_info = docElement.firstChildElement( "creator" ).text();
m_creator = docElement.firstChildElement( "info" ).text();
QDomNodeList tracklist;
QDomElement n = docElement.firstChildElement();
for ( ; !n.isNull(); n = n.nextSiblingElement() ) {
if (n.namespaceURI() == NS && n.localName() == "title") {
origTitle = n.text();
} else if (n.namespaceURI() == NS && n.localName() == "creator") {
m_creator = n.text();
} else if (n.namespaceURI() == NS && n.localName() == "info") {
m_info = n.text();
} else if (n.namespaceURI() == NS && n.localName() == "trackList") {
tracklist = n.childNodes();
}
}
m_title = origTitle;
if ( m_title.isEmpty() )
m_title = tr( "New Playlist" );
QDomNodeList tracklist = docElement.elementsByTagName( "track" );
for ( unsigned int i = 0; i < tracklist.length(); i++ )
{
QDomNode e = tracklist.at( i );
QString artist, album, track, duration, annotation;
QDomElement n = e.firstChildElement();
for ( ; !n.isNull(); n = n.nextSiblingElement() ) {
if (n.namespaceURI() == NS && n.localName() == "duration") {
duration = n.text();
} else if (n.namespaceURI() == NS && n.localName() == "annotation") {
annotation = n.text();
} else if (n.namespaceURI() == NS && n.localName() == "creator") {
artist = n.text();
} else if (n.namespaceURI() == NS && n.localName() == "album") {
album = n.text();
} else if (n.namespaceURI() == NS && n.localName() == "title") {
track = n.text();
}
}
plentry_ptr p( new PlaylistEntry );
p->setGuid( uuid() );
p->setDuration( e.firstChildElement( "duration" ).text().toInt() / 1000 );
p->setDuration( duration.toInt() / 1000 );
p->setLastmodified( 0 );
p->setAnnotation( e.firstChildElement( "annotation" ).text() );
QString artist, album, track;
artist = e.firstChildElement( "creator" ).text();
album = e.firstChildElement( "album" ).text();
track = e.firstChildElement( "title" ).text();
p->setAnnotation( annotation );
p->setQuery( Tomahawk::Query::get( artist, track, album, uuid() ) );
p->query()->setDuration( e.firstChildElement( "duration" ).text().toInt() / 1000 );
p->query()->setDuration( duration.toInt() / 1000 );
m_entries << p;
}

View File

@ -25,6 +25,7 @@ public:
explicit XSPFLoader( bool autoCreate = true, QObject* parent = 0 )
: QObject( parent )
, m_autoCreate( autoCreate )
, NS("http://xspf.org/ns/0/")
{}
virtual ~XSPFLoader()
@ -47,6 +48,7 @@ private slots:
void networkError( QNetworkReply::NetworkError e );
private:
QString NS;
void reportError();
void gotBody();