]> git.sesse.net Git - vlc/blobdiff - modules/misc/audioscrobbler.c
wait INTERVAL if needed on submitting, and don't try to submit data
[vlc] / modules / misc / audioscrobbler.c
index 154ee6ffb5b71adb8f023c0240660db09cb01a9f..d28b6beec211314bcdecc3dde0a21d6ab3f30789 100644 (file)
@@ -30,8 +30,6 @@
  * Preamble
  *****************************************************************************/
 
-#define _GNU_SOURCE
-#include <string.h>
 
 #if defined( WIN32 )
 #include <time.h>
@@ -151,7 +149,7 @@ vlc_module_begin();
     set_description( N_("Audioscrobbler submission Plugin") );
     add_string( "lastfm-username", "", NULL,
                 USERNAME_TEXT, USERNAME_LONGTEXT, VLC_FALSE );
-    add_string( "lastfm-password", "", NULL,
+    add_password( "lastfm-password", "", NULL,
                 PASSWORD_TEXT, PASSWORD_LONGTEXT, VLC_FALSE );
     set_capability( "interface", 0 );
     set_callbacks( Open, Close );
@@ -367,6 +365,10 @@ static void Run( intf_thread_t *p_this )
                         vlc_mutex_unlock ( &p_sys->lock );
                         break;
                 }
+                /* handshake is done or failed, lets start from 
+                 * beginning to check it out and wait INTERVAL if needed
+                 */
+                continue;
             }
 
             msg_Dbg( p_this, "Going to submit some data..." );
@@ -630,8 +632,10 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
     p_sys->p_current_song->psz_i = encode_URI_component( psz_date );
     p_sys->p_current_song->time_playing = epoch;
 
-    p_sys->b_paused = ( p_input->b_dead || !input_GetItem(p_input)->psz_name )
+    char *psz_name = input_item_GetName( input_GetItem( p_input ) );
+    p_sys->b_paused = ( p_input->b_dead || !psz_name )
                       ? VLC_TRUE : VLC_FALSE;
+    free( psz_name );
 
     vlc_mutex_unlock( &p_sys->lock );
 
@@ -1003,7 +1007,7 @@ static int ReadMetaData( intf_thread_t *p_this )
 
     var_Change( p_input, "video-es", VLC_VAR_CHOICESCOUNT, &video_val, NULL );
     if( ( video_val.i_int > 0 ) || \
-        ( input_GetItem(p_input)->i_type == ITEM_TYPE_NET ) )
+        ( input_GetItem( p_input )->i_type == ITEM_TYPE_NET ) )
     {
         msg_Dbg( p_this, "Not an audio only local file -> no submission");
         vlc_object_release( p_input );
@@ -1038,16 +1042,19 @@ static int ReadMetaData( intf_thread_t *p_this )
             return VLC_SUCCESS; \
         }
 
+    char *psz_meta;
     #define ALLOC_ITEM_META( a, b ) \
-        if ( input_GetItem(p_input)->b ) \
+        psz_meta = input_item_Get##b( input_GetItem( p_input ) ); \
+        if( psz_meta ) \
         { \
-            a = encode_URI_component( \
-                input_GetItem(p_input)->b ); \
+            a = encode_URI_component( psz_meta ); \
             if( !a ) \
             { \
+                free( psz_meta ); \
                 FREE_INPUT_AND_CHARS \
                 return VLC_ENOMEM; \
             } \
+            free( psz_meta ); \
         }
 
     i_status = input_GetItem(p_input)->p_meta->i_status;
@@ -1058,29 +1065,39 @@ static int ReadMetaData( intf_thread_t *p_this )
 
     if( i_status & ( !b_waiting ? ITEM_PREPARSED : ITEM_META_FETCHED ) )
     {
-        ALLOC_ITEM_META( psz_artist, p_meta->psz_artist )
+        ALLOC_ITEM_META( psz_artist, Artist )
         else
         {
             msg_Dbg( p_this, "No artist.." );
             WAIT_METADATA_FETCHING( psz_artist )
         }
-
-        ALLOC_ITEM_META( psz_title, psz_name )
+        psz_meta = input_item_GetName( input_GetItem( p_input ) );
+        if( psz_meta )
+        {
+            psz_title = encode_URI_component( psz_meta );
+            if( !psz_title )
+            {
+                free( psz_meta );
+                FREE_INPUT_AND_CHARS
+                return VLC_ENOMEM;
+            }
+            free( psz_meta );
+        }
         else
         {
             msg_Dbg( p_this, "No track name.." );
             WAIT_METADATA_FETCHING( psz_title );
         }
 
-        ALLOC_ITEM_META( psz_album, p_meta->psz_album )
+        ALLOC_ITEM_META( psz_album, Album )
         else
             psz_album = calloc( 1, 1 );
 
-        ALLOC_ITEM_META( psz_trackid, p_meta->psz_trackid )
+        ALLOC_ITEM_META( psz_trackid, TrackID )
         else
             psz_trackid = calloc( 1, 1 );
 
-        i_length = input_GetItem(p_input)->i_duration / 1000000;
+        i_length = input_item_GetDuration( input_GetItem( p_input ) ) / 1000000;
 
         vlc_mutex_lock ( &p_sys->lock );