X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fmisc%2Fplaylist%2Fm3u.c;h=72e9581b87f8d147d17034087b9d0dee2ce2a25d;hb=e50a251c828bfc7ce98813959abc49e1ce0580fe;hp=01f4dcfe327c6b7090fdd20ef27826539ff941ce;hpb=ed0b72e3714ad87cb4e10b9a7239e19b9ef0724e;p=vlc diff --git a/modules/misc/playlist/m3u.c b/modules/misc/playlist/m3u.c index 01f4dcfe32..72e9581b87 100644 --- a/modules/misc/playlist/m3u.c +++ b/modules/misc/playlist/m3u.c @@ -1,7 +1,7 @@ /***************************************************************************** - * m3u.c : M3U playlist export module + * m3u.c : M3U playlist export module ***************************************************************************** - * Copyright (C) 2004 the VideoLAN team + * Copyright (C) 2004-2009 the VideoLAN team * $Id$ * * Authors: Clément Stenac @@ -24,78 +24,117 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include #include +#include +#include -#include /* ENOMEM */ +#include /***************************************************************************** * Local prototypes *****************************************************************************/ int Export_M3U ( vlc_object_t * ); +int Export_M3U8( vlc_object_t * ); /***************************************************************************** * Export_M3U: main export function *****************************************************************************/ -int Export_M3U( vlc_object_t *p_this ) +static void DoChildren( playlist_export_t *p_export, playlist_item_t *p_root, + int (*pf_fprintf) (FILE *, const char *, ...) ) { - playlist_t *p_playlist = (playlist_t*)p_this; - playlist_export_t *p_export = (playlist_export_t *)p_playlist->p_private; - int i, j; - - msg_Dbg(p_playlist, "saving using M3U format"); - /* Write header */ - fprintf( p_export->p_file, "#EXTM3U\n" ); + fputs( "#EXTM3U\n", p_export->p_file ); /* Go through the playlist and add items */ - for( i = 0; i< p_export->p_root->i_children ; i++) + for( int i = 0; i< p_root->i_children ; i++) { - playlist_item_t *p_current = p_export->p_root->pp_children[i]; + playlist_item_t *p_current = p_root->pp_children[i]; + assert( p_current ); + if( p_current->i_flags & PLAYLIST_SAVE_FLAG ) continue; + if( p_current->i_children >= 0 ) + { + DoChildren( p_export, p_current, pf_fprintf ); + continue; + } + /* General info */ - if( p_current->p_input->psz_name && - strcmp( p_current->p_input->psz_uri, - p_current->p_input->psz_name ) ) + + char *psz_uri = input_item_GetURI( p_current->p_input ); + + assert( psz_uri ); + + char *psz_name = input_item_GetName( p_current->p_input ); + if( psz_name && strcmp( psz_uri, psz_name ) ) { - char *psz_artist = p_current->p_input->p_meta->psz_artist ? - strdup( p_current->p_input->p_meta->psz_artist ): - strdup( "" ); + char *psz_artist = input_item_GetArtist( p_current->p_input ); + if( psz_artist == NULL ) psz_artist = strdup( "" ); + mtime_t i_duration = input_item_GetDuration( p_current->p_input ); if( psz_artist && *psz_artist ) { /* write EXTINF with artist */ - fprintf( p_export->p_file, "#EXTINF:%i,%s - %s\n", - (int)( p_current->p_input->i_duration/1000000 ), - psz_artist, - p_current->p_input->psz_name); + pf_fprintf( p_export->p_file, "#EXTINF:%"PRIu64",%s - %s\n", + i_duration / CLOCK_FREQ, psz_artist, psz_name); } else { /* write EXTINF without artist */ - fprintf( p_export->p_file, "#EXTINF:%i,%s\n", - (int)( p_current->p_input->i_duration/1000000 ), - p_current->p_input->psz_name); + pf_fprintf( p_export->p_file, "#EXTINF:%"PRIu64",%s\n", + i_duration / CLOCK_FREQ, psz_name); } - if( psz_artist ) - free( psz_artist ); + free( psz_artist ); } + free( psz_name ); /* VLC specific options */ - for( j = 0; j < p_current->p_input->i_options; j++ ) + vlc_mutex_lock( &p_current->p_input->lock ); + for( int j = 0; j < p_current->p_input->i_options; j++ ) { - fprintf( p_export->p_file, "#EXTVLCOPT:%s\n", - p_current->p_input->ppsz_options[j][0] == ':' ? - p_current->p_input->ppsz_options[j] + 1 : - p_current->p_input->ppsz_options[j] ); + pf_fprintf( p_export->p_file, "#EXTVLCOPT:%s\n", + p_current->p_input->ppsz_options[j][0] == ':' ? + p_current->p_input->ppsz_options[j] + 1 : + p_current->p_input->ppsz_options[j] ); } + vlc_mutex_unlock( &p_current->p_input->lock ); - fprintf( p_export->p_file, "%s\n", - p_current->p_input->psz_uri ); + /* Stupid third party players don't understand file: URIs. */ + char *psz_path = make_path( psz_uri ); + if( psz_path != NULL ) + { + free( psz_uri ); + psz_uri = psz_path; + } + fprintf( p_export->p_file, "%s\n", psz_uri ); + free( psz_uri ); } +} + +int Export_M3U( vlc_object_t *p_this ) +{ + playlist_export_t *p_export = (playlist_export_t *)p_this; + + msg_Dbg( p_export, "saving using M3U format"); + + DoChildren( p_export, p_export->p_root, utf8_fprintf ); + return VLC_SUCCESS; +} + +int Export_M3U8( vlc_object_t *p_this ) +{ + playlist_export_t *p_export = (playlist_export_t *)p_this; + + msg_Dbg( p_export, "saving using M3U8 format"); + + DoChildren( p_export, p_export->p_root, fprintf ); return VLC_SUCCESS; }