demux/playlist/*: Added a special "shoutcast" mode to b4s parser

rest: new services discovery module to get channels from shoutcast
parent b48b8ff1
......@@ -985,7 +985,7 @@ VLC_ADD_PLUGINS([packetizer_mpeg4video packetizer_mpeg4audio])
if test "${SYS}" != "mingwce"; then
VLC_ADD_PLUGINS([externrun])
VLC_ADD_PLUGINS([access_fake access_filter_timeshift])
VLC_ADD_PLUGINS([gestures rc telnet hotkeys netsync showintf time marq sap])
VLC_ADD_PLUGINS([gestures rc telnet hotkeys netsync showintf time marq sap shout])
VLC_ADD_PLUGINS([picture mosaic wall motiondetect clone crop])
VLC_ADD_PLUGINS([i420_yuy2 i422_yuy2 i420_ymga])
VLC_ADD_PLUGINS([aout_file linear_resampler bandlimited_resampler])
......
/*****************************************************************************
* b4s.c : B4S playlist format import
*****************************************************************************
* Copyright (C) 2004 VideoLAN
* $Id: m3u.c 10101 2005-03-02 16:47:31Z robux4 $
* Copyright (C) 2005 VideoLAN
* $Id$
*
* Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
*
......@@ -40,6 +40,7 @@ struct demux_sys_t
playlist_t *p_playlist;
xml_t *p_xml;
xml_reader_t *p_xml_reader;
int b_shout;
};
/*****************************************************************************
......@@ -48,6 +49,9 @@ struct demux_sys_t
static int Demux( demux_t *p_demux);
static int Control( demux_t *p_demux, int i_query, va_list args );
static int IsWhitespace( char *psz_string );
static void ShoutcastAdd( playlist_t *p_playlist, playlist_item_t* p_genre,
playlist_item_t *p_bitrate, playlist_item_t *p_item,
char *psz_genre, char *psz_bitrate );
/*****************************************************************************
* Import_B4S: main import function
......@@ -61,7 +65,8 @@ int Import_B4S( vlc_object_t *p_this )
psz_ext = strrchr ( p_demux->psz_path, '.' );
if( ( psz_ext && !strcasecmp( psz_ext, ".b4s") ) ||
( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "b4s-open") ) )
( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "b4s-open") ) ||
( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "shout-b4s") ) )
{
;
}
......@@ -79,6 +84,8 @@ int Import_B4S( vlc_object_t *p_this )
msg_Err( p_demux, "Out of memory" );
return VLC_ENOMEM;
}
p_demux->p_sys->b_shout = p_demux->psz_demux &&
!strcmp(p_demux->psz_demux, "shout-b4s");
p_demux->p_sys->psz_prefix = FindPrefix( p_demux );
return VLC_SUCCESS;
......@@ -103,7 +110,7 @@ static int Demux( demux_t *p_demux )
{
demux_sys_t *p_sys = p_demux->p_sys;
playlist_t *p_playlist;
playlist_item_t *p_item, *p_current;
playlist_item_t *p_item, *p_current, *p_bitrate, *p_genre;
vlc_bool_t b_play;
int i_ret;
......@@ -111,11 +118,13 @@ static int Demux( demux_t *p_demux )
xml_t *p_xml;
xml_reader_t *p_xml_reader;
char *psz_elname = NULL;
int i_type;
int i_type, b_shoutcast;
char *psz_mrl = NULL, *psz_name = NULL, *psz_genre = NULL;
char *psz_now = NULL, *psz_listeners = NULL, *psz_bitrate = NULL;
b_shoutcast = p_sys->b_shout;
p_playlist = (playlist_t *) vlc_object_find( p_demux, VLC_OBJECT_PLAYLIST,
FIND_PARENT );
if( !p_playlist )
......@@ -129,6 +138,14 @@ static int Demux( demux_t *p_demux )
playlist_ItemToNode( p_playlist, p_current );
p_current->input.i_type = ITEM_TYPE_PLAYLIST;
if( b_shoutcast )
{
p_genre = playlist_NodeCreate( p_playlist, p_current->pp_parents[0]->i_view, "Genre", p_current );
playlist_CopyParents( p_current, p_genre );
p_bitrate = playlist_NodeCreate( p_playlist, p_current->pp_parents[0]->i_view, "Bitrate", p_current );
playlist_CopyParents( p_current, p_bitrate );
}
p_xml = p_sys->p_xml = xml_Create( p_demux );
if( !p_xml ) return -1;
......@@ -334,6 +351,9 @@ static int Demux( demux_t *p_demux )
vlc_input_item_CopyOptions( &p_current->input,
&p_item->input );
if( b_shoutcast )
ShoutcastAdd( p_playlist, p_genre, p_bitrate, p_item,
psz_genre, psz_bitrate );
#define FREE(a) if( a ) free( a ); a = NULL;
FREE( psz_name );
FREE( psz_mrl );
......@@ -355,6 +375,12 @@ static int Demux( demux_t *p_demux )
{
msg_Warn( p_demux, "error while parsing data" );
}
if( b_shoutcast )
{
vlc_mutex_lock( &p_playlist->object_lock );
playlist_NodeSort( p_playlist, p_bitrate, SORT_TITLE_NUMERIC, ORDER_NORMAL );
vlc_mutex_unlock( &p_playlist->object_lock );
}
/* Go back and play the playlist */
if( b_play )
......@@ -387,3 +413,38 @@ static int IsWhitespace( char *psz_string )
}
return VLC_TRUE;
}
static void ShoutcastAdd( playlist_t *p_playlist, playlist_item_t* p_genre,
playlist_item_t *p_bitrate, playlist_item_t *p_item,
char *psz_genre, char *psz_bitrate )
{
playlist_item_t *p_parent;
if( psz_bitrate )
{
playlist_item_t *p_copy = playlist_ItemCopy(p_playlist,p_item);
p_parent = playlist_ChildSearchName( p_bitrate, psz_bitrate );
if( !p_parent )
{
p_parent = playlist_NodeCreate( p_playlist, p_genre->pp_parents[0]->i_view, psz_bitrate,
p_bitrate );
playlist_CopyParents( p_bitrate, p_parent );
}
playlist_NodeAddItem( p_playlist, p_copy, p_parent->pp_parents[0]->i_view, p_parent, PLAYLIST_APPEND, PLAYLIST_END );
playlist_CopyParents( p_parent, p_copy );
}
if( psz_genre )
{
playlist_item_t *p_copy = playlist_ItemCopy(p_playlist,p_item);
p_parent = playlist_ChildSearchName( p_genre, psz_genre );
if( !p_parent )
{
p_parent = playlist_NodeCreate( p_playlist, p_genre->pp_parents[0]->i_view, psz_genre,
p_genre );
playlist_CopyParents( p_genre, p_parent );
}
playlist_NodeAddItem( p_playlist, p_copy, p_parent->pp_parents[0]->i_view, p_parent, PLAYLIST_APPEND, PLAYLIST_END );
playlist_CopyParents( p_parent, p_copy );
}
}
......@@ -63,6 +63,7 @@ vlc_module_begin();
add_submodule();
set_description( _("B4S playlist import") );
add_shortcut( "b4s-open" );
add_shortcut( "shout-b4s" );
set_capability( "demux2", 10 );
set_callbacks( Import_B4S, Close_B4S );
vlc_module_end();
......
SOURCES_sap = sap.c
SOURCES_hal = hal.c
SOURCES_daap = daap.c
SOURCES_shout = shout.c
/*****************************************************************************
* sap.c : SAP interface module
*****************************************************************************
* Copyright (C) 2004 VideoLAN
* $Id: sap.c 9217 2004-11-07 11:02:59Z courmisch $
*
* Authors: Clment Stenac <zorglub@videolan.org>
*
* 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.
*****************************************************************************/
/*****************************************************************************
* Includes
*****************************************************************************/
#include <stdlib.h> /* malloc(), free() */
#include <vlc/vlc.h>
#include <vlc/intf.h>
#include <vlc/input.h>
#include "network.h"
#include <errno.h> /* ENOMEM */
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
/************************************************************************
* Macros and definitions
************************************************************************/
#define MAX_LINE_LENGTH 256
/*****************************************************************************
* Module descriptor
*****************************************************************************/
/* Callbacks */
static int Open ( vlc_object_t * );
static void Close( vlc_object_t * );
vlc_module_begin();
set_description( _("HAL device detection") );
set_category( CAT_PLAYLIST );
set_subcategory( SUBCAT_PLAYLIST_SD );
set_capability( "services_discovery", 0 );
set_callbacks( Open, Close );
vlc_module_end();
/*****************************************************************************
* Local structures
*****************************************************************************/
struct services_discovery_sys_t
{
/* playlist node */
playlist_item_t *p_node;
input_thread_t *p_input;
};
/*****************************************************************************
* Local prototypes
*****************************************************************************/
/* Main functions */
static void Run ( services_discovery_t *p_intf );
/*****************************************************************************
* Open: initialize and create stuff
*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
services_discovery_t *p_sd = ( services_discovery_t* )p_this;
services_discovery_sys_t *p_sys = malloc(
sizeof( services_discovery_sys_t ) );
vlc_value_t val;
playlist_t *p_playlist;
playlist_view_t *p_view;
playlist_item_t *p_item;
p_sd->pf_run = Run;
p_sd->p_sys = p_sys;
/* Create our playlist node */
p_playlist = (playlist_t *)vlc_object_find( p_sd, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
if( !p_playlist )
{
msg_Warn( p_sd, "unable to find playlist, cancelling");
return VLC_EGENERIC;
}
p_view = playlist_ViewFind( p_playlist, VIEW_CATEGORY );
p_sys->p_node = playlist_NodeCreate( p_playlist, VIEW_CATEGORY,
_("Shoutcast"), p_view->p_root );
p_item = playlist_ItemNew( p_playlist, "http/shout-b4s://shoutcast.com/sbin/xmllister.phtml?service=vlc&no_compress=1&limit=1000", "Top 1000" );
playlist_NodeAddItem( p_playlist, p_item,
p_sys->p_node->pp_parents[0]->i_view,
p_sys->p_node, PLAYLIST_APPEND,
PLAYLIST_END );
p_sys->p_input = input_CreateThread( p_playlist, &p_item->input );
/* We need to declare the parents of the node as the same of the
* parent's ones */
playlist_CopyParents( p_sys->p_node, p_item );
p_sys->p_node->i_flags |= PLAYLIST_RO_FLAG;
val.b_bool = VLC_TRUE;
var_Set( p_playlist, "intf-change", val );
vlc_object_release( p_playlist );
return VLC_SUCCESS;
}
/*****************************************************************************
* Close:
*****************************************************************************/
static void Close( vlc_object_t *p_this )
{
services_discovery_t *p_sd = ( services_discovery_t* )p_this;
services_discovery_sys_t *p_sys = p_sd->p_sys;
playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_sd,
VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
if( p_playlist )
{
playlist_NodeDelete( p_playlist, p_sys->p_node, VLC_TRUE, VLC_TRUE );
vlc_object_release( p_playlist );
}
if( p_sd->p_sys->p_input )
{
input_StopThread( p_sd->p_sys->p_input );
input_DestroyThread( p_sd->p_sys->p_input );
vlc_object_detach( p_sd->p_sys->p_input );
vlc_object_destroy( p_sd->p_sys->p_input );
p_sd->p_sys->p_input = NULL;
}
free( p_sys );
}
/*****************************************************************************
* Run: main thread
*****************************************************************************/
static void Run( services_discovery_t *p_sd )
{
while( !p_sd->b_die )
{
if( p_sd->p_sys->p_input &&
( p_sd->p_sys->p_input->b_eof || p_sd->p_sys->p_input->b_error ) )
{
input_StopThread( p_sd->p_sys->p_input );
input_DestroyThread( p_sd->p_sys->p_input );
vlc_object_detach( p_sd->p_sys->p_input );
vlc_object_destroy( p_sd->p_sys->p_input );
p_sd->p_sys->p_input = NULL;
}
msleep( 100000 );
}
}
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