Changeset 9a128b542b2d94a3b24c6a7d88d76644c989f948

Show
Ignore:
Timestamp:
09/30/06 17:29:11 (2 years ago)
Author:
Clément Stenac <zorglub@videolan.org>
git-committer:
Clément Stenac <zorglub@videolan.org> 1159630151 +0000
git-parent:

[242e2fc809c9dde96652e00094ca3f102b76261a]

git-author:
Clément Stenac <zorglub@videolan.org> 1159630151 +0000
Message:

Split the musicbrainz module : meta fetcher (to retrieve MB Album and Track id) and art finder (to retrieve Amazon art url)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/meta_engine/musicbrainz.c

    rde9d74a r9a128b5  
    3636 * Local prototypes 
    3737 *****************************************************************************/ 
    38 static int FindMeta( vlc_object_t * ); 
     38static int FindArt( vlc_object_t * ); 
     39static int FindMetaMBId( vlc_object_t *p_this ); 
    3940 
    4041/***************************************************************************** 
     
    4344 
    4445vlc_module_begin(); 
    45 /*    set_category( CAT_INTERFACE ); 
    46     set_subcategory( SUBCAT_INTERFACE_CONTROL );*/ 
    4746    set_shortname( N_( "MusicBrainz" ) ); 
    4847    set_description( _("MusicBrainz meta data") ); 
    4948 
    50     set_capability( "meta fetcher", 80 ); 
    51     set_callbacks( FindMeta, NULL ); 
     49    set_capability( "meta fetcher", 10 ); 
     50        /* This meta fetcher module only retrieves the musicbrainz track id 
     51         * and stores it 
     52         * TODO: 
     53         *  - Actually do it 
     54         *  - Also store the album id 
     55         * */ 
     56        set_callbacks( FindMetaMBId, NULL ); 
     57    add_submodule(); 
     58        /* This art finder module fetches the album ID from musicbrainz and 
     59         * uses it to fetch the amazon ASIN from musicbrainz. 
     60         * TODO: 
     61         *  - Add ability to reuse MB album ID if we already have it 
     62         */ 
     63        set_capability( "art finder", 80 ); 
     64        set_callbacks( FindArt, NULL ); 
    5265vlc_module_end(); 
    5366 
    5467/***************************************************************************** 
    5568 *****************************************************************************/ 
    56 static int FindMeta( vlc_object_t *p_this ) 
     69 
     70static int GetData( vlc_object_t *p_obj, input_item_t *p_item, 
     71                    vlc_bool_t b_art ) 
    5772{ 
    58     meta_engine_t *p_me = (meta_engine_t *)p_this; 
    59     input_item_t *p_item = p_me->p_item; 
    60  
    61     char *psz_title = NULL; 
    62     char *psz_artist = NULL; 
    63     char *psz_album = NULL; 
    64  
    6573    char psz_buf[256]; 
    6674    char psz_data[256]; 
     
    6876    char *ppsz_args[4]; 
    6977    uint32_t i_meta; 
     78 
     79    char *psz_title; 
     80    char *psz_artist; 
     81    char *psz_album; 
    7082 
    7183    if( !p_item->p_meta ) return VLC_EGENERIC; 
     
    7688    if( !psz_artist || !psz_album ) 
    7789        return VLC_EGENERIC; 
     90 
    7891    musicbrainz_t p_mb; 
    7992 
     
    8295    mb_WSAInit( p_mb ); 
    8396#endif 
     97 
    8498    mb_SetDepth( p_mb, 2 ); 
    8599    ppsz_args[0] = psz_album; 
     
    95109    { 
    96110        mb_GetQueryError( p_mb, psz_buf, 256 ); 
    97         msg_Err( p_me, "Query failed: %s\n", psz_buf ); 
     111        msg_Err( p_obj, "Query failed: %s\n", psz_buf ); 
    98112        mb_Delete( p_mb ); 
    99113        return VLC_EGENERIC; 
     
    103117    if( i_album_count < 1 ) 
    104118    { 
    105         msg_Err( p_me, "No albums found.\n" ); 
    106119        mb_Delete( p_mb ); 
    107120        return VLC_EGENERIC; 
    108121    } 
    109122 
    110     msg_Dbg( p_me, "Found %d albums.\n", i_album_count ); 
     123    /** \todo Get the MB Track ID and store it */ 
     124    msg_Dbg( p_obj, "found %d albums.\n", i_album_count ); 
    111125 
    112126    for( i = 1; i <= i_album_count; i++ ) 
     
    117131        mb_GetResultData( p_mb, MBE_AlbumGetAlbumId, psz_data, 256 ); 
    118132        mb_GetIDFromURL( p_mb, psz_data, psz_buf, 256 ); 
    119         msg_Dbg( p_me, "Album Id: %s", psz_buf ); 
     133        msg_Dbg( p_obj, "album Id: %s", psz_buf ); 
     134 
     135 
     136        if( !b_art ) 
     137            break; 
    120138 
    121139        if( mb_GetResultData( p_mb, MBE_AlbumGetAmazonAsin, psz_buf, 256 ) ) 
    122140        { 
    123             msg_Dbg( p_me, "Amazon ASIN: %s", psz_buf ); 
    124             sprintf( psz_data, "http://images.amazon.com/images/P/%s.01._SCLZZZZZZZ_.jpg", psz_buf ); 
     141            msg_Dbg( p_obj, "Amazon ASIN: %s", psz_buf ); 
     142            snprintf( psz_data, 255, 
     143                    "http://images.amazon.com/images/P/%s.01._SCLZZZZZZZ_.jpg", 
     144                    psz_buf ); 
    125145            vlc_meta_SetArtURL( p_item->p_meta, psz_data ); 
    126146            break; 
     
    130150    mb_WSAInit( p_mb ); 
    131151#endif 
    132  
    133152    mb_Delete( p_mb ); 
    134153 
    135     i_meta = input_CurrentMetaFlags( p_item->p_meta ); 
    136     p_me->i_mandatory &= ~i_meta; 
    137     p_me->i_optional &= ~i_meta; 
    138     if( p_me->i_mandatory ) 
    139         return VLC_EGENERIC; 
     154    if( !b_art ) 
     155        return VLC_SUCCESS; 
    140156    else 
    141         return VLC_SUCCESS; 
     157        return p_item->p_meta->psz_arturl && *p_item->p_meta->psz_arturl ? 
     158               VLC_SUCCESS : VLC_EGENERIC; 
    142159} 
     160 
     161static int FindMetaMBId( vlc_object_t *p_this ) 
     162{ 
     163    meta_engine_t *p_me = (meta_engine_t *)p_this; 
     164    input_item_t *p_item = p_me->p_item; 
     165    int i_ret = GetData( VLC_OBJECT(p_me), p_item, VLC_FALSE ); 
     166 
     167    if( !i_ret ) 
     168    { 
     169        uint32_t i_meta = input_CurrentMetaFlags( p_item->p_meta ); 
     170        p_me->i_mandatory &= ~i_meta; 
     171        p_me->i_optional &= ~i_meta; 
     172        return p_me->i_mandatory ? VLC_EGENERIC : VLC_SUCCESS; 
     173    } 
     174    return VLC_EGENERIC; 
     175} 
     176 
     177static int FindArt( vlc_object_t *p_this ) 
     178{ 
     179    playlist_t *p_playlist; 
     180    input_item_t *p_item = (input_item_t *)p_playlist->p_private; 
     181    assert( p_item ); 
     182 
     183    return GetData( p_playlist, p_item, VLC_TRUE ); 
     184}