Made the download entries work with the jsons

This commit is contained in:
Leon Etienne (ubuntu wsl)
2020-09-30 18:09:09 +02:00
parent 5d04df3422
commit ad7eac5343
7 changed files with 184 additions and 60 deletions

View File

@@ -152,7 +152,8 @@ void DownloadManager::DownloadNext()
std::string ytdl_call_video_base =
"youtube-dl --newline --no-call-home --no-playlist --no-part --no-warnings --limit-rate $$DL_RATE"
" --no-mtime --no-cache-dir --recode-video mp4 --format \"bestvideo[ext=mp4]+bestaudio/best[ext=mp4]/best\""
" --merge-output-format mp4 -o \"$$DL_FILE\" $$DL_URL > \"$$DL_PROG_BUF_FILE\"";
" --merge-output-format mp4 -o \"$$DL_FILE\" \"$$DL_URL\" > \"$$DL_PROG_BUF_FILE\"";
ytdl_call_video_base = Internal::StringHelpers::Replace(ytdl_call_video_base, "$$DL_RATE", XGConfig::downloader.max_dlrate_per_thread);
ytdl_call_video_base = Internal::StringHelpers::Replace(ytdl_call_video_base, "$$DL_FILE", XGConfig::downloader.cachedir + "/download/" + entry->tubio_id + ".%(ext)s");
@@ -167,7 +168,7 @@ void DownloadManager::DownloadNext()
std::string ytdl_call_audio_base =
"youtube-dl --newline --no-call-home --no-playlist --no-part --no-warnings --limit-rate $$DL_RATE"
" --no-mtime --no-cache-dir --audio-format mp3 --audio-quality 0 --extract-audio -o \"$$DL_FILE\""
" $$DL_URL > \"$$DL_PROG_BUF_FILE\"";
" \"$$DL_URL\" > \"$$DL_PROG_BUF_FILE\"";
ytdl_call_audio_base = Internal::StringHelpers::Replace(ytdl_call_audio_base, "$$DL_RATE", XGConfig::downloader.max_dlrate_per_thread);
ytdl_call_audio_base = Internal::StringHelpers::Replace(ytdl_call_audio_base, "$$DL_FILE", XGConfig::downloader.cachedir + "/download/" + entry->tubio_id + ".%(ext)s");
@@ -572,7 +573,7 @@ std::vector<DownloadEntry> DownloadManager::ParseJsonArrayToEntries(const JasonP
void DownloadManager::FetchInformation(std::string url, std::string tubId)
{
std::stringstream ss;
ss << "youtube-dl.exe --skip-download --dump-json " << url << " > \"" << XGConfig::downloader.cachedir << "/metadata/" << tubId << ".json" << "\"" << std::endl;
ss << "youtube-dl.exe --skip-download --dump-json \"" << url << "\" > \"" << XGConfig::downloader.cachedir << "/metadata/" << tubId << ".json" << "\"" << std::endl;
system(ss.str().c_str());
return;
}

View File

@@ -145,6 +145,7 @@ bool RestQueryHandler::FetchAlltimeCache(const JsonBlock& request, JsonBlock& re
JsonArray cache = DownloadManager::GetAlltimeCacheAsJson(-1, -1); // Get ALL the data
responseBody.Set("cache_size") = (long long int)cache.Size();
responseBody.Set("cache") = cache;
return true;
}

View File

@@ -1133,7 +1133,6 @@ std::string StringHelpers::Replace(const std::string str, const std::string find
return ss.str();
}
std::string StringHelpers::Escape(const std::string str)
{
std::stringstream ss;
@@ -1161,7 +1160,43 @@ std::string StringHelpers::Escape(const std::string str)
ss << "\\\"";
break;
case '\\':
ss << "\\\\";
// All of this bullshit basically means:
// If we find an escaped utf-16 sequence, it was most likely ignored behind by the utf-8 parser (because it can only escape utf-8, duh), so we will not escape it.
// If we found a \u and the string is long enought that it could be a utf sequence
if ((str.length() > i + 5) && (str[i + 1] == 'u'))
{
// Check that the found so-called utf sequence is followed by a valid 16-bit hex string
std::string wouldbeHex = str.substr(i + 2, 4);
bool isValidHex = true;
for (std::size_t j = 0; j < wouldbeHex.size(); j++)
{
// Make any capitcal hex digit lowercase
if ((wouldbeHex[j] >= 'A') && (wouldbeHex[j] <= 'F')) wouldbeHex[j] += 32;
// Check that it is indeed a hex literal
if (!(((wouldbeHex[j] >= '0') && (wouldbeHex[j] <= '9')) ||
((wouldbeHex[j] >= 'a') && (wouldbeHex[j] <= 'f'))))
{
isValidHex = false;
}
}
// Check that it is a UTF-16 escape sequence (because these are left unparsed)
if ((isValidHex) && (wouldbeHex.substr(0, 2) != "00"))
{
ss << str[i];
}
// If it is not an unescaped utf-16 sequence, just escape it
else
{
ss << "\\\\";
}
}
// If it is not an unescaped utf-16 sequence, just escape it
else
{
ss << "\\\\";
}
break;
default:
if (str[i] < 0) ss << EscapeUTF8(str[i]);

View File

@@ -2148,7 +2148,7 @@ namespace JasonPP
};
}
#define JASONPP_VERSION (1.0216)
#define JASONPP_VERSION (1.022)
namespace JasonPP
{