Esempio n. 1
0
/**
 * @brief Called when backdrops are loaded
 */
void VideoBuster::backdropFinished()
{
    QNetworkReply *reply = static_cast<QNetworkReply*>(QObject::sender());
    Movie *movie = reply->property("storage").value<Storage*>()->movie();
    QList<int> infos = reply->property("infosToLoad").value<Storage*>()->infosToLoad();
    reply->deleteLater();
    if (!movie)
        return;

    if (reply->error() == QNetworkReply::NoError ) {
        QString msg = reply->readAll();
        QRegExp rx("href=\"https://gfx.videobuster.de/archive/resized/([^\"]*)\"(.*)([^<]*)<img (.*) src=\"https://gfx.videobuster.de/archive/resized/c110/([^\"]*)\"");
        rx.setMinimal(true);
        int pos = 0;
        while ((pos = rx.indexIn(msg, pos)) != -1) {
            pos += rx.matchedLength();
            if (rx.cap(2).contains("titledtl_cover_pictures")) {
                continue;
            }
            Poster p;
            p.thumbUrl = QUrl(QString("https://gfx.videobuster.de/archive/resized/w700/%1").arg(rx.cap(5)));
            p.originalUrl = QUrl(QString("https://gfx.videobuster.de/archive/resized/%1").arg(rx.cap(1)));
            movie->addBackdrop(p);
        }
    } else {
        qWarning() << "Network Error" << reply->errorString();
    }
    movie->controller()->scraperLoadDone();
}
void QgsArcGisRestCatalogProvider::parseFolderDo()
{
  QNetworkReply* reply = qobject_cast<QNetworkReply*>( QObject::sender() );
  reply->deleteLater();
  QString path = reply->property( "path" ).toString();
  QStringList catTitles = reply->property( "catTitles" ).toStringList();

  if ( reply->error() == QNetworkReply::NoError )
  {
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    QJson::Parser parser;
    QVariantMap folderData = parser.parse( reply->readAll() ).toMap();
#else
    QVariantMap folderData = QJsonDocument::fromJson( reply->readAll() ).object().toVariantMap();
#endif
    QString catName = QFileInfo( path ).baseName();
    if ( !catName.isEmpty() )
    {
      catTitles.append( catName );
    }
    foreach ( const QVariant& folderName, folderData["folders"].toList() )
    {
      parseFolder( path + "/" + folderName.toString(), catTitles );
    }
    foreach ( const QVariant& serviceData, folderData["services"].toList() )
    {
      parseService( QString( "/" ) + serviceData.toMap()["name"].toString(), catTitles );
    }
  }
Esempio n. 3
0
void IMDB::onLoadFinished()
{
    QNetworkReply *reply = static_cast<QNetworkReply*>(QObject::sender());
    reply->deleteLater();
    Movie *movie = reply->property("storage").value<Storage*>()->movie();
    QList<int> infos = reply->property("infosToLoad").value<Storage*>()->infosToLoad();
    if (!movie)
        return;

    if (reply->error() == QNetworkReply::NoError ) {
        QString msg = QString::fromUtf8(reply->readAll());
        parseAndAssignInfos(msg, movie, infos);
        QString posterUrl = parsePosters(msg);
        if (infos.contains(MovieScraperInfos::Poster) && !posterUrl.isEmpty()) {
            QNetworkReply *reply = qnam()->get(QNetworkRequest(posterUrl));
            reply->setProperty("storage", Storage::toVariant(reply, movie));
            reply->setProperty("infosToLoad", Storage::toVariant(reply, infos));
            connect(reply, SIGNAL(finished()), this, SLOT(onPosterLoadFinished()));
        } else {
            movie->controller()->scraperLoadDone(this);
        }
    } else {
        qWarning() << "Network Error (load)" << reply->errorString();
    }
}
Esempio n. 4
0
/**
 * @brief Called when the tv show actors are downloaded
 * Starts download of banners
 * @see TheTvDb::parseAndAssignActors
 * @see TheTvDb::onBannersFinished
 */
void TheTvDb::onActorsFinished()
{
    QNetworkReply *reply = static_cast<QNetworkReply*>(QObject::sender());
    reply->deleteLater();
    TvShow *show = reply->property("storage").value<Storage*>()->show();
    TvShowUpdateType updateType = static_cast<TvShowUpdateType>(reply->property("updateType").toInt());
    QList<int> infos = reply->property("infosToLoad").value<Storage*>()->infosToLoad();
    if (!show)
        return;

    if (reply->error() == QNetworkReply::NoError ) {
        QString msg = QString::fromUtf8(reply->readAll());
        if (show->infosToLoad().contains(TvShowScraperInfos::Actors) &&
                (updateType == UpdateShow || updateType == UpdateShowAndAllEpisodes || updateType == UpdateShowAndNewEpisodes))
            parseAndAssignActors(msg, show);
    } else {
        qWarning() << "Network Error" << reply->errorString();
    }
    QString mirror = m_xmlMirrors.at(qrand()%m_xmlMirrors.count());
    QUrl url(QString("%1/api/%2/series/%3/banners.xml").arg(mirror).arg(m_apiKey).arg(show->tvdbId()));
    reply = qnam()->get(QNetworkRequest(url));
    reply->setProperty("storage", Storage::toVariant(reply, show));
    reply->setProperty("updateType", updateType);
    reply->setProperty("infosToLoad", Storage::toVariant(reply, infos));
    connect(reply, SIGNAL(finished()), this, SLOT(onBannersFinished()));
}
Esempio n. 5
0
void
LastFmPlugin::coverArtReturned()
{
    qDebug() << Q_FUNC_INFO;
    QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
    QUrl redir = reply->attribute( QNetworkRequest::RedirectionTargetAttribute ).toUrl();
    if ( redir.isEmpty() )
    {
        QByteArray ba = reply->readAll();
        foreach ( const QUrl& url, m_badUrls )
        {
            if ( reply->url().toString().startsWith( url.toString() ) )
                ba = QByteArray();
        }

        InfoCustomData returnedData;
        returnedData["imgbytes"] = ba;
        returnedData["url"] = reply->url().toString();

        InfoCustomData customData = reply->property( "customData" ).value< Tomahawk::InfoSystem::InfoCustomData >();
        InfoType type = (Tomahawk::InfoSystem::InfoType)(reply->property( "type" ).toUInt());
        emit info(
            reply->property( "caller" ).toString(),
            type,
            reply->property( "origData" ),
            returnedData,
            customData
        );

        InfoCriteriaHash origData = reply->property( "origData" ).value< Tomahawk::InfoSystem::InfoCriteriaHash >();
        Tomahawk::InfoSystem::InfoCriteriaHash criteria;
        criteria["artist"] = origData["artist"];
        criteria["album"] = origData["album"];
        emit updateCache( criteria, 2419200000, type, returnedData );
    }
Esempio n. 6
0
/**
 * @brief Called when the episode infos are downloaded
 * @see TheTvDb::parseAndAssignSingleEpisodeInfos
 */
void TheTvDb::onEpisodeLoadFinished()
{
    QNetworkReply *reply = static_cast<QNetworkReply*>(QObject::sender());
    QList<int> infos = reply->property("infosToLoad").value<Storage*>()->infosToLoad();
    reply->deleteLater();
    TvShowEpisode *episode = reply->property("storage").value<Storage*>()->episode();
    if (!episode)
        return;

    if (reply->error() == QNetworkReply::NoError ) {
        QString msg = QString::fromUtf8(reply->readAll());
        QDomDocument domDoc;
        domDoc.setContent(msg);
        for (int i=0, n=domDoc.elementsByTagName("Episode").count() ; i<n ; ++i) {
            QDomElement elem = domDoc.elementsByTagName("Episode").at(i).toElement();
            if (!elem.elementsByTagName("SeasonNumber").isEmpty() && !elem.elementsByTagName("EpisodeNumber").isEmpty()) {
                int seasonNumber = elem.elementsByTagName("SeasonNumber").at(0).toElement().text().toInt();
                int episodeNumber = elem.elementsByTagName("EpisodeNumber").at(0).toElement().text().toInt();
                if (episode->season() == seasonNumber && episode->episode() == episodeNumber) {
                    episode->clear(episode->infosToLoad());
                    parseAndAssignSingleEpisodeInfos(elem, episode, infos);
                }
            }
        }
    } else {
        qWarning() << "Network Error" << reply->errorString();
    }
    episode->scraperLoadDone();
}
Esempio n. 7
0
void
MusixMatchPlugin::trackSearchSlot()
{
    tDebug() << Q_FUNC_INFO;
    QNetworkReply* oldReply = qobject_cast<QNetworkReply*>( sender() );
    if ( !oldReply )
        return; //timeout will handle it
    oldReply->deleteLater();

    QDomDocument doc;
    doc.setContent(oldReply->readAll());
    qDebug() << Q_FUNC_INFO << doc.toString();
    QDomNodeList domNodeList = doc.elementsByTagName("track_id");
    if ( domNodeList.isEmpty() )
    {
        emit info( oldReply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant() );
        return;
    }
    QString track_id = domNodeList.at(0).toElement().text();
    QString requestString( "http://api.musixmatch.com/ws/1.1/track.lyrics.get?track_id=%1&format=xml&apikey=%2" );
    QUrl url( requestString );

    TomahawkUtils::urlAddQueryItem( url, "apikey", m_apiKey );
    TomahawkUtils::urlAddQueryItem( url, "track_id", track_id );

    QNetworkReply* newReply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
    newReply->setProperty( "requestData", oldReply->property( "requestData" ) );
    connect( newReply, SIGNAL( finished() ), SLOT( trackLyricsSlot() ) );
}
Esempio n. 8
0
void
MusicBrainzPlugin::albumSearchSlot()
{
    QNetworkReply* oldReply = qobject_cast<QNetworkReply*>( sender() );
    if ( !oldReply )
        return; //timeout will handle it

    QDomDocument doc;
    doc.setContent( oldReply->readAll() );
    QDomNodeList domNodeList = doc.elementsByTagName( "artist" );
    if ( domNodeList.isEmpty() )
    {
        emit info( oldReply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant() );
        return;
    }

    QString artist_id = domNodeList.at( 0 ).toElement().attribute( "id" );
    QString requestString( "http://musicbrainz.org/ws/2/release?status=official&type=album|ep" );
    QUrl url( requestString );
    url.addQueryItem( "artist", artist_id );

    QNetworkReply* newReply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
    newReply->setProperty( "requestData", oldReply->property( "requestData" ) );
    connect( newReply, SIGNAL( finished() ), SLOT( tracksSearchSlot() ) );
}
Esempio n. 9
0
/**
 * @brief Called when backdrop scraping has finished
 * Starts the next backdrop download or tells the movie that scraping is done
 */
void Cinefacts::backdropFinished()
{
    QNetworkReply *reply = static_cast<QNetworkReply*>(QObject::sender());
    reply->deleteLater();
    Movie *movie = reply->property("storage").value<Storage*>()->movie();
    QStringList backdrops = reply->property("backdrops").toStringList();
    QList<int> infos = reply->property("infosToLoad").value<Storage*>()->infosToLoad();
    if (!movie)
        return;

    if (reply->error() == QNetworkReply::NoError) {
        QString msg = QString::fromUtf8(reply->readAll());
        QRegExp rx("<a href=\"([^\"]*)\" target=\"_blank\">Bild in Originalgr..e</a>");
        rx.setMinimal(true);
        if (rx.indexIn(msg) != -1) {
            Poster p;
            p.thumbUrl = rx.cap(1);
            p.originalUrl = rx.cap(1);
            movie->addBackdrop(p);
        }

        if (!backdrops.isEmpty()) {
            reply = qnam()->get(QNetworkRequest(QUrl(QString("http://www.cinefacts.de%1").arg(backdrops.takeFirst()))));
            reply->setProperty("storage", Storage::toVariant(reply, movie));
            reply->setProperty("backdrops", backdrops);
            reply->setProperty("infosToLoad", Storage::toVariant(reply, infos));
            connect(reply, SIGNAL(finished()), this, SLOT(backdropFinished()));
            return;
        }
    }
    movie->controller()->scraperLoadDone(this);
}
Esempio n. 10
0
void
MusicBrainzPlugin::albumFoundSlot()
{
    QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() );
    if ( !reply )
        return; //timeout will handle it

    QDomDocument doc;
    doc.setContent( reply->readAll() );
    QDomNodeList domNodeList = doc.elementsByTagName( "title" );
    if ( domNodeList.isEmpty() )
    {
        emit info( reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant() );
        return;
    }

    QStringList albums;
    for ( int i = 0; i < domNodeList.count(); i++ )
    {
        QString album = domNodeList.at( i ).toElement().text();
        if ( !albums.contains( album ) )
            albums << album;
    }

    Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();
    QVariantMap returnedData;
    returnedData["albums"] = albums;
    emit info( requestData, returnedData );

    Tomahawk::InfoSystem::InfoStringHash origData = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash>();
    Tomahawk::InfoSystem::InfoStringHash criteria;
    criteria["artist"] = origData["artist"];
    emit updateCache( criteria, 0, requestData.type, returnedData );
}
Esempio n. 11
0
void UniversalMusicScraper::onArtistRelsFinished()
{
    QNetworkReply *reply = static_cast<QNetworkReply*>(QObject::sender());
    Artist *artist = reply->property("storage").value<Storage*>()->artist();
    QList<int> infos = reply->property("infosToLoad").value<Storage*>()->infosToLoad();
    reply->deleteLater();
    if (!artist)
        return;

    if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 302 ||
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 301) {
        qDebug() << "Got redirect" << reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
        reply = qnam()->get(QNetworkRequest(reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl()));
        reply->setProperty("storage", Storage::toVariant(reply, artist));
        reply->setProperty("infosToLoad", Storage::toVariant(reply, infos));
        connect(reply, SIGNAL(finished()), this, SLOT(onArtistRelsFinished()));
        return;
    }

    QString discogsUrl;
    if (reply->error() == QNetworkReply::NoError) {
        QString msg = QString::fromUtf8(reply->readAll());
        QDomDocument domDoc;
        domDoc.setContent(msg);
        for (int i=0, n=domDoc.elementsByTagName("relation").count() ; i<n ; ++i) {
            QDomElement elem = domDoc.elementsByTagName("relation").at(i).toElement();
            if (elem.attribute("type") == "allmusic" && elem.elementsByTagName("target").count() > 0) {
                QString url = elem.elementsByTagName("target").at(0).toElement().text();
                QRegExp rx("allmusic\\.com/artist/(.*)$");
                if (rx.indexIn(url) != -1)
                    artist->setAllMusicId(rx.cap(1));
            }
            if (elem.attribute("type") == "discogs" && elem.elementsByTagName("target").count() > 0)
                discogsUrl = elem.elementsByTagName("target").at(0).toElement().text();
        }
    }

    if (!m_artistDownloads.contains(artist))
        m_artistDownloads.insert(artist, QList<DownloadElement>());
    m_artistDownloads[artist].clear();

    appendDownloadElement(artist, "theaudiodb", "tadb_data", QUrl(QString("http://www.theaudiodb.com/api/v1/json/%1/artist-mb.php?i=%2").arg(m_tadbApiKey).arg(artist->mbId())));
    appendDownloadElement(artist, "theaudiodb", "tadb_discography", QUrl(QString("http://www.theaudiodb.com/api/v1/json/%1/discography-mb.php?s=%2").arg(m_tadbApiKey).arg(artist->mbId())));
    if (!artist->allMusicId().isEmpty()) {
        appendDownloadElement(artist, "allmusic", "am_data", QUrl(QString("http://www.allmusic.com/artist/%1").arg(artist->allMusicId())));
        appendDownloadElement(artist, "allmusic", "am_biography", QUrl(QString("http://www.allmusic.com/artist/%1/biography").arg(artist->allMusicId())));
    }
    if (!discogsUrl.isEmpty())
        appendDownloadElement(artist, "discogs", "discogs_data", QUrl(discogsUrl + "?type=Releases&subtype=Albums"));

    foreach (DownloadElement elem, m_artistDownloads[artist]) {
        QNetworkRequest request(elem.url);
        request.setRawHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0");
        QNetworkReply *reply = qnam()->get(request);
        new NetworkReplyWatcher(this, reply);
        reply->setProperty("storage", Storage::toVariant(reply, artist));
        reply->setProperty("infosToLoad", Storage::toVariant(reply, infos));
        connect(reply, SIGNAL(finished()), this, SLOT(onArtistLoadFinished()));
    }
void SidebarPrivate::linkClickedFinished()
{
    QNetworkReply * reply = static_cast< QNetworkReply * >(sender());

    QString target = reply->property("__target").toString();
    QVariant redirectsVariant = reply->property("__redirects");
    int redirects = redirectsVariant.isNull() ? 20 : redirectsVariant.toInt();

    // Redirect?
    QUrl redirectedUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
    if (redirectedUrl.isValid())
    {
        if (redirectedUrl.isRelative())
        {
            QUrl oldUrl = reply->url();
            redirectedUrl.setScheme(oldUrl.scheme());
            redirectedUrl.setAuthority(oldUrl.authority());
        }
        if (redirects > 0)
        {
            QNetworkRequest request = reply->request();
            request.setUrl(redirectedUrl);
            QNetworkReply * reply = networkAccessManager()->get(request);
            reply->setProperty("__target", target);
            connect(reply, SIGNAL(finished()), this, SLOT(linkClickedFinished()));
        }
        else
        {
            // TOO MANY REDIRECTS
        }
        reply->deleteLater();
        return;
    }

    // Check headers... if PDF then launch a new window, otherwise give it to the OS
    QString contentType(reply->header(QNetworkRequest::ContentTypeHeader).toString());
    if (contentType.contains("application/pdf")) {
        emit urlRequested(reply->request().url(), "tab");
    } else {
        QUrl href(reply->request().url());
        if (href.isValid()) {
            if (href.scheme() == "http" || href.scheme() == "https") {
                if (target == "sidebar") {
                    webView->setUrl(href);
                    slideLayout->push("web");
                    return;
                }
            }

            QDesktopServices::openUrl(href);
        }
        // FIXME error
    }

    reply->deleteLater();
}
Esempio n. 13
0
void
MusicBrainzPlugin::gotReleaseGroupsSlot()
{
    QNetworkReply* oldReply = qobject_cast<QNetworkReply*>( sender() );
    if ( !oldReply )
        return; //timeout will handle it

    QDomDocument doc;
    doc.setContent( oldReply->readAll() );
    QDomNodeList releaseGroupsNL = doc.elementsByTagName( "release-group" );
    if ( releaseGroupsNL.isEmpty() )
    {
        emit info( oldReply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant() );
        tDebug() << Q_FUNC_INFO << doc.toString();
        return;
    }

    Tomahawk::InfoSystem::InfoRequestData requestData = oldReply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();
    InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >();
    switch ( requestData.type )
    {
        case InfoArtistReleases:
        {
            QString popularId = releaseGroupsNL.at(0).firstChildElement( "artist-credit" ).firstChildElement( "name-credit" ).firstChildElement( "artist" ).attribute( "id" );

            QStringList albums;
            for ( int i = 0; i < releaseGroupsNL.count(); i++ )
            {
                QString groupTitle = releaseGroupsNL.at(i).firstChildElement("title").text();
                QString a = releaseGroupsNL.at(i).firstChildElement( "artist-credit" ).firstChildElement( "name-credit" ).firstChildElement( "artist" ).firstChildElement( "name" ).text();
                QString id = releaseGroupsNL.at(i).firstChildElement( "artist-credit" ).firstChildElement( "name-credit" ).firstChildElement( "artist" ).attribute( "id" );
                if ( !albums.contains( groupTitle ) && id == popularId && a.normalized( QString::NormalizationForm_KC ) == hash["artist"].normalized( QString::NormalizationForm_KC ) )
                {
                    albums << groupTitle;
                    tDebug() << Q_FUNC_INFO << groupTitle;
                }
            }

            QVariantMap returnedData;
            returnedData["albums"] = albums;
            emit info( requestData, returnedData );

            Tomahawk::InfoSystem::InfoStringHash origData = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash>();
            Tomahawk::InfoSystem::InfoStringHash criteria;
            criteria["artist"] = origData["artist"];
            emit updateCache( criteria, 0, requestData.type, returnedData );
            break;
        }

        default:
        {
            Q_ASSERT( false );
            break;
        }
    }
}
Esempio n. 14
0
void ImgurUploader::tokenReady()
{
  QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
  if (!reply)
    return;

  const QVariantMap data = JSON::parse(reply->readAll()).toMap();
  if (reply->error() == QNetworkReply::NoError && !m_queue.isEmpty()) {
    QVariantMap map;
    QVariantList a;
    a.append(m_clientId);
    a.append(m_clientSecret);
    a.append(data.value(LS("refresh_token")));
    a.append(data.value(LS("access_token")));
    map.insert("a", a);

    while (!m_queue.isEmpty())
      upload(m_net, m_queue.dequeue(), map);
  }

  QVariantMap map;
  map.insert(LS("type"),  LS("token"));
  map.insert(LS("reply"), data);

  emit finished(reply->property("id").toByteArray(), LS("imgur"), map);
  reply->deleteLater();
}
Esempio n. 15
0
void WebSocketManager::retrieveCallerInfoFinished()
{
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
    QByteArray data = reply->readAll();
    QString callerNumber = reply->property("caller_number").toString();
    reply->deleteLater();

    QJsonParseError error;
    QJsonDocument document = QJsonDocument::fromJson(data, &error);
    if (error.error != QJsonParseError::NoError)
        return;

    QString contactPerson = document.object().value("contact_person").toString();
    QString loginName = document.object().value("login_name").toString();
    QString callingNumber = document.object().value("calling_number").toString();
    QString companyName = document.object().value("company_name").toString();
    double balance = document.object().value("cur_balance").toDouble();

    ContactInfo *ci = new ContactInfo();
    ci->setContactPerson(contactPerson);
    ci->setLogin(loginName);
    ci->setCallingNumber(callingNumber);
    ci->setCompanyName(companyName);
    ci->setBalance(balance);

    m_contactsHash.insert(callerNumber, ci);

    emit channelCreated(ci);
}
Esempio n. 16
0
void AppDownloader::packageFetched()
{
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
    reply->deleteLater();

    QString file = reply->property("file").toString();

    QFile f(m_storagePath + file);
    if (!f.open(QFile::WriteOnly | QFile::Truncate)) {
        qWarning() << "Error opening file for writing";
        return;
    }
    f.write(reply->readAll());
    f.flush();
    f.close();

    QString appid = file.split("/").first();

    if (!ZipHelper::unpackArchive(m_storagePath+file, m_storagePath + appid)) {
        qWarning() << "Error unpacking App zip file";
        return;
    }

    emit downloadFinished(appid);
}
void TwitterDataTypeSyncAdaptor::errorHandler(QNetworkReply::NetworkError err)
{
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
    QByteArray replyData = reply->readAll();
    int accountId = reply->property("accountId").toInt();

    SOCIALD_LOG_ERROR(SocialNetworkSyncAdaptor::dataTypeName(m_dataType) <<
                      "request with account" << accountId <<
                      "experienced error:" << err <<
                      "HTTP:" << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
    // set "isError" on the reply so that adapters know to ignore the result in the finished() handler
    reply->setProperty("isError", QVariant::fromValue<bool>(true));
    // Note: not all errors are "unrecoverable" errors, so we don't change the status here.

    bool ok = false;
    QJsonObject parsed = parseJsonObjectReplyData(replyData, &ok);
    if (ok && parsed.contains(QLatin1String("errors"))) {
        QJsonArray dataList = parsed.value(QLatin1String("errors")).toArray();
        // API v1.1 returns only one element in the array, but looks like these
        // are constantly updated: https://dev.twitter.com/docs/error-codes-responses
        foreach (QJsonValue data, dataList) {
            QJsonObject dataMap = data.toObject();
            if (dataMap.value("code").toDouble() == 32 || dataMap.value("code").toDouble() == 89) {
                Accounts::Account *account = Accounts::Account::fromId(m_accountManager, accountId, this);
                if (account) {
                    setCredentialsNeedUpdate(account);
                }
            }
        }
Esempio n. 18
0
void ShortenedUrl::finished()
{
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());

    if (reply) {
        if (reply->error() == QNetworkReply::NoError) {
            QString shortenedUrl(reply->readAll());
            QString longUrl = reply->property("longurl").toString();
            emit finishedShortingUrl(shortenedUrl, longUrl);
        } else {
            QString longUrl = reply->property("longurl").toString();
            emit finishedShortingUrl(QString(), longUrl);
        }
        reply->deleteLater();
    }
}
Esempio n. 19
0
void IMDB::onLoadFinished()
{
    QNetworkReply *reply = static_cast<QNetworkReply*>(QObject::sender());
    Movie *movie = reply->property("storage").value<Storage*>()->movie();
    QList<int> infos = reply->property("infosToLoad").value<Storage*>()->infosToLoad();
    if (!movie)
        return;

    if (reply->error() == QNetworkReply::NoError ) {
        QString msg = QString::fromUtf8(reply->readAll());
        parseAndAssignInfos(msg, movie, infos);
    } else {
        qWarning() << "Network Error (load)" << reply->errorString();
    }
    reply->deleteLater();
    movie->controller()->scraperLoadDone(this);
}
Esempio n. 20
0
/**
 * @brief Called when the movie infos are downloaded
 * @see OFDb::parseAndAssignInfos
 */
void OFDb::loadFinished()
{
    QNetworkReply *reply = static_cast<QNetworkReply*>(QObject::sender());
    Movie *movie = reply->property("storage").value<Storage*>()->movie();
    QString ofdbId = reply->property("ofdbId").toString();
    QList<int> infos = reply->property("infosToLoad").value<Storage*>()->infosToLoad();
    int notFoundCounter = reply->property("notFoundCounter").toInt();
    if (!movie)
        return;

    if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 302 ||
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 301) {
        qDebug() << "Got redirect" << reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
        reply->deleteLater();
        reply = qnam()->get(QNetworkRequest(reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl()));
        reply->setProperty("storage", Storage::toVariant(reply, movie));
        reply->setProperty("ofdbId", ofdbId);
        reply->setProperty("infosToLoad", Storage::toVariant(reply, infos));
        connect(reply, SIGNAL(finished()), this, SLOT(loadFinished()));
        return;
    }

    if (reply->error() == QNetworkReply::ContentNotFoundError && notFoundCounter < 3) {
        qWarning() << "Got 404";
        notFoundCounter++;
        reply->deleteLater();
        QUrl url(QString("http://ofdbgw.org/movie/%1").arg(ofdbId));
        reply = qnam()->get(QNetworkRequest(url));
        reply->setProperty("storage", Storage::toVariant(reply, movie));
        reply->setProperty("ofdbId", ofdbId);
        reply->setProperty("notFoundCounter", notFoundCounter);
        reply->setProperty("infosToLoad", Storage::toVariant(reply, infos));
        connect(reply, SIGNAL(finished()), this, SLOT(loadFinished()));
        return;
    }


    if (reply->error() == QNetworkReply::NoError ) {
        QString msg = QString::fromUtf8(reply->readAll());
        parseAndAssignInfos(msg, movie, infos);
    } else {
        qWarning() << "Network Error" << reply->errorString();
    }
    reply->deleteLater();
    movie->controller()->scraperLoadDone(this);
}
Esempio n. 21
0
void
RoviPlugin::albumLookupFinished()
{
    QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
    Q_ASSERT( reply );

    if ( reply->error() != QNetworkReply::NoError )
        return;

    Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();

    QJson::Parser p;
    bool ok;
    QVariantMap response = p.parse( reply, &ok ).toMap();

    if ( !ok || response.isEmpty() || !response.contains( "searchResponse" ) )
    {
        tLog() << "Error parsing JSON from Rovi!" << p.errorString() << response;
        emit info( requestData, QVariant() );
        return;
    }

    QVariantList resultList = response[ "searchResponse" ].toMap().value( "results" ).toList();
    if ( resultList.size() == 0 )
    {
        emit info( requestData, QVariant() );
        return;
    }

    QVariantMap results = resultList.first().toMap();
    QVariantList tracks = results[ "album" ].toMap()[ "tracks" ].toList();

    if ( tracks.isEmpty() )
    {
        tLog() << "Error parsing JSON from Rovi!" << p.errorString() << response;
        emit info( requestData, QVariant() );
    }


    QStringList trackNameList;
    foreach ( const QVariant& track, tracks )
    {
        const QVariantMap trackData = track.toMap();
        if ( trackData.contains( "title" ) )
            trackNameList << trackData[ "title" ].toString();
    }

    QVariantMap returnedData;
    returnedData["tracks"] = trackNameList;

    emit info( requestData, returnedData );

    Tomahawk::InfoSystem::InfoStringHash criteria;
    criteria["artist"] = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash>()["artist"];
    criteria["album"] = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash>()["album"];

    emit updateCache( criteria, 0, requestData.type, returnedData );
}
Esempio n. 22
0
void
MusicBrainzPlugin::gotReleasesSlot()
{
    QNetworkReply* oldReply = qobject_cast<QNetworkReply*>( sender() );
    if ( !oldReply )
        return; //timeout will handle it

    QDomDocument doc;
    doc.setContent( oldReply->readAll() );
    QDomNodeList releasesNL = doc.elementsByTagName( "release" );
    if ( releasesNL.isEmpty() )
    {
        emit info( oldReply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant() );
        tDebug() << Q_FUNC_INFO << doc.toString();
        return;
    }

    Tomahawk::InfoSystem::InfoRequestData requestData = oldReply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();
    switch ( requestData.type )
    {
        case InfoAlbumSongs:
        {
            // we can simply use the first result as they are sorted by score
            QString release_id = releasesNL.at(0).toElement().attribute( "id" );

            QString requestString = QString( "http://musicbrainz.org/ws/2/release/%1" ).arg( release_id );
            QUrl url( requestString );
            url.addQueryItem( "inc", "recordings" );
            tDebug() << Q_FUNC_INFO << url.toString();

            QNetworkReply* newReply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
            newReply->setProperty( "requestData", oldReply->property( "requestData" ) );
            connect( newReply, SIGNAL( finished() ), SLOT( gotRecordingsSlot() ) );

            break;
        }

        default:
        {
            Q_ASSERT( false );
            break;
        }
    }

}
Esempio n. 23
0
/**
 * @brief Called when the tv show banners are downloaded
 * @see TheTvDb::parseAndAssignBanners
 * Tells the current show that scraping has ended
 */
void TheTvDb::onBannersFinished()
{
    QNetworkReply *reply = static_cast<QNetworkReply*>(QObject::sender());
    reply->deleteLater();
    TvShow *show = reply->property("storage").value<Storage*>()->show();
    TvShowUpdateType updateType = static_cast<TvShowUpdateType>(reply->property("updateType").toInt());
    QList<int> infos = reply->property("infosToLoad").value<Storage*>()->infosToLoad();
    if (!show)
        return;

    if (reply->error() == QNetworkReply::NoError ) {
        QString msg = QString::fromUtf8(reply->readAll());
        parseAndAssignBanners(msg, show, updateType, infos);
    } else {
        qDebug() << "Network Error" << reply->errorString();
    }
    show->scraperLoadDone();
}
Esempio n. 24
0
void
MusicBrainzPlugin::albumFoundSlot()
{
    QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() );
    if ( !reply )
        return; //timeout will handle it

    QDomDocument doc;
    doc.setContent( reply->readAll() );
    QDomNodeList groups = doc.elementsByTagName( "release-group" );
    if ( groups.isEmpty() )
    {
        emit info( reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant() );
        return;
    }

    QStringList albums;
    for ( int i = 0; i < groups.count(); i++ )
    {
        QDomElement group = groups.at(i).toElement();
        QDomNodeList secTypesDL = group.elementsByTagName("secondary-type");
        QStringList secTypesSL;
        for ( int i = 0; i < secTypesDL.count(); i++ )
        {
            secTypesSL.append(secTypesDL.at(i).toElement().text());
        }
        if ( !secTypesSL.contains("Live") && !secTypesSL.contains("Compilation") )
        {
            QString album = group.firstChildElement("title").text();
            if ( !albums.contains( album ) )
                albums << album;
        }
    }

    Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();
    QVariantMap returnedData;
    returnedData["albums"] = albums;
    emit info( requestData, returnedData );

    Tomahawk::InfoSystem::InfoStringHash origData = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash>();
    Tomahawk::InfoSystem::InfoStringHash criteria;
    criteria["artist"] = origData["artist"];
    emit updateCache( criteria, 0, requestData.type, returnedData );
}
Esempio n. 25
0
void
MusixMatchPlugin::trackLyricsSlot()
{
    tDebug() << Q_FUNC_INFO;
    QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() );
    if ( !reply )
        return; //timeout will handle it

    QDomDocument doc;
    doc.setContent( reply->readAll() );
    QDomNodeList domNodeList = doc.elementsByTagName( "lyrics_body" );
    if ( domNodeList.isEmpty() )
    {
        emit info( reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant() );
        return;
    }
    QString lyrics = domNodeList.at(0).toElement().text();
    emit info( reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant( lyrics ) );
}
Esempio n. 26
0
/**
 * @brief Called when the movie images are downloaded
 * @see TMDbImages::parseMovieData
 */
void FanartTv::onLoadMovieDataFinished()
{
    QNetworkReply *reply = static_cast<QNetworkReply*>(QObject::sender());
    reply->deleteLater();
    QList<Poster> posters;
    if (reply->error() == QNetworkReply::NoError ) {
        QString msg = QString::fromUtf8(reply->readAll());
        posters = parseMovieData(msg, reply->property("infoToLoad").toInt());
    }
    emit sigImagesLoaded(posters);
}
Esempio n. 27
0
/**
 * @brief Called when all movie images are downloaded
 * @see TMDbImages::parseMovieData
 */
void FanartTv::onLoadAllMovieDataFinished()
{
    QNetworkReply *reply = static_cast<QNetworkReply*>(QObject::sender());
    Movie *movie = reply->property("storage").value<Storage*>()->movie();
    reply->deleteLater();
    QMap<int, QList<Poster> > posters;
    if (reply->error() == QNetworkReply::NoError ) {
        QString msg = QString::fromUtf8(reply->readAll());
        foreach (int type, reply->property("infosToLoad").value<Storage*>()->infosToLoad())
            posters.insert(type, parseMovieData(msg, type));
    }
Esempio n. 28
0
// creates a total download progress for multiple QNetworkReplies
void SettingsDialog::downloadProgress(qint64 received, qint64 total)
{
    // Don't show progress for non-docset pages
    if (total == -1 || received < 10240)
        return;

    QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
    if (!reply || !reply->isOpen())
        return;

    if (reply->property(DownloadTypeProperty).toInt() == DownloadDocset)  {
        const QString docsetName = reply->property(DocsetNameProperty).toString();

        QTemporaryFile *tmpFile = m_tmpFiles[docsetName];
        if (!tmpFile) {
            tmpFile = new QTemporaryFile(this);
            tmpFile->open();
            m_tmpFiles.insert(docsetName, tmpFile);
        }

        tmpFile->write(reply->read(received));
    }

    // Try to get the item associated to the request
    QListWidgetItem *item
            = ui->availableDocsetList->item(reply->property(ListItemIndexProperty).toInt());
    if (item)
        item->setData(ProgressItemDelegate::ValueRole, percent(received, total));

    qint64 previousReceived = 0;
    const QVariant previousReceivedVariant = reply->property(DownloadPreviousReceived);
    if (!previousReceivedVariant.isValid())
        m_combinedTotal += total;
    else
        previousReceived = previousReceivedVariant.toLongLong();

    m_combinedReceived += received - previousReceived;
    reply->setProperty(DownloadPreviousReceived, received);

    displayProgress();
}
Esempio n. 29
0
void
MusicBrainzPlugin::tracksSearchSlot()
{
    QNetworkReply* oldReply = qobject_cast<QNetworkReply*>( sender() );
    if ( !oldReply )
        return; //timeout will handle it

    QDomDocument doc;
    doc.setContent( oldReply->readAll() );
    QDomNodeList domNodeList = doc.elementsByTagName( "release" );
    if ( domNodeList.isEmpty() )
    {
        emit info( oldReply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant() );
        return;
    }

    Tomahawk::InfoSystem::InfoRequestData requestData = oldReply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();
    InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >();

    QDomElement element;
    for ( int i = 0; i < domNodeList.count(); i++ )
    {
        QDomNodeList albumNodeList = domNodeList.at( i ).toElement().elementsByTagName( "title" );
        if ( albumNodeList.at( 0 ).toElement().text() == hash["album"] )
            element = domNodeList.at( i ).toElement();
    }

    if ( element.isNull() )
    {
        emit info( oldReply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant() );
        return;
    }

    QString release_id = element.attribute( "id" );
    QString requestString = QString( "http://musicbrainz.org/ws/2/release/%1?inc=recordings" ).arg( release_id );
    QUrl url( requestString );

    QNetworkReply* newReply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
    newReply->setProperty( "requestData", oldReply->property( "requestData" ) );
    connect( newReply, SIGNAL( finished() ), SLOT( tracksFoundSlot() ) );
}
Esempio n. 30
0
void
MusicBrainzPlugin::gotRecordingsSlot()
{
    QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() );
    if ( !reply )
        return; //timeout will handle it

    QDomDocument doc;
    doc.setContent( reply->readAll() );
    QDomNodeList mediumList = doc.elementsByTagName( "medium-list" );
    if ( mediumList.isEmpty() )
    {
        emit info( reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant() );
        tDebug() << Q_FUNC_INFO << doc.toString();
        return;
    }


    QDomNodeList tracksNL = mediumList.at(0).toElement().elementsByTagName( "track" );
    QStringList tracksSL;
    for ( int i = 0; i < tracksNL.count(); i++ )
    {
        QString track = tracksNL.at(i).firstChildElement( "recording" ).firstChildElement( "title" ).text();
        if ( !tracksSL.contains( track ) )
        {
            tracksSL << track;
            tDebug(LOGVERBOSE) << Q_FUNC_INFO << track;
        }
    }

    Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();
    QVariantMap returnedData;
    returnedData["tracks"] = tracksSL;
    emit info( requestData, returnedData );

    Tomahawk::InfoSystem::InfoStringHash origData = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash>();
    Tomahawk::InfoSystem::InfoStringHash criteria;
    criteria["artist"] = origData["artist"];
    criteria["album"] = origData["album"];
    emit updateCache( criteria, 0, requestData.type, returnedData );
}