fixed spelling mistake

This commit is contained in:
Martchus 2015-10-14 23:08:57 +02:00
parent 7b671da37a
commit fd6afe426d
16 changed files with 146 additions and 44 deletions

View File

@ -20,9 +20,9 @@ BitshareDownload::BitshareDownload(const QUrl &url, QObject *parent) :
HttpDownloadWithInfoRequst(url, parent) HttpDownloadWithInfoRequst(url, parent)
{} {}
Download *BitshareDownload::infoRequestDownload(bool &sucess, QString &) Download *BitshareDownload::infoRequestDownload(bool &success, QString &)
{ {
sucess = true; success = true;
HttpDownload *download = new HttpDownload(initialUrl()); HttpDownload *download = new HttpDownload(initialUrl());
download->setCookieJar(usedCookieJar()); download->setCookieJar(usedCookieJar());
return download; return download;

View File

@ -12,7 +12,7 @@ class BitshareDownload : public HttpDownloadWithInfoRequst
public: public:
explicit BitshareDownload(const QUrl &url, QObject *parent = nullptr); explicit BitshareDownload(const QUrl &url, QObject *parent = nullptr);
virtual Download *infoRequestDownload(bool &sucess, QString &reasonForFail); virtual Download *infoRequestDownload(bool &success, QString &reasonForFail);
virtual QString typeName() const; virtual QString typeName() const;
protected: protected:

View File

@ -77,28 +77,28 @@ void FileNukeDownload::evalVideoInformation(Download *, QBuffer *videoInfoBuffer
} }
} }
Download *FileNukeDownload::infoRequestDownload(bool &sucess, QString &reasonForFail) Download *FileNukeDownload::infoRequestDownload(bool &success, QString &reasonForFail)
{ {
HttpDownload *download; HttpDownload *download;
switch(m_currentStep) { switch(m_currentStep) {
case 0: case 0:
download = new HttpDownload(initialUrl()); download = new HttpDownload(initialUrl());
sucess = true; success = true;
return download; return download;
case 1: case 1:
download = new HttpDownload(initialUrl()); download = new HttpDownload(initialUrl());
download->setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); download->setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
download->setMethod(HttpDownloadMethod::Post); download->setMethod(HttpDownloadMethod::Post);
download->setPostData(m_postData); download->setPostData(m_postData);
sucess = true; success = true;
return download; return download;
case 2: case 2:
download = new HttpDownload(m_playlistUrl); download = new HttpDownload(m_playlistUrl);
sucess = true; success = true;
return download; return download;
default: default:
reasonForFail = tr("Internal error."); reasonForFail = tr("Internal error.");
sucess = false; success = false;
return nullptr; return nullptr;
} }
} }

View File

@ -12,7 +12,7 @@ class FileNukeDownload : public HttpDownloadWithInfoRequst
public: public:
explicit FileNukeDownload(const QUrl &url, QObject *parent = nullptr); explicit FileNukeDownload(const QUrl &url, QObject *parent = nullptr);
Download *infoRequestDownload(bool &sucess, QString &reasonForFail); Download *infoRequestDownload(bool &success, QString &reasonForFail);
QString typeName() const; QString typeName() const;
protected: protected:

View File

@ -67,7 +67,7 @@ private slots:
private: private:
void emitNewResultsSignal(); void emitNewResultsSignal();
void emitFinishedSignal(bool sucess, const QString &reason = QString()); void emitFinishedSignal(bool success, const QString &reason = QString());
std::unique_ptr<Download> m_download; std::unique_ptr<Download> m_download;
std::unique_ptr<QBuffer> m_buffer; std::unique_ptr<QBuffer> m_buffer;
@ -177,10 +177,10 @@ inline void DownloadFinder::reportCollectionTitle(const QString &title)
/*! /*!
* \brief Emits the finished signal. * \brief Emits the finished signal.
*/ */
inline void DownloadFinder::emitFinishedSignal(bool sucess, const QString &reason) inline void DownloadFinder::emitFinishedSignal(bool success, const QString &reason)
{ {
m_finished = true; m_finished = true;
emit finished(sucess, reason); emit finished(success, reason);
} }
} }

View File

