X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fmisc%2Faudioscrobbler.c;h=d464118cf39546367c4975b544bcce1847c1cab1;hb=c3cc1221caf65094bc4611e71f314f3eb050a797;hp=e15616fec6d672ddd6ac22f5bfc70706026f8f83;hpb=5b63839284565821b5aff349378eddbb9d7f1ee0;p=vlc diff --git a/modules/misc/audioscrobbler.c b/modules/misc/audioscrobbler.c index e15616fec6..d464118cf3 100644 --- a/modules/misc/audioscrobbler.c +++ b/modules/misc/audioscrobbler.c @@ -92,7 +92,7 @@ struct intf_sys_t int i_nowp_port; /**< port to which submit */ char *psz_nowp_file; /**< file to which submit */ #endif - bool b_handshaked; /**< are we authenticated ? */ + bool b_handshaked; /**< are we authenticated ? */ char psz_auth_token[33]; /**< Authentication token */ /* data about song currently playing */ @@ -101,12 +101,12 @@ struct intf_sys_t mtime_t time_pause; /**< time when vlc paused */ mtime_t time_total_pauses; /**< total time in pause */ - bool b_submit; /**< do we have to submit ? */ + bool b_submit; /**< do we have to submit ? */ - bool b_state_cb; /**< if we registered the + bool b_state_cb; /**< if we registered the * "state" callback */ - bool b_meta_read; /**< if we read the song's + bool b_meta_read; /**< if we read the song's * metadata already */ }; @@ -184,7 +184,7 @@ static int Open( vlc_object_t *p_this ) vlc_mutex_init( &p_sys->lock ); vlc_cond_init( &p_sys->wait ); - p_playlist = pl_Yield( p_intf ); + p_playlist = pl_Hold( p_intf ); PL_LOCK; var_AddCallback( p_playlist, "playlist-current", ItemChange, p_intf ); PL_UNLOCK; @@ -205,29 +205,24 @@ static void Close( vlc_object_t *p_this ) intf_thread_t *p_intf = ( intf_thread_t* ) p_this; intf_sys_t *p_sys = p_intf->p_sys; - p_playlist = pl_Yield( p_intf ); + p_playlist = pl_Hold( p_intf ); if( p_playlist ) { - PL_LOCK; var_DelCallback( p_playlist, "playlist-current", ItemChange, p_intf ); - p_input = p_playlist->p_input; + p_input = playlist_CurrentInput( p_playlist ); if ( p_input ) { - vlc_object_yield( p_input ); - if( p_sys->b_state_cb ) var_DelCallback( p_input, "state", PlayingChange, p_intf ); vlc_object_release( p_input ); } - PL_UNLOCK; pl_Release( p_intf ); } - p_intf->b_dead = true; int i; for( i = 0; i < p_sys->i_songs; i++ ) DeleteSong( &p_sys->p_queue[i] ); @@ -470,9 +465,6 @@ static int PlayingChange( vlc_object_t *p_this, const char *psz_var, VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); - if( p_intf->b_dead ) - return VLC_SUCCESS; - if( p_sys->b_meta_read == false && newval.i_int >= PLAYING_S ) { ReadMetaData( p_intf ); @@ -505,26 +497,19 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var, VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval ); VLC_UNUSED( newval ); - if( p_intf->b_dead ) - return VLC_SUCCESS; - p_sys->b_state_cb = false; p_sys->b_meta_read = false; p_sys->b_submit = false; - p_playlist = pl_Yield( p_intf ); - PL_LOCK; - p_input = p_playlist->p_input; + p_playlist = pl_Hold( p_intf ); + p_input = playlist_CurrentInput( p_playlist ); if( !p_input || p_input->b_dead ) { - PL_UNLOCK; pl_Release( p_intf ); return VLC_SUCCESS; } - vlc_object_yield( p_input ); - PL_UNLOCK; pl_Release( p_intf ); p_item = input_GetItem( p_input ); @@ -575,30 +560,31 @@ static void AddToQueue ( intf_thread_t *p_this ) p_sys->time_total_pauses; played_time /= 1000000; /* µs → s */ - if( ( played_time < 60 ) && - ( played_time < ( p_sys->p_current_song.i_l / 2 ) ) ) + /*HACK: it seam that the preparsing sometime fail, + so use the playing time as the song length */ + if( p_sys->p_current_song.i_l == 0 ) + p_sys->p_current_song.i_l = played_time; + + /* Don't send song shorter than 30s */ + if( p_sys->p_current_song.i_l < 30 ) { - msg_Dbg( p_this, "Song not listened long enough, not submitting" ); + msg_Dbg( p_this, "Song too short (< 30s), not submitting" ); goto end; } - if( p_sys->p_current_song.i_l < 30 ) + /* Send if the user had listen more than 240s OR half the track length */ + if( ( played_time < 240 ) && + ( played_time < ( p_sys->p_current_song.i_l / 2 ) ) ) { - if( played_time < 30 ) - { - msg_Dbg( p_this, "Song too short (< 30s), not submitting" ); - goto end; - } - else - /* This is a HACK to avoid length = 0 (seems to be rejected by audioscrobbler) */ - p_sys->p_current_song.i_l = played_time; + msg_Dbg( p_this, "Song not listened long enough, not submitting" ); + goto end; } + /* Check that all meta are present */ if( !p_sys->p_current_song.psz_a || !*p_sys->p_current_song.psz_a || !p_sys->p_current_song.psz_t || !*p_sys->p_current_song.psz_t ) { msg_Dbg( p_this, "Missing artist or title, not submitting" ); -/*XXX*/ msg_Dbg( p_this, "%s %s", p_sys->p_current_song.psz_a, p_sys->p_current_song.psz_t ); goto end; } @@ -926,18 +912,14 @@ static int ReadMetaData( intf_thread_t *p_this ) intf_sys_t *p_sys = p_this->p_sys; - p_playlist = pl_Yield( p_this ); - PL_LOCK; - p_input = p_playlist->p_input; + p_playlist = pl_Hold( p_this ); + p_input = playlist_CurrentInput( p_playlist ); if( !p_input ) { - PL_UNLOCK; pl_Release( p_this ); return( VLC_SUCCESS ); } - vlc_object_yield( p_input ); - PL_UNLOCK; pl_Release( p_this ); p_item = input_GetItem( p_input ); @@ -952,6 +934,8 @@ static int ReadMetaData( intf_thread_t *p_this ) a = encode_URI_component( psz_meta ); \ if( !a ) \ { \ + vlc_mutex_unlock( &p_sys->lock ); \ + vlc_object_release( p_input ); \ free( psz_meta ); \ return VLC_ENOMEM; \ } \