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
+4 -3
View File
@@ -6,9 +6,7 @@
#include <arpa/inet.h>
namespace playback {
inline bool validNetworkURL(const char *text) {
if (!text) return false;
const std::string_view url(text);
inline bool validNetworkURL(std::string_view url) {
if (url.size() > 65536) return false;
const std::size_t start = url.starts_with("https://") ? 8 : url.starts_with("http://") ? 7 : 0;
if (!start) return false;
@@ -52,6 +50,9 @@ inline bool validNetworkURL(const char *text) {
}
return port.empty() || number > 0;
}
inline bool validNetworkURL(const char *text) {
return text && validNetworkURL(std::string_view(text));
}
inline bool validHeaders(const char *text) {
if (!text) return true;
const std::string_view headers(text);
+2 -2
View File
@@ -58,8 +58,8 @@ typedef struct PlayerNetworkSource {
const char *audio_headers;
double duration;
bool is_live;
// Canonical YouTube webpage or stable miruro:<base64url media_id>:<positive episode>
// identity, never an extracted stream/CDN URL.
// Original HTTP(S) video URL (canonical for YouTube), or stable
// miruro:<base64url media_id>:<positive episode> identity, never an extracted CDN URL.
// NULL/empty means no reporting for this source.
const char *media_url;
// Initial restored position, applied before publishing ready state. Zero
+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);