html.c
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:5k
源码类别:

midi

开发平台:

Unix_Linux

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