]> git.sesse.net Git - vlc/blob - modules/misc/playlist/m3u.c
* configure.ac : Added new folders
[vlc] / modules / misc / playlist / m3u.c
1 /*****************************************************************************
2  * m3u.c :  M3U playlist export module
3  *****************************************************************************
4  * Copyright (C) 2004 VideoLAN
5  * $Id: m3u.c,v 1.1 2004/01/11 00:45:06 zorglub Exp $
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28
29 #include <vlc/vlc.h>
30 #include <vlc/intf.h>
31
32 #include <errno.h>                                                 /* ENOMEM */
33
34 /*****************************************************************************
35  * Local prototypes
36  *****************************************************************************/
37 int Export_M3U ( vlc_object_t * );
38
39 /*****************************************************************************
40  * Export_M3U: main export function
41  *****************************************************************************/
42 int Export_M3U( vlc_object_t *p_this )
43 {
44     playlist_t *p_playlist = (playlist_t*)p_this;
45     playlist_export_t *p_export = (playlist_export_t *)p_playlist->p_private;
46     int i;
47
48     msg_Dbg(p_playlist, "Saving using M3U format");
49
50     /* Write header */
51     fprintf( p_export->p_file, "#EXTM3U\n" );
52
53     /* Go through the playlist and add items */
54     for( i = 0; i< p_playlist->i_size ; i++)
55     {
56         if( strcmp( p_playlist->pp_items[i]->psz_name,
57                     p_playlist->pp_items[i]->psz_uri ) )
58         {
59             char *psz_author = playlist_GetInfo( p_playlist, i, _("General"),
60                                                  _("Author") );
61             fprintf( p_export->p_file,"#EXTINF:%i,%s%s\n",
62                      (int)(p_playlist->pp_items[i]->i_duration/1000000),
63                      psz_author ? psz_author : "",
64                      p_playlist->pp_items[i]->psz_name );
65         }
66         fprintf( p_export->p_file, "%s\n", p_playlist->pp_items[i]->psz_uri );
67     }
68     return VLC_SUCCESS;
69 }