void RadioTuner::onTuneReturn() { if ( !d->m_retuneStation.url().isEmpty() ) { d->m_station = d->m_retuneStation; d->m_retuneStation = RadioStation(); } XmlQuery lfm; if ( lfm.parse( qobject_cast<QNetworkReply*>(sender()) ) ) { qDebug() << lfm; d->m_station.setTitle( lfm["station"]["name"].text() ); d->m_station.setUrl( lfm["station"]["url"].text() ); emit title( lfm["station"]["name"].text() ); emit supportsDisco( lfm["station"]["supportsdiscovery"].text() == "1" ); d->fetchFiveMoreTracks(); } else { emit error( lfm.parseError().enumValue(), lfm.parseError().message() ); } }
void RadioTuner::onGetPlaylistReturn() { // We shouldn't request another playlist for 2 seconds because we'll get the same one // in a different order. This QTimer will block until it has finished. If one or more // playlists have been requested in the meantime, it will fetch one on timeout d->m_twoSecondTimer->start( 2000 ); // This will block us fetching two playlists at once d->m_fetchingPlaylist = false; XmlQuery lfm; if ( lfm.parse( qobject_cast<QNetworkReply*>(sender()) ) ) { qDebug() << lfm; d->m_station.setTitle( lfm["playlist"]["title"].text() ); // we don't get the radio url in the playlist //d->m_station.setUrl( lfm["station"]["url"].text() ); emit title( lfm["playlist"]["title"].text() ); Xspf* xspf = new Xspf( lfm["playlist"], this ); if ( xspf->isEmpty() ) { // give up after too many empty playlists :( if (!d->tryAgain()) emit error( ws::NotEnoughContent, "Not enough content" ); } else { d->m_retry_counter = 0; d->m_playlist << xspf->tracks(); emit trackAvailable(); } delete xspf; } else { qDebug() << lfm.parseError().message() << lfm.parseError().enumValue(); emit error( lfm.parseError().enumValue(), lfm.parseError().message() ); } }
bool TrackImageFetcher::downloadImage( QNetworkReply* reply, const QString& root_node ) { XmlQuery lfm; if ( reply && lfm.parse( reply->readAll() ) ) { // cache all the sizes if ( root_node == "album" ) { m_track.album().setImageUrl( Track::MegaImage, lfm[root_node]["image size=mega"].text() ); m_track.album().setImageUrl( Track::ExtraLargeImage, lfm[root_node]["image size=extralarge"].text() ); m_track.album().setImageUrl( Track::LargeImage, lfm[root_node]["image size=large"].text() ); m_track.album().setImageUrl( Track::MediumImage, lfm[root_node]["image size=medium"].text() ); m_track.album().setImageUrl( Track::SmallImage, lfm[root_node]["image size=small"].text() ); } else if ( root_node == "artist" ) { m_track.artist().setImageUrl( Track::MegaImage, lfm[root_node]["image size=mega"].text() ); m_track.artist().setImageUrl( Track::ExtraLargeImage, lfm[root_node]["image size=extralarge"].text() ); m_track.artist().setImageUrl( Track::LargeImage, lfm[root_node]["image size=large"].text() ); m_track.artist().setImageUrl( Track::MediumImage, lfm[root_node]["image size=medium"].text() ); m_track.artist().setImageUrl( Track::SmallImage, lfm[root_node]["image size=small"].text() ); } } else { qWarning() << lfm.parseError().message(); } QUrl imageUrl = url( root_node ); qWarning() << root_node << imageUrl; if ( imageUrl.isValid() ) { QNetworkReply* get = lastfm::nam()->get( QNetworkRequest( imageUrl ) ); if ( root_node == "album" ) connect( get, SIGNAL(finished()), SLOT(onAlbumImageDownloaded()) ); else if ( root_node == "track" ) connect( get, SIGNAL(finished()), SLOT(onTrackImageDownloaded()) ); else connect( get, SIGNAL(finished()), SLOT(onArtistImageDownloaded()) ); return true; } return false; }
QMap<int, QString> //static Tag::list( QNetworkReply* r ) { QMap<int, QString> tags; XmlQuery lfm; if ( lfm.parse( r ) ) { foreach ( XmlQuery xq, lfm.children("tag") ) // we toLower always as otherwise it is ugly mixed case, as first // ever tag decides case, and Last.fm is case insensitive about it // anyway tags.insertMulti( xq["count"].text().toInt(), xq["name"].text().toLower() ); } else { qDebug() << lfm.parseError().message() << lfm.parseError().enumValue(); } return tags; }
void TrackImageFetcher::onTrackGotInfo( const QByteArray& data ) { XmlQuery lfm; if ( lfm.parse( data ) ) { lastfm::MutableTrack track( m_track ); track.setImageUrl( Track::MegaImage, lfm["track"]["image size=mega"].text() ); track.setImageUrl( Track::ExtraLargeImage, lfm["track"]["image size=extralarge"].text() ); track.setImageUrl( Track::LargeImage, lfm["track"]["image size=large"].text() ); track.setImageUrl( Track::MediumImage, lfm["track"]["image size=medium"].text() ); track.setImageUrl( Track::SmallImage, lfm["track"]["image size=small"].text() ); if (!downloadImage( 0, "track" )) startArtist(); } else { qWarning() << lfm.parseError().message(); } }