Changeset 12087b5571643095d90eb5ecc1825594d93e31da

Show
Ignore:
Timestamp:
01/19/08 21:56:18 (8 months ago)
Author:
Pierre d'Herbemont <pdherbemont@videolan.org>
git-committer:
Pierre d'Herbemont <pdherbemont@videolan.org> 1200776178 +0000
git-parent:

[3613b8a933d9e4785f6d3541cf5f2aaca25b3402]

git-author:
Pierre d'Herbemont <pdherbemont@videolan.org> 1200776178 +0000
Message:

services/discovery/shout.c: Add a French TV service discovery. For now it only has C+ and les guignols.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/services_discovery/shout.c

    rf087502 r12087b5  
    3535 *****************************************************************************/ 
    3636 
    37 enum type_e { ShoutRadio = 0, ShoutTV = 1, Freebox = 2 }; 
     37enum type_e { ShoutRadio = 0, ShoutTV = 1, Freebox = 2, FrenchTV = 3 }; 
    3838 
    3939static int  Open( vlc_object_t *, enum type_e ); 
    4040static void Close( vlc_object_t * ); 
    4141 
    42 static const struc
     42struct shout_item_
    4343{ 
    4444    const char *psz_url; 
    4545    const char *psz_name; 
    4646    const char *ppsz_options[2]; 
    47 } p_items[] = { 
    48     { "http/shout-winamp://www.shoutcast.com/sbin/newxml.phtml", 
    49       N_("Shoutcast Radio"), { NULL } }, 
    50     { "http/shout-winamp://www.shoutcast.com/sbin/newtvlister.phtml?alltv=1", 
    51       N_("Shoutcast TV"), { NULL } }, 
    52     { "http://mafreebox.freebox.fr/freeboxtv/playlist.m3u", 
    53       N_("Freebox TV"), { "m3u-extvlcopt=1", NULL } }, 
     47    const struct shout_item_t * p_children; 
     48}; 
     49 
     50#define endItem( ) { NULL, NULL, { NULL }, NULL } 
     51#define item( title, url ) { url, title, { NULL }, NULL } 
     52#define itemWithOption( title, url, option ) { url, title, { option, NULL }, NULL } 
     53#define itemWithChildren( title, children ) { "vlc:skip", title, { NULL }, children } 
     54 
     55/* WARN: We support only two levels */ 
     56 
     57static const struct shout_item_t p_frenchtv_canalplus[] = { 
     58    item( N_("Les Guignols"), "http://www.canalplus.fr/index.php?pid=1784" ), 
     59    endItem() 
     60}; 
     61     
     62static const struct shout_item_t p_frenchtv[] = { 
     63    itemWithChildren( N_("Canal +"),  p_frenchtv_canalplus ), 
     64    endItem() 
     65}; 
     66 
     67static const struct shout_item_t p_items[] = { 
     68    item(            N_("Shoutcast Radio"), "http/shout-winamp://www.shoutcast.com/sbin/newxml.phtml" ), 
     69    item(            N_("Shoutcast TV"),    "http/shout-winamp://www.shoutcast.com/sbin/newtvlister.phtml?alltv=1" ), 
     70    itemWithOption ( N_("Freebox TV"),      "http://mafreebox.freebox.fr/freeboxtv/playlist.m3u", "m3u-extvlcopt=1" ), 
     71    itemWithChildren(N_("French TV"),        p_frenchtv ), 
     72    endItem() 
     73}; 
     74 
     75#undef endItem 
     76#undef item 
     77#undef itemWithOptions 
     78#undef itemWithChildren 
     79 
     80struct shout_category_t { 
     81    services_discovery_t * p_sd; 
     82    const char * psz_category; 
    5483}; 
    5584 
     
    5887static int Open ## type ( vlc_object_t *p_this )    \ 
    5988{                                                   \ 
     89    msg_Dbg( p_this, "Starting " #type );           \ 
    6090    return Open( p_this, type );                    \ 
    6191} 
     
    6494OPEN( ShoutTV ) 
    6595OPEN( Freebox ) 
     96OPEN( FrenchTV ) 
    6697 
    6798vlc_module_begin(); 
     
    83114        set_callbacks( OpenShoutTV, Close ); 
    84115        add_shortcut( "shoutcasttv" ); 
     116 
     117    add_submodule(); 
     118        set_shortname( "frenchtv"); 
     119        set_description( _("French TV") ); 
     120        set_capability( "services_discovery", 0 ); 
     121        set_callbacks( OpenFrenchTV, Close ); 
     122        add_shortcut( "frenchtv" ); 
    85123 
    86124    add_submodule(); 
     
    118156static void ItemAdded( const vlc_event_t * p_event, void * user_data ) 
    119157{ 
    120     services_discovery_t *p_sd = user_data; 
    121     services_discovery_AddItem( p_sd, 
     158    struct shout_category_t * params = user_data; 
     159    services_discovery_AddItem( params->p_sd, 
    122160            p_event->u.input_item_subitem_added.p_new_child, 
    123             NULL /* no category */ ); 
    124 } 
    125  
    126 /***************************************************************************** 
    127  * Run
    128  *****************************************************************************/ 
    129 static void Run( services_discovery_t *p_sd ) 
    130 
    131     enum type_e i_type = (enum type_e)p_sd->p_sys; 
     161            params->psz_category ); 
     162} 
     163 
     164/***************************************************************************** 
     165 * CreateInputItemFromShoutItem
     166 *****************************************************************************/ 
     167static input_item_t * CreateInputItemFromShoutItem( services_discovery_t *p_sd, 
     168                                         const struct shout_item_t * p_item ) 
     169
    132170    int i; 
     171    /* Create the item */ 
    133172    input_item_t *p_input = input_ItemNewExt( p_sd, 
    134                         p_items[i_type].psz_url, _(p_items[i_type].psz_name), 
    135                         0, NULL, -1 ); 
    136     for( i = 0; p_items[i_type].ppsz_options[i] != NULL; i++ ) 
    137         input_ItemAddOption( p_input, p_items[i_type].ppsz_options[i] ); 
     173                    p_item->psz_url, _(p_item->psz_name), 
     174                    0, NULL, -1 ); 
     175 
     176    /* Copy options */ 
     177    for( i = 0; p_item->ppsz_options[i] != NULL; i++ ) 
     178        input_ItemAddOption( p_input, p_item->ppsz_options[i] ); 
    138179    input_ItemAddOption( p_input, "no-playlist-autostart" ); 
    139180 
     181    return p_input; 
     182} 
     183 
     184/***************************************************************************** 
     185 * AddSubitemsOfShoutItemURL: 
     186 *****************************************************************************/ 
     187static void AddSubitemsOfShoutItemURL( services_discovery_t *p_sd, 
     188                                       const struct shout_item_t * p_item, 
     189                                       const char * psz_category ) 
     190{ 
     191    struct shout_category_t category = { p_sd, psz_category }; 
     192 
     193    /* Create the item */ 
     194    input_item_t *p_input = CreateInputItemFromShoutItem( p_sd, p_item ); 
     195 
     196    /* Read every subitems, and add them in ItemAdded */ 
    140197    vlc_event_attach( &p_input->event_manager, vlc_InputItemSubItemAdded, 
    141                       ItemAdded, p_sd ); 
     198                      ItemAdded, &category ); 
    142199    input_Read( p_sd, p_input, VLC_TRUE ); 
    143200    vlc_event_detach( &p_input->event_manager, vlc_InputItemSubItemAdded, 
    144                       ItemAdded, p_sd ); 
     201                      ItemAdded, &category ); 
     202 
    145203    vlc_gc_decref( p_input ); 
    146204} 
    147205 
    148206/***************************************************************************** 
     207 * Run: 
     208 *****************************************************************************/ 
     209static void Run( services_discovery_t *p_sd ) 
     210{ 
     211    enum type_e i_type = (enum type_e)p_sd->p_sys; 
     212    int i, j; 
     213     
     214    if( !p_items[i_type].p_children ) 
     215    { 
     216        AddSubitemsOfShoutItemURL( p_sd, &p_items[i_type], NULL ); 
     217        return; 
     218    } 
     219    for( i = 0; p_items[i_type].p_children[i].psz_name; i++ ) 
     220    { 
     221        const struct shout_item_t * p_subitem = &p_items[i_type].p_children[i]; 
     222        if( !p_subitem->p_children ) 
     223        { 
     224            AddSubitemsOfShoutItemURL( p_sd, p_subitem, p_subitem->psz_name ); 
     225            continue; 
     226        } 
     227        for( j = 0; p_subitem->p_children[j].psz_name; j++ ) 
     228        { 
     229            input_item_t *p_input = CreateInputItemFromShoutItem( p_sd, &p_subitem->p_children[j] ); 
     230            services_discovery_AddItem( p_sd, 
     231                p_input, 
     232                p_subitem->psz_name ); 
     233            vlc_gc_decref( p_input ); 
     234        } 
     235    } 
     236} 
     237 
     238/***************************************************************************** 
    149239 * Close: 
    150240 *****************************************************************************/