From fd6afe426d3edc6de45048bead72bf7e86739888 Mon Sep 17 00:00:00 2001 From: Martchus Date: Wed, 14 Oct 2015 23:08:57 +0200 Subject: [PATCH] fixed spelling mistake --- network/bitsharedownload.cpp | 4 +- network/bitsharedownload.h | 2 +- network/filenukedownload.cpp | 10 +-- network/filenukedownload.h | 2 +- network/finder/downloadfinder.h | 6 +- network/groovesharkdownload.cpp | 14 ++-- network/groovesharkdownload.h | 2 +- network/httpdownloadwithinforequst.h | 2 +- network/socksharedownload.cpp | 10 +-- network/socksharedownload.h | 2 +- network/spotifydownload.cpp | 10 +-- network/spotifydownload.h | 2 +- network/vimeodownload.cpp | 100 ++++++++++++++++++++++++++- network/vimeodownload.h | 16 +++-- network/youtubedownload.cpp | 6 +- network/youtubedownload.h | 2 +- 16 files changed, 146 insertions(+), 44 deletions(-) diff --git a/network/bitsharedownload.cpp b/network/bitsharedownload.cpp index 37a5e6c..5cfced1 100644 --- a/network/bitsharedownload.cpp +++ b/network/bitsharedownload.cpp @@ -20,9 +20,9 @@ BitshareDownload::BitshareDownload(const QUrl &url, QObject *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()); download->setCookieJar(usedCookieJar()); return download; diff --git a/network/bitsharedownload.h b/network/bitsharedownload.h index d313d07..1ce4bae 100644 --- a/network/bitsharedownload.h +++ b/network/bitsharedownload.h @@ -12,7 +12,7 @@ class BitshareDownload : public HttpDownloadWithInfoRequst public: 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; protected: diff --git a/network/filenukedownload.cpp b/network/filenukedownload.cpp index de78551..4124af4 100644 --- a/network/filenukedownload.cpp +++ b/network/filenukedownload.cpp @@ -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; switch(m_currentStep) { case 0: download = new HttpDownload(initialUrl()); - sucess = true; + success = true; 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); - sucess = true; + success = true; return download; case 2: download = new HttpDownload(m_playlistUrl); - sucess = true; + success = true; return download; default: reasonForFail = tr("Internal error."); - sucess = false; + success = false; return nullptr; } } diff --git a/network/filenukedownload.h b/network/filenukedownload.h index 798a56e..18d94f9 100644 --- a/network/filenukedownload.h +++ b/network/filenukedownload.h @@ -12,7 +12,7 @@ class FileNukeDownload : public HttpDownloadWithInfoRequst public: explicit FileNukeDownload(const QUrl &url, QObject *parent = nullptr); - Download *infoRequestDownload(bool &sucess, QString &reasonForFail); + Download *infoRequestDownload(bool &success, QString &reasonForFail); QString typeName() const; protected: diff --git a/network/finder/downloadfinder.h b/network/finder/downloadfinder.h index e9c9f0f..5bbbe21 100644 --- a/network/finder/downloadfinder.h +++ b/network/finder/downloadfinder.h @@ -67,7 +67,7 @@ private slots: private: void emitNewResultsSignal(); - void emitFinishedSignal(bool sucess, const QString &reason = QString()); + void emitFinishedSignal(bool success, const QString &reason = QString()); std::unique_ptr m_download; std::unique_ptr m_buffer; @@ -177,10 +177,10 @@ inline void DownloadFinder::reportCollectionTitle(const QString &title) /*! * \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; - emit finished(sucess, reason); + emit finished(success, reason); } } diff --git a/network/groovesharkdownload.cpp b/network/groovesharkdownload.cpp index 23b4a44..63e3764 100644 --- a/network/groovesharkdownload.cpp +++ b/network/groovesharkdownload.cpp @@ -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; QJsonObject headerObj; QJsonObject paramObj; switch(m_currentStep) { case -1: - sucess = true; + success = true; break; case 0: if(m_sessionId.isNull()) { @@ -108,7 +108,7 @@ Download *GroovesharkDownload::infoRequestDownload(bool &sucess, QString &reason headerObj.insert(QStringLiteral("country"), m_country); download = createJsonPostRequest(QStringLiteral("initiateSession"), headerObj, paramObj); } - sucess = true; + success = true; break; case 1: if(m_token.isEmpty()) { @@ -122,7 +122,7 @@ Download *GroovesharkDownload::infoRequestDownload(bool &sucess, QString &reason paramObj.insert(QStringLiteral("secretKey"), generateSecretKey()); download = createJsonPostRequest(QStringLiteral("getCommunicationToken"), headerObj, paramObj, true); } - sucess = true; + success = true; break; case 2: // getStreamKeyFromSongIDEx @@ -138,11 +138,11 @@ Download *GroovesharkDownload::infoRequestDownload(bool &sucess, QString &reason paramObj.insert(QStringLiteral("songID"), QJsonValue(id())); paramObj.insert(QStringLiteral("prefetch"), QJsonValue(false)); download = createJsonPostRequest("getStreamKeyFromSongIDEx", headerObj, paramObj); - sucess = true; + success = true; break; default: reasonForFail = QStringLiteral("Internal error."); - sucess = false; + success = false; } return download; } @@ -476,7 +476,7 @@ GroovesharkRequestType GroovesharkDownload::requestType() const QString GroovesharkDownload::suitableFilename() const { - QString filename = Download::suitableFilename(); + auto filename = Download::suitableFilename(); if(!filename.endsWith(QLatin1String(".mp3"))) { filename.append(QStringLiteral(".mp3")); } diff --git a/network/groovesharkdownload.h b/network/groovesharkdownload.h index 09330f4..614c20a 100644 --- a/network/groovesharkdownload.h +++ b/network/groovesharkdownload.h @@ -36,7 +36,7 @@ public: explicit GroovesharkDownload(const QString &songId, 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; static QJsonValue sessionId(); diff --git a/network/httpdownloadwithinforequst.h b/network/httpdownloadwithinforequst.h index 73caedc..00d4bfc 100644 --- a/network/httpdownloadwithinforequst.h +++ b/network/httpdownloadwithinforequst.h @@ -19,7 +19,7 @@ public: explicit HttpDownloadWithInfoRequst(const QUrl &url, QObject *parent = nullptr); ~HttpDownloadWithInfoRequst(); - virtual Download *infoRequestDownload(bool &sucess, QString &reasonForFail) = 0; + virtual Download *infoRequestDownload(bool &success, QString &reasonForFail) = 0; void doInit(); void abortDownload(); diff --git a/network/socksharedownload.cpp b/network/socksharedownload.cpp index 8b0a5c7..0d6acff 100644 --- a/network/socksharedownload.cpp +++ b/network/socksharedownload.cpp @@ -23,29 +23,29 @@ SockshareDownload::SockshareDownload(const QUrl &url, QObject *parent) : m_currentStep(0) {} -Download *SockshareDownload::infoRequestDownload(bool &sucess, QString &reasonForFail) +Download *SockshareDownload::infoRequestDownload(bool &success, QString &reasonForFail) { HttpDownload *download; switch(m_currentStep) { case 0: download = new HttpDownload(initialUrl()); - sucess = true; + success = true; 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); - sucess = true; + success = true; return download; case 2: download = new HttpDownload(m_playlistUrl); - sucess = true; + success = true; return download; default: reasonForFail = tr("Internal error."); - sucess = false; + success = false; return nullptr; } } diff --git a/network/socksharedownload.h b/network/socksharedownload.h index db02906..17de929 100644 --- a/network/socksharedownload.h +++ b/network/socksharedownload.h @@ -12,7 +12,7 @@ class SockshareDownload : public HttpDownloadWithInfoRequst public: explicit SockshareDownload(const QUrl &url, QObject *parent = nullptr); - Download *infoRequestDownload(bool &sucess, QString &reasonForFail); + Download *infoRequestDownload(bool &success, QString &reasonForFail); QString typeName() const; protected: diff --git a/network/spotifydownload.cpp b/network/spotifydownload.cpp index 45a72f2..761aff6 100644 --- a/network/spotifydownload.cpp +++ b/network/spotifydownload.cpp @@ -54,26 +54,26 @@ void SpotifyDownload::resetSession() m_creationFlow.clear(); } -Download *SpotifyDownload::infoRequestDownload(bool &sucess, QString &reasonForFail) +Download *SpotifyDownload::infoRequestDownload(bool &success, QString &reasonForFail) { HttpDownload *download = nullptr; if(m_csrftoken.isEmpty() || m_trackingId.isEmpty()/* || creationFlow.isEmpty()*/) { if(m_triesToGetAuthenticationData < 2) { download = new HttpDownload(m_spotifyUrl); download->setCustomUserAgent(m_supportedUseragents.at(0)); - sucess = true; + success = true; ++m_triesToGetAuthenticationData; m_currentRequest = SpotifyRequestType::GetAuthenticationData; } else { reasonForFail = tr("Unable to find data required for autentication."); - sucess = false; + success = false; } } else if(!m_authenticationCredentialsValidated) { 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.")); reasonForFail = tr("Authentication credentials not given."); //networkError = QNetworkReply::AuthenticationRequiredError; - sucess = false; + success = false; } else { QUrl url(m_spotifyUrl); url.setPath(QStringLiteral("/xhr/json/auth.php")); @@ -92,7 +92,7 @@ Download *SpotifyDownload::infoRequestDownload(bool &sucess, QString &reasonForF download->setPostData(postData); download->setCustomUserAgent(m_supportedUseragents.at(0)); - sucess = true; + success = true; m_currentRequest = SpotifyRequestType::Authenticate; } } diff --git a/network/spotifydownload.h b/network/spotifydownload.h index c2241ac..fb227ae 100644 --- a/network/spotifydownload.h +++ b/network/spotifydownload.h @@ -19,7 +19,7 @@ class SpotifyDownload : public HttpDownloadWithInfoRequst public: explicit SpotifyDownload(const QString &songid, QObject *parent = nullptr); - Download *infoRequestDownload(bool &sucess, QString &reasonForFail); + Download *infoRequestDownload(bool &success, QString &reasonForFail); QString typeName() const; static void resetSession(); diff --git a/network/vimeodownload.cpp b/network/vimeodownload.cpp index de7a944..5056811 100644 --- a/network/vimeodownload.cpp +++ b/network/vimeodownload.cpp @@ -1,10 +1,104 @@ -#include "vimeodownload.h" +#include "./vimeodownload.h" + +#include + +#include +#include +#include + +using namespace ChronoUtilities; 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 diff --git a/network/vimeodownload.h b/network/vimeodownload.h index 7a89ec5..9d324b1 100644 --- a/network/vimeodownload.h +++ b/network/vimeodownload.h @@ -1,17 +1,25 @@ #ifndef NETWORK_VIMEODOWNLOAD_H #define NETWORK_VIMEODOWNLOAD_H +#include "./httpdownloadwithinforequst.h" namespace Network { -class VimeoDownload +class VimeoDownload : public HttpDownloadWithInfoRequst { + Q_OBJECT + 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 diff --git a/network/youtubedownload.cpp b/network/youtubedownload.cpp index 23f25a7..905fadc 100644 --- a/network/youtubedownload.cpp +++ b/network/youtubedownload.cpp @@ -33,7 +33,7 @@ YoutubeDownload::YoutubeDownload(const QString &id, QObject *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(); QString videoId; @@ -44,12 +44,12 @@ Download *YoutubeDownload::infoRequestDownload(bool &sucess, QString &reasonForF videoId.remove(0, 1); } if(videoId.isEmpty()) { - sucess = false; + success = false; reasonForFail = tr("The video ID couldn't be identified."); return nullptr; } else { 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))); } } diff --git a/network/youtubedownload.h b/network/youtubedownload.h index bcf35d6..cd8789a 100644 --- a/network/youtubedownload.h +++ b/network/youtubedownload.h @@ -17,7 +17,7 @@ public: explicit YoutubeDownload(const QUrl &url, 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 suitableFilename() const; QString typeName() const;