]> git.sesse.net Git - vlc/blob - modules/services_discovery/shout.c
87f3520c1a20209a0ff1f817e9cbf5a2e4b9314f
[vlc] / modules / services_discovery / shout.c
1 /*****************************************************************************
2  * shout.c:  Shoutcast services discovery module
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
8  *          Antoine Cellerier <dionoea -@T- videolan -d.t- org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Includes
27  *****************************************************************************/
28 #include <stdlib.h>                                      /* malloc(), free() */
29
30 #include <vlc/vlc.h>
31 #include <vlc_playlist.h>
32 #include <vlc_interface.h>
33
34 #include <vlc_network.h>
35
36 #include <errno.h>                                                 /* ENOMEM */
37
38 #ifdef HAVE_UNISTD_H
39 #    include <unistd.h>
40 #endif
41 #ifdef HAVE_SYS_TIME_H
42 #    include <sys/time.h>
43 #endif
44
45 /************************************************************************
46  * Macros and definitions
47  ************************************************************************/
48
49 #define MAX_LINE_LENGTH 256
50 #define SHOUTCAST_BASE_URL "http/shout-winamp://www.shoutcast.com/sbin/newxml.phtml"
51 #define SHOUTCAST_TV_BASE_URL "http/shout-winamp://www.shoutcast.com/sbin/newtvlister.phtml?alltv=1"
52
53 /*****************************************************************************
54  * Module descriptor
55  *****************************************************************************/
56
57 /* Callbacks */
58     static int  Open ( vlc_object_t *, int );
59     static int  OpenRadio ( vlc_object_t * );
60     static int  OpenTV ( vlc_object_t * );
61     static void Close( vlc_object_t * );
62
63 vlc_module_begin();
64     set_shortname( "Shoutcast");
65     set_description( _("Shoutcast radio listings") );
66     add_shortcut( "shoutcast" );
67     set_category( CAT_PLAYLIST );
68     set_subcategory( SUBCAT_PLAYLIST_SD );
69
70     add_suppressed_integer( "shoutcast-limit" );
71
72     set_capability( "services_discovery", 0 );
73     set_callbacks( OpenRadio, Close );
74
75     add_submodule();
76         set_shortname( "ShoutcastTV" );
77         set_description( _("Shoutcast TV listings") );
78         set_capability( "services_discovery", 0 );
79         set_callbacks( OpenTV, Close );
80         add_shortcut( "shoutcasttv" );
81
82 vlc_module_end();
83
84
85 /*****************************************************************************
86  * Local structures
87  *****************************************************************************/
88
89 struct services_discovery_sys_t
90 {
91     playlist_item_t *p_node_cat,*p_node_one;
92     input_item_t *p_input;
93     vlc_bool_t b_dialog;
94 };
95
96 #define RADIO 0
97 #define TV 1
98
99 /*****************************************************************************
100  * Local prototypes
101  *****************************************************************************/
102
103 /* Main functions */
104 static int OpenRadio( vlc_object_t *p_this )
105 {
106     return Open( p_this, RADIO );
107 }
108
109 static int OpenTV( vlc_object_t *p_this )
110 {
111     return Open( p_this, TV );
112 }
113
114 /*****************************************************************************
115  * Open: initialize and create stuff
116  *****************************************************************************/
117 static int Open( vlc_object_t *p_this, int i_type )
118 {
119     services_discovery_t *p_sd = ( services_discovery_t* )p_this;
120     playlist_t          *p_playlist = pl_Yield( p_this );
121     DECMALLOC_ERR( p_sys, services_discovery_sys_t );
122     p_sd->p_sys  = p_sys;
123
124     switch( i_type )
125     {
126         case TV:
127             p_sys->p_input = input_ItemNewExt( p_playlist,
128                                 SHOUTCAST_TV_BASE_URL, _("Shoutcast TV"),
129                                 0, NULL, -1 );
130             break;
131         case RADIO:
132         default:
133             p_sys->p_input = input_ItemNewExt( p_playlist,
134                                 SHOUTCAST_BASE_URL, _("Shoutcast"),
135                                 0, NULL, -1 );
136             break;
137     }
138     input_ItemAddOption( p_sys->p_input, "no-playlist-autostart" );
139     p_sys->p_input->b_prefers_tree = VLC_TRUE;
140     p_sys->p_node_cat = playlist_NodeAddInput( p_playlist, p_sys->p_input,
141                            p_playlist->p_root_category,
142                            PLAYLIST_APPEND, PLAYLIST_END, VLC_FALSE );
143     p_sys->p_node_one = playlist_NodeAddInput( p_playlist, p_sys->p_input,
144                            p_playlist->p_root_onelevel,
145                            PLAYLIST_APPEND, PLAYLIST_END, VLC_FALSE );
146     p_sys->p_node_cat->i_flags |= PLAYLIST_RO_FLAG;
147     p_sys->p_node_cat->i_flags |= PLAYLIST_SKIP_FLAG;
148     p_sys->p_node_one->i_flags |= PLAYLIST_RO_FLAG;
149     p_sys->p_node_one->i_flags |= PLAYLIST_SKIP_FLAG;
150     p_sys->p_node_one->p_input->i_id = p_sys->p_node_cat->p_input->i_id;
151
152     var_SetVoid( p_playlist, "intf-change" );
153
154     pl_Release( p_this );
155
156     input_Read( p_sd, p_sys->p_input, VLC_FALSE );
157     return VLC_SUCCESS;
158 }
159
160 /*****************************************************************************
161  * Close:
162  *****************************************************************************/
163 static void Close( vlc_object_t *p_this )
164 {
165     services_discovery_t *p_sd = ( services_discovery_t* )p_this;
166     services_discovery_sys_t *p_sys  = p_sd->p_sys;
167     playlist_t *p_playlist =  pl_Yield( p_sd );
168     playlist_NodeDelete( p_playlist, p_sys->p_node_cat, VLC_TRUE, VLC_FALSE );
169     playlist_NodeDelete( p_playlist, p_sys->p_node_one, VLC_TRUE, VLC_FALSE );
170     pl_Release( p_sd );
171     free( p_sys );
172 }