[vlc-commits] [Git][videolan/vlc][master] subtitle: extract language from URL, not file path

Steve Lhomme (@robUx4) gitlab at videolan.org
Tue Oct 14 05:41:03 UTC 2025



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
26da6a88 by Rémi Denis-Courmont at 2025-10-14T05:11:46+00:00
subtitle: extract language from URL, not file path

Not all subtitle access have a local file path.

Fixes #25837.

- - - - -


1 changed file:

- modules/demux/subtitle.c


Changes:

=====================================
modules/demux/subtitle.c
=====================================
@@ -35,6 +35,7 @@
 #include <vlc_common.h>
 #include <vlc_arrays.h>
 #include <vlc_plugin.h>
+#include <vlc_url.h>
 
 #include <ctype.h>
 #include <math.h>
@@ -239,7 +240,7 @@ static int Demux( demux_t * );
 static int Control( demux_t *, int, va_list );
 
 static void Fix( demux_t * );
-static char * get_language_from_filename( const char * );
+static char *get_language_from_url(const char *);
 
 /*****************************************************************************
  * Decoder format output function
@@ -708,7 +709,7 @@ static int Open ( vlc_object_t *p_this )
     }
     else
     {
-        fmt.psz_language = get_language_from_filename( p_demux->psz_filepath );
+        fmt.psz_language = get_language_from_url( p_demux->psz_url );
         if( fmt.psz_language )
             msg_Dbg( p_demux, "selected '%s' as possible filename language substring of subtitle: %s",
                      fmt.psz_language, p_demux->psz_location );
@@ -2498,39 +2499,40 @@ static int ParseSCC( vlc_object_t *p_obj, subs_properties_t *p_props,
 
 /* Tries to extract language from common filename patterns PATH/filename.LANG.ext
    and PATH/Subs/x_LANG.ext (where 'x' is an integer). */
-static char * get_language_from_filename( const char * psz_sub_file )
+static char *get_language_from_url(const char *urlstr)
 {
-    char *psz_ret = NULL;
-    char *psz_tmp;
+    vlc_url_t url;
+    const char *filename = NULL;
+    char *ret = NULL;
 
-    if( !psz_sub_file )
-        return NULL;
-
-    /* Remove path */
-    const char *psz_fname = strrchr( psz_sub_file, DIR_SEP_CHAR );
-    psz_fname = (psz_fname == NULL) ? psz_sub_file : psz_fname + 1;
+    assert(urlstr != NULL);
 
-    char *psz_work = strdup( psz_fname );
-    if( !psz_work )
+    if (vlc_UrlParse(&url, urlstr) != 0)
         return NULL;
+    if (url.psz_path != NULL)
+        filename = strrchr(url.psz_path, '/');
+    if (filename != NULL) {
+        filename++; // skip forward slash
 
-    psz_tmp = strrchr( psz_work, '.' ); /* Find extension */
-    if( psz_tmp )
-    {
-        psz_tmp[0] = '\0'; /* Remove it */
+        const char *ext = strrchr(filename, '.');
 
-        /* Get substr after next last period - hopefully our language string */
-        psz_tmp = strrchr( psz_work, '.' );
-        /* Otherwise try substr after last underscore for alternate pattern */
-        if( !psz_tmp )
-            psz_tmp = strchr( psz_work, '_' );
+        if (ext != NULL) {
+            /* Get string between last two periods, hopefully the language. */
+            const char *lang = memrchr(filename, '.', ext - filename);
 
-        if( psz_tmp )
-            psz_ret = strdup(++psz_tmp);
+            /* Otherwise try string after last underscore. */
+            if (lang == NULL)
+                lang = memrchr(filename, '_', ext - filename);
+
+            if (lang != NULL) {
+                lang++; // skip period or underscore
+                ret = strndup(lang, ext - lang);
+            }
+       }
     }
 
-    free( psz_work );
-    return psz_ret;
+    vlc_UrlClean(&url);
+    return ret;
 }
 
 #ifdef ENABLE_TEST



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/26da6a882a4c74595671148bcd8451994411d54d

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/26da6a882a4c74595671148bcd8451994411d54d
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list