<div>This patch was motivated by the following forum topic:</div><a href="http://forum.videolan.org/viewtopic.php?f=7&t=98342">http://forum.videolan.org/viewtopic.php?f=7&t=98342</a><div><br><div class="gmail_quote">
On Fri, Feb 1, 2013 at 5:46 PM, Walter Cacau <span dir="ltr"><<a href="mailto:waltercacau@gmail.com" target="_blank">waltercacau@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
A user who has many subtitles for a single video can now distinguish<br>
between them by the suffix containing language information.<br>
<br>
So, for example, suppose the user has a video file named "video.mp4".<br>
If he names a subtitle as "video.en.srt", the English language will<br>
be detected. Similarly, he can name other subtitles with different<br>
languages, ex: "video.pt.srt", "video.pt-BR.srt", ...<br>
<br>
If the subtitle name is equal to the video name (except for the<br>
file extension), then no language is detected.<br>
<br>
This change has the positive side effect of making the subtitle menu<br>
show the detected language instead of only "Track X".<br>
---<br>
modules/demux/subtitle.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++<br>
1 file changed, 57 insertions(+)<br>
<br>
diff --git a/modules/demux/subtitle.c b/modules/demux/subtitle.c<br>
index aa1c7e6..dd91dbe 100644<br>
--- a/modules/demux/subtitle.c<br>
+++ b/modules/demux/subtitle.c<br>
@@ -35,6 +35,7 @@<br>
#include <vlc_plugin.h><br>
#include <vlc_input.h><br>
#include <vlc_memory.h><br>
+#include <vlc_url.h><br>
<br>
#include <ctype.h><br>
<br>
@@ -223,6 +224,7 @@ static int Demux( demux_t * );<br>
static int Control( demux_t *, int, va_list );<br>
<br>
static void Fix( demux_t * );<br>
+static char * get_language_from_filename( const char *, const char * );<br>
<br>
/*****************************************************************************<br>
* Module initializer<br>
@@ -529,6 +531,19 @@ static int Open ( vlc_object_t *p_this )<br>
}<br>
else<br>
es_format_Init( &fmt, SPU_ES, VLC_CODEC_SUBT );<br>
+<br>
+ /* Detecting subtitle language using its filename */<br>
+ char * psz_language = get_language_from_filename(<br>
+ p_demux->psz_location,<br>
+ input_GetItem(p_demux->p_input)->psz_uri<br>
+ );<br>
+ if( psz_language )<br>
+ {<br>
+ fmt.psz_language = psz_language;<br>
+ msg_Dbg( p_demux, "detected language %s of subtitle: %s", psz_language,<br>
+ p_demux->psz_location );<br>
+ }<br>
+<br>
if( unicode )<br>
fmt.subs.psz_encoding = strdup( "UTF-8" );<br>
char *psz_description = var_InheritString( p_demux, "sub-description" );<br>
@@ -2079,3 +2094,45 @@ static int ParseSubViewer1( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx<br>
return VLC_SUCCESS;<br>
}<br>
<br>
+static char * get_language_from_filename( const char * psz_sub_location,<br>
+ const char * psz_video_url )<br>
+{<br>
+ char * psz_ret = NULL;<br>
+ char * psz_video_file = NULL;<br>
+ char * psz_sub_file = NULL;<br>
+ char * psz_tmp;<br>
+ char * psz_sub_suffix;<br>
+ char * ps_language_end;<br>
+<br>
+ psz_video_file = strrchr( psz_video_url, '/' );<br>
+ if( !psz_video_file ) goto end;<br>
+ psz_video_file++;<br>
+ psz_video_file = decode_URI_duplicate(psz_video_file);<br>
+ if( !psz_video_file ) goto end;<br>
+<br>
+ psz_sub_file = strrchr( psz_sub_location, '/' );<br>
+ if( !psz_sub_file ) goto end;<br>
+ psz_sub_file++;<br>
+ psz_sub_file = decode_URI_duplicate(psz_sub_file);<br>
+ if( !psz_video_file ) goto end;<br>
+<br>
+ /* Removing extension, but leaving the dot */<br>
+ psz_tmp = strrchr( psz_video_file, '.' );<br>
+ if( !psz_tmp ) goto end;<br>
+ psz_tmp[1] = '\0';<br>
+<br>
+ /* Extracting sub file prefix */<br>
+ if( strstr(psz_sub_file, psz_video_file) != psz_sub_file ) goto end;<br>
+ psz_sub_suffix = psz_sub_file + strlen(psz_video_file);<br>
+<br>
+ ps_language_end = strrchr( psz_sub_suffix, '.' );<br>
+ if( !ps_language_end ) goto end;<br>
+ *ps_language_end = '\0';<br>
+<br>
+ psz_ret = strdup(psz_sub_suffix);<br>
+<br>
+end:<br>
+ FREENULL(psz_video_file);<br>
+ FREENULL(psz_sub_file);<br>
+ return psz_ret;<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.12.4 (Apple Git-37)<br>
<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>Walter Carlos P. Cacau Filho<br>ITA T12 - Engenharia de Computação<div><a href="mailto:waltercacau@gmail.com" target="_blank">waltercacau@gmail.com</a></div>
</div>