Changeset 5e2ac0157084dd2f643431ae3516326c3820ee4a

Show
Ignore:
Timestamp:
29/09/06 01:44:09 (2 years ago)
Author:
Rafaël Carré <funman@videolan.org>
git-committer:
Rafaël Carré <funman@videolan.org> 1159487049 +0000
git-parent:

[20915248113c509219912c03b51c89c82c795fcc]

git-author:
Rafaël Carré <funman@videolan.org> 1159487049 +0000
Message:

Don't Close() on connection error, retry every minute
Fix a _() that should have been N_()
Username & Password are non-advanced settings
Warn user with interaction if Username is bad or not set
Handshake only if there is something to submit
Get rid of hexa() for printf("%02x")
Replace % 256 and / (2x) by bitwise operations : & 0xff and >> x
Don't cancel submission of song if user has paused playing
Code for new meta_engine (not enabled yet)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/misc/audioscrobbler.c

    r52e7774 r5e2ac01  
    3939/* 
    4040 * TODO : 
    41  * review/replace : 
    42  *   hexa() 
    43  *   md5 to char[] 
     41 * implement musicbrainz unique track identifier in p_meta 
     42 * check meta_engine's state, and remove delaying of metadata reading 
     43 * check md5 operations on BIGENDIAN and 64 bits architectures 
    4444 */ 
    4545#include <vlc/vlc.h> 
     
    5151#include <vlc_url.h> 
    5252#include <network.h> 
     53#include <vlc_interaction.h> 
    5354 
    5455/***************************************************************************** 
     
    101102    vlc_bool_t              b_metadata_read;    /* did we read metadata ? */ 
    102103    vlc_bool_t              b_paused;           /* are we playing ?       */ 
     104    vlc_bool_t              b_waiting_meta;     /* we need fetched data?  */ 
    103105}; 
    104106 
     
    115117static int Handshake    ( intf_thread_t *p_sd ); 
    116118static int ReadMetaData ( intf_thread_t *p_this ); 
     119static int ReadLocalMetaData( intf_thread_t *p_this, input_thread_t  *p_input ); 
    117120void DeleteQueue( audioscrobbler_queue_t *p_queue ); 
    118 char *hexa( short int i ); 
    119121 
    120122#if !defined(strlwr) && !defined( WIN32 ) 
     
    129131#define APPLICATION_NAME "VLC media player" 
    130132#define USERNAME_TEXT N_("Username") 
    131 #define USERNAME_LONGTEXT N_("Audioscrobbler username") 
     133#define USERNAME_LONGTEXT N_("The username of your last.fm account") 
    132134#define PASSWORD_TEXT N_("Password") 
    133 #define PASSWORD_LONGTEXT N_("Audioscrobbler password") 
     135#define PASSWORD_LONGTEXT N_("The password of your last.fm account") 
     136/* if something goes wrong, we wait at least one minute before trying again */ 
    134137#define DEFAULT_INTERVAL 60 
    135138#define CLIENT_NAME     PACKAGE 
     
    156159    set_subcategory( SUBCAT_INTERFACE_CONTROL ); 
    157160    set_shortname( N_( "Audioscrobbler" ) ); 
    158     set_description( _("Audioscrobbler submission Plugin") ); 
     161    set_description( N_("Audioscrobbler submission Plugin") ); 
    159162    add_string( "lastfm-username", "", NULL, 
    160                 USERNAME_TEXT, USERNAME_LONGTEXT, VLC_TRUE ); 
     163                USERNAME_TEXT, USERNAME_LONGTEXT, VLC_FALSE ); 
    161164    add_string( "lastfm-password", "", NULL, 
    162                 PASSWORD_TEXT, PASSWORD_LONGTEXT, VLC_TRUE ); 
     165                PASSWORD_TEXT, PASSWORD_LONGTEXT, VLC_FALSE ); 
    163166    set_capability( "interface", 0 ); 
    164167    set_callbacks( Open, Close ); 
     
    179182      goto error; 
    180183    } 
    181  
    182184    vlc_mutex_init( p_this, &p_sys->lock ); 
    183185 
     
    309311    uint8_t                 *p_buffer = NULL; 
    310312    char                    *p_buffer_pos = NULL; 
     313    audioscrobbler_queue_t  *p_first_queue; 
     314    /* TODO: remove when meta_engine works */ 
    311315    time_t                  played_time; 
    312     audioscrobbler_queue_t  *p_first_queue; 
    313316 
    314317    p_this->p_sys = p_sys_global; 
     
    317320    while( !p_this->b_die ) 
    318321    { 
    319         if( p_sys->b_handshaked == VLC_FALSE ) 
    320         { 
    321             if ( time( NULL ) >= 
    322                 ( p_sys->time_last_interval + p_sys->i_interval ) ) 
    323             { 
    324                 msg_Dbg( p_this, "Handshaking with last.fm ..." ); 
    325                 i_handshake = Handshake( p_this ); 
    326  
    327                 if( i_handshake == VLC_ENOMEM ) 
     322 
     323        if ( ( p_sys->p_first_queue->i_songs_nb > 0 ) && 
     324            ( time( NULL ) >= 
     325            ( p_sys->time_last_interval + p_sys->i_interval )  ) ) 
     326        { 
     327 
     328            if( p_sys->b_handshaked == VLC_FALSE ) 
     329            { 
     330                if ( time( NULL ) >= 
     331                    ( p_sys->time_last_interval + p_sys->i_interval ) ) 
    328332                { 
    329                     msg_Err( p_this, "Out of memory" ); 
    330                     return; 
     333                    msg_Dbg( p_this, "Handshaking with last.fm ..." ); 
     334                    i_handshake = Handshake( p_this ); 
     335 
     336                    if( i_handshake == VLC_ENOMEM ) 
     337                    { 
     338                        msg_Err( p_this, "Out of memory" ); 
     339                        return; 
     340                    } 
     341 
     342                    else if( i_handshake == VLC_ENOVAR ) 
     343                    /* username not set */ 
     344                    { 
     345                        vlc_mutex_unlock ( &p_sys->lock ); 
     346                        intf_UserFatal( p_this, VLC_FALSE, 
     347                            _("last.fm username not set"), 
     348                            _("You have to set a username," 
     349                            " and then restart VLC.\n" 
     350                            "Visit https://www.last.fm/join/" 
     351                            " if you don't have one.") 
     352                        ); 
     353                        return; 
     354                    } 
     355 
     356                    else if( i_handshake == VLC_SUCCESS ) 
     357                    { 
     358                        msg_Dbg( p_this, "Handshake successfull :)" ); 
     359                        vlc_mutex_lock ( &p_sys->lock ); 
     360                        p_sys->b_handshaked = VLC_TRUE; 
     361                        vlc_mutex_unlock ( &p_sys->lock ); 
     362                    } 
     363 
     364                    else 
     365                    /* VLC_GENERIC : we'll try later */ 
     366                    { 
     367                        vlc_mutex_lock ( &p_sys->lock ); 
     368                        p_sys->i_interval = DEFAULT_INTERVAL; 
     369                        time( &p_sys->time_last_interval ); 
     370                        vlc_mutex_unlock ( &p_sys->lock ); 
     371                    } 
    331372                } 
    332  
    333                 else if( i_handshake == VLC_ENOVAR ) 
    334                 /* username not set */ 
     373            } 
     374 
     375 
     376            msg_Dbg( p_this, "Going to submit some data..." ); 
     377            vlc_mutex_lock ( &p_sys->lock ); 
     378            psz_submit_string = malloc( 2048 * sizeof( char ) ); 
     379 
     380            if (!psz_submit_string) 
     381            { 
     382                msg_Err( p_this, "Out of memory" ); 
     383                vlc_mutex_unlock ( &p_sys->lock ); 
     384                return; 
     385            } 
     386 
     387            for (i_song = 0; i_song < p_sys->p_first_queue->i_songs_nb ; 
     388                i_song++ ) 
     389            { 
     390                snprintf( psz_submit_string, 2048, POST_DATA, 
     391                    p_sys->psz_username, p_sys->psz_response_md5, 
     392                    i_song, p_sys->p_first_queue->p_queue[i_song]->psz_a, 
     393                    i_song, p_sys->p_first_queue->p_queue[i_song]->psz_t, 
     394                    i_song, p_sys->p_first_queue->p_queue[i_song]->psz_b, 
     395                    i_song, 
     396                    i_song, p_sys->p_first_queue->p_queue[i_song]->i_l, 
     397                    i_song, p_sys->p_first_queue->p_queue[i_song]->psz_i 
     398                ); 
     399            } 
     400 
     401            p_sys->i_post_socket = net_ConnectTCP( p_this, 
     402                p_sys->psz_submit_host, p_sys->i_submit_port); 
     403 
     404            i_netprintf = net_Printf( 
     405                VLC_OBJECT(p_this), p_sys->i_post_socket, NULL, 
     406                POST_REQUEST, p_sys->psz_submit_file, 
     407                strlen( psz_submit_string), p_sys->psz_submit_file, 
     408                VERSION, psz_submit_string 
     409            ); 
     410 
     411            if ( i_netprintf == -1 ) 
     412            { 
     413                /* If connection fails, we assume we must handshake again */ 
     414                p_sys->i_interval = DEFAULT_INTERVAL; 
     415                time( &p_sys->time_last_interval ); 
     416                p_sys->b_handshaked = VLC_FALSE; 
     417                vlc_mutex_unlock ( &p_sys->lock ); 
     418                continue; 
     419            } 
     420 
     421            p_buffer = ( uint8_t* ) calloc( 1, 1024 ); 
     422            if ( !p_buffer ) 
     423            { 
     424                msg_Err( p_this, "Out of memory" ); 
     425                vlc_mutex_unlock ( &p_sys->lock ); 
     426                return; 
     427            } 
     428 
     429            net_Read( p_this, p_sys->i_post_socket, NULL, 
     430                        p_buffer, 1024, VLC_FALSE ); 
     431            net_Close( p_sys->i_post_socket ); 
     432 
     433            p_buffer_pos = strstr( ( char * ) p_buffer, "INTERVAL" ); 
     434 
     435            if ( p_buffer_pos ) 
     436            { 
     437                p_sys->i_interval = atoi( p_buffer_pos + 
     438                                            strlen( "INTERVAL " ) ); 
     439                time( &p_sys->time_last_interval ); 
     440            } 
     441 
     442            p_buffer_pos = strstr( ( char * ) p_buffer, "FAILED" ); 
     443 
     444            if ( p_buffer_pos ) 
     445            { 
     446                msg_Dbg( p_this, p_buffer_pos ); 
     447                vlc_mutex_unlock ( &p_sys->lock ); 
     448                continue; 
     449            } 
     450 
     451            p_buffer_pos = strstr( ( char * ) p_buffer, "BADAUTH" ); 
     452 
     453            if ( p_buffer_pos ) 
     454            { 
     455                msg_Dbg( p_this, "Authentification failed, handshaking again" ); 
     456                p_sys->b_handshaked = VLC_FALSE; 
     457                vlc_mutex_unlock ( &p_sys->lock ); 
     458                continue; 
     459            } 
     460 
     461            p_buffer_pos = strstr( ( char * ) p_buffer, "OK" ); 
     462 
     463            if ( p_buffer_pos ) 
     464            { 
     465                if ( p_sys->p_first_queue->i_songs_nb == 10 ) 
    335466                { 
    336                     msg_Dbg( p_this, "Set an username then restart vlc" ); 
    337                     vlc_mutex_unlock ( &p_sys->lock ); 
    338                     return; 
     467                    p_first_queue = p_sys->p_first_queue->p_next_queue; 
     468                    DeleteQueue( p_sys->p_first_queue ); 
     469                    free( p_sys->p_first_queue ); 
     470                    p_sys->p_first_queue = p_first_queue; 
    339471                } 
    340  
    341                 else if( i_handshake == VLC_SUCCESS ) 
    342                 { 
    343                     msg_Dbg( p_this, "Handshake successfull :)" ); 
    344                     vlc_mutex_lock ( &p_sys->lock ); 
    345                     p_sys->b_handshaked = VLC_TRUE; 
    346                     vlc_mutex_unlock ( &p_sys->lock ); 
    347                 } 
    348  
    349472                else 
    350473                { 
    351                     vlc_mutex_lock ( &p_sys->lock ); 
    352                     p_sys->i_interval = DEFAULT_INTERVAL; 
    353                     time( &p_sys->time_last_interval ); 
    354                     vlc_mutex_unlock ( &p_sys->lock ); 
     474                    DeleteQueue( p_sys->p_first_queue ); 
     475                    p_sys->p_first_queue->i_songs_nb = 0; 
    355476                } 
    356             } 
    357         } 
    358  
    359         else 
    360         { 
    361             if ( ( p_sys->p_first_queue->i_songs_nb > 0 ) && 
    362                 ( time( NULL ) >= 
    363                 ( p_sys->time_last_interval + p_sys->i_interval )  ) ) 
    364             { 
    365                 msg_Dbg( p_this, "Going to submit some data..." ); 
    366                 vlc_mutex_lock ( &p_sys->lock ); 
    367                 psz_submit_string = malloc( 2048 * sizeof( char ) ); 
    368  
    369                 if (!psz_submit_string) 
    370                 { 
    371                     msg_Err( p_this, "Out of memory" ); 
    372                     vlc_mutex_unlock ( &p_sys->lock ); 
    373                     return; 
    374                 } 
    375  
    376                 for (i_song = 0; i_song < p_sys->p_first_queue->i_songs_nb ; 
    377                     i_song++ ) 
    378                 { 
    379                     snprintf( psz_submit_string, 2048, POST_DATA, 
    380                         p_sys->psz_username, p_sys->psz_response_md5, 
    381                         i_song, p_sys->p_first_queue->p_queue[i_song]->psz_a, 
    382                         i_song, p_sys->p_first_queue->p_queue[i_song]->psz_t, 
    383                         i_song, p_sys->p_first_queue->p_queue[i_song]->psz_b, 
    384                         i_song, 
    385                         i_song, p_sys->p_first_queue->p_queue[i_song]->i_l, 
    386                         i_song, p_sys->p_first_queue->p_queue[i_song]->psz_i 
    387                     ); 
    388                 } 
    389  
    390                 p_sys->i_post_socket = net_ConnectTCP( p_this, 
    391                     p_sys->psz_submit_host, p_sys->i_submit_port); 
    392  
    393                 i_netprintf = net_Printf( 
    394                     VLC_OBJECT(p_this), p_sys->i_post_socket, NULL, 
    395                     POST_REQUEST, p_sys->psz_submit_file, 
    396                     strlen( psz_submit_string), p_sys->psz_submit_file, 
    397                     VERSION, psz_submit_string 
    398                 ); 
    399  
    400                 if ( i_netprintf == -1 ) 
    401                 { 
    402                 /* If connection fails, we assume we must handshake again */ 
    403                     p_sys->i_interval = DEFAULT_INTERVAL; 
    404                     time( &p_sys->time_last_interval ); 
    405                     p_sys->b_handshaked = VLC_FALSE; 
    406                     vlc_mutex_unlock ( &p_sys->lock ); 
    407                     return; 
    408                 } 
    409  
    410                 p_buffer = ( uint8_t* ) calloc( 1, 1024 ); 
    411                 if ( !p_buffer ) 
    412                 { 
    413                     msg_Err( p_this, "Out of memory" ); 
    414                     vlc_mutex_unlock ( &p_sys->lock ); 
    415                     return; 
    416                 } 
    417  
    418                 net_Read( p_this, p_sys->i_post_socket, NULL, 
    419                           p_buffer, 1024, VLC_FALSE ); 
    420                 net_Close( p_sys->i_post_socket ); 
    421  
    422                 p_buffer_pos = strstr( ( char * ) p_buffer, "INTERVAL" ); 
    423  
    424                 if ( p_buffer_pos ) 
    425                 { 
    426                     p_sys->i_interval = atoi( p_buffer_pos + 
    427                                               strlen( "INTERVAL " ) ); 
    428                     time( &p_sys->time_last_interval ); 
    429                 } 
    430  
    431                 p_buffer_pos = strstr( ( char * ) p_buffer, "FAILED" ); 
    432  
    433                 if ( p_buffer_pos ) 
    434                 { 
    435                     msg_Err( p_this, p_buffer_pos ); 
    436                     vlc_mutex_unlock ( &p_sys->lock ); 
    437                     return; 
    438                 } 
    439  
    440                 p_buffer_pos = strstr( ( char * ) p_buffer, "BADAUTH" ); 
    441  
    442                 if ( p_buffer_pos ) 
    443                 { 
    444                     msg_Err( p_this, 
    445                              "Authentification failed, handshaking again" ); 
    446                     p_sys->b_handshaked = VLC_FALSE; 
    447                     vlc_mutex_unlock ( &p_sys->lock ); 
    448                     return; 
    449                 } 
    450  
    451                 p_buffer_pos = strstr( ( char * ) p_buffer, "OK" ); 
    452  
    453                 if ( p_buffer_pos ) 
    454                 { 
    455                     if ( p_sys->p_first_queue->i_songs_nb == 10 ) 
    456                     { 
    457                         p_first_queue = p_sys->p_first_queue->p_next_queue; 
    458                         DeleteQueue( p_sys->p_first_queue ); 
    459                         free( p_sys->p_first_queue ); 
    460                         p_sys->p_first_queue = p_first_queue; 
    461                     } 
    462                     else 
    463                     { 
    464                         DeleteQueue( p_sys->p_first_queue ); 
    465                         p_sys->p_first_queue->i_songs_nb = 0; 
    466                     } 
    467                     msg_Dbg( p_this, "Submission successfull!" ); 
    468                 } 
    469                 vlc_mutex_unlock ( &p_sys->lock ); 
    470             } 
    471         } 
     477                msg_Dbg( p_this, "Submission successfull!" ); 
     478            } 
     479            vlc_mutex_unlock ( &p_sys->lock ); 
     480        } 
     481 
    472482        msleep( INTF_IDLE_SLEEP ); 
    473483 
     
    491501 
    492502        vlc_mutex_lock( &p_sys->lock ); 
    493  
    494503        if( p_sys->b_metadata_read == VLC_FALSE ) 
    495504        { 
     505            /* TODO: remove when meta_engine works */ 
    496506            time( &played_time ); 
    497507            played_time -= p_sys->p_current_song->time_playing; 
    498508            played_time -= p_sys->time_total_pauses; 
    499509 
    500  
    501510            vlc_mutex_unlock( &p_sys->lock ); 
    502511 
    503             /* ok now we can read meta data */ 
     512            /* TODO: remove when meta_engine works */ 
    504513            if( played_time > 10 ) 
    505514            { 
    506                 ReadMetaData( p_this ); 
     515                if ( ReadMetaData( p_this ) == VLC_ENOMEM ) 
     516                { 
     517                    msg_Err( p_this, "Out of memory" ); 
     518                    return; 
     519                } 
    507520            } 
    508521        } 
     
    549562    { 
    550563        p_sys->time_total_pauses += time( NULL ) - p_sys->time_pause; 
    551         p_sys->b_paused = VLC_TRUE; 
     564        p_sys->b_paused = VLC_FALSE; 
    552565    } 
    553566 
     
    603616    p_sys->time_total_pauses = 0; 
    604617 
    605     /* we'll read after to be sure it's present */ 
     618    /* we'll read metadata when it's present */ 
    606619    p_sys->b_metadata_read = VLC_FALSE; 
    607  
     620    p_sys->b_waiting_meta = VLC_FALSE; 
    608621    p_sys->b_queued = VLC_TRUE; 
    609622 
     
    637650    intf_sys_t *p_sys = p_this->p_sys; 
    638651 
    639     /* has it been queued already ? is it long enough ? */ 
     652    /* wait for the user to listen enough before submitting */ 
     653    time ( &played_time ); 
     654    played_time -= p_sys->p_current_song->time_playing; 
     655    played_time -= p_sys->time_total_pauses; 
     656 
    640657    vlc_mutex_lock( &p_sys->lock ); 
     658    if( ( played_time < 240 ) 
     659        && ( played_time < ( p_sys->p_current_song->i_l / 2 ) ) ) 
     660    { 
     661        vlc_mutex_unlock ( &p_sys->lock ); 
     662        return VLC_SUCCESS; 
     663    } 
     664 
    641665    if( p_sys->p_current_song->i_l < 30 ) 
    642666    { 
     
    647671    } 
    648672 
    649     /* wait for the user to listen enough before submitting */ 
    650     time ( &played_time ); 
    651     played_time -= p_sys->p_current_song->time_playing; 
    652     played_time -= p_sys->time_total_pauses; 
    653  
    654     if( ( played_time < 240 ) 
    655         && ( played_time < ( p_sys->p_current_song->i_l / 2 ) ) ) 
    656     { 
     673    if( !*p_sys->p_current_song->psz_a || !*p_sys->p_current_song->psz_t ) 
     674    { 
     675        msg_Dbg( p_this, "Missing artist or title -> not submitting" ); 
     676        p_sys->b_queued = VLC_TRUE; 
    657677        vlc_mutex_unlock ( &p_sys->lock ); 
    658678        return VLC_SUCCESS; 
     
    661681    msg_Dbg( p_this, "Ok. We'll put it in the queue for submission" ); 
    662682 
     683    /* go to last queue */ 
    663684    p_queue = p_sys->p_first_queue; 
    664  
    665685    while( ( p_queue->i_songs_nb == 10 ) && ( p_queue->p_next_queue != NULL ) ) 
    666686    { 
     
    727747    int                 i_url_pos, i; 
    728748 
    729     char                *b1, *b2, *b3, *b4; 
    730  
    731749    intf_thread_t *p_intf = ( intf_thread_t* ) p_this; 
    732750    intf_sys_t *p_sys = p_this->p_sys; 
     
    743761    if ( !*p_sys->psz_username ) 
    744762    { 
    745         msg_Info( p_this, "You have to set an username! " 
    746          "Visit https://www.last.fm/join/" ); 
    747763        return VLC_ENOVAR; 
    748764    } 
     
    764780    if( !p_stream ) 
    765781    { 
    766         p_sys->i_interval = DEFAULT_INTERVAL; 
    767         time( &p_sys->time_last_interval ); 
    768782        vlc_mutex_unlock ( &p_sys->lock ); 
    769783        return VLC_EGENERIC; 
     
    799813    if ( p_buffer_pos ) 
    800814    { 
    801         msg_Info( p_this, p_buffer_pos ); 
     815        msg_Dbg( p_this, p_buffer_pos ); 
    802816        free( p_buffer ); 
    803817        vlc_mutex_unlock ( &p_sys->lock ); 
     
    809823    if ( p_buffer_pos ) 
    810824    { 
    811         msg_Info( p_intf, "Username is incorrect" ); 
     825        intf_UserFatal( p_this, VLC_FALSE, _("Bad last.fm Username"), 
     826            _("last.fm username is incorrect, please verify your settings") 
     827        ); 
    812828        free( p_buffer ); 
    813829        vlc_mutex_unlock ( &p_sys->lock ); 
     
    902918    for ( i = 0; i < 4; i++ ) 
    903919    { 
    904     /* TODO check that this works on every arch/platform (uint32_t to char) */ 
    905         b1 = hexa( p_struct_md5->p_digest[i] % 256 ); 
    906         b2 = hexa( ( p_struct_md5->p_digest[i] / 256 ) % 256 ); 
    907         b3 = hexa( ( p_struct_md5->p_digest[i] / 65536 ) % 256 ); 
    908         b4 = hexa( p_struct_md5->p_digest[i] / 16777216 ); 
    909         sprintf( &psz_password_md5[8*i], "%s%s%s%s", b1, b2, b3, b4 ); 
    910         free( b1 ); 
    911         free( b2 ); 
    912         free( b3 ); 
    913         free( b4 ); 
     920        sprintf( &psz_password_md5[8*i], "%02x%02x%02x%02x", 
     921            p_struct_md5->p_digest[i] & 0xff, 
     922            ( p_struct_md5->p_digest[i] >> 8 ) & 0xff, 
     923            ( p_struct_md5->p_digest[i] >> 16 ) & 0xff, 
     924            p_struct_md5->p_digest[i] >> 24 
     925        ); 
    914926    } 
    915927 
     
    926938    for ( i = 0; i < 4; i++ ) 
    927939    { 
    928         b1 = hexa( p_struct_md5->p_digest[i] % 256 ); 
    929         b2 = hexa( ( p_struct_md5->p_digest[i] / 256 ) % 256 ); 
    930         b3 = hexa( ( p_struct_md5->p_digest[i] / 65536 ) % 256 ); 
    931         b4 = hexa( p_struct_md5->p_digest[i] / 16777216 ); 
    932         sprintf( &p_sys->psz_response_md5[8*i],"%s%s%s%s", b1, b2, b3, b4 ); 
    933         free( b1 ); 
    934         free( b2 ); 
    935         free( b3 ); 
    936         free( b4 ); 
     940        sprintf( &p_sys->psz_response_md5[8*i], "%02x%02x%02x%02x", 
     941            p_struct_md5->p_digest[i] & 0xff, 
     942            ( p_struct_md5->p_digest[i] >> 8 ) & 0xff, 
     943            ( p_struct_md5->p_digest[i] >> 16 ) & 0xff, 
     944            p_struct_md5->p_digest[i] >> 24 
     945        ); 
    937946    } 
    938947 
     
    954963} 
    955964 
    956 /***************************************************************************** 
    957  * hexa : Converts a byte to a string in its hexadecimal value 
    958  *****************************************************************************/ 
    959 char *hexa( short int i ) 
    960 { 
    961     char        *res = calloc( 3 , sizeof( char ) ); 
    962  
    963     ((i/16) < 10) ? res[0] = (i / 16) + '0' : ( res[0] = (i/16) + 'a' - 10 ); 
    964     ((i%16) < 10) ? res[1] = (i % 16) + '0' : ( res[1] = (i%16) + 'a' - 10 ); 
    965  
    966     return res; 
    967 } 
    968965/***************************************************************************** 
    969966 * strlwr : Converts a string to lower case 
     
    998995 
    999996/***************************************************************************** 
    1000  * ReadMetaData : Puts current song's meta data in p_sys->p_current_song 
     997 * ReadMetaData : Read meta data when parsed by vlc 
     998 * or wait for fetching if unavailable 
    1001999 *****************************************************************************/ 
    10021000static int ReadMetaData( intf_thread_t *p_this ) 
    10031001{ 
    10041002    playlist_t          *p_playlist; 
     1003    input_thread_t      *p_input = NULL; 
     1004    vlc_value_t         video_val; 
     1005 
     1006    intf_sys_t *p_sys = p_this->p_sys; 
     1007 
     1008    p_playlist = pl_Yield( p_this ); 
     1009    PL_LOCK; 
     1010    p_input = p_playlist->p_input; 
     1011 
     1012    if( !p_input ) 
     1013    { 
     1014        PL_UNLOCK; 
     1015        pl_Release( p_playlist ); 
     1016        return( VLC_SUCCESS ); 
     1017    } 
     1018 
     1019    vlc_object_yield( p_input ); 
     1020    PL_UNLOCK; 
     1021    pl_Release( p_playlist ); 
     1022 
     1023    var_Change( p_input, "video-es", VLC_VAR_CHOICESCOUNT, &video_val, NULL ); 
     1024    if( ( video_val.i_int > 0 ) || \ 
     1025        ( p_input->input.p_item->i_type == ITEM_TYPE_NET ) ) 
     1026    { 
     1027        msg_Dbg( p_this, "Not an audio file -> no submission"); 
     1028        vlc_object_release( p_input ); 
     1029 
     1030        vlc_mutex_lock( &p_sys->lock ); 
     1031        p_sys->b_queued = VLC_TRUE; 
     1032        p_sys->b_metadata_read = VLC_TRUE; 
     1033        vlc_mutex_unlock( &p_sys->lock ); 
     1034 
     1035        return VLC_SUCCESS; 
     1036    } 
     1037 
     1038    return ReadLocalMetaData( p_this, p_input );     
     1039} 
     1040 
     1041/***************************************************************************** 
     1042 * ReadLocalMetaData : Puts current song's meta data in p_sys->p_current_song 
     1043 *****************************************************************************/ 
     1044static int ReadLocalMetaData( intf_thread_t *p_this, input_thread_t  *p_input ) 
     1045{ 
    10051046    char                *psz_title = NULL; 
    10061047    char                *psz_artist = NULL; 
    10071048    char                *psz_album = NULL; 
    10081049    int                 i_length = -1; 
    1009     input_thread_t      *p_input = NULL
    1010     vlc_value_t         video_val
     1050    vlc_bool_t          b_waiting
     1051    int                 i_status
    10111052 
    10121053    intf_sys_t *p_sys = p_this->p_sys; 
    10131054 
    1014     p_playlist = pl_Yield( p_this ); 
    1015     PL_LOCK; 
    1016     p_input = p_playlist->p_input; 
    1017  
    1018     if( !p_input ) 
    1019     { 
    1020         PL_UNLOCK; 
    1021         pl_Release( p_playlist ); 
    1022         return( VLC_SUCCESS ); 
    1023     } 
    1024  
    1025     vlc_object_yield( p_input ); 
    1026     PL_UNLOCK; 
    1027     pl_Release( p_playlist ); 
    1028  
    1029     if ( p_input->input.p_item->i_type == ITEM_TYPE_NET ) 
    1030     { 
    1031         msg_Dbg( p_this, "We play a stream -> no submission"); 
    1032         goto no_submission; 
    1033     } 
    1034  
    1035     var_Change( p_input, "video-es", VLC_VAR_CHOICESCOUNT, &video_val, NULL ); 
    1036     if( video_val.i_int > 0 ) 
    1037     { 
    1038         msg_Dbg( p_this, "We play a video -> no submission"); 
    1039         goto no_submission; 
    1040     } 
    1041  
    1042     if ( p_input->input.p_item->p_meta->psz_artist ) 
    1043     { 
    1044         psz_artist = encode_URI_component( 
    1045             p_input->input.p_item->p_meta->psz_artist ); 
    1046         if ( !psz_artist ) 
    1047         { 
    1048             goto error; 
    1049         } 
    1050     } 
    1051     else 
    1052     { 
    1053         msg_Dbg( p_this, "No artist.." ); 
    1054         goto no_submission; 
    1055     } 
    1056  
    1057     if ( p_input->input.p_item->p_meta->psz_album ) 
    1058     { 
    1059         psz_album = encode_URI_component( 
    1060             p_input->input.p_item->p_meta->psz_album ); 
    1061         if ( !psz_album ) 
    1062         { 
    1063             goto error; 
    1064         } 
    1065     } 
    1066     else 
    1067     { 
    1068         psz_album = calloc( 1, sizeof( char ) ); 
    1069     } 
    1070  
    1071     if ( p_input->input.p_item->psz_name ) 
    1072     { 
    1073         psz_title = encode_URI_component( p_input->input.p_item->psz_name ); 
    1074         if ( !psz_title ) 
    1075         { 
    1076             goto error; 
    1077         } 
    1078     } 
    1079     else 
    1080     { 
    1081         msg_Dbg( p_this, "No track name.." ); 
    1082         goto no_submission; 
    1083     } 
    1084  
    1085     i_length = p_input->input.p_item->i_duration / 1000000; 
    1086  
     1055    i_status = p_input->input.p_item->p_meta->i_status; 
     1056 
     1057    vlc_mutex_lock( &p_sys->lock ); 
     1058    b_waiting = p_sys->b_waiting_meta; 
     1059    vlc_mutex_unlock( &p_sys->lock ); 
     1060 
     1061    /* TODO : remove if (1) when meta_engine works */ 
     1062    if ( (1/*( i_status & ITEM_PREPARSED )*/&& ( b_waiting == VLC_FALSE ) ) || \ 
     1063        ( ( i_status & ITEM_META_FETCHED ) && ( b_waiting == VLC_TRUE ) ) ) 
     1064    { 
     1065        if ( p_input->input.p_item->p_meta->psz_artist ) 
     1066        { 
     1067            psz_artist = encode_URI_component( 
     1068                p_input->input.p_item->p_meta->psz_artist ); 
     1069            if ( !psz_artist ) 
     1070            { 
     1071                goto error; 
     1072            } 
     1073        } 
     1074        else 
     1075        { 
     1076            msg_Dbg( p_this, "No artist.." ); 
     1077            if ( b_waiting == VLC_TRUE ) 
     1078            { 
     1079                psz_artist = calloc( 1, sizeof( char ) ); 
     1080            } 
     1081            else 
     1082            { 
     1083                goto waiting_meta_data_fetching; 
     1084            } 
     1085        } 
     1086 
     1087        if ( p_input->input.p_item->psz_name ) 
     1088        { 
     1089            psz_title = encode_URI_component( p_input->input.p_item->psz_name ); 
     1090            if ( !psz_title ) 
     1091            { 
     1092                goto error; 
     1093            } 
     1094        } 
     1095        else 
     1096        { 
     1097            msg_Dbg( p_this, "No track name.." ); 
     1098            if ( b_waiting == VLC_TRUE ) 
     1099            { 
     1100                psz_title = calloc( 1, sizeof( char ) ); 
     1101            } 
     1102            else 
     1103            { 
     1104                goto waiting_meta_data_fetching; 
     1105            } 
     1106        } 
     1107 
     1108        if ( p_input->input.p_item->p_meta->psz_album ) 
     1109        { 
     1110            psz_album = encode_URI_component( 
     1111                p_input->input.p_item->p_meta->psz_album ); 
     1112            if ( !psz_album ) 
     1113            { 
     1114                goto error; 
     1115            } 
     1116        } 
     1117        else 
     1118        { 
     1119            psz_album = calloc( 1, sizeof( char ) ); 
     1120        } 
     1121 
     1122        i_length = p_input->input.p_item->i_duration / 1000000; 
     1123 
     1124        vlc_object_release( p_input ); 
     1125 
     1126        vlc_mutex_lock ( &p_sys->lock ); 
     1127 
     1128        p_sys->p_current_song->psz_a = strdup( psz_artist ); 
     1129        p_sys->p_current_song->psz_t = strdup( psz_title ); 
     1130        p_sys->p_current_song->psz_b = strdup( psz_album ); 
     1131        p_sys->p_current_song->i_l = i_length; 
     1132        p_sys->b_queued = VLC_FALSE; 
     1133        p_sys->b_metadata_read = VLC_TRUE; 
     1134 
     1135        vlc_mutex_unlock ( &p_sys->lock ); 
     1136 
     1137        msg_Dbg( p_this, "Meta data registered, waiting to be queued" ); 
     1138 
     1139        free( psz_title ); 
     1140        free( psz_artist ); 
     1141        free( psz_album ); 
     1142 
     1143        return VLC_SUCCESS; 
     1144    } 
     1145     
     1146    return VLC_SUCCESS; 
     1147 
     1148waiting_meta_data_fetching: 
    10871149    vlc_object_release( p_input ); 
    10881150 
    1089     vlc_mutex_lock ( &p_sys->lock ); 
    1090  
    1091     p_sys->p_current_song->psz_a = strdup( psz_artist ); 
    1092     p_sys->p_current_song->psz_t = strdup( psz_title ); 
    1093     p_sys->p_current_song->psz_b = strdup( psz_album ); 
    1094     p_sys->p_current_song->i_l = i_length; 
    1095     p_sys->b_queued = VLC_FALSE; 
    1096     p_sys->b_metadata_read = VLC_TRUE; 
    1097  
    1098     vlc_mutex_unlock ( &p_sys->lock ); 
    1099  
    1100     msg_Dbg( p_this, "Meta data registered, waiting to be queued" ); 
    1101  
    1102     free( psz_title ); 
     1151    vlc_mutex_lock( &p_sys->lock ); 
     1152    p_sys->b_waiting_meta = VLC_TRUE; 
     1153    vlc_mutex_unlock( &p_sys->lock ); 
     1154 
    11031155    free( psz_artist ); 
    11041156    free( psz_album ); 
     1157    free( psz_title ); 
    11051158 
    11061159    return VLC_SUCCESS; 
     
    11131166    free( psz_title ); 
    11141167    return VLC_ENOMEM; 
    1115  
    1116 no_submission: 
    1117     vlc_object_release( p_input ); 
    1118  
    1119     free( psz_title ); 
    1120     free( psz_artist ); 
    1121     free( psz_album ); 
    1122  
    1123     vlc_mutex_lock( &p_sys->lock ); 
    1124     p_sys->b_queued = VLC_TRUE; 
    1125     p_sys->b_metadata_read = VLC_TRUE; 
    1126     vlc_mutex_unlock( &p_sys->lock ); 
    1127  
    1128     return VLC_SUCCESS; 
    11291168}