Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

shout.c

00001 /*****************************************************************************
00002  * shout.c:  Shoutcast services discovery module
00003  *****************************************************************************
00004  * Copyright (C) 2005 the VideoLAN team
00005  * $Id: shout.c 12836 2005-10-15 13:23:08Z sigmunau $
00006  *
00007  * Authors: Sigmund Augdal Helberg <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Includes
00026  *****************************************************************************/
00027 #include <stdlib.h>                                      /* malloc(), free() */
00028 
00029 #include <vlc/vlc.h>
00030 #include <vlc/intf.h>
00031 
00032 #include <vlc/input.h>
00033 
00034 #include "network.h"
00035 
00036 #include <errno.h>                                                 /* ENOMEM */
00037 
00038 #ifdef HAVE_UNISTD_H
00039 #    include <unistd.h>
00040 #endif
00041 #ifdef HAVE_SYS_TIME_H
00042 #    include <sys/time.h>
00043 #endif
00044 
00045 /************************************************************************
00046  * Macros and definitions
00047  ************************************************************************/
00048 
00049 #define MAX_LINE_LENGTH 256
00050 
00051 
00052 /*****************************************************************************
00053  * Module descriptor
00054  *****************************************************************************/
00055 
00056 /* Callbacks */
00057     static int  Open ( vlc_object_t * );
00058     static void Close( vlc_object_t * );
00059 
00060 #define LIMIT_TEXT N_("Maximum number of shoutcast servers to be listed")
00061 #define LIMIT_LONGTEXT LIMIT_TEXT
00062 
00063 vlc_module_begin();
00064     set_shortname( "Shoutcast");
00065     set_description( _("Shoutcast radio listings") );
00066     set_category( CAT_PLAYLIST );
00067     set_subcategory( SUBCAT_PLAYLIST_SD );
00068 
00069     add_integer( "shoutcast-limit", 1000, NULL, LIMIT_TEXT,
00070                     LIMIT_LONGTEXT, VLC_TRUE );
00071 
00072     set_capability( "services_discovery", 0 );
00073     set_callbacks( Open, Close );
00074 
00075 vlc_module_end();
00076 
00077 
00078 /*****************************************************************************
00079  * Local structures
00080  *****************************************************************************/
00081 
00082 struct services_discovery_sys_t
00083 {
00084     /* playlist node */
00085     playlist_item_t *p_node;
00086     input_thread_t *p_input;
00087 
00088 };
00089 
00090 /*****************************************************************************
00091  * Local prototypes
00092  *****************************************************************************/
00093 
00094 /* Main functions */
00095     static void Run    ( services_discovery_t *p_intf );
00096 
00097 /*****************************************************************************
00098  * Open: initialize and create stuff
00099  *****************************************************************************/
00100 static int Open( vlc_object_t *p_this )
00101 {
00102     services_discovery_t *p_sd = ( services_discovery_t* )p_this;
00103     services_discovery_sys_t *p_sys  = malloc(
00104                                     sizeof( services_discovery_sys_t ) );
00105 
00106     vlc_value_t         val;
00107     playlist_t          *p_playlist;
00108     playlist_view_t     *p_view;
00109     playlist_item_t     *p_item;
00110 
00111     int i_limit;
00112     char *psz_shoutcast_url;
00113     char *psz_shoutcast_title;
00114 
00115     p_sd->pf_run = Run;
00116     p_sd->p_sys  = p_sys;
00117 
00118     /* Create our playlist node */
00119     p_playlist = (playlist_t *)vlc_object_find( p_sd, VLC_OBJECT_PLAYLIST,
00120                                                 FIND_ANYWHERE );
00121     if( !p_playlist )
00122     {
00123         msg_Warn( p_sd, "unable to find playlist, cancelling");
00124         return VLC_EGENERIC;
00125     }
00126 
00127     i_limit = config_GetInt( p_this->p_libvlc, "shoutcast-limit" );
00128     #define SHOUTCAST_BASE_URL "http/shout-b4s://www.shoutcast.com/sbin/xmllister.phtml?service=vlc&no_compress=1&limit="
00129     psz_shoutcast_url = (char *)malloc( strlen( SHOUTCAST_BASE_URL ) + 20 );
00130     psz_shoutcast_title = (char *)malloc( 6 + 20 );
00131 
00132     sprintf( psz_shoutcast_url, SHOUTCAST_BASE_URL "%d", i_limit );
00133     sprintf( psz_shoutcast_title, "Top %d", i_limit );
00134 
00135     p_view = playlist_ViewFind( p_playlist, VIEW_CATEGORY );
00136     p_sys->p_node = playlist_NodeCreate( p_playlist, VIEW_CATEGORY,
00137                                          _("Shoutcast"), p_view->p_root );
00138     p_item = playlist_ItemNew( p_playlist, psz_shoutcast_url,
00139                                      psz_shoutcast_title );
00140     free( psz_shoutcast_url );
00141     free( psz_shoutcast_title );
00142     playlist_NodeAddItem( p_playlist, p_item,
00143                           p_sys->p_node->pp_parents[0]->i_view,
00144                           p_sys->p_node, PLAYLIST_APPEND,
00145                           PLAYLIST_END );
00146 
00147     /* We need to declare the parents of the node as the same of the
00148      * parent's ones */
00149     playlist_CopyParents( p_sys->p_node, p_item );
00150     
00151 
00152     p_sys->p_input = input_CreateThread( p_playlist, &p_item->input );
00153 
00154     p_sys->p_node->i_flags |= PLAYLIST_RO_FLAG;
00155     val.b_bool = VLC_TRUE;
00156     var_Set( p_playlist, "intf-change", val );
00157 
00158     vlc_object_release( p_playlist );
00159 
00160     return VLC_SUCCESS;
00161 }
00162 
00163 /*****************************************************************************
00164  * Close:
00165  *****************************************************************************/
00166 static void Close( vlc_object_t *p_this )
00167 {
00168     services_discovery_t *p_sd = ( services_discovery_t* )p_this;
00169     services_discovery_sys_t *p_sys  = p_sd->p_sys;
00170     playlist_t *p_playlist =  (playlist_t *) vlc_object_find( p_sd,
00171                                  VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00172     if( p_sd->p_sys->p_input )
00173     {
00174         input_StopThread( p_sd->p_sys->p_input );
00175         input_DestroyThread( p_sd->p_sys->p_input );
00176         vlc_object_detach( p_sd->p_sys->p_input );
00177         vlc_object_destroy( p_sd->p_sys->p_input );
00178         p_sd->p_sys->p_input = NULL;        
00179     }
00180     if( p_playlist )
00181     {
00182         playlist_NodeDelete( p_playlist, p_sys->p_node, VLC_TRUE, VLC_TRUE );
00183         vlc_object_release( p_playlist );
00184     }
00185     free( p_sys );
00186 }
00187 
00188 /*****************************************************************************
00189  * Run: main thread
00190  *****************************************************************************/
00191 static void Run( services_discovery_t *p_sd )
00192 {
00193     while( !p_sd->b_die )
00194     {
00195         if( p_sd->p_sys->p_input &&
00196             ( p_sd->p_sys->p_input->b_eof || p_sd->p_sys->p_input->b_error ) )
00197         {
00198             input_StopThread( p_sd->p_sys->p_input );
00199             input_DestroyThread( p_sd->p_sys->p_input );
00200             vlc_object_detach( p_sd->p_sys->p_input );
00201             vlc_object_destroy( p_sd->p_sys->p_input );
00202             p_sd->p_sys->p_input = NULL;
00203         }
00204         msleep( 100000 );
00205     }
00206 }

Generated on Tue Dec 20 10:14:27 2005 for vlc-0.8.4a by  doxygen 1.4.2