]> git.sesse.net Git - vlc/blob - modules/misc/playlist/html.c
Make playlist_export_t a VLC object
[vlc] / modules / misc / playlist / html.c
1 /*****************************************************************************
2  * html.c : HTML playlist export module
3  *****************************************************************************
4  * Copyright (C) 2008-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: RĂ©mi Duraffort <ivoire@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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <vlc_common.h>
29 #include <vlc_playlist.h>
30 #include <vlc_input.h>
31 #include <vlc_strings.h>
32
33 #include <assert.h>
34
35
36 // Export the playlist in HTML
37 int Export_HTML( vlc_object_t *p_this );
38
39
40 /**
41  * Recursively follow the playlist
42  * @param p_export: the export structure
43  * @param p_root: the current node
44  */
45 static void DoChildren( playlist_export_t *p_export, playlist_item_t *p_root )
46 {
47     /* Go through the playlist and add items */
48     for( int i = 0; i < p_root->i_children ; i++)
49     {
50         playlist_item_t *p_current = p_root->pp_children[i];
51         assert( p_current );
52
53         if( p_current->i_flags & PLAYLIST_SAVE_FLAG )
54             continue;
55
56         if( p_current->i_children >= 0 )
57         {
58             DoChildren( p_export, p_current );
59             continue;
60         }
61
62         char* psz_name = NULL;
63         char *psz_tmp = input_item_GetName( p_current->p_input );
64         if( psz_tmp )
65             psz_name = convert_xml_special_chars( psz_tmp );
66         free( psz_tmp );
67
68         if( psz_name )
69         {
70             char* psz_artist = NULL;
71             psz_tmp = input_item_GetArtist( p_current->p_input );
72             if( psz_tmp )
73                 psz_artist = convert_xml_special_chars( psz_tmp );
74             free( psz_tmp );
75
76             mtime_t i_duration = input_item_GetDuration( p_current->p_input );
77             int min = ( i_duration / 1000000 ) / 60;
78             int sec = ( i_duration / 1000000 ) - min * 60;
79
80             // Print the artist if we have one
81             if( psz_artist && *psz_artist )
82                 fprintf( p_export->p_file, "    <li>%s - %s (%02d:%02d)</li>\n", psz_artist, psz_name, min, sec );
83             else
84                 fprintf( p_export->p_file, "    <li>%s (%2d:%2d)</li>\n", psz_name, min, sec );
85
86             free( psz_artist );
87         }
88         free( psz_name );
89     }
90 }
91
92
93 /**
94  * Export the playlist as an HTML page
95  * @param p_this: the playlist
96  * @return VLC_SUCCESS if everything goes fine
97  */
98 int Export_HTML( vlc_object_t *p_this )
99 {
100     playlist_export_t *p_export = (playlist_export_t *)p_this;
101
102     msg_Dbg( p_export, "saving using HTML format" );
103
104     /* Write header */
105     fprintf( p_export->p_file, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
106 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"
107 "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n"
108 "<head>\n"
109 "  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"
110 "  <meta name=\"Generator\" content=\"VLC media player\" />\n"
111 "  <meta name=\"Author\" content=\"videolan@videolan.org (VideoLAN team)\" />\n"
112 "  <title>VLC generated playlist</title>\n"
113 "  <style type=\"text/css\">\n"
114 "    body {\n"
115 "      background-color: #E4F3FF;\n"
116 "      font-family: sans-serif, Helvetica, Arial;\n"
117 "      font-size: 13px;\n"
118 "    }\n"
119 "    h1 {\n"
120 "      color: #2D58AE;\n"
121 "      font-size: 25px;\n"
122 "    }\n"
123 "    hr {\n"
124 "      color: #555555;\n"
125 "    }\n"
126 "  </style>\n"
127 "</head>\n\n"
128 "<body>\n"
129 "  <h1>Playlist</h1>\n"
130 "  <hr />\n"
131 "  <ol>\n" );
132
133     // Call the playlist constructor
134     DoChildren( p_export, p_export->p_root );
135
136     // Print the footer
137     fprintf( p_export->p_file, "  </ol>\n"
138 "  <hr />\n"
139 "</body>\n"
140 "</html>" );
141     return VLC_SUCCESS;
142 }
143