mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 22:26:32 +02:00
Handle namespaces in xspf files
This commit is contained in:
@@ -76,36 +76,57 @@ XSPFLoader::gotBody()
|
|||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
QDomDocument xmldoc;
|
QDomDocument xmldoc;
|
||||||
xmldoc.setContent( m_body );
|
bool namespaceProcessing = true;
|
||||||
|
xmldoc.setContent( m_body, namespaceProcessing );
|
||||||
QDomElement docElement( xmldoc.documentElement() );
|
QDomElement docElement( xmldoc.documentElement() );
|
||||||
|
|
||||||
QString origTitle;
|
QString origTitle;
|
||||||
origTitle = docElement.firstChildElement( "title" ).text();
|
QDomNodeList tracklist;
|
||||||
m_info = docElement.firstChildElement( "creator" ).text();
|
QDomElement n = docElement.firstChildElement();
|
||||||
m_creator = docElement.firstChildElement( "info" ).text();
|
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;
|
m_title = origTitle;
|
||||||
if ( m_title.isEmpty() )
|
if ( m_title.isEmpty() )
|
||||||
m_title = tr( "New Playlist" );
|
m_title = tr( "New Playlist" );
|
||||||
|
|
||||||
QDomNodeList tracklist = docElement.elementsByTagName( "track" );
|
|
||||||
for ( unsigned int i = 0; i < tracklist.length(); i++ )
|
for ( unsigned int i = 0; i < tracklist.length(); i++ )
|
||||||
{
|
{
|
||||||
QDomNode e = tracklist.at( 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 );
|
plentry_ptr p( new PlaylistEntry );
|
||||||
p->setGuid( uuid() );
|
p->setGuid( uuid() );
|
||||||
p->setDuration( e.firstChildElement( "duration" ).text().toInt() / 1000 );
|
p->setDuration( duration.toInt() / 1000 );
|
||||||
p->setLastmodified( 0 );
|
p->setLastmodified( 0 );
|
||||||
p->setAnnotation( e.firstChildElement( "annotation" ).text() );
|
p->setAnnotation( annotation );
|
||||||
|
|
||||||
QString artist, album, track;
|
|
||||||
artist = e.firstChildElement( "creator" ).text();
|
|
||||||
album = e.firstChildElement( "album" ).text();
|
|
||||||
track = e.firstChildElement( "title" ).text();
|
|
||||||
|
|
||||||
p->setQuery( Tomahawk::Query::get( artist, track, album, uuid() ) );
|
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;
|
m_entries << p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,6 +25,7 @@ public:
|
|||||||
explicit XSPFLoader( bool autoCreate = true, QObject* parent = 0 )
|
explicit XSPFLoader( bool autoCreate = true, QObject* parent = 0 )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
, m_autoCreate( autoCreate )
|
, m_autoCreate( autoCreate )
|
||||||
|
, NS("http://xspf.org/ns/0/")
|
||||||
{}
|
{}
|
||||||
|
|
||||||
virtual ~XSPFLoader()
|
virtual ~XSPFLoader()
|
||||||
@@ -47,6 +48,7 @@ private slots:
|
|||||||
void networkError( QNetworkReply::NetworkError e );
|
void networkError( QNetworkReply::NetworkError e );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QString NS;
|
||||||
void reportError();
|
void reportError();
|
||||||
void gotBody();
|
void gotBody();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user