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 *****************************************************************************/
29 #include <vlc_interface.h>
30 #include <vlc_playlist.h>
31 #include <vlc_input.h>
34 #include <errno.h> /* ENOMEM */
36 /*****************************************************************************
38 *****************************************************************************/
39 int Export_M3U ( vlc_object_t * );
41 /*****************************************************************************
42 * Export_M3U: main export function
43 *****************************************************************************/
44 static void DoChildren( playlist_t *p_playlist, playlist_export_t *p_export,
45 playlist_item_t *p_root )
49 /* Go through the playlist and add items */
50 for( i = 0; i< p_root->i_children ; i++)
52 playlist_item_t *p_current = p_root->pp_children[i];
55 if( p_current->i_flags & PLAYLIST_SAVE_FLAG )
58 if( p_current->i_children >= 0 )
60 DoChildren( p_playlist, p_export, p_current );
66 char *psz_uri = input_item_GetURI( p_current->p_input );
70 char *psz_name = input_item_GetName( p_current->p_input );
71 if( psz_name && strcmp( psz_uri, psz_name ) )
73 char *psz_artist = input_item_GetArtist( p_current->p_input );
74 if( psz_artist == NULL ) psz_artist = strdup( "" );
75 mtime_t i_duration = input_item_GetDuration( p_current->p_input );
76 if( psz_artist && *psz_artist )
78 /* write EXTINF with artist */
79 fprintf( p_export->p_file, "#EXTINF:%i,%s - %s\n",
80 (int)( i_duration / 1000000 ), psz_artist, psz_name);
84 /* write EXTINF without artist */
85 fprintf( p_export->p_file, "#EXTINF:%i,%s\n",
86 (int)( i_duration / 1000000 ), psz_name);
93 /* VLC specific options */
94 vlc_mutex_lock( &p_current->p_input->lock );
95 for( j = 0; j < p_current->p_input->i_options; j++ )
97 fprintf( p_export->p_file, "#EXTVLCOPT:%s\n",
98 p_current->p_input->ppsz_options[j][0] == ':' ?
99 p_current->p_input->ppsz_options[j] + 1 :
100 p_current->p_input->ppsz_options[j] );
102 vlc_mutex_unlock( &p_current->p_input->lock );
104 fprintf( p_export->p_file, "%s\n", psz_uri );
108 int Export_M3U( vlc_object_t *p_this )
110 playlist_t *p_playlist = (playlist_t*)p_this;
111 playlist_export_t *p_export = (playlist_export_t *)p_playlist->p_private;
113 msg_Dbg(p_playlist, "saving using M3U format");
116 fprintf( p_export->p_file, "#EXTM3U\n" );
118 DoChildren( p_playlist, p_export, p_export->p_root );