Add a module to export the playlist in HTML (feature requested on the forum).
authorRémi Duraffort <ivoire@videolan.org>
Sun, 26 Oct 2008 16:13:08 +0000 (17:13 +0100)
committerRémi Duraffort <ivoire@videolan.org>
Sun, 26 Oct 2008 16:19:08 +0000 (17:19 +0100)
modules/gui/qt4/dialogs_provider.cpp
modules/misc/playlist/Modules.am
modules/misc/playlist/export.c
modules/misc/playlist/html.c [new file with mode: 0644]

index 8143b28..c9f3920 100644 (file)
@@ -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);
index 46b6cbe..ce20e1b 100644 (file)
@@ -1,5 +1,6 @@
 SOURCES_export = \
        export.c \
+        html.c \
        m3u.c \
        xspf.c \
        xspf.h \
index 498e6a9..7b05a4c 100644 (file)
@@ -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 (file)
index 0000000..34f37d5
--- /dev/null
@@ -0,0 +1,146 @@
+/*****************************************************************************
+ * html.c : HTML playlist export module
+ *****************************************************************************
+ * Copyright (C) 2008 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Rémi Duraffort <ivoire@videolan.org>
+ *
+ * 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 <vlc_common.h>
+#include <vlc_playlist.h>
+#include <vlc_input.h>
+#include <vlc_meta.h>
+#include <vlc_strings.h>
+
+
+
+// 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, "    <li>%s - %s (%02d:%02d)</li>\n", psz_artist, psz_name, min, sec );
+            else
+                fprintf( p_export->p_file, "    <li>%s (%2d:%2d)</li>\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, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
+"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"
+"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n"
+"<head>\n"
+"  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"
+"  <meta name=\"Generator\" content=\"VLC media player\" />\n"
+"  <meta name=\"Author\" content=\"videolan@videolan.org (VideoLAN team)\" />\n"
+"  <title>VLC generated playlist</title>\n"
+"  <style type=\"text/css\">\n"
+"    body {\n"
+"      background-color: #E4F3FF;\n"
+"      font-family: sans-serif, Helvetica, Arial;\n"
+"      font-size: 13px;\n"
+"    }\n"
+"    h1 {\n"
+"      color: #2D58AE;\n"
+"      font-size: 25px;\n"
+"    }\n"
+"    hr {\n"
+"      color: #555555;\n"
+"    }\n"
+"  </style>\n"
+"</head>\n\n"
+"<body>\n"
+"  <h1>Playlist</h1>\n"
+"  <hr />\n"
+"  <ol>\n" );
+
+    // Call the playlist constructor
+    DoChildren( p_playlist, p_export, p_export->p_root );
+
+    // Print the footer
+    fprintf( p_export->p_file, "  </ol>\n"
+"  <hr />\n"
+"</body>\n"
+"</html>" );
+    return VLC_SUCCESS;
+}
+