Technical changes to use yt-dlp instead of youtube-dl as a downloader
This commit is contained in:
parent
2f7f1d742c
commit
c75ca8ee6f
@ -160,7 +160,7 @@ void DownloadManager::DownloadNext()
|
|||||||
{
|
{
|
||||||
// Call template
|
// Call template
|
||||||
std::string ytdl_call_video_base =
|
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"
|
" --no-mtime --no-cache-dir -f \"$$QUALITY\" --recode-video mp4 --prefer-ffmpeg"
|
||||||
" -o \"$$DL_FILE\" \"$$DL_URL\" > \"$$DL_PROG_BUF_FILE\"";
|
" -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_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");
|
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";
|
entry->downloaded_filename = XGConfig::downloader.cachedir + "/download/" + entry->tubio_id + ".mp4";
|
||||||
ss << ytdl_call_video_base;
|
ss << ytdl_call_video_base;
|
||||||
}
|
}
|
||||||
@ -179,7 +178,7 @@ void DownloadManager::DownloadNext()
|
|||||||
{
|
{
|
||||||
// Call template
|
// Call template
|
||||||
std::string ytdl_call_audio_base =
|
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\""
|
" --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\"";
|
" \"$$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)
|
void DownloadManager::FetchInformation(std::string url, std::string tubId)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
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());
|
system(ss.str().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -708,9 +707,9 @@ std::string DownloadManager::CreateNewTubioID()
|
|||||||
void DownloadManager::WarnIfMissingDependenciesWIN()
|
void DownloadManager::WarnIfMissingDependenciesWIN()
|
||||||
{
|
{
|
||||||
#ifdef _WIN
|
#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)";
|
<< "Dependencies HAVE to lie in Tubios working directory! (where the config.json is)";
|
||||||
log->Flush();
|
log->Flush();
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,71 @@
|
|||||||
#include "Updater.h"
|
#include "Updater.h"
|
||||||
|
|
||||||
|
using namespace JasonPP;
|
||||||
|
|
||||||
std::string Updater::UpdateYoutubeDL()
|
std::string Updater::UpdateYoutubeDL()
|
||||||
{
|
{
|
||||||
#ifdef _WIN
|
#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<IStream> 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))
|
if (SUCCEEDED(res))
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
#ifdef _WIN
|
#ifdef _WIN
|
||||||
#include <urlmon.h>
|
#include <urlmon.h>
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
#include <atlbase.h>
|
||||||
|
#include "external_dependencies/leonetienne/JasonPP/JasonPP.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class Updater
|
class Updater
|
||||||
|
Binary file not shown.
BIN
Tubio/yt-dlp.exe
Normal file
BIN
Tubio/yt-dlp.exe
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user