[vlc-commits] [Git][videolan/vlc][master] 11 commits: yt-dlp: fix audio and video incorrectly judged as present

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Mon Nov 23 10:20:43 UTC 2026



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
31a01e86 by Wassim Lalaoui at 2026-11-23T11:08:28+01:00
yt-dlp: fix audio and video incorrectly judged as present

- - - - -
7565294f by Wassim Lalaoui at 2026-11-23T11:08:28+01:00
win32/spawn: fix return value to match the documented and expected behavior

provides meaningful error messages

- - - - -
26426cb8 by Wassim Lalaoui at 2026-11-23T11:08:28+01:00
win32/spawn: add CREATE_NO_WINDOW argument

- - - - -
b32ac1f2 by Wassim Lalaoui at 2026-11-23T11:08:28+01:00
win32/spawn: redirect unusable standard streams to the nul device

- - - - -
7b7c9cbe by Wassim Lalaoui at 2026-11-23T11:08:28+01:00
hls: support EXT-X-MEDIA

- - - - -
85fe9563 by Wassim Lalaoui at 2026-11-23T11:08:28+01:00
yt-dlp: prefer original audio language over dubs

- - - - -
f8975997 by Wassim Lalaoui at 2026-11-23T11:08:28+01:00
yt-dlp: open the manifest of adaptive formats

- - - - -
661f4ff8 by Wassim Lalaoui at 2026-11-23T11:08:28+01:00
yt-dlp: judge manifests by all their formats

A manifest was judged incorrectly because each of its formats was passed to CompareFormats, altough the whole manifest is opened

Now a manifest is judged by all of its formats

- - - - -
0766ea49 by Wassim Lalaoui at 2026-11-23T11:08:28+01:00
yt-dlp: prefer audio tracks in the language selected by yt-dlp

Raise the priority of the audio tracks in the language that yt-dlp would select.

- - - - -
f627dc1a by Wassim Lalaoui at 2026-11-23T11:08:28+01:00
yt-dlp: fix the preferred resolution selection

Follow the documentation for preferred-resolution:
Prefer the highest resolution not above the preferred one, or else the lowest resolution (or the highest if there is no preference)

- - - - -
e9956053 by Wassim Lalaoui at 2026-11-23T11:08:28+01:00
yt-dlp: use the HTTP headers of yt-dlp

The User Agent should be the one of yt-dlp, they are the ones patching it and keeping up with the updates of different websites
It fixes yt-dlp for some sites returning 403 Forbidden with the VLC User Agent.

- - - - -


3 changed files:

- modules/demux/hls/HLSManager.cpp
- modules/demux/ytdl.c
- src/win32/spawn.c


Changes:

=====================================
modules/demux/hls/HLSManager.cpp
=====================================
@@ -75,6 +75,7 @@ bool HLSManager::isHTTPLiveStreaming(stream_t *s)
             "ALLOW-CACHE",
             "ENDLIST",
             "STREAM-INF",
+            "MEDIA",
             "DISCONTINUITY",
             "VERSION"
         };


=====================================
modules/demux/ytdl.c
=====================================
@@ -123,43 +123,158 @@ static int vlc_kill(pid_t pid, int signum)
 struct ytdl_playlist {
     struct json_object json;
     stream_t *source;
+    struct {
+        es_out_t out;
+        es_out_t *target;
+        const char *lang;
+    } esout;
 };
 
-static int CompareFormats(const struct json_object *f_a,
-                          const struct json_object *f_b, double pref_height)
+static bool FormatHasManifest(const struct json_object *fmt)
 {
-    double h_a = json_get_num(f_a, "height");
-    double abr_a = json_get_num(f_a, "abr");
-    double h_b = json_get_num(f_b, "height");
-    double abr_b = json_get_num(f_b, "abr");
+    const char *protocol = json_get_str(fmt, "protocol");
 
-    /* Prefer non-mute formats */
-    if (!isnan(abr_a) != !isnan(abr_b))
-        return isnan(abr_a) ? -1 : +1;
+    if (protocol == NULL || json_get_str(fmt, "manifest_url") == NULL)
+        return false;
 
-    /* Prefer non-blind formats */
-    if (!isnan(h_a) != !isnan(h_b))
-        return isnan(h_a) ? -1 : +1;
+    return strncmp(protocol, "m3u8", 4) == 0 /* HLS */
+        || strcmp(protocol, "http_dash_segments") == 0 /* DASH */
+        || strcmp(protocol, "ism") == 0; /* Smooth Streaming */
+}
+
+static const char *FormatURL(const struct json_object *fmt)
+{
+    if (FormatHasManifest(fmt))
+        return json_get_str(fmt, "manifest_url");
+
+    return json_get_str(fmt, "url");
+}
 
-    if (islessequal(h_a, pref_height)) {
+/* yt-dlp sets the codec to "none" when a format has no such track.
+ * Treat unknown as a present track. */
+static bool FormatHasTrack(const struct json_object *fmt, const char *codec)
+{
+    const char *str = json_get_str(fmt, codec);
+
+    return str == NULL || strcmp(str, "none") != 0;
+}
+
+/* Prefer the highest resolution not above the preferred one, or else
+ * the lowest resolution (or the highest if there is no preference). */
+static int CompareHeight(double h_a, double h_b, double pref_height)
+{
+    if (isnan(pref_height)) {
+        if (isgreater(h_a, h_b))
+            return +1;
+        if (isless(h_a, h_b))
+            return -1;
+    } else if (islessequal(h_a, pref_height)) {
         if (!islessequal(h_b, pref_height))
             return +1;
         if (h_a > h_b)
-            return -1;
-        if (h_a < h_b)
             return +1;
+        if (h_a < h_b)
+            return -1;
     } else {
         if (islessequal(h_b, pref_height))
             return -1;
         if (isless(h_a, h_b))
-            return -1;
-        if (isgreater(h_a, h_b))
             return +1;
+        if (isgreater(h_a, h_b))
+            return -1;
+    }
+
+    return 0;
+}
+
+/* What is played if a format is picked */
+struct ytdl_tracks {
+    bool manifest;
+    bool audio;
+    bool video;
+    double lang;
+    double height;
+    double abr;
+};
+
+static void AddFormatTracks(struct ytdl_tracks *t,
+                            const struct json_object *fmt, double pref_height)
+{
+    double lang = json_get_num(fmt, "language_preference");
+    double abr = json_get_num(fmt, "abr");
+
+    if (FormatHasTrack(fmt, "acodec"))
+        t->audio = true;
+
+    if (FormatHasTrack(fmt, "vcodec")) {
+        double height = json_get_num(fmt, "height");
+
+        if (isnan(t->height) || CompareHeight(height, t->height,
+                                              pref_height) > 0)
+            t->height = height;
+        t->video = true;
+    }
+
+    if (isnan(t->lang) || isgreater(lang, t->lang))
+        t->lang = lang;
+    if (isnan(t->abr) || isgreater(abr, t->abr))
+        t->abr = abr;
+}
+
+static void GetFormatTracks(struct ytdl_tracks *t,
+                            const struct json_array *fmts,
+                            const struct json_object *fmt, double pref_height)
+{
+    t->manifest = FormatHasManifest(fmt);
+    t->audio = t->video = false;
+    t->lang = t->height = t->abr = NAN;
+
+    if (!t->manifest) {
+        AddFormatTracks(t, fmt, pref_height);
+        return;
     }
 
-    if (isgreater(abr_a, abr_b))
+    /* The manifest provides all the formats that it lists, not only the
+     * variant described by this format. */
+    const char *url = json_get_str(fmt, "manifest_url");
+
+    for (size_t i = 0; i < fmts->size; i++) {
+        const struct json_value *v = &fmts->entries[i];
+
+        if (v->type == JSON_OBJECT && FormatHasManifest(&v->object)
+         && strcmp(json_get_str(&v->object, "manifest_url"), url) == 0)
+            AddFormatTracks(t, &v->object, pref_height);
+    }
+}
+
+static int CompareTracks(const struct ytdl_tracks *a,
+                         const struct ytdl_tracks *b, double pref_height)
+{
+    /* Prefer non-mute formats */
+    if (a->audio != b->audio)
+        return a->audio ? +1 : -1;
+
+    /* Prefer non-blind formats */
+    if (a->video != b->video)
+        return a->video ? +1 : -1;
+
+    /* Prefer the original audio language over dubs */
+    if (isgreater(a->lang, b->lang))
         return +1;
-    if (isgreater(abr_b, abr_a))
+    if (isgreater(b->lang, a->lang))
+        return -1;
+
+    int val = CompareHeight(a->height, b->height, pref_height);
+    if (val != 0)
+        return val;
+
+    /* Prefer formats with manifests */
+    if (a->manifest != b->manifest)
+        return a->manifest ? +1 : -1;
+
+    if (isgreater(a->abr, b->abr))
+        return +1;
+    if (isgreater(b->abr, a->abr))
         return -1;
 
     return 0;
@@ -176,6 +291,7 @@ static const struct json_object *PickFormat(stream_t *s,
          return NULL;
 
      const struct json_object *best_fmt = NULL;
+     struct ytdl_tracks best = { 0 };
      double pref_height = var_InheritInteger(s, "preferred-resolution");
 
      if (isless(pref_height, 0.))
@@ -188,19 +304,139 @@ static const struct json_object *PickFormat(stream_t *s,
              continue;
 
          const struct json_object *fmt = &v->object;
+         struct ytdl_tracks tracks;
 
-         if (best_fmt == NULL) {
+         GetFormatTracks(&tracks, &fmts->array, fmt, pref_height);
+
+         /* On a tie, prefer the later format as yt-dlp sorts them from worst
+          * to best. */
+         if (best_fmt == NULL
+          || CompareTracks(&tracks, &best, pref_height) >= 0) {
              best_fmt = fmt;
-             continue;
+             best = tracks;
          }
-
-         if (CompareFormats(fmt, best_fmt, pref_height) > 0)
-              best_fmt = fmt;
      }
 
      return best_fmt;
 }
 
+static void SetHTTPHeader(vlc_object_t *obj, const struct json_object *headers,
+                          const char *name, const char *varname)
+{
+    const char *value = json_get_str(headers, name);
+
+    if (value != NULL) {
+        var_Create(obj, varname, VLC_VAR_STRING);
+        var_SetString(obj, varname, value);
+    }
+}
+
+/* Use the same HTTP headers as yt-dlp, as some servers reject requests
+ * with another User-Agent or without a Referer. */
+static void SetHTTPHeaders(vlc_object_t *obj, const struct json_object *fmt)
+{
+    const struct json_object *headers = json_get_object(fmt, "http_headers");
+
+    if (headers == NULL)
+        return;
+
+    SetHTTPHeader(obj, headers, "User-Agent", "http-user-agent");
+    SetHTTPHeader(obj, headers, "Referer", "http-referrer");
+}
+
+static void AddHTTPOption(input_item_t *item, const struct json_object *headers,
+                          const char *name, const char *varname)
+{
+    const char *value = json_get_str(headers, name);
+    char *option;
+
+    if (value != NULL && asprintf(&option, "%s=%s", varname, value) != -1) {
+        input_item_AddOption(item, option, VLC_INPUT_OPTION_UNIQUE);
+        free(option);
+    }
+}
+
+static void AddHTTPOptions(input_item_t *item, const struct json_object *fmt)
+{
+    const struct json_object *headers = json_get_object(fmt, "http_headers");
+
+    if (headers == NULL)
+        return;
+
+    AddHTTPOption(item, headers, "User-Agent", "http-user-agent");
+    AddHTTPOption(item, headers, "Referer", "http-referrer");
+}
+
+static bool LanguageMatch(const char *a, const char *b)
+{
+    size_t len = strcspn(a, "-_");
+
+    return len > 0 && strcspn(b, "-_") == len
+        && vlc_ascii_strncasecmp(a, b, len) == 0;
+}
+
+static es_out_id_t *EsOutAdd(es_out_t *out, input_source_t *in,
+                             const es_format_t *fmt)
+{
+    struct ytdl_playlist *sys = container_of(out, struct ytdl_playlist,
+                                             esout.out);
+    es_out_t *target = sys->esout.target;
+
+    if (sys->esout.lang != NULL && fmt->i_cat == AUDIO_ES
+     && fmt->i_priority == ES_PRIORITY_SELECTABLE_MIN
+     && fmt->psz_language != NULL
+     && LanguageMatch(fmt->psz_language, sys->esout.lang)) {
+        es_format_t copy = *fmt;
+
+        /* Prefer the tracks in the language selected by yt-dlp */
+        copy.i_priority = ES_PRIORITY_SELECTABLE_MIN + 1;
+        return target->cbs->add(target, in, &copy);
+    }
+
+    return target->cbs->add(target, in, fmt);
+}
+
+static int EsOutSend(es_out_t *out, es_out_id_t *id, block_t *block)
+{
+    struct ytdl_playlist *sys = container_of(out, struct ytdl_playlist,
+                                             esout.out);
+    es_out_t *target = sys->esout.target;
+
+    return target->cbs->send(target, id, block);
+}
+
+static void EsOutDel(es_out_t *out, es_out_id_t *id)
+{
+    struct ytdl_playlist *sys = container_of(out, struct ytdl_playlist,
+                                             esout.out);
+    es_out_t *target = sys->esout.target;
+
+    target->cbs->del(target, id);
+}
+
+static int EsOutControl(es_out_t *out, input_source_t *in, int query,
+                        va_list args)
+{
+    struct ytdl_playlist *sys = container_of(out, struct ytdl_playlist,
+                                             esout.out);
+    es_out_t *target = sys->esout.target;
+
+    return target->cbs->control(target, in, query, args);
+}
+
+static void EsOutDestroy(es_out_t *out)
+{
+    (void) out;
+}
+
+static const struct es_out_callbacks ytdl_esout_cbs = {
+    .add = EsOutAdd,
+    .send = EsOutSend,
+    .del = EsOutDel,
+    .control = EsOutControl,
+    .destroy = EsOutDestroy,
+};
+
 static const char *PickArt(const struct json_object *entry)
 {
     const struct json_value *v = json_get(entry, "thumbnails");
@@ -243,7 +479,7 @@ static int ReadItem(stream_t *s, input_item_node_t *node,
     if (fmt == NULL)
         return VLC_EGENERIC;
 
-    const char *url = json_get_str(fmt, "url");
+    const char *url = FormatURL(fmt);
 
     if (url == NULL)
         return VLC_EGENERIC;
@@ -268,6 +504,7 @@ static int ReadItem(stream_t *s, input_item_node_t *node,
 
     /* Don't care to lock, the item is still private. */
     GetMeta(item->p_meta, json);
+    AddHTTPOptions(item, fmt);
     input_item_node_AppendItem(node, item);
     input_item_Release(item);
 
@@ -434,11 +671,20 @@ static int OpenCommon(vlc_object_t *obj, const char *src_url)
     stream_t *demux = NULL;
 
     if (fmt != NULL) {
-        const char *url = json_get_str(fmt, "url");
+        const char *url = FormatURL(fmt);
 
         if (url != NULL) {
+            sys->esout.out.cbs = &ytdl_esout_cbs;
+            sys->esout.target = s->out;
+            /* Language of the format yt-dlp would itself select */
+            sys->esout.lang = json_get_str(&sys->json, "language");
+
+            if (sys->esout.lang != NULL)
+                msg_Dbg(s, "preferred audio language: %s", sys->esout.lang);
+
             var_Create(obj, "ytdl", VLC_VAR_BOOL);
-            demux = vlc_demux_NewURL(obj, url, s->out);
+            SetHTTPHeaders(obj, fmt);
+            demux = vlc_demux_NewURL(obj, url, &sys->esout.out);
 
             if (demux == NULL)
                 msg_Err(s, "cannot open URL: %s", url);


=====================================
src/win32/spawn.c
=====================================
@@ -24,6 +24,7 @@
 
 #include <windows.h>
 #include <assert.h>
+#include <errno.h>
 #include <fcntl.h>
 
 #include <vlc_common.h>
@@ -99,7 +100,7 @@ static int vlc_spawn_inner(pid_t *restrict pid, const char *path,
     assert(fdv != NULL);
     assert(argv != NULL);
 
-    int ret = -1;
+    int ret = EINVAL;
     int nulfd = -1;
     HANDLE nul_handle = INVALID_HANDLE_VALUE;
     PROCESS_INFORMATION pi = {0};
@@ -116,39 +117,50 @@ static int vlc_spawn_inner(pid_t *restrict pid, const char *path,
     wchar_t *application_name = NULL;
     wchar_t *wide_path = ToWide(path);
     if (unlikely(wide_path == NULL))
-        return ret;
+        return ENOMEM;
     wchar_t *cmdline = NULL;
 
-    if (fdv[0] == -1 || fdv[1] == -1) {
+    HANDLE hstd[3] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE,
+                       INVALID_HANDLE_VALUE };
+    bool need_nul = false;
+
+    for (int i = 0; i < 3; i++) {
+        if (fdv[i] == -1) {
+            need_nul = true;
+            continue;
+        }
+
+        hstd[i] = dup_handle_from_fd(fdv[i]);
+        if (hstd[i] == INVALID_HANDLE_VALUE) {
+            if (fdv[i] < 0 || fdv[i] > 2) {
+                ret = EBADF;
+                goto error;
+            }
+            need_nul = true;
+        }
+    }
+
+    if (need_nul) {
         nulfd = _open("\\\\.\\NUL", O_RDWR);
-        if (unlikely(nulfd == -1))
+        if (unlikely(nulfd == -1)) {
+            ret = errno;
             goto error;
+        }
 
         nul_handle = dup_handle_from_fd(nulfd);
-        if (unlikely(nul_handle == INVALID_HANDLE_VALUE))
+        if (unlikely(nul_handle == INVALID_HANDLE_VALUE)) {
+            ret = EBADF;
             goto error;
+        }
 
-        if (fdv[0] == -1)
-            siEx.StartupInfo.hStdInput = nul_handle;
-        if (fdv[1] == -1)
-            siEx.StartupInfo.hStdOutput = nul_handle;
+        for (int i = 0; i < 3; i++)
+            if (hstd[i] == INVALID_HANDLE_VALUE)
+                hstd[i] = nul_handle;
     }
 
-    if (fdv[0] != -1) {
-        siEx.StartupInfo.hStdInput = dup_handle_from_fd(fdv[0]);
-        if (unlikely(siEx.StartupInfo.hStdInput == INVALID_HANDLE_VALUE))
-            goto error;
-    }
-    if (fdv[1] != -1) {
-        siEx.StartupInfo.hStdOutput = dup_handle_from_fd(fdv[1]);
-        if (unlikely(siEx.StartupInfo.hStdOutput == INVALID_HANDLE_VALUE))
-            goto error;
-    }
-    if (fdv[2] != -1) {
-        siEx.StartupInfo.hStdError = dup_handle_from_fd(fdv[2]);
-        if (unlikely(siEx.StartupInfo.hStdError == INVALID_HANDLE_VALUE))
-            goto error;
-    }
+    siEx.StartupInfo.hStdInput  = hstd[0];
+    siEx.StartupInfo.hStdOutput = hstd[1];
+    siEx.StartupInfo.hStdError  = hstd[2];
 
     HANDLE handles[3] = {
         siEx.StartupInfo.hStdInput,
@@ -156,8 +168,10 @@ static int vlc_spawn_inner(pid_t *restrict pid, const char *path,
         siEx.StartupInfo.hStdError
     };
     siEx.lpAttributeList = allow_hstd_inherit(handles);
-    if (unlikely(!siEx.lpAttributeList))
+    if (unlikely(!siEx.lpAttributeList)) {
+        ret = ENOMEM;
         goto error;
+    }
 
     if (search) {
         wchar_t short_path[MAX_PATH];
@@ -165,20 +179,28 @@ static int vlc_spawn_inner(pid_t *restrict pid, const char *path,
             goto error;
 
         DWORD path_size = SearchPathW(NULL, wide_path, NULL, ARRAY_SIZE(short_path), short_path, NULL);
-        if (path_size == 0)
+        if (path_size == 0) {
+            ret = ENOENT;
             goto error;
+        }
         if (path_size <= ARRAY_SIZE(short_path)) {
             application_name = _wcsdup(short_path);
-            if (unlikely(!application_name))
+            if (unlikely(!application_name)) {
+                ret = ENOMEM;
                 goto error;
+            }
         } else {
             application_name = malloc(path_size * sizeof(*application_name));
-            if (unlikely(!application_name))
+            if (unlikely(!application_name)) {
+                ret = ENOMEM;
                 goto error;
+            }
 
             DWORD full_path_size = SearchPathW(NULL, wide_path, NULL, path_size, application_name, NULL);
-            if (unlikely(path_size < full_path_size))
+            if (unlikely(path_size < full_path_size)) {
+                ret = ENOENT;
                 goto error;
+            }
         }
     } else {
         application_name = wide_path;
@@ -186,24 +208,46 @@ static int vlc_spawn_inner(pid_t *restrict pid, const char *path,
 
     if (likely(argv[0])) {
         struct vlc_memstream cmdline_s;
-        if (unlikely(vlc_memstream_open(&cmdline_s) != 0))
+        if (unlikely(vlc_memstream_open(&cmdline_s) != 0)) {
+            ret = ENOMEM;
             goto error;
+        }
         vlc_memstream_printf(&cmdline_s, "%s", argv[0]);
         for (int argc = 1; argv[argc]; ++argc)
             vlc_memstream_printf(&cmdline_s, " %s", argv[argc]);
-        if (vlc_memstream_close(&cmdline_s) != 0)
+        if (vlc_memstream_close(&cmdline_s) != 0) {
+            ret = ENOMEM;
             goto error;
+        }
         cmdline = ToWide(cmdline_s.ptr);
         free(cmdline_s.ptr);
-        if (unlikely(cmdline == NULL))
+        if (unlikely(cmdline == NULL)) {
+            ret = ENOMEM;
             goto error;
+        }
     }
 
     BOOL bSuccess = CreateProcessW(application_name, cmdline, NULL,
-                                   NULL, TRUE, EXTENDED_STARTUPINFO_PRESENT,
+                                   NULL, TRUE,
+                                   EXTENDED_STARTUPINFO_PRESENT | CREATE_NO_WINDOW,
                                    NULL, NULL, &siEx.StartupInfo, &pi);
-    if (!bSuccess)
-        goto error;
+    if (!bSuccess) {
+        switch (GetLastError()) {
+            case ERROR_FILE_NOT_FOUND:
+            case ERROR_PATH_NOT_FOUND:
+                ret = ENOENT;
+                goto error;
+            case ERROR_ACCESS_DENIED:
+                ret = EACCES;
+                goto error;
+            case ERROR_BAD_EXE_FORMAT:
+                ret = ENOEXEC;
+                goto error;
+            default:
+                ret = EINVAL;
+                goto error;
+        }
+    }
 
     pid_t id = GetProcessId(pi.hProcess);
     if (unlikely(!id))
@@ -221,12 +265,9 @@ error:
     if (nul_handle != INVALID_HANDLE_VALUE)
         CloseHandle(nul_handle);
 
-    if (fdv[0] != -1 && siEx.StartupInfo.hStdInput != INVALID_HANDLE_VALUE)
-        CloseHandle(siEx.StartupInfo.hStdInput);
-    if (fdv[1] != -1 && siEx.StartupInfo.hStdOutput != INVALID_HANDLE_VALUE)
-        CloseHandle(siEx.StartupInfo.hStdOutput);
-    if (siEx.StartupInfo.hStdError != INVALID_HANDLE_VALUE)
-        CloseHandle(siEx.StartupInfo.hStdError);
+    for (int i = 0; i < 3; i++)
+        if (hstd[i] != INVALID_HANDLE_VALUE && hstd[i] != nul_handle)
+            CloseHandle(hstd[i]);
 
     if (siEx.lpAttributeList) {
         DeleteProcThreadAttributeList(siEx.lpAttributeList);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/391a3bf87302769a3e45143b8a2f9961be45db0e...e9956053e46b09a1701049ba0baef3ad2f516d6d

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/391a3bf87302769a3e45143b8a2f9961be45db0e...e9956053e46b09a1701049ba0baef3ad2f516d6d
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list