Commit c790b667 authored by suheaven's avatar suheaven Committed by Rémi Duraffort

Add support for wpl zpl playlist

Signed-off-by: default avatarRémi Duraffort <ivoire@videolan.org>
parent 12d37b44
/*****************************************************************************
* wpl.c : WPL playlist format import
*****************************************************************************
* Copyright (C) 2009 the VideoLAN team
*
* Authors: Su Heaven <suheaven@gmail.com>
*
* 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.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
#include <vlc_demux.h>
#include <vlc_charset.h>
#include "playlist.h"
struct demux_sys_t
{
char *psz_prefix;
};
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int Demux( demux_t *p_demux);
static int Control( demux_t *p_demux, int i_query, va_list args );
static char* ParseUriValue(char* psz_string);
/*****************************************************************************
* Import_WPL: main import function
*****************************************************************************/
int Import_WPL( vlc_object_t *p_this )
{
demux_t *p_demux = (demux_t *)p_this;
const uint8_t *p_peek;
CHECK_PEEK( p_peek, 8 );
if(! ( demux_IsPathExtension( p_demux, ".wpl" ) || demux_IsForced( p_demux, "wpl" )))
return VLC_EGENERIC;
STANDARD_DEMUX_INIT_MSG( "found valid WPL playlist" );
p_demux->p_sys->psz_prefix = FindPrefix( p_demux );
return VLC_SUCCESS;
}
/*****************************************************************************
* Deactivate: frees unused data
*****************************************************************************/
void Close_WPL( vlc_object_t *p_this )
{
demux_t *p_demux = (demux_t *)p_this;
free( p_demux->p_sys->psz_prefix );
free( p_demux->p_sys );
}
static inline void MaybeFromLocaleRep (char **str)
{
char *const orig_str = *str;
if ((orig_str != NULL) && !IsUTF8 (orig_str))
{
*str = FromLocaleDup (orig_str);
free (orig_str);
}
}
static int Demux( demux_t *p_demux )
{
char *psz_line;
char *psz_uri = NULL;
char *psz_parse;
input_item_t *p_input;
INIT_PLAYLIST_STUFF;
psz_line = stream_ReadLine( p_demux->s );
while( psz_line )
{
psz_parse = psz_line;
/* Skip leading tabs and spaces */
while( *psz_parse == ' ' || *psz_parse == '\t' ||
*psz_parse == '\n' || *psz_parse == '\r' ) psz_parse++;
if( !strncasecmp( psz_parse, "<media src=\"", sizeof( "<media src=\"" ) - 1 ) )/*if the line is uri of media item*/
{
psz_uri = ParseUriValue( psz_parse );
if( psz_uri && *psz_uri )
{
psz_uri = ProcessMRL( psz_uri, p_demux->p_sys->psz_prefix );
MaybeFromLocaleRep( &psz_uri );
p_input = input_item_NewExt( p_demux, psz_uri, psz_uri,
0, NULL, 0, -1 );
input_item_AddSubItem( p_current_input, p_input );
p_input = NULL;
free( psz_uri );
}
}
free( psz_line );
psz_line = NULL;
/* Fetch another line */
psz_line = stream_ReadLine( p_demux->s );
}
HANDLE_PLAY_AND_RELEASE;
var_Destroy( p_demux, "wpl-extvlcopt" );
return 0; /* Needed for correct operation of go back */
}
static int Control( demux_t *p_demux, int i_query, va_list args )
{
VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);
return VLC_EGENERIC;
}
static char* ParseUriValue(char* psz_string)
{
int i_len = strlen( psz_string );
if(i_len <= 3 )
return NULL;
char* psz_value = (char *)malloc( i_len );
if( ! psz_value )
return NULL;
memset( psz_value, 0, i_len );
sscanf( psz_string,"%*[^=]=\"%[^\0\r\t\n\"]", psz_value );
if( strlen( psz_value ) )
return psz_value;
free( psz_value );
return NULL;
}
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment