Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

m3u.c

00001 /*****************************************************************************
00002  * m3u.c :  M3U playlist export module
00003  *****************************************************************************
00004  * Copyright (C) 2004 the VideoLAN team
00005  * $Id: m3u.c 12558 2005-09-15 06:17:33Z zorglub $
00006  *
00007  * Authors: Clément Stenac <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>                                      /* malloc(), free() */
00028 
00029 #include <vlc/vlc.h>
00030 #include <vlc/intf.h>
00031 
00032 #include <errno.h>                                                 /* ENOMEM */
00033 
00034 /*****************************************************************************
00035  * Local prototypes
00036  *****************************************************************************/
00037 int Export_M3U ( vlc_object_t * );
00038 
00039 /*****************************************************************************
00040  * Export_M3U: main export function
00041  *****************************************************************************/
00042 int Export_M3U( vlc_object_t *p_this )
00043 {
00044     playlist_t *p_playlist = (playlist_t*)p_this;
00045     playlist_export_t *p_export = (playlist_export_t *)p_playlist->p_private;
00046     int i, j;
00047 
00048     msg_Dbg(p_playlist, "Saving using M3U format");
00049 
00050     /* Write header */
00051     fprintf( p_export->p_file, "#EXTM3U\n" );
00052 
00053     /* Go through the playlist and add items */
00054     for( i = 0; i< p_playlist->i_size ; i++)
00055     {
00056         if( (p_playlist->pp_items[i]->i_flags & PLAYLIST_SAVE_FLAG) == 0 )
00057         {
00058             continue;
00059         }
00060 
00061         /* General info */
00062         if( p_playlist->pp_items[i]->input.psz_name &&
00063              strcmp( p_playlist->pp_items[i]->input.psz_name,
00064                     p_playlist->pp_items[i]->input.psz_uri ) )
00065         {
00066             char *psz_artist =
00067                 vlc_input_item_GetInfo( &p_playlist->pp_items[i]->input,
00068                                         _("Meta-information"), _("Artist") );
00069             if( psz_artist && *psz_artist )
00070             {
00071                 /* write EXTINF with artist */
00072                 fprintf( p_export->p_file, "#EXTINF:%i,%s - %s\n",
00073                          (int)(p_playlist->pp_items[i]->input.i_duration/1000000),
00074                          psz_artist,
00075                          p_playlist->pp_items[i]->input.psz_name );
00076             }
00077             else
00078             {
00079                 /* write EXTINF without artist */
00080                 fprintf( p_export->p_file, "#EXTINF:%i,%s\n",
00081                        (int)(p_playlist->pp_items[i]->input.i_duration/1000000),
00082                          p_playlist->pp_items[i]->input.psz_name );
00083             }
00084             if( psz_artist )
00085                 free( psz_artist );
00086         }
00087 
00088         /* VLC specific options */
00089         for( j = 0; j < p_playlist->pp_items[i]->input.i_options; j++ )
00090         {
00091             fprintf( p_export->p_file, "#EXTVLCOPT:%s\n",
00092                      p_playlist->pp_items[i]->input.ppsz_options[j][0] == ':' ?
00093                      p_playlist->pp_items[i]->input.ppsz_options[j] + 1 :
00094                      p_playlist->pp_items[i]->input.ppsz_options[j] );
00095         }
00096 
00097         fprintf( p_export->p_file, "%s\n",
00098                  p_playlist->pp_items[i]->input.psz_uri );
00099     }
00100     return VLC_SUCCESS;
00101 }

Generated on Tue Dec 20 10:14:32 2005 for vlc-0.8.4a by  doxygen 1.4.2