diff --git a/Tubio/DownloadManager.cpp b/Tubio/DownloadManager.cpp index d2f206e..4613a17 100644 --- a/Tubio/DownloadManager.cpp +++ b/Tubio/DownloadManager.cpp @@ -160,7 +160,7 @@ void DownloadManager::DownloadNext() { // Call template std::string ytdl_call_video_base = - "youtube-dl --newline --no-call-home --no-playlist --no-part --no-warnings --socket-timeout 5 --limit-rate $$DL_RATE" + "yt-dlp --newline --no-call-home --no-playlist --no-part --no-warnings --socket-timeout 5 --limit-rate $$DL_RATE" " --no-mtime --no-cache-dir -f \"$$QUALITY\" --recode-video mp4 --prefer-ffmpeg" " -o \"$$DL_FILE\" \"$$DL_URL\" > \"$$DL_PROG_BUF_FILE\""; @@ -171,7 +171,6 @@ void DownloadManager::DownloadNext() ytdl_call_video_base = Internal::StringHelpers::Replace(ytdl_call_video_base, "$$DL_URL", entry->webpage_url); ytdl_call_video_base = Internal::StringHelpers::Replace(ytdl_call_video_base, "$$DL_PROG_BUF_FILE", XGConfig::downloader.cachedir + "/dlprogbuf/" + entry->tubio_id + ".buf"); - entry->downloaded_filename = XGConfig::downloader.cachedir + "/download/" + entry->tubio_id + ".mp4"; ss << ytdl_call_video_base; } @@ -179,7 +178,7 @@ void DownloadManager::DownloadNext() { // Call template std::string ytdl_call_audio_base = - "youtube-dl --newline --no-call-home --no-playlist --no-part --no-warnings --socket-timeout 5 --limit-rate $$DL_RATE" + "yt-dlp --newline --no-call-home --no-playlist --no-part --no-warnings --socket-timeout 5 --limit-rate $$DL_RATE" " --no-mtime --no-cache-dir -f worstvideo+bestaudio --audio-format mp3 --audio-quality 0 --extract-audio -o \"$$DL_FILE\"" " \"$$DL_URL\" > \"$$DL_PROG_BUF_FILE\""; @@ -676,7 +675,7 @@ DOWNLOAD_QUALITY DownloadManager::GetDownloadQualityByName(const std::string& qu void DownloadManager::FetchInformation(std::string url, std::string tubId) { std::stringstream ss; - ss << "youtube-dl --skip-download --no-warnings --no-call-home --no-playlist --socket-timeout 5 --dump-json \"" << url << "\" > \"" << XGConfig::downloader.cachedir << "/metadata/" << tubId << ".json" << "\""; + ss << "yt-dlp --skip-download --no-warnings --no-call-home --no-playlist --socket-timeout 5 --dump-json \"" << url << "\" > \"" << XGConfig::downloader.cachedir << "/metadata/" << tubId << ".json" << "\""; system(ss.str().c_str()); return; } @@ -708,9 +707,9 @@ std::string DownloadManager::CreateNewTubioID() void DownloadManager::WarnIfMissingDependenciesWIN() { #ifdef _WIN - if (!FileSystem::Exists("youtube-dl.exe")) + if (!FileSystem::Exists("yt-dlp.exe")) { - log->cout << log->Warn() << "Dependency youtube-dl.exe missing! Try updating it! (\"request\": \"update_dep_youtubedl\"). " + log->cout << log->Warn() << "Dependency yt-dlp.exe missing! Try updating it! (\"request\": \"update_dep_youtubedl\"). " << "Dependencies HAVE to lie in Tubios working directory! (where the config.json is)"; log->Flush(); } diff --git a/Tubio/Updater.cpp b/Tubio/Updater.cpp index 9b5689b..67a4664 100644 --- a/Tubio/Updater.cpp +++ b/Tubio/Updater.cpp @@ -1,9 +1,71 @@ #include "Updater.h" +using namespace JasonPP; + std::string Updater::UpdateYoutubeDL() { #ifdef _WIN - HRESULT res = URLDownloadToFileA(NULL, "https://yt-dl.org/downloads/latest/youtube-dl.exe", "youtube-dl.exe", 0, NULL); + // Fetch rest respone for latest yt-dlp release + CComPtr dlStream; + HRESULT res = URLOpenBlockingStreamA( + nullptr, + "https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest", + &dlStream, + 0, + nullptr + ); + if (FAILED(res)) + { + return "Error fetching latest yt-dlp release identifier. Error code: 0x" + (JasonPP::Internal::Helpers::Base10_2_X(res, "0123456789abcdef")); + } + + char buffer[4096]; + std::stringstream restContent; + do + { + DWORD bytesRead = 0; + res = dlStream->Read(buffer, sizeof(buffer), &bytesRead); + + if (bytesRead) + restContent.write(buffer, bytesRead); + } while ((SUCCEEDED(res)) && (res != S_FALSE)); + + // Parse response + Json json; + try + { + json.Parse(restContent.str()); + } + catch (JsonException& e) + { + return "Error parsing the json githubs rest api returned, whilst trying to update yt-dlp."; + } + + // Look for the asset in the release that's named "yt-dlp.exe" + std::string downloadUrlLatestExe = ""; + try + { + const JsonArray assetsArr = json.AsJson["assets"].AsArray; + + for (std::size_t i = 0; i < assetsArr.Size(); i++) + { + if (assetsArr[i].AsJson["name"] == "yt-dlp.exe") + downloadUrlLatestExe = assetsArr[i].AsJson["browser_download_url"]; + } + } + catch (JsonException& e) + { + return "Error whilst trying to access the json key assets[n][\"name\"/\"browser_download_url\"] whilst trying to update yt-dlp."; + } + + if (downloadUrlLatestExe == "") + { + return "Error: No suitable asset found in latest release. Looking for name \"yt-dlp.exe\"."; + } + + + // Download the latest yt-dlp.exe + res = URLDownloadToFileA(NULL, downloadUrlLatestExe.c_str(), "yt-dlp.exe", 0, NULL); if (SUCCEEDED(res)) { diff --git a/Tubio/Updater.h b/Tubio/Updater.h index 8c2d39f..89e9f11 100644 --- a/Tubio/Updater.h +++ b/Tubio/Updater.h @@ -5,6 +5,8 @@ #ifdef _WIN #include #include +#include +#include "external_dependencies/leonetienne/JasonPP/JasonPP.hpp" #endif class Updater diff --git a/Tubio/youtube-dl.exe b/Tubio/youtube-dl.exe deleted file mode 100644 index 3464953..0000000 Binary files a/Tubio/youtube-dl.exe and /dev/null differ diff --git a/Tubio/yt-dlp.exe b/Tubio/yt-dlp.exe new file mode 100644 index 0000000..870e2f7 Binary files /dev/null and b/Tubio/yt-dlp.exe differ