@ -89,14 +89,14 @@ GroovesharkDownload::GroovesharkDownload(GroovesharkRequestType requestType, con
} }
} }
Download *GroovesharkDownload::infoRequestDownload(bool &sucess, QString &reasonForFail) Download *GroovesharkDownload::infoRequestDownload(bool &success, QString &reasonForFail)
{ {
Download *download = nullptr; Download *download = nullptr;
QJsonObject headerObj; QJsonObject headerObj;
QJsonObject paramObj; QJsonObject paramObj;
switch(m_currentStep) { switch(m_currentStep) {
case -1: case -1:
sucess = true; success = true;
break; break;
case 0: case 0:
if(m_sessionId.isNull()) { if(m_sessionId.isNull()) {
@ -108,7 +108,7 @@ Download *GroovesharkDownload::infoRequestDownload(bool &sucess, QString &reason
headerObj.insert(QStringLiteral("country"), m_country); headerObj.insert(QStringLiteral("country"), m_country);
download = createJsonPostRequest(QStringLiteral("initiateSession"), headerObj, paramObj); download = createJsonPostRequest(QStringLiteral("initiateSession"), headerObj, paramObj);
} }
sucess = true; success = true;
break; break;
case 1: case 1:
if(m_token.isEmpty()) { if(m_token.isEmpty()) {
@ -122,7 +122,7 @@ Download *GroovesharkDownload::infoRequestDownload(bool &sucess, QString &reason
paramObj.insert(QStringLiteral("secretKey"), generateSecretKey()); paramObj.insert(QStringLiteral("secretKey"), generateSecretKey());
download = createJsonPostRequest(QStringLiteral("getCommunicationToken"), headerObj, paramObj, true); download = createJsonPostRequest(QStringLiteral("getCommunicationToken"), headerObj, paramObj, true);
} }
sucess = true; success = true;
break; break;
case 2: case 2:
// getStreamKeyFromSongIDEx // getStreamKeyFromSongIDEx
@ -138,11 +138,11 @@ Download *GroovesharkDownload::infoRequestDownload(bool &sucess, QString &reason
paramObj.insert(QStringLiteral("songID"), QJsonValue(id())); paramObj.insert(QStringLiteral("songID"), QJsonValue(id()));
paramObj.insert(QStringLiteral("prefetch"), QJsonValue(false)); paramObj.insert(QStringLiteral("prefetch"), QJsonValue(false));
download = createJsonPostRequest("getStreamKeyFromSongIDEx", headerObj, paramObj); download = createJsonPostRequest("getStreamKeyFromSongIDEx", headerObj, paramObj);
sucess = true; success = true;
break; break;
default: default:
reasonForFail = QStringLiteral("Internal error."); reasonForFail = QStringLiteral("Internal error.");
sucess = false; success = false;
} }
return download; return download;
} }
@ -476,7 +476,7 @@ GroovesharkRequestType GroovesharkDownload::requestType() const
QString GroovesharkDownload::suitableFilename() const QString GroovesharkDownload::suitableFilename() const
{ {
QString filename = Download::suitableFilename(); auto filename = Download::suitableFilename();
if(!filename.endsWith(QLatin1String(".mp3"))) { if(!filename.endsWith(QLatin1String(".mp3"))) {
filename.append(QStringLiteral(".mp3")); filename.append(QStringLiteral(".mp3"));
} }

View File

@ -36,7 +36,7 @@ public:
explicit GroovesharkDownload(const QString &songId, QObject *parent = nullptr); explicit GroovesharkDownload(const QString &songId, QObject *parent = nullptr);
explicit GroovesharkDownload(GroovesharkRequestType requestType, const QVariant &requestData, QObject *parent = nullptr); explicit GroovesharkDownload(GroovesharkRequestType requestType, const QVariant &requestData, QObject *parent = nullptr);
Download *infoRequestDownload(bool &sucess, QString &reasonForFail); Download *infoRequestDownload(bool &success, QString &reasonForFail);
bool isInitiatingInstantlyRecommendable() const; bool isInitiatingInstantlyRecommendable() const;
static QJsonValue sessionId(); static QJsonValue sessionId();

View File

@ -19,7 +19,7 @@ public:
explicit HttpDownloadWithInfoRequst(const QUrl &url, QObject *parent = nullptr); explicit HttpDownloadWithInfoRequst(const QUrl &url, QObject *parent = nullptr);
~HttpDownloadWithInfoRequst(); ~HttpDownloadWithInfoRequst();
virtual Download *infoRequestDownload(bool &sucess, QString &reasonForFail) = 0; virtual Download *infoRequestDownload(bool &success, QString &reasonForFail) = 0;
void doInit(); void doInit();
void abortDownload(); void abortDownload();

View File

@ -23,29 +23,29 @@ SockshareDownload::SockshareDownload(const QUrl &url, QObject *parent) :
m_currentStep(0) m_currentStep(0)
{} {}
Download *SockshareDownload::infoRequestDownload(bool &sucess, QString &reasonForFail) Download *SockshareDownload::infoRequestDownload(bool &success, QString &reasonForFail)
{ {
HttpDownload *download; HttpDownload *download;
switch(m_currentStep) switch(m_currentStep)
{ {
case 0: case 0:
download = new HttpDownload(initialUrl()); download = new HttpDownload(initialUrl());
sucess = true; success = true;
return download; return download;
case 1: case 1:
download = new HttpDownload(initialUrl()); download = new HttpDownload(initialUrl());
download->setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); download->setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
download->setMethod(HttpDownloadMethod::Post); download->setMethod(HttpDownloadMethod::Post);
download->setPostData(m_postData); download->setPostData(m_postData);
sucess = true; success = true;
return download; return download;
case 2: case 2:
download = new HttpDownload(m_playlistUrl); download = new HttpDownload(m_playlistUrl);
sucess = true; success = true;
return download; return download;
default: default:
reasonForFail = tr("Internal error."); reasonForFail = tr("Internal error.");
sucess = false; success = false;
return nullptr; return nullptr;
} }
} }

View File

@ -12,7 +12,7 @@ class SockshareDownload : public HttpDownloadWithInfoRequst
public: public:
explicit SockshareDownload(const QUrl &url, QObject *parent = nullptr); explicit SockshareDownload(const QUrl &url, QObject *parent = nullptr);
Download *infoRequestDownload(bool &sucess, QString &reasonForFail); Download *infoRequestDownload(bool &success, QString &reasonForFail);
QString typeName() const; QString typeName() const;
protected: protected:

View File

@ -54,26 +54,26 @@ void SpotifyDownload::resetSession()
m_creationFlow.clear(); m_creationFlow.clear();
} }
Download *SpotifyDownload::infoRequestDownload(bool &sucess, QString &reasonForFail) Download *SpotifyDownload::infoRequestDownload(bool &success, QString &reasonForFail)
{ {
HttpDownload *download = nullptr; HttpDownload *download = nullptr;
if(m_csrftoken.isEmpty() || m_trackingId.isEmpty()/* || creationFlow.isEmpty()*/) { if(m_csrftoken.isEmpty() || m_trackingId.isEmpty()/* || creationFlow.isEmpty()*/) {
if(m_triesToGetAuthenticationData < 2) { if(m_triesToGetAuthenticationData < 2) {
download = new HttpDownload(m_spotifyUrl); download = new HttpDownload(m_spotifyUrl);
download->setCustomUserAgent(m_supportedUseragents.at(0)); download->setCustomUserAgent(m_supportedUseragents.at(0));
sucess = true; success = true;
++m_triesToGetAuthenticationData; ++m_triesToGetAuthenticationData;
m_currentRequest = SpotifyRequestType::GetAuthenticationData; m_currentRequest = SpotifyRequestType::GetAuthenticationData;
} else { } else {
reasonForFail = tr("Unable to find data required for autentication."); reasonForFail = tr("Unable to find data required for autentication.");
sucess = false; success = false;
} }
} else if(!m_authenticationCredentialsValidated) { } else if(!m_authenticationCredentialsValidated) {
if(initialAuthenticationCredentials().isIncomplete()) { if(initialAuthenticationCredentials().isIncomplete()) {
reportAuthenticationRequired(-1, tr("To download songs from Spotify authentication is required so you have to enter the credentials of your Spotify account.")); reportAuthenticationRequired(-1, tr("To download songs from Spotify authentication is required so you have to enter the credentials of your Spotify account."));
reasonForFail = tr("Authentication credentials not given."); reasonForFail = tr("Authentication credentials not given.");
//networkError = QNetworkReply::AuthenticationRequiredError; //networkError = QNetworkReply::AuthenticationRequiredError;
sucess = false; success = false;
} else { } else {
QUrl url(m_spotifyUrl); QUrl url(m_spotifyUrl);
url.setPath(QStringLiteral("/xhr/json/auth.php")); url.setPath(QStringLiteral("/xhr/json/auth.php"));
@ -92,7 +92,7 @@ Download *SpotifyDownload::infoRequestDownload(bool &sucess, QString &reasonForF
download->setPostData(postData); download->setPostData(postData);
download->setCustomUserAgent(m_supportedUseragents.at(0)); download->setCustomUserAgent(m_supportedUseragents.at(0));
sucess = true; success = true;
m_currentRequest = SpotifyRequestType::Authenticate; m_currentRequest = SpotifyRequestType::Authenticate;
} }
} }

View File

@ -19,7 +19,7 @@ class SpotifyDownload : public HttpDownloadWithInfoRequst
public: public:
explicit SpotifyDownload(const QString &songid, QObject *parent = nullptr); explicit SpotifyDownload(const QString &songid, QObject *parent = nullptr);
Download *infoRequestDownload(bool &sucess, QString &reasonForFail); Download *infoRequestDownload(bool &success, QString &reasonForFail);
QString typeName() const; QString typeName() const;
static void resetSession(); static void resetSession();

View File

@ -1,10 +1,104 @@
#include "vimeodownload.h" #include "./vimeodownload.h"
#include <c++utilities/chrono/timespan.h>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
using namespace ChronoUtilities;
namespace Network { namespace Network {
VimeoDownload::VimeoDownload() /*!
{ * \class VimeoDownload
* \brief Download implementation for Vimeo videos.
*/
/*!
* \brief Constructs a new VimeoDownload for the specified \a url.
*/
VimeoDownload::VimeoDownload(const QUrl &url, QObject *parent) :
HttpDownloadWithInfoRequst(url, parent)
{}
/*!
* \brief Constructs a new VimeoDownload for the specified video \a id.
*/
VimeoDownload::VimeoDownload(const QString &id, QObject *parent) :
HttpDownloadWithInfoRequst(QUrl(QStringLiteral("https://vimeo.com/%1").arg(id)), parent)
{}
Download *VimeoDownload::infoRequestDownload(bool &success, QString &reasonForFail)
{
const auto pathParts = initialUrl().path(QUrl::FullyDecoded).splitRef(QChar('/'), QString::SkipEmptyParts);
if(pathParts.size() < 2) {
const auto &id = pathParts.back();
bool isInt;
id.toULongLong(&isInt);
if(isInt) {
setId(id.toString());
success = true;
return new HttpDownload(QUrl(QStringLiteral("https://player.vimeo.com/video/%1/config").arg(id.toString())));
}
}
success = false;
reasonForFail = tr("The video ID couldn't be identified.");
return nullptr;
}
QString VimeoDownload::suitableFilename() const
{
auto filename = Download::suitableFilename();
if(!filename.endsWith(QLatin1String(".mp4"))) {
filename.append(QStringLiteral(".mp4"));
}
return filename;
}
QString VimeoDownload::typeName() const
{
return tr("Vimeo");
}
void VimeoDownload::evalVideoInformation(Download *, QBuffer *videoInfoBuffer)
{
QJsonParseError error;
const QJsonDocument doc = QJsonDocument::fromJson(videoInfoBuffer->readAll(), &error);
if(error.error == QJsonParseError::NoError) {
const auto h264Object = doc.object().value(QStringLiteral("request"))
.toObject().value(QStringLiteral("files"))
.toObject().value(QStringLiteral("h264")).toObject();
const auto videoObject = doc.object().value(QStringLiteral("video")).toObject();
const auto title = videoObject.value(QStringLiteral("title")).toString();
if(!title.isEmpty()) {
setTitle(title);
}
const auto uploader = videoObject.value(QStringLiteral("owner")).toObject().value(QStringLiteral("name")).toString();
if(!uploader.isEmpty()) {
setUploader(uploader);
}
if(const auto duration = videoObject.value(QStringLiteral("duration")).toInt()) {
setDuration(TimeSpan::fromSeconds(duration));
}
for(const auto &value : h264Object) {
const auto optionObject = value.toObject();
const auto url = optionObject.value(QStringLiteral("url")).toString();
if(!url.isEmpty()) {
const auto width = optionObject.value(QStringLiteral("width")).toInt();
const auto height = optionObject.value(QStringLiteral("height")).toInt();
const auto bitrate = optionObject.value(QStringLiteral("bitrate")).toInt();
addDownloadUrl(QStringLiteral("%1 x %2, %3 kbit/s").arg(width).arg(height).arg(bitrate), url);
}
}
if(availableOptionCount() > 0) {
reportInitiated(true);
} else {
reportInitiated(false, tr("No video URLs found. The video config could be parsed, but it seems like Vimeo changed something in their API."));
}
} else {
reportInitiated(false, tr("Couldn't parse video configuration (invalid JSON)."));
}
} }
} // namespace Network } // namespace Network

View File

@ -1,17 +1,25 @@
#ifndef NETWORK_VIMEODOWNLOAD_H #ifndef NETWORK_VIMEODOWNLOAD_H
#define NETWORK_VIMEODOWNLOAD_H #define NETWORK_VIMEODOWNLOAD_H
#include "./httpdownloadwithinforequst.h"
namespace Network { namespace Network {
class VimeoDownload class VimeoDownload : public HttpDownloadWithInfoRequst
{ {
Q_OBJECT
public: public:
VimeoDownload(); explicit VimeoDownload(const QUrl &url, QObject *parent = nullptr);
explicit VimeoDownload(const QString &id, QObject *parent = nullptr);
signals: Download *infoRequestDownload(bool &success, QString &reasonForFail);
QString suitableFilename() const;
QString typeName() const;
protected:
void evalVideoInformation(Download *, QBuffer *videoInfoBuffer);
public slots:
}; };
} // namespace Network } // namespace Network

View File

@ -33,7 +33,7 @@ YoutubeDownload::YoutubeDownload(const QString &id, QObject *parent) :
HttpDownloadWithInfoRequst(QUrl(QStringLiteral("http://www.youtube.com/watch?v=%1").arg(id)), parent) HttpDownloadWithInfoRequst(QUrl(QStringLiteral("http://www.youtube.com/watch?v=%1").arg(id)), parent)
{} {}
Download *YoutubeDownload::infoRequestDownload(bool &sucess, QString &reasonForFail) Download *YoutubeDownload::infoRequestDownload(bool &success, QString &reasonForFail)
{ {
const QUrl &url = initialUrl(); const QUrl &url = initialUrl();
QString videoId; QString videoId;
@ -44,12 +44,12 @@ Download *YoutubeDownload::infoRequestDownload(bool &sucess, QString &reasonForF
videoId.remove(0, 1); videoId.remove(0, 1);
} }
if(videoId.isEmpty()) { if(videoId.isEmpty()) {
sucess = false; success = false;
reasonForFail = tr("The video ID couldn't be identified."); reasonForFail = tr("The video ID couldn't be identified.");
return nullptr; return nullptr;
} else { } else {
setId(videoId); setId(videoId);
sucess = true; success = true;
return new HttpDownload(QUrl(QStringLiteral("http://www.youtube.com/get_video_info?video_id=%1&asv=3&el=detailpage&hl=en_US").arg(videoId))); return new HttpDownload(QUrl(QStringLiteral("http://www.youtube.com/get_video_info?video_id=%1&asv=3&el=detailpage&hl=en_US").arg(videoId)));
} }
} }

View File

@ -17,7 +17,7 @@ public:
explicit YoutubeDownload(const QUrl &url, QObject *parent = nullptr); explicit YoutubeDownload(const QUrl &url, QObject *parent = nullptr);
explicit YoutubeDownload(const QString &id, QObject *parent = nullptr); explicit YoutubeDownload(const QString &id, QObject *parent = nullptr);
Download *infoRequestDownload(bool &sucess, QString &reasonForFail); Download *infoRequestDownload(bool &success, QString &reasonForFail);
QString videoInfo(QString field, const QString &defaultValue); QString videoInfo(QString field, const QString &defaultValue);
QString suitableFilename() const; QString suitableFilename() const;
QString typeName() const; QString typeName() const;