diff --git a/dataengines/potd/noaaprovider.h b/dataengines/potd/noaaprovider.h --- a/dataengines/potd/noaaprovider.h +++ b/dataengines/potd/noaaprovider.h @@ -30,8 +30,8 @@ /** * This class provides the image for NOAA Environmental Visualization Laboratory - * Picture Of the Day - * located at http://www.nnvl.noaa.gov/imageoftheday.php. + * Image Of the Day + * located at https://www.nesdis.noaa.gov/content/imagery-and-data. */ class NOAAProvider : public PotdProvider { @@ -60,7 +60,8 @@ QImage image() const override; private: - void pageRequestFinished(KJob *job); + void firstPageRequestFinished(KJob *job); + void secondPageRequestFinished(KJob *job); void imageRequestFinished(KJob *job); private: diff --git a/dataengines/potd/noaaprovider.cpp b/dataengines/potd/noaaprovider.cpp --- a/dataengines/potd/noaaprovider.cpp +++ b/dataengines/potd/noaaprovider.cpp @@ -26,14 +26,13 @@ #include #include - NOAAProvider::NOAAProvider(QObject *parent, const QVariantList &args) : PotdProvider(parent, args) { - const QUrl url(QStringLiteral("http://www.nnvl.noaa.gov/imageoftheday.php")); + const QUrl url(QStringLiteral("https://www.nesdis.noaa.gov/content/imagery-and-data")); KIO::StoredTransferJob *job = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo); - connect(job, &KIO::StoredTransferJob::finished, this, &NOAAProvider::pageRequestFinished); + connect(job, &KIO::StoredTransferJob::finished, this, &NOAAProvider::firstPageRequestFinished); } NOAAProvider::~NOAAProvider() = default; @@ -43,7 +42,40 @@ return mImage; } -void NOAAProvider::pageRequestFinished(KJob* _job) +void NOAAProvider::firstPageRequestFinished(KJob* _job) +{ + KIO::StoredTransferJob *job = static_cast( _job ); + if (job->error()) { + emit error(this); + return; + } + + const QString data = QString::fromUtf8( job->data() ); + + // Using regular expression could be fragile in such case, but the HTML + // NOAA page itself is not a valid XML file and unfortunately it could + // not be parsed successfully till the content we want. And we do not want + // to use heavy weight QtWebkit. So we use QRegularExpression to capture + // the wanted url here. + QString url; + QRegularExpression re(QStringLiteral("href=\"[ -~]*\">\"Latest( _job ); if (job->error()) { @@ -59,10 +91,11 @@ // to use heavy weight QtWebkit. So we use QRegularExpression to capture // the wanted url here. QString url; - QRegularExpression re(QStringLiteral("_curPic = (.*?)")); + QRegularExpression re(QStringLiteral("a href='[ -~]*'>