1 /*****************************************************************************
2 * audioscrobbler.c : audioscrobbler submission plugin
3 *****************************************************************************
4 * Copyright © 2006-2011 the VideoLAN team
7 * Author: Rafaël Carré <funman at videolanorg>
8 * Ilkka Ollakka <ileoo at videolan org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /* audioscrobbler protocol version: 1.2
26 * http://www.audioscrobbler.net/development/protocol/
28 * TODO: "Now Playing" feature (not mandatory)
29 * Update to new API? http://www.lastfm.fr/api
31 /*****************************************************************************
33 *****************************************************************************/
41 #include <vlc_common.h>
42 #include <vlc_plugin.h>
43 #include <vlc_interface.h>
44 #include <vlc_dialog.h>
47 #include <vlc_stream.h>
49 #include <vlc_network.h>
50 #include <vlc_playlist.h>
52 /*****************************************************************************
54 *****************************************************************************/
58 /* Keeps track of metadata to be submitted */
59 typedef struct audioscrobbler_song_t
61 char *psz_a
; /**< track artist */
62 char *psz_t
; /**< track title */
63 char *psz_b
; /**< track album */
64 char *psz_n
; /**< track number */
65 int i_l
; /**< track length */
66 char *psz_m
; /**< musicbrainz id */
67 time_t date
; /**< date since epoch */
68 mtime_t i_start
; /**< playing start */
69 } audioscrobbler_song_t
;
73 audioscrobbler_song_t p_queue
[QUEUE_MAX
]; /**< songs not submitted yet*/
74 int i_songs
; /**< number of songs */
76 vlc_mutex_t lock
; /**< p_sys mutex */
77 vlc_cond_t wait
; /**< song to submit event */
78 vlc_thread_t thread
; /**< thread to submit song */
80 /* submission of played songs */
81 vlc_url_t p_submit_url
; /**< where to submit data */
83 /* submission of playing song */
85 char *psz_nowp_host
; /**< where to submit data */
86 int i_nowp_port
; /**< port to which submit */
87 char *psz_nowp_file
; /**< file to which submit */
89 char psz_auth_token
[33]; /**< Authentication token */
91 /* data about song currently playing */
92 audioscrobbler_song_t p_current_song
; /**< song being played */
94 mtime_t time_pause
; /**< time when vlc paused */
95 mtime_t time_total_pauses
; /**< total time in pause */
97 bool b_submit
; /**< do we have to submit ? */
99 bool b_state_cb
; /**< if we registered the
100 * "state" callback */
102 bool b_meta_read
; /**< if we read the song's
103 * metadata already */
106 static int Open (vlc_object_t
*);
107 static void Close (vlc_object_t
*);
108 static void *Run (void *);
110 /*****************************************************************************
112 ****************************************************************************/
114 #define USERNAME_TEXT N_("Username")
115 #define USERNAME_LONGTEXT N_("The username of your last.fm account")
116 #define PASSWORD_TEXT N_("Password")
117 #define PASSWORD_LONGTEXT N_("The password of your last.fm account")
118 #define URL_TEXT N_("Scrobbler URL")
119 #define URL_LONGTEXT N_("The URL set for an alternative scrobbler engine")
121 /* This error value is used when last.fm plugin has to be unloaded. */
122 #define VLC_AUDIOSCROBBLER_EFATAL -69
124 /* last.fm client identifier */
125 #define CLIENT_NAME PACKAGE
126 #define CLIENT_VERSION VERSION
129 set_category(CAT_INTERFACE
)
130 set_subcategory(SUBCAT_INTERFACE_CONTROL
)
131 set_shortname(N_("Audioscrobbler"))
132 set_description(N_("Submission of played songs to last.fm"))
133 add_string("lastfm-username", "",
134 USERNAME_TEXT
, USERNAME_LONGTEXT
, false)
135 add_password("lastfm-password", "",
136 PASSWORD_TEXT
, PASSWORD_LONGTEXT
, false)
137 add_string("scrobbler-url", "post.audioscrobbler.com",
138 URL_TEXT
, URL_LONGTEXT
, false)
139 set_capability("interface", 0)
140 set_callbacks(Open
, Close
)
143 /*****************************************************************************
144 * DeleteSong : Delete the char pointers in a song
145 *****************************************************************************/
146 static void DeleteSong(audioscrobbler_song_t
* p_song
)
148 FREENULL(p_song
->psz_a
);
149 FREENULL(p_song
->psz_b
);
150 FREENULL(p_song
->psz_t
);
151 FREENULL(p_song
->psz_m
);
152 FREENULL(p_song
->psz_n
);
155 /*****************************************************************************
156 * ReadMetaData : Read meta data when parsed by vlc
157 *****************************************************************************/
158 static void ReadMetaData(intf_thread_t
*p_this
)
160 input_thread_t
*p_input
;
161 input_item_t
*p_item
;
163 intf_sys_t
*p_sys
= p_this
->p_sys
;
165 p_input
= playlist_CurrentInput(pl_Get(p_this
));
169 p_item
= input_GetItem(p_input
);
172 vlc_object_release(p_input
);
176 #define ALLOC_ITEM_META(a, b) do { \
177 char *psz_meta = input_item_Get##b(p_item); \
178 if (psz_meta && *psz_meta) \
179 a = encode_URI_component(psz_meta); \
183 vlc_mutex_lock(&p_sys
->lock
);
185 p_sys
->b_meta_read
= true;
187 ALLOC_ITEM_META(p_sys
->p_current_song
.psz_a
, Artist
);
188 if (!p_sys
->p_current_song
.psz_a
)
190 msg_Dbg(p_this
, "No artist..");
191 DeleteSong(&p_sys
->p_current_song
);
195 ALLOC_ITEM_META(p_sys
->p_current_song
.psz_t
, Title
);
196 if (!p_sys
->p_current_song
.psz_t
)
198 msg_Dbg(p_this
, "No track name..");
199 DeleteSong(&p_sys
->p_current_song
);
203 /* Now we have read the mandatory meta data, so we can submit that info */
204 p_sys
->b_submit
= true;
206 ALLOC_ITEM_META(p_sys
->p_current_song
.psz_b
, Album
);
207 if (!p_sys
->p_current_song
.psz_b
)
208 p_sys
->p_current_song
.psz_b
= calloc(1, 1);
210 ALLOC_ITEM_META(p_sys
->p_current_song
.psz_m
, TrackID
);
211 if (!p_sys
->p_current_song
.psz_m
)
212 p_sys
->p_current_song
.psz_m
= calloc(1, 1);
214 p_sys
->p_current_song
.i_l
= input_item_GetDuration(p_item
) / 1000000;
216 ALLOC_ITEM_META(p_sys
->p_current_song
.psz_n
, TrackNum
);
217 if (!p_sys
->p_current_song
.psz_n
)
218 p_sys
->p_current_song
.psz_n
= calloc(1, 1);
219 #undef ALLOC_ITEM_META
221 msg_Dbg(p_this
, "Meta data registered");
224 vlc_mutex_unlock(&p_sys
->lock
);
225 vlc_object_release(p_input
);
228 /*****************************************************************************
229 * AddToQueue: Add the played song to the queue to be submitted
230 *****************************************************************************/
231 static void AddToQueue (intf_thread_t
*p_this
)
234 intf_sys_t
*p_sys
= p_this
->p_sys
;
236 vlc_mutex_lock(&p_sys
->lock
);
237 if (!p_sys
->b_submit
)
240 /* wait for the user to listen enough before submitting */
241 played_time
= mdate() - p_sys
->p_current_song
.i_start
-
242 p_sys
->time_total_pauses
;
243 played_time
/= 1000000; /* µs → s */
245 /*HACK: it seam that the preparsing sometime fail,
246 so use the playing time as the song length */
247 if (p_sys
->p_current_song
.i_l
== 0)
248 p_sys
->p_current_song
.i_l
= played_time
;
250 /* Don't send song shorter than 30s */
251 if (p_sys
->p_current_song
.i_l
< 30)
253 msg_Dbg(p_this
, "Song too short (< 30s), not submitting");
257 /* Send if the user had listen more than 240s OR half the track length */
258 if ((played_time
< 240) &&
259 (played_time
< (p_sys
->p_current_song
.i_l
/ 2)))
261 msg_Dbg(p_this
, "Song not listened long enough, not submitting");
265 /* Check that all meta are present */
266 if (!p_sys
->p_current_song
.psz_a
|| !*p_sys
->p_current_song
.psz_a
||
267 !p_sys
->p_current_song
.psz_t
|| !*p_sys
->p_current_song
.psz_t
)
269 msg_Dbg(p_this
, "Missing artist or title, not submitting");
273 if (p_sys
->i_songs
>= QUEUE_MAX
)
275 msg_Warn(p_this
, "Submission queue is full, not submitting");
279 msg_Dbg(p_this
, "Song will be submitted.");
281 #define QUEUE_COPY(a) \
282 p_sys->p_queue[p_sys->i_songs].a = p_sys->p_current_song.a
284 #define QUEUE_COPY_NULL(a) \
286 p_sys->p_current_song.a = NULL
289 QUEUE_COPY_NULL(psz_n
);
290 QUEUE_COPY_NULL(psz_a
);
291 QUEUE_COPY_NULL(psz_t
);
292 QUEUE_COPY_NULL(psz_b
);
293 QUEUE_COPY_NULL(psz_m
);
295 #undef QUEUE_COPY_NULL
300 /* signal the main loop we have something to submit */
301 vlc_cond_signal(&p_sys
->wait
);
304 DeleteSong(&p_sys
->p_current_song
);
305 p_sys
->b_submit
= false;
306 vlc_mutex_unlock(&p_sys
->lock
);
309 /*****************************************************************************
310 * PlayingChange: Playing status change callback
311 *****************************************************************************/
312 static int PlayingChange(vlc_object_t
*p_this
, const char *psz_var
,
313 vlc_value_t oldval
, vlc_value_t newval
, void *p_data
)
317 intf_thread_t
*p_intf
= (intf_thread_t
*) p_data
;
318 intf_sys_t
*p_sys
= p_intf
->p_sys
;
319 input_thread_t
*p_input
= (input_thread_t
*)p_this
;
324 if (newval
.i_int
!= INPUT_EVENT_STATE
) return VLC_SUCCESS
;
326 if (var_CountChoices(p_input
, "video-es"))
328 msg_Dbg(p_this
, "Not an audio-only input, not submitting");
332 state
= var_GetInteger(p_input
, "state");
334 if (!p_sys
->b_meta_read
&& state
>= PLAYING_S
)
336 ReadMetaData(p_intf
);
343 else if (state
== PAUSE_S
)
344 p_sys
->time_pause
= mdate();
345 else if (p_sys
->time_pause
> 0 && state
== PLAYING_S
)
347 p_sys
->time_total_pauses
+= (mdate() - p_sys
->time_pause
);
348 p_sys
->time_pause
= 0;
354 /*****************************************************************************
355 * ItemChange: Playlist item change callback
356 *****************************************************************************/
357 static int ItemChange(vlc_object_t
*p_this
, const char *psz_var
,
358 vlc_value_t oldval
, vlc_value_t newval
, void *p_data
)
360 input_thread_t
*p_input
;
361 intf_thread_t
*p_intf
= (intf_thread_t
*) p_data
;
362 intf_sys_t
*p_sys
= p_intf
->p_sys
;
363 input_item_t
*p_item
;
365 VLC_UNUSED(p_this
); VLC_UNUSED(psz_var
);
366 VLC_UNUSED(oldval
); VLC_UNUSED(newval
);
368 p_sys
->b_state_cb
= false;
369 p_sys
->b_meta_read
= false;
370 p_sys
->b_submit
= false;
372 p_input
= playlist_CurrentInput(pl_Get(p_intf
));
374 if (!p_input
|| p_input
->b_dead
)
377 p_item
= input_GetItem(p_input
);
380 vlc_object_release(p_input
);
384 if (var_CountChoices(p_input
, "video-es"))
386 msg_Dbg(p_this
, "Not an audio-only input, not submitting");
387 vlc_object_release(p_input
);
391 p_sys
->time_total_pauses
= 0;
392 time(&p_sys
->p_current_song
.date
); /* to be sent to last.fm */
393 p_sys
->p_current_song
.i_start
= mdate(); /* only used locally */
395 var_AddCallback(p_input
, "intf-event", PlayingChange
, p_intf
);
396 p_sys
->b_state_cb
= true;
398 if (input_item_IsPreparsed(p_item
))
399 ReadMetaData(p_intf
);
400 /* if the input item was not preparsed, we'll do it in PlayingChange()
401 * callback, when "state" == PLAYING_S */
403 vlc_object_release(p_input
);
407 /*****************************************************************************
408 * Open: initialize and create stuff
409 *****************************************************************************/
410 static int Open(vlc_object_t
*p_this
)
412 intf_thread_t
*p_intf
= (intf_thread_t
*) p_this
;
413 intf_sys_t
*p_sys
= calloc(1, sizeof(intf_sys_t
));
418 p_intf
->p_sys
= p_sys
;
420 vlc_mutex_init(&p_sys
->lock
);
421 vlc_cond_init(&p_sys
->wait
);
423 if (vlc_clone(&p_sys
->thread
, Run
, p_intf
, VLC_THREAD_PRIORITY_LOW
))
425 vlc_cond_destroy(&p_sys
->wait
);
426 vlc_mutex_destroy(&p_sys
->lock
);
431 var_AddCallback(pl_Get(p_intf
), "activity", ItemChange
, p_intf
);
436 /*****************************************************************************
437 * Close: destroy interface stuff
438 *****************************************************************************/
439 static void Close(vlc_object_t
*p_this
)
441 playlist_t
*p_playlist
= pl_Get(p_this
);
442 input_thread_t
*p_input
;
443 intf_thread_t
*p_intf
= (intf_thread_t
*) p_this
;
444 intf_sys_t
*p_sys
= p_intf
->p_sys
;
446 var_DelCallback(p_playlist
, "activity", ItemChange
, p_intf
);
448 vlc_cancel(p_sys
->thread
);
449 vlc_join(p_sys
->thread
, NULL
);
451 p_input
= playlist_CurrentInput(p_playlist
);
454 if (p_sys
->b_state_cb
)
455 var_DelCallback(p_input
, "intf-event", PlayingChange
, p_intf
);
456 vlc_object_release(p_input
);
460 for (i
= 0; i
< p_sys
->i_songs
; i
++)
461 DeleteSong(&p_sys
->p_queue
[i
]);
462 vlc_UrlClean(&p_sys
->p_submit_url
);
464 free(p_sys
->psz_nowp_host
);
465 free(p_sys
->psz_nowp_file
);
467 vlc_cond_destroy(&p_sys
->wait
);
468 vlc_mutex_destroy(&p_sys
->lock
);
472 /*****************************************************************************
473 * Handshake : Init audioscrobbler connection
474 *****************************************************************************/
475 static int Handshake(intf_thread_t
*p_this
)
477 char *psz_username
, *psz_password
;
478 char *psz_scrobbler_url
;
480 char psz_timestamp
[21];
482 struct md5_s p_struct_md5
;
485 char *psz_handshake_url
;
486 uint8_t p_buffer
[1024];
492 intf_thread_t
*p_intf
= (intf_thread_t
*) p_this
;
493 intf_sys_t
*p_sys
= p_this
->p_sys
;
495 psz_username
= var_InheritString(p_this
, "lastfm-username");
499 psz_password
= var_InheritString(p_this
, "lastfm-password");
506 /* username or password have not been setup */
507 if (!*psz_username
|| !*psz_password
)
516 /* generates a md5 hash of the password */
517 InitMD5(&p_struct_md5
);
518 AddMD5(&p_struct_md5
, (uint8_t*) psz_password
, strlen(psz_password
));
519 EndMD5(&p_struct_md5
);
523 char *psz_password_md5
= psz_md5_hash(&p_struct_md5
);
524 if (!psz_password_md5
)
530 snprintf(psz_timestamp
, sizeof(psz_timestamp
), "%"PRIu64
,
531 (uint64_t)timestamp
);
533 /* generates a md5 hash of :
534 * - md5 hash of the password, plus
535 * - timestamp in clear text
537 InitMD5(&p_struct_md5
);
538 AddMD5(&p_struct_md5
, (uint8_t*) psz_password_md5
, 32);
539 AddMD5(&p_struct_md5
, (uint8_t*) psz_timestamp
, strlen(psz_timestamp
));
540 EndMD5(&p_struct_md5
);
541 free(psz_password_md5
);
543 char *psz_auth_token
= psz_md5_hash(&p_struct_md5
);
550 psz_scrobbler_url
= var_InheritString(p_this
, "scrobbler-url");
551 if (!psz_scrobbler_url
)
557 i_ret
= asprintf(&psz_handshake_url
,
558 "http://%s/?hs=true&p=1.2&c="CLIENT_NAME
"&v="CLIENT_VERSION
"&u=%s&t=%s&a=%s"
559 , psz_scrobbler_url
, psz_username
, psz_timestamp
, psz_auth_token
);
561 free(psz_scrobbler_url
);
566 /* send the http handshake request */
567 p_stream
= stream_UrlNew(p_intf
, psz_handshake_url
);
568 free(psz_handshake_url
);
574 i_ret
= stream_Read(p_stream
, p_buffer
, sizeof(p_buffer
) - 1);
577 stream_Delete(p_stream
);
580 p_buffer
[i_ret
] = '\0';
581 stream_Delete(p_stream
);
583 p_buffer_pos
= strstr((char*) p_buffer
, "FAILED ");
586 /* handshake request failed, sorry */
587 msg_Err(p_this
, "last.fm handshake failed: %s", p_buffer_pos
+ 7);
591 if (strstr((char*) p_buffer
, "BADAUTH"))
593 /* authentication failed, bad username/password combination */
595 _("last.fm: Authentication failed"),
596 "%s", _("last.fm username or password is incorrect. "
597 "Please verify your settings and relaunch VLC."));
598 return VLC_AUDIOSCROBBLER_EFATAL
;
601 if (strstr((char*) p_buffer
, "BANNED"))
603 /* oops, our version of vlc has been banned by last.fm servers */
604 msg_Err(p_intf
, "This version of VLC has been banned by last.fm. "
605 "You should upgrade VLC, or disable the last.fm plugin.");
606 return VLC_AUDIOSCROBBLER_EFATAL
;
609 if (strstr((char*) p_buffer
, "BADTIME"))
611 /* The system clock isn't good */
612 msg_Err(p_intf
, "last.fm handshake failed because your clock is too "
613 "much shifted. Please correct it, and relaunch VLC.");
614 return VLC_AUDIOSCROBBLER_EFATAL
;
617 p_buffer_pos
= strstr((char*) p_buffer
, "OK");
621 p_buffer_pos
= strstr(p_buffer_pos
, "\n");
622 if (!p_buffer_pos
|| strlen(p_buffer_pos
) < 33)
624 p_buffer_pos
++; /* we skip the '\n' */
626 /* save the session ID */
627 memcpy(p_sys
->psz_auth_token
, p_buffer_pos
, 32);
628 p_sys
->psz_auth_token
[32] = '\0';
630 p_buffer_pos
= strstr(p_buffer_pos
, "http://");
631 if (!p_buffer_pos
|| strlen(p_buffer_pos
) == 7)
634 /* We need to read the nowplaying url */
635 p_buffer_pos
+= 7; /* we skip "http://" */
637 psz_url
= strndup(p_buffer_pos
, strcspn(p_buffer_pos
, "\n"));
641 switch(ParseURL(psz_url
, &p_sys
->psz_nowp_host
,
642 &p_sys
->psz_nowp_file
, &p_sys
->i_nowp_port
))
653 p_buffer_pos
= strstr(p_buffer_pos
, "http://");
654 if (!p_buffer_pos
|| strlen(p_buffer_pos
) == 7)
657 /* We need to read the submission url */
658 p_buffer_pos
+= 7; /* we skip "http://" */
659 psz_url
= strndup(p_buffer_pos
, strcspn(p_buffer_pos
, "\n"));
663 /* parse the submission url */
664 vlc_UrlParse(&p_sys
->p_submit_url
, psz_url
, 0);
673 msg_Err(p_intf
, "Handshake: can't recognize server protocol");
677 static void HandleInterval(mtime_t
*next
, unsigned int *i_interval
)
679 if (*i_interval
== 0)
681 /* first interval is 1 minute */
686 /* else we double the previous interval, up to 120 minutes */
688 if (*i_interval
> 120)
691 *next
= mdate() + (*i_interval
* 1000000 * 60);
694 /*****************************************************************************
695 * Run : call Handshake() then submit songs
696 *****************************************************************************/
697 static void *Run(void *data
)
699 intf_thread_t
*p_intf
= data
;
700 uint8_t p_buffer
[1024];
701 int canc
= vlc_savecancel();
702 bool b_handshaked
= false;
704 /* data about audioscrobbler session */
705 mtime_t next_exchange
= -1; /**< when can we send data */
706 unsigned int i_interval
; /**< waiting interval (secs)*/
708 intf_sys_t
*p_sys
= p_intf
->p_sys
;
713 vlc_restorecancel(canc
);
714 vlc_mutex_lock(&p_sys
->lock
);
715 mutex_cleanup_push(&p_sys
->lock
);
718 vlc_cond_wait(&p_sys
->wait
, &p_sys
->lock
);
719 while (mdate() < next_exchange
);
722 canc
= vlc_savecancel();
724 /* handshake if needed */
727 msg_Dbg(p_intf
, "Handshaking with last.fm ...");
729 switch(Handshake(p_intf
))
735 /* username not set */
737 _("Last.fm username not set"),
738 "%s", _("Please set a username or disable the "
739 "audioscrobbler plugin, and restart VLC.\n"
740 "Visit http://www.last.fm/join/ to get an account."));
744 msg_Dbg(p_intf
, "Handshake successful :)");
747 next_exchange
= mdate();
750 case VLC_AUDIOSCROBBLER_EFATAL
:
751 msg_Warn(p_intf
, "Exiting...");
756 /* protocol error : we'll try later */
757 HandleInterval(&next_exchange
, &i_interval
);
760 /* if handshake failed let's restart the loop */
765 msg_Dbg(p_intf
, "Going to submit some data...");
767 if (asprintf(&psz_submit
, "s=%s", p_sys
->psz_auth_token
) == -1)
770 /* forge the HTTP POST request */
771 vlc_mutex_lock(&p_sys
->lock
);
772 audioscrobbler_song_t
*p_song
;
773 for (int i_song
= 0 ; i_song
< p_sys
->i_songs
; i_song
++)
775 char *psz_submit_song
, *psz_submit_tmp
;
776 p_song
= &p_sys
->p_queue
[i_song
];
777 if (asprintf(&psz_submit_song
,
787 i_song
, p_song
->psz_a
,
788 i_song
, p_song
->psz_t
,
789 i_song
, (unsigned)p_song
->date
, /* HACK: %ju (uintmax_t) unsupported on Windows */
793 i_song
, p_song
->psz_b
,
794 i_song
, p_song
->psz_n
,
795 i_song
, p_song
->psz_m
797 { /* Out of memory */
798 vlc_mutex_unlock(&p_sys
->lock
);
801 psz_submit_tmp
= psz_submit
;
802 if (asprintf(&psz_submit
, "%s%s",
803 psz_submit_tmp
, psz_submit_song
) == -1)
804 { /* Out of memory */
805 free(psz_submit_tmp
);
806 free(psz_submit_song
);
807 vlc_mutex_unlock(&p_sys
->lock
);
810 free(psz_submit_song
);
811 free(psz_submit_tmp
);
813 vlc_mutex_unlock(&p_sys
->lock
);
815 int i_post_socket
= net_ConnectTCP(p_intf
, p_sys
->p_submit_url
.psz_host
,
816 p_sys
->p_submit_url
.i_port
);
818 if (i_post_socket
== -1)
820 /* If connection fails, we assume we must handshake again */
821 HandleInterval(&next_exchange
, &i_interval
);
822 b_handshaked
= false;
827 /* we transmit the data */
828 int i_net_ret
= net_Printf(p_intf
, i_post_socket
, NULL
,
830 "Accept-Encoding: identity\n"
831 "Content-length: %zu\n"
832 "Connection: close\n"
833 "Content-type: application/x-www-form-urlencoded\n"
835 "User-agent: VLC media player/"VERSION
"\r\n"
839 p_sys
->p_submit_url
.psz_path
, strlen(psz_submit
),
840 p_sys
->p_submit_url
.psz_host
, psz_submit
846 /* If connection fails, we assume we must handshake again */
847 HandleInterval(&next_exchange
, &i_interval
);
848 b_handshaked
= false;
852 i_net_ret
= net_Read(p_intf
, i_post_socket
, NULL
,
853 p_buffer
, sizeof(p_buffer
) - 1, false);
856 /* if we get no answer, something went wrong : try again */
860 net_Close(i_post_socket
);
861 p_buffer
[i_net_ret
] = '\0';
863 char *failed
= strstr((char *) p_buffer
, "FAILED");
866 msg_Warn(p_intf
, "%s", failed
);
867 HandleInterval(&next_exchange
, &i_interval
);
871 if (strstr((char *) p_buffer
, "BADSESSION"))
873 msg_Err(p_intf
, "Authentication failed (BADSESSION), are you connected to last.fm with another program ?");
874 b_handshaked
= false;
875 HandleInterval(&next_exchange
, &i_interval
);
879 if (strstr((char *) p_buffer
, "OK"))
881 for (int i
= 0; i
< p_sys
->i_songs
; i
++)
882 DeleteSong(&p_sys
->p_queue
[i
]);
885 next_exchange
= mdate();
886 msg_Dbg(p_intf
, "Submission successful!");
890 msg_Err(p_intf
, "Authentication failed, handshaking again (%s)",
892 b_handshaked
= false;
893 HandleInterval(&next_exchange
, &i_interval
);
897 vlc_restorecancel(canc
);