Skip to content

Commit

Permalink
Merge pull request #17 from Leonetienne/develop
Browse files Browse the repository at this point in the history
Switched to yt-dlp downloader and dependabot bumps
  • Loading branch information
Leonetienne authored Feb 6, 2022
2 parents 4ff8670 + 0cd35b4 commit d9d4a3e
Show file tree
Hide file tree
Showing 30 changed files with 109 additions and 46 deletions.
11 changes: 5 additions & 6 deletions Tubio/DownloadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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\"";

Expand All @@ -171,15 +171,14 @@ 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;
}
else // DOWNLOAD_MODE::AUDIO
{
// 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\"";

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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_YtDlp\"). "
<< "Dependencies HAVE to lie in Tubios working directory! (where the config.json is)";
log->Flush();
}
Expand Down
4 changes: 2 additions & 2 deletions Tubio/DownloadManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ namespace Downloader
static std::vector<DownloadEntry> ParseJsonArrayToEntries(const JasonPP::JsonArray& arr);

/// <summary>
/// Will return a youtube-dl quality string based on 'quality'
/// Will return a yt-dlp quality string based on 'quality'
/// </summary>
/// <param name="quality">The download quality to get the parameter from</param>
/// <returns>The youtube-dl quality parameter</returns>
/// <returns>The yt-dlp quality parameter</returns>
static std::string DownloadQualityToStringParams(DOWNLOAD_QUALITY quality);

/// <summary>
Expand Down
18 changes: 9 additions & 9 deletions Tubio/RestQueryHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bool RestQueryHandler::ProcessQuery(const std::string clientAdress, const Json&
else if (requestName == "get_os_name") return GetOSName(requestBody, responseBody, responseCode);
else if (requestName == "fetch_session_logs") return FetchSessionLogs(requestBody, responseBody, responseCode);
else if (requestName == "fetch_alltime_logs") return FetchAlltimeLogs(requestBody, responseBody, responseCode);
else if (requestName == "update_dep_youtubedl") return UpdateYoutubeDL(requestBody, responseBody, responseCode);
else if (requestName == "update_dep_yt-dlp") return UpdateYtDlp(requestBody, responseBody, responseCode);
else if (requestName == "remove_download_entry") return RemoveDownloadEntry(requestBody, responseBody, responseCode);
else if (requestName == "update_config") return UpdateConfig(requestBody, responseBody, responseCode);
else if (requestName == "reset_config_to_default_values") return ResetConfigDefaults(requestBody, responseBody, responseCode);
Expand Down Expand Up @@ -370,9 +370,9 @@ bool RestQueryHandler::GetDiskUsage(const JsonBlock& request, JsonBlock& respons
{
dependencies += FileSystem::CalculateSize("ffplay.exe");
}
if (FileSystem::Exists("youtube-dl.exe"))
if (FileSystem::Exists("yt-dlp.exe"))
{
dependencies += FileSystem::CalculateSize("youtube-dl.exe");
dependencies += FileSystem::CalculateSize("yt-dlp.exe");
}
diskUsages.Set("dependencies") = dependencies;

Expand All @@ -397,20 +397,20 @@ bool RestQueryHandler::ClearLogs(const JsonBlock& request, JsonBlock& responseBo
return true;
}

bool RestQueryHandler::UpdateYoutubeDL(const JsonBlock& request, JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode)
bool RestQueryHandler::UpdateYtDlp(const JsonBlock& request, JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode)
{
log->cout << "Updating youtube-dl...";
log->cout << "Updating yt-dlp...";
log->Flush();

std::string result = Updater::UpdateYoutubeDL();
std::string result = Updater::UpdateYtDlp();
if (result == "OK")
{
log->cout << " => OK!";
log->Flush();

responseCode = HTTP_STATUS_CODE::OK;
responseBody.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::OK));
responseBody.Set("message") = "Updated youtube-dl.exe successfully!";
responseBody.Set("message") = "Updated yt-dlp.exe successfully!";
}
else if (result == "not implemented")
{
Expand All @@ -420,7 +420,7 @@ bool RestQueryHandler::UpdateYoutubeDL(const JsonBlock& request, JsonBlock& resp
log->Flush();
responseCode = HTTP_STATUS_CODE::NOT_IMPLEMENTED;
responseBody.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::NOT_IMPLEMENTED));
responseBody.Set("message") = "On linux you have to update youtube-dl yourself since it is a system-wide package handled by various package managers!";
responseBody.Set("message") = "On linux you have to update yt-dlp yourself since it is a system-wide package handled by various package managers!";
}
else // Some other error
{
Expand All @@ -429,7 +429,7 @@ bool RestQueryHandler::UpdateYoutubeDL(const JsonBlock& request, JsonBlock& resp

responseCode = HTTP_STATUS_CODE::INTERNAL_SERVER_ERROR;
responseBody.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::INTERNAL_SERVER_ERROR));
responseBody.Set("message") = "Unable do update youtube-dl.exe! See urlmon " + result;
responseBody.Set("message") = "Unable do update yt-dlp.exe! See urlmon " + result;
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion Tubio/RestQueryHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Rest
static bool FetchAlltimeLogs(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode);
static bool FetchSessionLogs(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode);
static bool GetDiskUsage(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode);
static bool UpdateYoutubeDL(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode);
static bool UpdateYtDlp(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode);
static bool RemoveDownloadEntry(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode);
static bool UpdateConfig(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode);
static bool ResetConfigDefaults(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode);
Expand Down
66 changes: 64 additions & 2 deletions Tubio/Updater.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,71 @@
#include "Updater.h"

