PageRenderTime 103ms CodeModel.GetById 40ms app.highlight 8ms RepoModel.GetById 52ms app.codeStats 0ms

/thirdparty/liblastfm2/src/types/Xspf.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 75 lines | 39 code | 14 blank | 22 comment | 3 complexity | 1269597dc297f813859f781fc7e93896 MD5 | raw file
 1/*
 2   Copyright 2009 Last.fm Ltd. 
 3      - Primarily authored by Max Howell, Jono Cole and Doug Mansell
 4
 5   This file is part of liblastfm.
 6
 7   liblastfm is free software: you can redistribute it and/or modify
 8   it under the terms of the GNU General Public License as published by
 9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   liblastfm is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with liblastfm.  If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#include <QTimer>
22#include <QUrl>
23
24#include "../core/XmlQuery.h"
25
26#include "Xspf.h"
27
28
29lastfm::Xspf::Xspf( const QDomElement& playlist_node, QObject* parent )
30    :QObject( parent )
31{
32    XmlQuery e( playlist_node );
33
34    int expirySeconds = e["link rel=http://www.last.fm/expiry"].text().toInt();
35    QTimer::singleShot( expirySeconds * 1000, this, SLOT(onExpired()));
36    
37    m_title = e["title"].text();
38        
39    //FIXME should we use UnicornUtils::urlDecode()?
40    //The title is url encoded, has + instead of space characters 
41    //and has a + at the begining. So it needs cleaning up:
42    m_title.replace( '+', ' ' );
43    m_title = QUrl::fromPercentEncoding( m_title.toAscii());
44    m_title = m_title.trimmed();
45    
46    foreach (XmlQuery e, e["trackList"].children( "track" ))
47    {
48        MutableTrack t;
49        t.setUrl( e["location"].text() );
50        t.setExtra( "trackauth", e["extension"]["trackauth"].text() );
51        t.setTitle( e["title"].text() );
52        t.setArtist( e["creator"].text() );
53        t.setAlbum( e["album"].text() );
54        t.setDuration( e["duration"].text().toInt() / 1000 );
55        t.setLoved( e["extension"]["loved"].text() == "1" );
56        t.setSource( Track::LastFmRadio );
57
58        QList<QString> contexts;
59        QDomNodeList contextsNodeList = QDomElement(e["extension"]["context"]).childNodes();
60
61        for ( int i = 0 ; i < contextsNodeList.count() ; ++i )
62            contexts.append( contextsNodeList.item(i).toElement().text() );
63
64        if ( contexts.count() > 0 )
65            t.setContext( TrackContext( contextsNodeList.item(0).toElement().tagName(), contexts ) );
66
67        m_tracks << t; // outside try block since location is enough basically
68    }
69}
70
71void
72lastfm::Xspf::onExpired()
73{
74    emit expired();
75}