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