std::string Updater::UpdateYoutubeDL()
using namespace JasonPP;

std::string Updater::UpdateYtDlp()
{
#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))
{
Expand Down
6 changes: 4 additions & 2 deletions Tubio/Updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
#ifdef _WIN
#include <urlmon.h>
#include <Windows.h>
#include <atlbase.h>
#include "external_dependencies/leonetienne/JasonPP/JasonPP.hpp"
#endif

class Updater
{
public:
/// <summary>
/// Will update youtube-dl.exe on windows only!! Returns error message. On linux, you have to update it yourself, since it is a package of its own!
/// Will update yt-dlp.exe on windows only!! Returns error message. On linux, you have to update it yourself, since it is a package of its own!
/// </summary>
/// <returns></returns>
static std::string UpdateYoutubeDL();
static std::string UpdateYtDlp();
};
2 changes: 1 addition & 1 deletion Tubio/Version.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#pragma once
#define TUBIO_SERVER_VERSION (0.5396)
#define TUBIO_SERVER_VERSION (0.6)
6 changes: 3 additions & 3 deletions Tubio/frontend/200.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!doctype html>
<html>
<head>
<title>Tubio - Video downloader</title><meta data-n-head="1" charset="utf-8"><meta data-n-head="1" name="viewport" content="width=device-width,initial-scale=1"><meta data-n-head="1" data-hid="description" name="description" content=""><meta data-n-head="1" name="msapplication-TileColor" content="#031934"><meta data-n-head="1" name="theme-color" content="#031934"><link data-n-head="1" rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link data-n-head="1" rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"><link data-n-head="1" rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link data-n-head="1" rel="manifest" href="/site.webmanifest"><link data-n-head="1" rel="mask-icon" href="/safari-pinned-tab.svg" color="#031934"><link rel="preload" href="/_nuxt/319ed71.js" as="script"><link rel="preload" href="/_nuxt/8a34dcc.js" as="script"><link rel="preload" href="/_nuxt/d640171.js" as="script"><link rel="preload" href="/_nuxt/b2e29d0.js" as="script">
<title>Tubio - Video downloader</title><meta data-n-head="1" charset="utf-8"><meta data-n-head="1" name="viewport" content="width=device-width,initial-scale=1"><meta data-n-head="1" data-hid="description" name="description" content=""><meta data-n-head="1" name="msapplication-TileColor" content="#031934"><meta data-n-head="1" name="theme-color" content="#031934"><link data-n-head="1" rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link data-n-head="1" rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"><link data-n-head="1" rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link data-n-head="1" rel="manifest" href="/site.webmanifest"><link data-n-head="1" rel="mask-icon" href="/safari-pinned-tab.svg" color="#031934"><link rel="preload" href="/_nuxt/10b0b66.js" as="script"><link rel="preload" href="/_nuxt/8a34dcc.js" as="script"><link rel="preload" href="/_nuxt/eb2cb16.js" as="script"><link rel="preload" href="/_nuxt/4ddf16a.js" as="script">
</head>
<body>
<div id="__nuxt"><style>#nuxt-loading{background:#fff;visibility:hidden;opacity:0;position:absolute;left:0;right:0;top:0;bottom:0;display:flex;justify-content:center;align-items:center;flex-direction:column;animation:nuxtLoadingIn 10s ease;-webkit-animation:nuxtLoadingIn 10s ease;animation-fill-mode:forwards;overflow:hidden}@keyframes nuxtLoadingIn{0%{visibility:hidden;opacity:0}20%{visibility:visible;opacity:0}100%{visibility:visible;opacity:1}}@-webkit-keyframes nuxtLoadingIn{0%{visibility:hidden;opacity:0}20%{visibility:visible;opacity:0}100%{visibility:visible;opacity:1}}#nuxt-loading>div,#nuxt-loading>div:after{border-radius:50%;width:5rem;height:5rem}#nuxt-loading>div{font-size:10px;position:relative;text-indent:-9999em;border:.5rem solid #f5f5f5;border-left:.5rem solid #000;-webkit-transform:translateZ(0);-ms-transform:translateZ(0);transform:translateZ(0);-webkit-animation:nuxtLoading 1.1s infinite linear;animation:nuxtLoading 1.1s infinite linear}#nuxt-loading.error>div{border-left:.5rem solid #ff4500;animation-duration:5s}@-webkit-keyframes nuxtLoading{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes nuxtLoading{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}</style><script>window.addEventListener("error",function(){var e=document.getElementById("nuxt-loading");e&&(e.className+=" error")})</script><div id="nuxt-loading" aria-live="polite" role="status"><div>Loading...</div></div></div><script>window.__NUXT__={config:{app:{basePath:"/",assetsPath:"/_nuxt/",cdnURL:null}},staticAssetsBase:"/_nuxt/static/1615643415"}</script>
<script src="/_nuxt/319ed71.js"></script><script src="/_nuxt/8a34dcc.js"></script><script src="/_nuxt/d640171.js"></script><script src="/_nuxt/b2e29d0.js"></script></body>
<div id="__nuxt"><style>#nuxt-loading{background:#fff;visibility:hidden;opacity:0;position:absolute;left:0;right:0;top:0;bottom:0;display:flex;justify-content:center;align-items:center;flex-direction:column;animation:nuxtLoadingIn 10s ease;-webkit-animation:nuxtLoadingIn 10s ease;animation-fill-mode:forwards;overflow:hidden}@keyframes nuxtLoadingIn{0%{visibility:hidden;opacity:0}20%{visibility:visible;opacity:0}100%{visibility:visible;opacity:1}}@-webkit-keyframes nuxtLoadingIn{0%{visibility:hidden;opacity:0}20%{visibility:visible;opacity:0}100%{visibility:visible;opacity:1}}#nuxt-loading>div,#nuxt-loading>div:after{border-radius:50%;width:5rem;height:5rem}#nuxt-loading>div{font-size:10px;position:relative;text-indent:-9999em;border:.5rem solid #f5f5f5;border-left:.5rem solid #000;-webkit-transform:translateZ(0);-ms-transform:translateZ(0);transform:translateZ(0);-webkit-animation:nuxtLoading 1.1s infinite linear;animation:nuxtLoading 1.1s infinite linear}#nuxt-loading.error>div{border-left:.5rem solid #ff4500;animation-duration:5s}@-webkit-keyframes nuxtLoading{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes nuxtLoading{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}</style><script>window.addEventListener("error",function(){var e=document.getElementById("nuxt-loading");e&&(e.className+=" error")})</script><div id="nuxt-loading" aria-live="polite" role="status"><div>Loading...</div></div></div><script>window.__NUXT__={config:{app:{basePath:"/",assetsPath:"/_nuxt/",cdnURL:null}},staticAssetsBase:"/_nuxt/static/1644155680"}</script>
<script src="/_nuxt/10b0b66.js"></script><script src="/_nuxt/8a34dcc.js"></script><script src="/_nuxt/eb2cb16.js"></script><script src="/_nuxt/4ddf16a.js"></script></body>
</html>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d9d4a3e

Please sign in to comment.