From 955442b8c805a40dfcfdba241c90f5906a446195 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Duraffort?= Date: Sun, 26 Oct 2008 17:13:08 +0100 Subject: [PATCH] Add a module to export the playlist in HTML (feature requested on the forum). --- modules/gui/qt4/dialogs_provider.cpp | 25 ++++- modules/misc/playlist/Modules.am | 1 + modules/misc/playlist/export.c | 13 ++- modules/misc/playlist/html.c | 146 +++++++++++++++++++++++++++ 4 files changed, 177 insertions(+), 8 deletions(-) create mode 100644 modules/misc/playlist/html.c diff --git a/modules/gui/qt4/dialogs_provider.cpp b/modules/gui/qt4/dialogs_provider.cpp index 8143b28e9e..c9f3920f81 100644 --- a/modules/gui/qt4/dialogs_provider.cpp +++ b/modules/gui/qt4/dialogs_provider.cpp @@ -478,7 +478,9 @@ void DialogsProvider::saveAPlaylist() qtr( "Save playlist as..." ), qfu( p_intf->p_sys->psz_filepath ), qtr( "XSPF playlist (*.xspf);; " ) + - qtr( "M3U playlist (*.m3u);; Any (*.*) " ) ); + qtr( "M3U playlist (*.m3u);; " ) + + qtr( "HTML playlist (*.html);;" ) + + qtr( "Any (*.*) " ) ); qfd->setFileMode( QFileDialog::AnyFile ); qfd->setAcceptMode( QFileDialog::AcceptSave ); qfd->setConfirmOverwrite( true ); @@ -488,25 +490,38 @@ void DialogsProvider::saveAPlaylist() if( qfd->selectedFiles().count() > 0 ) { static const char psz_xspf[] = "export-xspf", - psz_m3u[] = "export-m3u"; + psz_m3u[] = "export-m3u", + psz_html[] = "export-html"; const char *psz_module; QString file = qfd->selectedFiles().first(); QString filter = qfd->selectedFilter(); + const char* filt = filter.toAscii(); - if( file.contains( ".xsp" ) || - ( filter.contains( ".xspf" ) && !file.contains( ".m3u" ) ) ) + if( file.contains( ".xsp" ) || filter.contains( "XSPF" ) ) { psz_module = psz_xspf; if( !file.contains( ".xsp" ) ) file.append( ".xspf" ); } - else + else if( file.contains( ".m3u" ) || filter.contains( "M3U" ) ) { psz_module = psz_m3u; if( !file.contains( ".m3u" ) ) file.append( ".m3u" ); } + else if( file.contains(".html" ) || filter.contains( "HTML" ) ) + { + psz_module = psz_html; + if( !file.contains( "html" ) ) + file.append( ".html" ); + } + else + { + msg_Err( p_intf, "Impossible to recognise the file type" ); + delete qfd; + return; + } playlist_Export( THEPL, qtu( toNativeSeparators( file ) ), THEPL->p_local_category, psz_module); diff --git a/modules/misc/playlist/Modules.am b/modules/misc/playlist/Modules.am index 46b6cbe9be..ce20e1b54e 100644 --- a/modules/misc/playlist/Modules.am +++ b/modules/misc/playlist/Modules.am @@ -1,5 +1,6 @@ SOURCES_export = \ export.c \ + html.c \ m3u.c \ xspf.c \ xspf.h \ diff --git a/modules/misc/playlist/export.c b/modules/misc/playlist/export.c index 498e6a9dbd..7b05a4c7ce 100644 --- a/modules/misc/playlist/export.c +++ b/modules/misc/playlist/export.c @@ -36,6 +36,7 @@ ***************************************************************************/ int Export_M3U ( vlc_object_t *p_intf ); int Export_Old ( vlc_object_t *p_intf ); +int Export_HTML ( vlc_object_t *p_intf ); int xspf_export_playlist( vlc_object_t *p_intf ); /***************************************************************************** @@ -48,19 +49,25 @@ vlc_module_begin(); add_submodule(); set_description( N_("M3U playlist exporter") ); add_shortcut( "export-m3u" ); - set_capability( "playlist export" , 0); + set_capability( "playlist export" , 0 ); set_callbacks( Export_M3U , NULL ); add_submodule(); set_description( N_("Old playlist exporter") ); add_shortcut( "export-old" ); - set_capability( "playlist export" , 0); + set_capability( "playlist export" , 0 ); set_callbacks( Export_Old , NULL ); add_submodule(); set_description( N_("XSPF playlist export") ); add_shortcut( "export-xspf" ); - set_capability( "playlist export" , 0); + set_capability( "playlist export" , 0 ); set_callbacks( xspf_export_playlist , NULL ); + add_submodule(); + set_description( N_("HTML playlist export") ); + add_shortcut( "export-html" ); + set_capability( "playlist export", 0 ); + set_callbacks( Export_HTML, NULL ); + vlc_module_end(); diff --git a/modules/misc/playlist/html.c b/modules/misc/playlist/html.c new file mode 100644 index 0000000000..34f37d5162 --- /dev/null +++ b/modules/misc/playlist/html.c @@ -0,0 +1,146 @@ +/***************************************************************************** + * html.c : HTML playlist export module + ***************************************************************************** + * Copyright (C) 2008 the VideoLAN team + * $Id$ + * + * Authors: Rémi Duraffort + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include +#include + + + +// Export the playlist in HTML +int Export_HTML( vlc_object_t *p_this ); + + +/** + * Recursiveyy follow the playlist + * @param p_playlist: the playlist + * @param p_export: the export structure + * @param p_root: the current node + */ +static void DoChildren( playlist_t *p_playlist, playlist_export_t *p_export, + playlist_item_t *p_root ) +{ + /* Go through the playlist and add items */ + for( int i = 0; i < p_root->i_children ; i++) + { + playlist_item_t *p_current = p_root->pp_children[i]; + assert( p_current ); + + if( p_current->i_flags & PLAYLIST_SAVE_FLAG ) + continue; + + if( p_current->i_children >= 0 ) + { + DoChildren( p_playlist, p_export, p_current ); + continue; + } + + char* psz_name = NULL; + char *psz_tmp = input_item_GetName( p_current->p_input ); + if( psz_tmp ) + psz_name = convert_xml_special_chars( psz_tmp ); + free( psz_tmp ); + + if( psz_name ) + { + char* psz_artist = NULL; + psz_tmp = input_item_GetArtist( p_current->p_input ); + if( psz_tmp ) + psz_artist = convert_xml_special_chars( psz_tmp ); + free( psz_tmp ); + + mtime_t i_duration = input_item_GetDuration( p_current->p_input ); + int min = ( i_duration / 1000000 ) / 60; + int sec = ( i_duration / 1000000 ) - min * 60; + + // Print the artist if we have one + if( psz_artist && *psz_artist ) + fprintf( p_export->p_file, "
  • %s - %s (%02d:%02d)
  • \n", psz_artist, psz_name, min, sec ); + else + fprintf( p_export->p_file, "
  • %s (%2d:%2d)
  • \n", psz_name, min, sec ); + + free( psz_artist ); + } + free( psz_name ); + } +} + + +/** + * Export the playlist as an HTML page + * @param p_this: the playlist + * @return VLC_SUCCESS if everything goes fine + */ +int Export_HTML( vlc_object_t *p_this ) +{ + playlist_t *p_playlist = (playlist_t*)p_this; + playlist_export_t *p_export = (playlist_export_t *)p_playlist->p_private; + + msg_Dbg( p_playlist, "saving using HTML format" ); + + /* Write header */ + fprintf( p_export->p_file, "\n" +"\n" +"\n" +"\n" +" \n" +" \n" +" \n" +" VLC generated playlist\n" +" \n" +"\n\n" +"\n" +"

    Playlist

    \n" +"
    \n" +"
      \n" ); + + // Call the playlist constructor + DoChildren( p_playlist, p_export, p_export->p_root ); + + // Print the footer + fprintf( p_export->p_file, "
    \n" +"
    \n" +"\n" +"" ); + return VLC_SUCCESS; +} + -- 2.20.1