shout.c 5.43 KB
Newer Older
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 11 12 13 14 15 16 17 18 19 20 21
 *
 * 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
Antoine Cellerier's avatar
Antoine Cellerier committed
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 24 25 26 27 28 29
 *****************************************************************************/

/*****************************************************************************
 * Includes
 *****************************************************************************/

#include <vlc/vlc.h>
Clément Stenac's avatar
Clément Stenac committed
30 31
#include <vlc_playlist.h>
#include <vlc_interface.h>
32

Clément Stenac's avatar
Clément Stenac committed
33
#include <vlc_network.h>
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

#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
49
#define SHOUTCAST_BASE_URL "http/shout-winamp://www.shoutcast.com/sbin/newxml.phtml"
50
#define SHOUTCAST_TV_BASE_URL "http/shout-winamp://www.shoutcast.com/sbin/newtvlister.phtml?alltv=1"
51 52 53 54 55 56

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/

/* Callbacks */
57 58 59
    static int  Open ( vlc_object_t *, int );
    static int  OpenRadio ( vlc_object_t * );
    static int  OpenTV ( vlc_object_t * );
60 61 62
    static void Close( vlc_object_t * );

vlc_module_begin();
63
    set_shortname( "Shoutcast");
64
    set_description( _("Shoutcast radio listings") );
65
    add_shortcut( "shoutcast" );
66 67 68
    set_category( CAT_PLAYLIST );
    set_subcategory( SUBCAT_PLAYLIST_SD );

69
    add_obsolete_integer( "shoutcast-limit" );
70

71
    set_capability( "services_discovery", 0 );
72 73 74 75 76 77 78 79
    set_callbacks( OpenRadio, Close );

    add_submodule();
        set_shortname( "ShoutcastTV" );
        set_description( _("Shoutcast TV listings") );
        set_capability( "services_discovery", 0 );
        set_callbacks( OpenTV, Close );
        add_shortcut( "shoutcasttv" );
80 81 82 83 84 85 86 87 88 89

vlc_module_end();


/*****************************************************************************
 * Local structures
 *****************************************************************************/

struct services_discovery_sys_t
{
Clément Stenac's avatar
Clément Stenac committed
90
    input_item_t *p_input;
91
    vlc_bool_t b_dialog;
92 93
};

94 95 96
#define RADIO 0
#define TV 1

97 98 99 100
/*****************************************************************************
 * Local prototypes
 *****************************************************************************/

101 102
static void Run( services_discovery_t *p_sd );

103
/* Main functions */
104 105 106 107 108 109 110 111 112 113
static int OpenRadio( vlc_object_t *p_this )
{
    return Open( p_this, RADIO );
}

static int OpenTV( vlc_object_t *p_this )
{
    return Open( p_this, TV );
}

114 115 116
/*****************************************************************************
 * Open: initialize and create stuff
 *****************************************************************************/
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
    DECMALLOC_ERR( p_sys, services_discovery_sys_t );
121
    p_sd->p_sys  = p_sys;
122
    p_sd->pf_run = Run;
123

124 125 126
    switch( i_type )
    {
        case TV:
127
            p_sys->p_input = input_ItemNewExt( p_sd,
Clément Stenac's avatar
Clément Stenac committed
128 129
                                SHOUTCAST_TV_BASE_URL, _("Shoutcast TV"),
                                0, NULL, -1 );
130 131 132
            break;
        case RADIO:
        default:
133
            p_sys->p_input = input_ItemNewExt( p_sd,
134
                                SHOUTCAST_BASE_URL, _("Shoutcast Radio"),
Clément Stenac's avatar
Clément Stenac committed
135
                                0, NULL, -1 );
136 137
            break;
    }
138
    input_ItemAddOption( p_sys->p_input, "no-playlist-autostart" );
139 140 141
    return VLC_SUCCESS;
}

142 143 144 145 146
/*****************************************************************************
 * Run:
 *****************************************************************************/
static void Run( services_discovery_t *p_sd )
{
Pierre d'Herbemont's avatar
Pierre d'Herbemont committed
147
    p_sd->p_sys->p_input->b_prefers_tree = VLC_TRUE;
148 149 150 151 152
    services_discovery_AddItem( p_sd, p_sd->p_sys->p_input, NULL /* no category */ );

    input_Read( pl_Yield(p_sd), p_sd->p_sys->p_input, VLC_FALSE );
}

153 154 155 156 157 158 159
/*****************************************************************************
 * 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;
160
    services_discovery_RemoveItem( p_sd, p_sys->p_input );
161 162
    free( p_sys );
}