1 /*****************************************************************************
2 * m3u.c : M3U playlist export module
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
30 #include <vlc_interface.h>
31 #include <vlc_playlist.h>
32 #include <vlc_input.h>
35 #include <errno.h> /* ENOMEM */
37 /*****************************************************************************
39 *****************************************************************************/
40 int Export_M3U ( vlc_object_t * );
42 /*****************************************************************************
43 * Export_M3U: main export function
44 *****************************************************************************/
45 int Export_M3U( vlc_object_t *p_this )
47 playlist_t *p_playlist = (playlist_t*)p_this;
48 playlist_export_t *p_export = (playlist_export_t *)p_playlist->p_private;
51 msg_Dbg(p_playlist, "saving using M3U format");
54 fprintf( p_export->p_file, "#EXTM3U\n" );
56 /* Go through the playlist and add items */
57 for( i = 0; i< p_export->p_root->i_children ; i++)
59 playlist_item_t *p_current = p_export->p_root->pp_children[i];
60 if( p_current->i_flags & PLAYLIST_SAVE_FLAG )
64 if( p_current->p_input->psz_name &&
65 strcmp( p_current->p_input->psz_uri,
66 p_current->p_input->psz_name ) )
68 char *psz_artist = p_current->p_input->p_meta->psz_artist ?
69 strdup( p_current->p_input->p_meta->psz_artist ):
71 if( psz_artist && *psz_artist )
73 /* write EXTINF with artist */
74 fprintf( p_export->p_file, "#EXTINF:%i,%s - %s\n",
75 (int)( p_current->p_input->i_duration/1000000 ),
77 p_current->p_input->psz_name);
81 /* write EXTINF without artist */
82 fprintf( p_export->p_file, "#EXTINF:%i,%s\n",
83 (int)( p_current->p_input->i_duration/1000000 ),
84 p_current->p_input->psz_name);
90 /* VLC specific options */
91 for( j = 0; j < p_current->p_input->i_options; j++ )
93 fprintf( p_export->p_file, "#EXTVLCOPT:%s\n",
94 p_current->p_input->ppsz_options[j][0] == ':' ?
95 p_current->p_input->ppsz_options[j] + 1 :
96 p_current->p_input->ppsz_options[j] );
99 fprintf( p_export->p_file, "%s\n",
100 p_current->p_input->psz_uri );