/** * @brief Parses info XML data and assigns it to the given tv show object * @param xml XML data * @param show Tv Show object * @param updateAllEpisodes Update all child episodes (regardless if they already have infos or not) */ void TheTvDb::parseAndAssignInfos(QString xml, TvShow *show, TvShowUpdateType updateType, QList<int> infosToLoad) { QDomDocument domDoc; domDoc.setContent(xml); if (updateType == UpdateShow || updateType == UpdateShowAndAllEpisodes || updateType == UpdateShowAndNewEpisodes) { show->clear(infosToLoad); if (!domDoc.elementsByTagName("Series").isEmpty()) { QDomElement elem = domDoc.elementsByTagName("Series").at(0).toElement(); if (infosToLoad.contains(TvShowScraperInfos::Certification) && !elem.elementsByTagName("ContentRating").isEmpty()) show->setCertification(Helper::mapCertification(elem.elementsByTagName("ContentRating").at(0).toElement().text())); if (infosToLoad.contains(TvShowScraperInfos::FirstAired) && !elem.elementsByTagName("FirstAired").isEmpty()) show->setFirstAired(QDate::fromString(elem.elementsByTagName("FirstAired").at(0).toElement().text(), "yyyy-MM-dd")); if (infosToLoad.contains(TvShowScraperInfos::Genres) && !elem.elementsByTagName("Genre").isEmpty()) show->setGenres(Helper::mapGenre(elem.elementsByTagName("Genre").at(0).toElement().text().split("|", QString::SkipEmptyParts))); if (infosToLoad.contains(TvShowScraperInfos::Network) && !elem.elementsByTagName("Network").isEmpty()) show->setNetwork(elem.elementsByTagName("Network").at(0).toElement().text()); if (infosToLoad.contains(TvShowScraperInfos::Overview) && !elem.elementsByTagName("Overview").isEmpty()) show->setOverview(elem.elementsByTagName("Overview").at(0).toElement().text()); if (infosToLoad.contains(TvShowScraperInfos::Rating) && !elem.elementsByTagName("Rating").isEmpty()) show->setRating(elem.elementsByTagName("Rating").at(0).toElement().text().toFloat()); if (infosToLoad.contains(TvShowScraperInfos::Title) && !elem.elementsByTagName("SeriesName").isEmpty()) show->setName(elem.elementsByTagName("SeriesName").at(0).toElement().text()); } } if (updateType == UpdateAllEpisodes || updateType == UpdateNewEpisodes || updateType == UpdateShowAndAllEpisodes || updateType == UpdateShowAndNewEpisodes) { 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(); TvShowEpisode *episode = show->episode(seasonNumber, episodeNumber); if (!episode->isValid()) continue; if (updateType == UpdateAllEpisodes || updateType == UpdateShowAndAllEpisodes || ((updateType == UpdateNewEpisodes || updateType == UpdateShowAndNewEpisodes) && !episode->infoLoaded())) { episode->clear(infosToLoad); parseAndAssignSingleEpisodeInfos(elem, episode, infosToLoad); } } } } }
/** * @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(); }
QDebug operator<<(QDebug dbg, const TvShowEpisode &episode) { QString nl = "\n"; QString out; out.append("TvShowEpisode").append(nl); out.append(QString(" Files: ").append(nl)); foreach (const QString &file, episode.files()) out.append(QString(" %1").arg(file).append(nl)); out.append(QString(" Name: ").append(episode.name()).append(nl)); out.append(QString(" ShowTitle: ").append(episode.showTitle()).append(nl)); out.append(QString(" Season: %1").arg(episode.season()).append(nl)); out.append(QString(" Episode: %1").arg(episode.episode()).append(nl)); out.append(QString(" Rating: %1").arg(episode.rating()).append(nl)); out.append(QString(" FirstAired: ").append(episode.firstAired().toString("yyyy-MM-dd")).append(nl)); out.append(QString(" LastPlayed: ").append(episode.lastPlayed().toString("yyyy-MM-dd")).append(nl)); out.append(QString(" Playcount: %1%2").arg(episode.playCount()).arg(nl)); out.append(QString(" Certification: ").append(episode.certification()).append(nl)); out.append(QString(" Overview: ").append(episode.overview())).append(nl); foreach (const QString &writer, episode.writers()) out.append(QString(" Writer: ").append(writer)).append(nl); foreach (const QString &director, episode.directors()) out.append(QString(" Director: ").append(director)).append(nl); /* foreach (const QString &studio, movie.studios()) out.append(QString(" Studio: ").append(studio)).append(nl); foreach (const QString &country, movie.countries()) out.append(QString(" Country: ").append(country)).append(nl); foreach (const Actor &actor, movie.actors()) { out.append(QString(" Actor: ").append(nl)); out.append(QString(" Name: ").append(actor.name)).append(nl); out.append(QString(" Role: ").append(actor.role)).append(nl); out.append(QString(" Thumb: ").append(actor.thumb)).append(nl); } foreach (const Poster &poster, movie.posters()) { out.append(QString(" Poster: ")).append(nl); out.append(QString(" ID: ").append(poster.id)).append(nl); out.append(QString(" Original: ").append(poster.originalUrl.toString())).append(nl); out.append(QString(" Thumb: ").append(poster.thumbUrl.toString())).append(nl); } foreach (const Poster &backdrop, movie.backdrops()) { out.append(QString(" Backdrop: ")).append(nl); out.append(QString(" ID: ").append(backdrop.id)).append(nl); out.append(QString(" Original: ").append(backdrop.originalUrl.toString())).append(nl); out.append(QString(" Thumb: ").append(backdrop.thumbUrl.toString())).append(nl); } */ dbg.nospace() << out; return dbg.maybeSpace(); }