diff --git a/sdrbase/util/httpdownloadmanager.cpp b/sdrbase/util/httpdownloadmanager.cpp index 95d09e997..41fde655f 100644 --- a/sdrbase/util/httpdownloadmanager.cpp +++ b/sdrbase/util/httpdownloadmanager.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include HttpDownloadManager::HttpDownloadManager() { @@ -119,36 +119,36 @@ void HttpDownloadManager::downloadFinished(QNetworkReply *reply) if (!isHttpRedirect(reply)) { QByteArray data = reply->readAll(); - QRegExp regexp("href=\\\"\\/uc\\?export\\=download\\&\\;confirm=([a-zA-Z0-9_\\-]*)\\&\\;id=([a-zA-Z0-9_\\-\\=\\;\\&]*)\\\""); // Google drive can redirect downloads to a virus scan warning page - // We need to extract the confirm code and retry + // We need to use URL with confirm code and retry if (url.startsWith("https://drive.google.com/uc?export=download") && data.startsWith("") && !filename.endsWith(".html") - && (regexp.indexIn(data) >= 0) ) { - QString confirm = regexp.capturedTexts()[1]; - QString id = regexp.capturedTexts()[2]; - if (confirm.isEmpty()) + QRegularExpression regexp("action=\\\"(.*?)\\\""); + QRegularExpressionMatch match = regexp.match(data); + if (match.hasMatch()) { - qDebug() << "HttpDownloadManager::downloadFinished - Got HTML response but not confirmation code"; - qDebug() << QString(data); - qDebug() << regexp.capturedTexts(); + m_downloads.removeAll(reply); + m_filenames.remove(idx); + + QString action = match.captured(1); + action = action.replace("&", "&"); + qDebug() << "HttpDownloadManager: Skipping Go ogle drive warning - downloading " << action; + QUrl newUrl(action); + QNetworkReply *newReply = download(newUrl, filename); + + // Indicate that we are retrying, so progress dialogs can be updated + emit retryDownload(filename, reply, newReply); + + retry = true; + } + else + { + qDebug() << "HttpDownloadManager: Can't find action URL in Google Drive page " << data; } - - m_downloads.removeAll(reply); - m_filenames.remove(idx); - - qDebug() << "HttpDownloadManager: Skipping Google drive warning: " << confirm << " " << id; - QUrl newUrl(QString("https://drive.google.com/uc?export=download&confirm=%1&id=%2").arg(confirm).arg(id)); - QNetworkReply *newReply = download(newUrl, filename); - - // Indicate that we are retrying, so progress dialogs can be updated - emit retryDownload(filename, reply, newReply); - - retry = true; } else if (writeToFile(filename, data)) {