📄 m3u.c
字号:
/***************************************************************************** * m3u.c: a meta demux to parse pls, m3u, asx et b4s playlists ***************************************************************************** * Copyright (C) 2001-2004 VideoLAN * $Id: m3u.c 9961 2005-02-16 22:01:41Z robux4 $ * * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no> * Gildas Bazin <gbazin@videolan.org> * Cl閙ent Stenac <zorglub@via.ecp.fr> * * 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <stdlib.h> /* malloc(), free() */#include <vlc/vlc.h>#include <vlc/input.h>#include <vlc_playlist.h>/***************************************************************************** * Constants and structures *****************************************************************************/#define MAX_LINE 8192#define TYPE_UNKNOWN 0#define TYPE_M3U 1#define TYPE_ASX 2#define TYPE_HTML 3#define TYPE_PLS 4#define TYPE_B4S 5#define TYPE_WMP 6#define TYPE_RTSP 7struct demux_sys_t{ int i_type; /* playlist type (m3u/asx) */};/***************************************************************************** * Local prototypes *****************************************************************************/static int Activate ( vlc_object_t * );static void Deactivate( vlc_object_t * );static int Demux ( demux_t * );static int Control ( demux_t *, int, va_list );/***************************************************************************** * Module descriptor *****************************************************************************/vlc_module_begin(); set_category( CAT_INPUT ); set_subcategory( SUBCAT_INPUT_DEMUX ); set_description( _("Playlist metademux") ); set_capability( "demux2", 5 ); set_callbacks( Activate, Deactivate ); add_shortcut( "m3u" ); add_shortcut( "asx" ); add_shortcut( "html" ); add_shortcut( "pls" ); add_shortcut( "b4s" );vlc_module_end();/***************************************************************************** * Activate: initializes m3u demux structures *****************************************************************************/static int Activate( vlc_object_t * p_this ){ demux_t *p_demux = (demux_t *)p_this; char *psz_ext; int i_type = TYPE_UNKNOWN; int i_type2 = TYPE_UNKNOWN; p_demux->pf_control = Control; p_demux->pf_demux = Demux; /* Check for m3u/asx file extension or if the demux has been forced */ psz_ext = strrchr ( p_demux->psz_path, '.' ); if( ( psz_ext && !strcasecmp( psz_ext, ".m3u") ) || /* a .ram file can contain a single rtsp link */ ( psz_ext && !strcasecmp( psz_ext, ".ram") ) || ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "m3u") ) ) { i_type = TYPE_M3U; } else if( ( psz_ext && !strcasecmp( psz_ext, ".asx") ) || ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "asx") ) ) { i_type = TYPE_ASX; } else if( ( psz_ext && !strcasecmp( psz_ext, ".html") ) || ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "html") ) ) { i_type = TYPE_HTML; } else if( ( psz_ext && !strcasecmp( psz_ext, ".pls") ) || ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "pls") ) ) { i_type = TYPE_PLS; } else if( ( psz_ext && !strcasecmp( psz_ext, ".b4s") ) || ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "b4s") ) ) { i_type = TYPE_B4S; } /* we had no luck looking at the file extention, so we have a look * at the content. This is useful for .asp, .php and similar files * that are actually html. Also useful for some asx files that have * another extension */ /* We double check for file != m3u as some asx are just m3u file */ if( i_type != TYPE_M3U ) { uint8_t *p_peek; int i_size = stream_Peek( p_demux->s, &p_peek, MAX_LINE ); i_size -= sizeof("[Reference]") - 1; if( i_size > 0 ) { while( i_size && strncasecmp(p_peek, "[playlist]", sizeof("[playlist]") - 1) && strncasecmp( p_peek, "[Reference]", sizeof("[Reference]") - 1 ) && strncasecmp( p_peek, "<html>", sizeof("<html>") - 1 ) && strncasecmp( p_peek, "<asx", sizeof("<asx") - 1 ) && strncasecmp( p_peek, "rtsptext", sizeof("rtsptext") - 1 ) && strncasecmp( p_peek, "<?xml", sizeof("<?xml") -1 ) ) { p_peek++; i_size--; } if( !i_size ) { ; } else if( !strncasecmp( p_peek, "[playlist]", sizeof("[playlist]") -1 ) ) { i_type2 = TYPE_PLS; } else if( !strncasecmp( p_peek, "[Reference]", sizeof("[Reference]") -1 ) ) { i_type2 = TYPE_WMP; } else if( !strncasecmp( p_peek, "<html>", sizeof("<html>") -1 ) ) { i_type2 = TYPE_HTML; } else if( !strncasecmp( p_peek, "<asx", sizeof("<asx") -1 ) ) { i_type2 = TYPE_ASX; } else if( !strncasecmp( p_peek, "rtsptext", sizeof("rtsptext") -1 ) ) { i_type2 = TYPE_RTSP; }#if 0 else if( !strncasecmp( p_peek, "<?xml", sizeof("<?xml") -1 ) ) { i_type2 = TYPE_B4S; }#endif } } if( i_type == TYPE_UNKNOWN && i_type2 == TYPE_UNKNOWN) { return VLC_EGENERIC; } if( i_type != TYPE_UNKNOWN && i_type2 == TYPE_UNKNOWN ) { i_type = TYPE_M3U; } else { i_type = i_type2; } /* Allocate p_m3u */ p_demux->p_sys = malloc( sizeof( demux_sys_t ) ); p_demux->p_sys->i_type = i_type; msg_Dbg( p_this, "Playlist type: %d - %d", i_type, i_type2 ); return VLC_SUCCESS;}/***************************************************************************** * Deactivate: frees unused data *****************************************************************************/static void Deactivate( vlc_object_t *p_this ){ demux_t *p_demux = (demux_t *)p_this; free( p_demux->p_sys );}/***************************************************************************** * XMLSpecialChars: Handle the special chars in a XML file. * ***************************************************************************/static void XMLSpecialChars ( char *str ){ char *src = str; char *dst = str; while( *src ) { if( *src == '&' ) { if( !strncasecmp( src, "à", 6 ) ) *dst++ = '
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -