mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-04 16:01:14 -05:00
Merge pull request #1164 from srcejon/fix_httpdownload_googledrive
HttpDownloadManager - Fix Google Drive downloads
This commit is contained in:
commit
21b2131148
@ -20,7 +20,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
HttpDownloadManager::HttpDownloadManager()
|
HttpDownloadManager::HttpDownloadManager()
|
||||||
{
|
{
|
||||||
@ -119,30 +119,25 @@ void HttpDownloadManager::downloadFinished(QNetworkReply *reply)
|
|||||||
if (!isHttpRedirect(reply))
|
if (!isHttpRedirect(reply))
|
||||||
{
|
{
|
||||||
QByteArray data = reply->readAll();
|
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
|
// 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")
|
if (url.startsWith("https://drive.google.com/uc?export=download")
|
||||||
&& data.startsWith("<!DOCTYPE html>")
|
&& data.startsWith("<!DOCTYPE html>")
|
||||||
&& !filename.endsWith(".html")
|
&& !filename.endsWith(".html")
|
||||||
&& (regexp.indexIn(data) >= 0)
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
QString confirm = regexp.capturedTexts()[1];
|
QRegularExpression regexp("action=\\\"(.*?)\\\"");
|
||||||
QString id = regexp.capturedTexts()[2];
|
QRegularExpressionMatch match = regexp.match(data);
|
||||||
if (confirm.isEmpty())
|
if (match.hasMatch())
|
||||||
{
|
{
|
||||||
qDebug() << "HttpDownloadManager::downloadFinished - Got HTML response but not confirmation code";
|
|
||||||
qDebug() << QString(data);
|
|
||||||
qDebug() << regexp.capturedTexts();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_downloads.removeAll(reply);
|
m_downloads.removeAll(reply);
|
||||||
m_filenames.remove(idx);
|
m_filenames.remove(idx);
|
||||||
|
|
||||||
qDebug() << "HttpDownloadManager: Skipping Google drive warning: " << confirm << " " << id;
|
QString action = match.captured(1);
|
||||||
QUrl newUrl(QString("https://drive.google.com/uc?export=download&confirm=%1&id=%2").arg(confirm).arg(id));
|
action = action.replace("&", "&");
|
||||||
|
qDebug() << "HttpDownloadManager: Skipping Go ogle drive warning - downloading " << action;
|
||||||
|
QUrl newUrl(action);
|
||||||
QNetworkReply *newReply = download(newUrl, filename);
|
QNetworkReply *newReply = download(newUrl, filename);
|
||||||
|
|
||||||
// Indicate that we are retrying, so progress dialogs can be updated
|
// Indicate that we are retrying, so progress dialogs can be updated
|
||||||
@ -150,6 +145,11 @@ void HttpDownloadManager::downloadFinished(QNetworkReply *reply)
|
|||||||
|
|
||||||
retry = true;
|
retry = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug() << "HttpDownloadManager: Can't find action URL in Google Drive page " << data;
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (writeToFile(filename, data))
|
else if (writeToFile(filename, data))
|
||||||
{
|
{
|
||||||
success = true;
|
success = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user