1 /*****************************************************************************
2 * m3u.c : M3U playlist export module
3 *****************************************************************************
4 * Copyright (C) 2004-2009 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 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_playlist.h>
34 #include <vlc_input.h>
36 #include <vlc_charset.h>
41 /*****************************************************************************
43 *****************************************************************************/
44 int Export_M3U ( vlc_object_t * );
45 int Export_M3U8( vlc_object_t * );
47 /*****************************************************************************
48 * Export_M3U: main export function
49 *****************************************************************************/
50 static void DoChildren( playlist_export_t *p_export, playlist_item_t *p_root,
51 int (*pf_fprintf) (FILE *, const char *, ...) )
54 fputs( "#EXTM3U\n", p_export->p_file );
56 /* Go through the playlist and add items */
57 for( int i = 0; i< p_root->i_children ; i++)
59 playlist_item_t *p_current = p_root->pp_children[i];
62 if( p_current->i_flags & PLAYLIST_SAVE_FLAG )
65 if( p_current->i_children >= 0 )
67 DoChildren( p_export, p_current, pf_fprintf );
73 char *psz_uri = input_item_GetURI( p_current->p_input );
77 char *psz_name = input_item_GetName( p_current->p_input );
78 if( psz_name && strcmp( psz_uri, psz_name ) )
80 char *psz_artist = input_item_GetArtist( p_current->p_input );
81 if( psz_artist == NULL ) psz_artist = strdup( "" );
82 mtime_t i_duration = input_item_GetDuration( p_current->p_input );
83 if( psz_artist && *psz_artist )
85 /* write EXTINF with artist */
86 pf_fprintf( p_export->p_file, "#EXTINF:%"PRIu64",%s - %s\n",
87 i_duration / CLOCK_FREQ, psz_artist, psz_name);
91 /* write EXTINF without artist */
92 pf_fprintf( p_export->p_file, "#EXTINF:%"PRIu64",%s\n",
93 i_duration / CLOCK_FREQ, psz_name);
99 /* VLC specific options */
100 vlc_mutex_lock( &p_current->p_input->lock );
101 for( int j = 0; j < p_current->p_input->i_options; j++ )
103 pf_fprintf( p_export->p_file, "#EXTVLCOPT:%s\n",
104 p_current->p_input->ppsz_options[j][0] == ':' ?
105 p_current->p_input->ppsz_options[j] + 1 :
106 p_current->p_input->ppsz_options[j] );
108 vlc_mutex_unlock( &p_current->p_input->lock );
110 /* Stupid third party players don't understand file: URIs. */
111 char *psz_path = make_path( psz_uri );
112 if( psz_path != NULL )
117 fprintf( p_export->p_file, "%s\n", psz_uri );
122 int Export_M3U( vlc_object_t *p_this )
124 playlist_export_t *p_export = (playlist_export_t *)p_this;
126 msg_Dbg( p_export, "saving using M3U format");
128 DoChildren( p_export, p_export->p_root, utf8_fprintf );
132 int Export_M3U8( vlc_object_t *p_this )
134 playlist_export_t *p_export = (playlist_export_t *)p_this;
136 msg_Dbg( p_export, "saving using M3U8 format");
138 DoChildren( p_export, p_export->p_root, fprintf );