feat: resolve HTTP video URLs with bundled yt-dlp

This commit is contained in:
2026-10-22 17:05:29 +02:00
parent 6a4afc9f0e
commit b132bab393
14 changed files with 121 additions and 79 deletions
+6 -8
View File
@@ -1,4 +1,5 @@
#include "progress_reporter.hpp"
#include "network_policy.hpp"
#include <cerrno>
#include <charconv>
#include <chrono>
@@ -87,13 +88,7 @@ void ProgressReporter::resume() {
}
bool ProgressReporter::validMediaURL(std::string_view url) noexcept {
constexpr std::string_view prefix = "https://www.youtube.com/watch?v=";
if (url.size() != prefix.size() + 11 || url.substr(0, prefix.size()) != prefix) return false;
for (char character : url.substr(prefix.size())) {
if (!((character >= 'a' && character <= 'z') || (character >= 'A' && character <= 'Z') ||
(character >= '0' && character <= '9') || character == '_' || character == '-')) return false;
}
return true;
return validNetworkURL(url);
}
bool ProgressReporter::validMediaIdentity(std::string_view identity) noexcept {
@@ -203,7 +198,10 @@ bool ProgressReporter::emit(const char *event) noexcept {
record += "},\"position_seconds\":";
} else {
record += "\",\"media_url\":\"";
record += mediaURL;
for (char character : mediaURL) {
if (character == '"' || character == '\\') record += '\\';
record += character;
}
record += "\",\"position_seconds\":";
}
appendNumber(record, snapshot.position);