]> git.sesse.net Git - vlc/blobdiff - modules/misc/audioscrobbler.c
Removes trailing spaces. Removes tabs.
[vlc] / modules / misc / audioscrobbler.c
index e08e79028027d5076537d0cdd31334644d845230..15213061c9cc7959f523c30109de844712c3ee55 100644 (file)
@@ -22,7 +22,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-/* audioscrobbler protocol version: 1.1 
+/* audioscrobbler protocol version: 1.1
  * http://audioscrobbler.net/wiki/Protocol1.1
  * */
 
@@ -30,8 +30,6 @@
  * Preamble
  *****************************************************************************/
 
-#define _GNU_SOURCE
-#include <string.h>
 
 #if defined( WIN32 )
 #include <time.h>
@@ -102,6 +100,7 @@ intf_sys_t *p_sys_global;     /* to retrieve p_sys in Run() thread */
 static int  Open        ( vlc_object_t * );
 static void Close       ( vlc_object_t * );
 static void Run         ( intf_thread_t * );
+static void Main        ( intf_thread_t * );
 static int ItemChange   ( vlc_object_t *, const char *, vlc_value_t,
                                 vlc_value_t, void * );
 static int PlayingChange( vlc_object_t *, const char *, vlc_value_t,
@@ -151,7 +150,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 );
@@ -282,10 +281,19 @@ static void Close( vlc_object_t *p_this )
     free( p_sys );
 }
 
+/****************************************************************************
+ * Run : create Main() thread
+ * **************************************************************************/
+static void Run( intf_thread_t *p_intf )
+{
+    if( vlc_thread_create( p_intf, "Audioscrobbler", Main, 0, VLC_TRUE ) )
+        msg_Err( p_intf, "failed to create Audioscrobbler thread" );
+}
+
 /*****************************************************************************
- * Run : call Handshake() then submit songs
+ * Main : call Handshake() then submit songs
  *****************************************************************************/
-static void Run( intf_thread_t *p_this )
+static void Main( intf_thread_t *p_this )
 {
     char                    *psz_submit         = NULL;
     char                    *psz_submit_song    = NULL;
@@ -298,6 +306,8 @@ static void Run( intf_thread_t *p_this )
     int                     i_post_socket;
     time_t                  played_time;
 
+    vlc_thread_ready( p_this );
+
     p_this->p_sys = p_sys_global;
     intf_sys_t *p_sys = p_this->p_sys;
 
@@ -320,7 +330,7 @@ static void Run( intf_thread_t *p_this )
     /* main loop */
     while( !p_this->b_die )
     {
-        /* verify if there is data to submit 
+        /* verify if there is data to submit
          * and if waiting interval is elapsed */
         if ( ( p_sys->p_first_queue->i_songs_nb > 0 ) &&
             ( time( NULL ) >= p_sys->time_next_exchange ) )
@@ -329,7 +339,7 @@ static void Run( intf_thread_t *p_this )
             if( p_sys->b_handshaked == VLC_FALSE )
             {
                 msg_Dbg( p_this, "Handshaking with last.fm ..." );
+
                 switch( Handshake( p_this ) )
                 {
                     case VLC_ENOMEM:
@@ -367,6 +377,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..." );
@@ -745,7 +759,7 @@ static int Handshake( intf_thread_t *p_this )
     stream_t            *p_stream;
     char                *psz_handshake_url      = NULL;
     uint8_t             *p_buffer               = NULL;
-    char                *p_buffer_pos           = NULL; 
+    char                *p_buffer_pos           = NULL;
     char                *psz_url_parser         = NULL;
     char                *psz_buffer_substring;
     int                 i_url_pos, i;
@@ -1069,7 +1083,7 @@ static int ReadMetaData( intf_thread_t *p_this )
             msg_Dbg( p_this, "No artist.." );
             WAIT_METADATA_FETCHING( psz_artist )
         }
-        psz_meta = input_item_GetName( input_GetItem( p_input ) );
+        psz_meta = input_item_GetTitle( input_GetItem( p_input ) );
         if( psz_meta )
         {
             psz_title = encode_URI_component( psz_meta );
@@ -1095,7 +1109,7 @@ static int ReadMetaData( intf_thread_t *p_this )
         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 );
 
@@ -1111,8 +1125,8 @@ static int ReadMetaData( intf_thread_t *p_this )
 
         msg_Dbg( p_this, "Meta data registered, waiting to be queued" );
     }
-   
-    FREE_INPUT_AND_CHARS 
+    FREE_INPUT_AND_CHARS
     return VLC_SUCCESS;
 #undef FREE_INPUT_AND_CHARS
 #undef ALLOC_ITEM_META