Remove redirect craziness from Magnatune downloading.
This commit is contained in:
parent
d93f2c64cb
commit
ac5511518f
@ -19,6 +19,7 @@
|
|||||||
#include "magnatuneservice.h"
|
#include "magnatuneservice.h"
|
||||||
#include "internetmodel.h"
|
#include "internetmodel.h"
|
||||||
#include "ui_magnatunedownloaddialog.h"
|
#include "ui_magnatunedownloaddialog.h"
|
||||||
|
#include "core/logging.h"
|
||||||
#include "core/network.h"
|
#include "core/network.h"
|
||||||
#include "widgets/progressitemdelegate.h"
|
#include "widgets/progressitemdelegate.h"
|
||||||
|
|
||||||
@ -182,43 +183,29 @@ void MagnatuneDownloadDialog::MetadataFinished() {
|
|||||||
url.setUserName(service_->username());
|
url.setUserName(service_->username());
|
||||||
url.setPassword(service_->password());
|
url.setPassword(service_->password());
|
||||||
|
|
||||||
|
qLog(Debug) << "Downloading" << url;
|
||||||
|
|
||||||
// Start the actual download
|
// Start the actual download
|
||||||
current_reply_ = network_->get(QNetworkRequest(url));
|
current_reply_ = network_->get(QNetworkRequest(url));
|
||||||
|
|
||||||
connect(current_reply_, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(Error(QNetworkReply::NetworkError)));
|
connect(current_reply_, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(Error(QNetworkReply::NetworkError)));
|
||||||
connect(current_reply_, SIGNAL(finished()), SLOT(DownloadFinished()));
|
connect(current_reply_, SIGNAL(finished()), SLOT(DownloadFinished()));
|
||||||
// No DownloadProgress connection because the first one is a redirect
|
connect(current_reply_, SIGNAL(downloadProgress(qint64,qint64)), SLOT(DownloadProgress(qint64,qint64)));
|
||||||
}
|
connect(current_reply_, SIGNAL(readyRead()), SLOT(DownloadReadyRead()));
|
||||||
|
|
||||||
void MagnatuneDownloadDialog::DownloadFinished() {
|
|
||||||
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
|
|
||||||
reply->deleteLater();
|
|
||||||
|
|
||||||
// Close any open file
|
// Close any open file
|
||||||
download_file_.reset();
|
download_file_.reset();
|
||||||
|
|
||||||
QUrl redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
|
|
||||||
if (redirect.isValid()) {
|
|
||||||
// Open the output file
|
// Open the output file
|
||||||
QString output_filename = GetOutputFilename();
|
QString output_filename = GetOutputFilename();
|
||||||
download_file_.reset(new QFile(output_filename));
|
download_file_.reset(new QFile(output_filename));
|
||||||
if (!download_file_->open(QIODevice::WriteOnly)) {
|
if (!download_file_->open(QIODevice::WriteOnly)) {
|
||||||
ShowError(tr("Couldn't open output file %1").arg(output_filename));
|
ShowError(tr("Couldn't open output file %1").arg(output_filename));
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Round and round we go
|
void MagnatuneDownloadDialog::DownloadFinished() {
|
||||||
redirect.setUserName(service_->username());
|
current_reply_->deleteLater();
|
||||||
redirect.setPassword(service_->password());
|
|
||||||
|
|
||||||
current_reply_ = network_->get(QNetworkRequest(redirect));
|
|
||||||
|
|
||||||
connect(current_reply_, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(Error(QNetworkReply::NetworkError)));
|
|
||||||
connect(current_reply_, SIGNAL(finished()), SLOT(DownloadFinished()));
|
|
||||||
connect(current_reply_, SIGNAL(downloadProgress(qint64,qint64)), SLOT(DownloadProgress(qint64,qint64)));
|
|
||||||
connect(current_reply_, SIGNAL(readyRead()), SLOT(DownloadReadyRead()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
next_row_ ++;
|
next_row_ ++;
|
||||||
DownloadNext();
|
DownloadNext();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user