From 553373180f18355c69e3487b04f4c2df9eeca729 Mon Sep 17 00:00:00 2001 From: fred Date: Wed, 17 May 2023 17:50:09 +0200 Subject: [PATCH] cleaning --- templates/.uqld/Downloader.cpp | 122 -------------------------- templates/.uqld/Downloader.h | 34 ------- templates/.uqld/uqload_downloader.cpp | 43 --------- 3 files changed, 199 deletions(-) delete mode 100644 templates/.uqld/Downloader.cpp delete mode 100644 templates/.uqld/Downloader.h delete mode 100644 templates/.uqld/uqload_downloader.cpp diff --git a/templates/.uqld/Downloader.cpp b/templates/.uqld/Downloader.cpp deleted file mode 100644 index 92ea8905..00000000 --- a/templates/.uqld/Downloader.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include "Downloader.h" - -#if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32__) && !defined(__NT__) -error_t fopen_s(FILE** f, const char* name, const char* mode) -{ // https://stackoverflow.com/questions/1513209/is-there-a-way-to-use-fopen-s-with-gcc-or-at-least-create-a-define-about-it - error_t ret = 0; - assert(f); - *f = fopen(name, mode); - if (!*f) - { - ret = errno; - } - return ret; -} -#endif - -using namespace std; - -Downloader::Downloader() -{ - m_fp = nullptr; - m_downloadCallback = nullptr; - curl_global_init(CURL_GLOBAL_DEFAULT); - m_curl = curl_easy_init(); - curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(m_curl, CURLOPT_COOKIEFILE, ""); - curl_easy_setopt(m_curl, CURLOPT_COOKIEJAR, ""); - curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, this); -} - -Downloader::Downloader(std::string uqUrl, std::string outputFile) : Downloader() -{ - setUqUrl(uqUrl); - setOutputFile(outputFile); -} - -void Downloader::setUqUrl(std::string uqUrl) -{ - m_uqUrl = uqUrl; -} - -void Downloader::setOutputFile(std::string outputFile) -{ - m_outputFile = outputFile; -} - -void Downloader::setDownloadCallback(void* callback) -{ - if (callback != nullptr) - { - curl_easy_setopt(m_curl, CURLOPT_NOPROGRESS, false); - m_downloadCallback = callback; - } -} - -Downloader::~Downloader() -{ - if (m_curl) - { - curl_easy_cleanup(m_curl); - curl_global_cleanup(); - } - if (m_fp != nullptr) - { - fclose(m_fp); - } -} - -size_t Downloader::writefunc(void* ptr, size_t size, size_t nmemb, std::string* s) -{ - s->append(static_cast(ptr), size * nmemb); - return size * nmemb; -} - -void Downloader::download() -{ - if (m_uqUrl == "" || m_outputFile == "") - { - throw string("Error: please specify URL and output file"); - } - if (!m_curl) - { - throw string("Error: curl init"); - } - if (uqdCheckAccess(m_outputFile.c_str(), 0) == 0) - { - throw string("Error: " + m_outputFile + " already exists"); - } - fopen_s(&m_fp, m_outputFile.c_str(), "wb"); - string strHTML; - curl_easy_setopt(m_curl, CURLOPT_URL, m_uqUrl.c_str()); - curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, &Downloader::writefunc); - curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, &strHTML); - m_res = curl_easy_perform(m_curl); - if (m_res != CURLE_OK) - { - throw string("Error: curl_easy_perform() failed: " + string(curl_easy_strerror(m_res))); - } - size_t posBegVid = strHTML.find("sources: [\"https://"); - size_t posEndVid = strHTML.find("/v.mp4\"]"); - if (posBegVid == std::string::npos || posEndVid == std::string::npos) - { - throw string("Video URL not found"); - } - string videoURL = strHTML.substr(posBegVid + 11, posEndVid - posBegVid - 5); - - if (m_downloadCallback != nullptr) - { - curl_easy_setopt(m_curl, CURLOPT_XFERINFOFUNCTION, m_downloadCallback); - } - - curl_easy_setopt(m_curl, CURLOPT_URL, videoURL.c_str()); - curl_easy_setopt(m_curl, CURLOPT_REFERER, m_uqUrl.c_str()); - curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, NULL); - curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, m_fp); - m_res = curl_easy_perform(m_curl); - if (m_res != CURLE_OK) - { - throw string("Error: curl_easy_perform() failed: " + string(curl_easy_strerror(m_res))); - } -} diff --git a/templates/.uqld/Downloader.h b/templates/.uqld/Downloader.h deleted file mode 100644 index 429248b1..00000000 --- a/templates/.uqld/Downloader.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) -#include -#define uqdCheckAccess(pathname, mode) _access(pathname, mode) -#else -#include -#include -#define uqdCheckAccess(pathname, mode) access(pathname, mode) -error_t fopen_s(FILE** f, const char* name, const char* mode); -#endif -#include - -class Downloader -{ -public: - Downloader(); - Downloader(std::string uqUrl, std::string outputFile); - ~Downloader(); - void setUqUrl(std::string uqUrl); - void setOutputFile(std::string outputFile); - void setDownloadCallback(void* callback); - void download(); - -private: - static size_t writefunc(void *curl, size_t size, std::size_t nmemb, std::string *s); - std::string m_uqUrl, m_outputFile; - CURL* m_curl; - CURLcode m_res; - FILE* m_fp; - void* m_downloadCallback; -}; diff --git a/templates/.uqld/uqload_downloader.cpp b/templates/.uqld/uqload_downloader.cpp deleted file mode 100644 index d428dd44..00000000 --- a/templates/.uqld/uqload_downloader.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include "Downloader.h" - -using namespace std; - -int downloadCallback(void* p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow); - -int main(int argc, char *argv[]) -{ - if (argc < 3) - { - cerr << "Usage: " << argv[0] << "https://uqload.com/embed-xxxxxxx.html movie.mp4" << endl; - return -1; - } - string pageInit = string(argv[1]), outputFile=string(argv[2]); - Downloader *uqDownloader=new Downloader(pageInit, outputFile); - uqDownloader->setDownloadCallback((void*)downloadCallback); - try - { - uqDownloader->download(); - } - catch (const string& e) - { - cerr << e << endl; - } - return 0; -} - -int downloadCallback(void* p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) -{ - if (dltotal != 0.0) - { - cout << setprecision(3) << ((double)dlnow / (double)dltotal) * 100 << " %\r" << flush; - } - return 0; -} - - -/** -https://uqload.com/embed-h63yfu9dkw1r.html -test.mp4 -*/