videodownloader/network/socksharedownload.cpp

139 lines
4.9 KiB
C++
Raw Normal View History

2015-09-08 17:05:59 +02:00
#include "./socksharedownload.h"
2015-04-22 19:32:04 +02:00
#include "../application/utils.h"
#include <QUrlQuery>
using namespace Application;
2019-06-10 22:50:15 +02:00
using namespace CppUtilities;
2015-04-22 19:32:04 +02:00
namespace Network {
/*!
* \class SockshareDownload
* \brief Download implementation for specific hoster.
* \remarks Not maintained anymore.
*/
/*!
* \brief Constructs a new SockshareDownload for the specified \a url.
*/
2017-05-01 03:22:50 +02:00
SockshareDownload::SockshareDownload(const QUrl &url, QObject *parent)
: HttpDownloadWithInfoRequst(url, parent)
, m_currentStep(0)
{
}
2015-04-22 19:32:04 +02:00
2015-10-14 23:08:57 +02:00
Download *SockshareDownload::infoRequestDownload(bool &success, QString &reasonForFail)
2015-04-22 19:32:04 +02:00
{
HttpDownload *download;
2017-05-01 03:22:50 +02:00
switch (m_currentStep) {
2015-04-22 19:32:04 +02:00
case 0:
download = new HttpDownload(initialUrl());
2015-10-14 23:08:57 +02:00
success = true;
2015-04-22 19:32:04 +02:00
return download;
case 1:
download = new HttpDownload(initialUrl());
download->setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
download->setMethod(HttpDownloadMethod::Post);
download->setPostData(m_postData);
2015-10-14 23:08:57 +02:00
success = true;
2015-04-22 19:32:04 +02:00
return download;
case 2:
download = new HttpDownload(m_playlistUrl);
2015-10-14 23:08:57 +02:00
success = true;
2015-04-22 19:32:04 +02:00
return download;
default:
reasonForFail = tr("Internal error.");
2015-10-14 23:08:57 +02:00
success = false;
2015-04-22 19:32:04 +02:00
return nullptr;
}
}
QString SockshareDownload::typeName() const
{
return tr("Sockshare/Putlocker");
}
void SockshareDownload::evalVideoInformation(Download *, QBuffer *videoInfoBuffer)
{
QString videoInfo(videoInfoBuffer->readAll());
int pos;
QString str;
2017-05-01 03:22:50 +02:00
switch (m_currentStep) {
2015-04-22 19:32:04 +02:00
case 0:
2017-05-01 03:22:50 +02:00
if (substring(videoInfo, str, 0, QStringLiteral("<h1>"), QStringLiteral("<")) > 0 && !str.isEmpty()) {
2015-04-22 19:32:04 +02:00
setTitle(str);
}
2017-05-01 03:22:50 +02:00
if (substring(videoInfo, str, 0, QStringLiteral("<input type=\"hidden\" value=\""), QStringLiteral("\"")) > 0) {
if (str.isEmpty()) {
2015-04-22 19:32:04 +02:00
reportInitiated(false, tr("Couldn't find the hash (empty \"value\"-attribute)."));
} else {
QUrlQuery query;
query.addQueryItem(QStringLiteral("hash"), str);
query.addQueryItem(QStringLiteral("confirm"), QStringLiteral("Continue as Free User"));
2020-09-04 00:57:42 +02:00
m_postData.append(query.toString(QUrl::FullyEncoded).toUtf8());
2015-04-22 19:32:04 +02:00
m_currentStep++;
doInit();
}
2017-05-01 03:22:50 +02:00
} else
2015-04-22 19:32:04 +02:00
reportInitiated(false, QStringLiteral("Couldn't find the hash."));
break;
case 1:
2017-05-01 03:22:50 +02:00
if (substring(videoInfo, str, 0, QStringLiteral("get_file.php?id="), QStringLiteral("\"")))
2015-04-22 19:32:04 +02:00
addDownloadUrl(tr("H.263/MP3/AVI"), QUrl(QStringLiteral("http://%1/get_file.php?id=%2").arg(initialUrl().host(), str)));
2017-05-01 03:22:50 +02:00
if (substring(videoInfo, str, 0, QStringLiteral("get_file.php?"), QStringLiteral("'")) != -1) {
2015-04-22 19:32:04 +02:00
m_playlistUrl = QUrl(QStringLiteral("http://%1/get_file.php?%2").arg(initialUrl().host(), str));
++m_currentStep;
doInit();
} else {
2017-05-01 03:22:50 +02:00
if (availableOptionCount() > 0) {
2015-04-22 19:32:04 +02:00
reportInitiated(true);
} else {
reportInitiated(false, tr("Couldn't find the \"get_file.php\"-url."));
}
}
break;
case 2:
pos = videoInfo.indexOf(QLatin1String("<media:content"));
2017-05-01 03:22:50 +02:00
if (pos > 0) {
if (substring(videoInfo, str, pos, QStringLiteral("url=\""), QStringLiteral("\"")) > 0) {
if (str.isEmpty()) {
if (availableOptionCount() < 1) {
2015-04-22 19:32:04 +02:00
reportInitiated(false, tr("The \"url\"-attribute in the \"media\"-tag is empty."));
} else {
reportInitiated(true);
}
} else {
str = str.replace(QLatin1String("&amp;"), QLatin1String("&"));
addDownloadUrl(tr("H.264/AAC/FLV"), QUrl(str));
setChosenOption(availableOptionCount() - 1);
2017-05-01 03:22:50 +02:00
if (substring(videoInfo, str, pos, QStringLiteral("duration=\""), QStringLiteral("\""))) {
2015-04-22 19:32:04 +02:00
bool ok;
int duration = str.toInt(&ok);
2017-05-01 03:22:50 +02:00
if (ok)
setDuration(TimeSpan(duration));
2015-04-22 19:32:04 +02:00
}
reportInitiated(true);
}
} else {
2017-05-01 03:22:50 +02:00
if (availableOptionCount() < 1) {
2015-04-22 19:32:04 +02:00
reportInitiated(false, tr("Couldn't find the \"url\"-attribute in the \"media\"-tag."));
} else {
reportInitiated(true);
}
}
} else {
2017-05-01 03:22:50 +02:00
if (availableOptionCount() < 1) {
2015-04-22 19:32:04 +02:00
reportInitiated(false, tr("Couldn't find the \"media\"-tag."));
} else {
reportInitiated(true);
}
}
break;
default:
reportInitiated(false, tr("Internal error."));
}
}
2019-07-20 20:20:58 +02:00
} // namespace Network