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