Commit d27f781f authored by Gildas Bazin's avatar Gildas Bazin

* modules/misc/playlist/m3u.c: save VLC input options with the "#EXTVLCOPT:" tag.

* modules/demux/m3u.c: parse the "#EXTVLCOPT:" tag.
parent 9f2aa4b1
...@@ -226,7 +226,6 @@ static void XMLSpecialChars ( char *str ) ...@@ -226,7 +226,6 @@ static void XMLSpecialChars ( char *str )
*dst = '\0'; *dst = '\0';
} }
/***************************************************************************** /*****************************************************************************
* ParseLine: read a "line" from the file and add any entries found * ParseLine: read a "line" from the file and add any entries found
* to the playlist. Returns: * to the playlist. Returns:
...@@ -237,11 +236,11 @@ static void XMLSpecialChars ( char *str ) ...@@ -237,11 +236,11 @@ static void XMLSpecialChars ( char *str )
* XXX psz_data has the same length that psz_line so no problem if you don't * XXX psz_data has the same length that psz_line so no problem if you don't
* expand it * expand it
* psz_line is \0 terminated * psz_line is \0 terminated
******************************************************************************/ *****************************************************************************/
static int ParseLine ( input_thread_t *p_input, char *psz_line, char *psz_data, vlc_bool_t *pb_next ) static int ParseLine( input_thread_t *p_input, char *psz_line, char *psz_data,
vlc_bool_t *pb_next )
{ {
demux_sys_t *p_m3u = p_input->p_demux_data; demux_sys_t *p_m3u = p_input->p_demux_data;
char *psz_bol, *psz_name; char *psz_bol, *psz_name;
psz_bol = psz_line; psz_bol = psz_line;
...@@ -261,18 +260,33 @@ static int ParseLine ( input_thread_t *p_input, char *psz_line, char *psz_data, ...@@ -261,18 +260,33 @@ static int ParseLine ( input_thread_t *p_input, char *psz_line, char *psz_data,
if( *psz_bol == '#' ) if( *psz_bol == '#' )
{ {
while( *psz_bol && while( *psz_bol &&
strncasecmp( psz_bol, "EXTINF:", sizeof("EXTINF:") - 1 ) ) strncasecmp( psz_bol, "EXTINF:",
psz_bol++; sizeof("EXTINF:") - 1 ) &&
strncasecmp( psz_bol, "EXTVLCOPT:",
sizeof("EXTVLCOPT:") - 1 ) ) psz_bol++;
if( !*psz_bol ) return 0; if( !*psz_bol ) return 0;
if( !strncasecmp( psz_bol, "EXTINF:", sizeof("EXTINF:") - 1 ) )
{
psz_bol = strchr( psz_bol, ',' ); psz_bol = strchr( psz_bol, ',' );
if ( !psz_bol ) return 0; if ( !psz_bol ) return 0;
psz_bol++; psz_bol++;
/* From now, we have a name line */
/* From now, we have a name line */
strcpy( psz_data , psz_bol ); strcpy( psz_data , psz_bol );
return 2; return 2;
} }
else
{
psz_bol = strchr( psz_bol, ':' );
if ( !psz_bol ) return 0;
psz_bol++;
strcpy( psz_data , psz_bol );
return 3;
}
}
/* If we don't have a comment, the line is directly the URI */ /* If we don't have a comment, the line is directly the URI */
} }
else if ( p_m3u->i_type == TYPE_PLS ) else if ( p_m3u->i_type == TYPE_PLS )
...@@ -525,6 +539,7 @@ static int ParseLine ( input_thread_t *p_input, char *psz_line, char *psz_data, ...@@ -525,6 +539,7 @@ static int ParseLine ( input_thread_t *p_input, char *psz_line, char *psz_data,
static void ProcessLine ( input_thread_t *p_input, playlist_t *p_playlist, static void ProcessLine ( input_thread_t *p_input, playlist_t *p_playlist,
char *psz_line, char *psz_line,
char **ppsz_uri, char **ppsz_name, char **ppsz_uri, char **ppsz_name,
int *pi_options, char ***pppsz_options,
int *pi_position ) int *pi_position )
{ {
char psz_data[MAX_LINE]; char psz_data[MAX_LINE];
...@@ -546,6 +561,12 @@ static void ProcessLine ( input_thread_t *p_input, playlist_t *p_playlist, ...@@ -546,6 +561,12 @@ static void ProcessLine ( input_thread_t *p_input, playlist_t *p_playlist,
} }
*ppsz_name = strdup( psz_data ); *ppsz_name = strdup( psz_data );
break; break;
case 3:
(*pi_options)++;
*pppsz_options = realloc( *pppsz_options,
sizeof(char *) * *pi_options );
(*pppsz_options)[*pi_options - 1] = strdup( psz_data );
break;
case 0: case 0:
default: default:
break; break;
...@@ -553,17 +574,20 @@ static void ProcessLine ( input_thread_t *p_input, playlist_t *p_playlist, ...@@ -553,17 +574,20 @@ static void ProcessLine ( input_thread_t *p_input, playlist_t *p_playlist,
if( b_next && *ppsz_uri ) if( b_next && *ppsz_uri )
{ {
playlist_Add( p_playlist, *ppsz_uri, playlist_AddExt( p_playlist, *ppsz_uri, *ppsz_name,
*ppsz_name ? *ppsz_name : *ppsz_uri, PLAYLIST_INSERT, *pi_position,
PLAYLIST_INSERT, *pi_position ); -1, (const char **)*pppsz_options, *pi_options );
(*pi_position)++; (*pi_position)++;
if( *ppsz_name ) if( *ppsz_name ) free( *ppsz_name ); *ppsz_name = NULL;
free( *ppsz_uri ); *ppsz_uri = NULL;
for( ; *pi_options; (*pi_options)-- )
{ {
free( *ppsz_name ); free( (*pppsz_options)[*pi_options - 1] );
if( *pi_options == 1 ) free( *pppsz_options );
} }
free( *ppsz_uri ); *pppsz_options = NULL;
*ppsz_name = NULL;
*ppsz_uri = NULL;
} }
} }
...@@ -583,9 +607,10 @@ static int Demux ( input_thread_t *p_input ) ...@@ -583,9 +607,10 @@ static int Demux ( input_thread_t *p_input )
playlist_t *p_playlist; playlist_t *p_playlist;
vlc_bool_t b_discard = VLC_FALSE; vlc_bool_t b_discard = VLC_FALSE;
char *psz_name = NULL; char *psz_name = NULL;
char *psz_uri = NULL; char *psz_uri = NULL;
int i_options = 0;
char **ppsz_options = NULL;
int i_position; int i_position;
...@@ -647,7 +672,7 @@ static int Demux ( input_thread_t *p_input ) ...@@ -647,7 +672,7 @@ static int Demux ( input_thread_t *p_input )
i_linepos = 0; i_linepos = 0;
ProcessLine( p_input, p_playlist, psz_line, &psz_uri, &psz_name, ProcessLine( p_input, p_playlist, psz_line, &psz_uri, &psz_name,
&i_position ); &i_options, &ppsz_options, &i_position );
} }
input_DeletePacket( p_input->p_method_data, p_data ); input_DeletePacket( p_input->p_method_data, p_data );
...@@ -658,22 +683,23 @@ static int Demux ( input_thread_t *p_input ) ...@@ -658,22 +683,23 @@ static int Demux ( input_thread_t *p_input )
psz_line[i_linepos] = '\0'; psz_line[i_linepos] = '\0';
ProcessLine( p_input, p_playlist, psz_line, &psz_uri, &psz_name, ProcessLine( p_input, p_playlist, psz_line, &psz_uri, &psz_name,
&i_position ); &i_options, &ppsz_options, &i_position );
/* is there a pendding uri without b_next */
/* Is there a pendding uri without b_next */
if( psz_uri ) if( psz_uri )
{ {
playlist_Add( p_playlist, psz_uri, psz_uri, playlist_AddExt( p_playlist, psz_uri, psz_name,
PLAYLIST_INSERT, i_position ); PLAYLIST_INSERT, i_position,
-1, (const char **)ppsz_options, i_options );
} }
} }
if( psz_uri ) if( psz_uri ) free( psz_uri );
if( psz_name ) free( psz_name );
for( ; i_options; i_options-- )
{ {
free( psz_uri ); free( ppsz_options[i_options - 1] );
} if( i_options == 1 ) free( ppsz_options );
if( psz_name )
{
free( psz_name );
} }
vlc_object_release( p_playlist ); vlc_object_release( p_playlist );
......
...@@ -43,7 +43,7 @@ int Export_M3U( vlc_object_t *p_this ) ...@@ -43,7 +43,7 @@ int Export_M3U( vlc_object_t *p_this )
{ {
playlist_t *p_playlist = (playlist_t*)p_this; playlist_t *p_playlist = (playlist_t*)p_this;
playlist_export_t *p_export = (playlist_export_t *)p_playlist->p_private; playlist_export_t *p_export = (playlist_export_t *)p_playlist->p_private;
int i; int i, j;
msg_Dbg(p_playlist, "Saving using M3U format"); msg_Dbg(p_playlist, "Saving using M3U format");
...@@ -53,16 +53,29 @@ int Export_M3U( vlc_object_t *p_this ) ...@@ -53,16 +53,29 @@ int Export_M3U( vlc_object_t *p_this )
/* Go through the playlist and add items */ /* Go through the playlist and add items */
for( i = 0; i< p_playlist->i_size ; i++) for( i = 0; i< p_playlist->i_size ; i++)
{ {
if( strcmp( p_playlist->pp_items[i]->input.psz_name, /* General info */
if( p_playlist->pp_items[i]->input.psz_name &&
strcmp( p_playlist->pp_items[i]->input.psz_name,
p_playlist->pp_items[i]->input.psz_uri ) ) p_playlist->pp_items[i]->input.psz_uri ) )
{ {
char *psz_author = playlist_GetInfo( p_playlist, i, _("General"), char *psz_author =
_("Author") ); playlist_GetInfo( p_playlist, i, _("General"), _("Author") );
fprintf( p_export->p_file,"#EXTINF:%i,%s%s\n",
fprintf( p_export->p_file, "#EXTINF:%i,%s,%s\n",
(int)(p_playlist->pp_items[i]->input.i_duration/1000000), (int)(p_playlist->pp_items[i]->input.i_duration/1000000),
psz_author ? psz_author : "", psz_author ? psz_author : "",
p_playlist->pp_items[i]->input.psz_name ); p_playlist->pp_items[i]->input.psz_name );
} }
/* VLC specific options */
for( j = 0; j < p_playlist->pp_items[i]->input.i_options; j++ )
{
fprintf( p_export->p_file, "#EXTVLCOPT:%s\n",
p_playlist->pp_items[i]->input.ppsz_options[j][0] == ':' ?
p_playlist->pp_items[i]->input.ppsz_options[j] + 1 :
p_playlist->pp_items[i]->input.ppsz_options[j] );
}
fprintf( p_export->p_file, "%s\n", fprintf( p_export->p_file, "%s\n",
p_playlist->pp_items[i]->input.psz_uri ); p_playlist->pp_items[i]->input.psz_uri );
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment