diff options
author | waker <wakeroid@gmail.com> | 2009-08-27 23:03:00 +0200 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2009-08-27 23:03:00 +0200 |
commit | 81d1b50a3bd28099b784e5b2a14295e715a48d01 (patch) | |
tree | c0b51d15a92d17ca79b2195fe6cf45d6b56b1243 | |
parent | be13f4e8c6ab99401f6eda6f7b91278c7fef3d47 (diff) |
lastfm submission works
-rw-r--r-- | deadbeef.h | 1 | ||||
-rw-r--r-- | playlist.c | 4 | ||||
-rw-r--r-- | playlist.h | 1 | ||||
-rw-r--r-- | plugins/lastfm/lastfm.c | 33 |
4 files changed, 37 insertions, 2 deletions
@@ -57,6 +57,7 @@ typedef struct { int endoffset; // offset from end of file where music data ends int shufflerating; // sort order for shuffle mode float playtime; // total playtime + time_t started_timestamp; // result of calling time(NULL) const char *filetype; // e.g. MP3 or OGG } DB_playItem_t; @@ -25,6 +25,7 @@ #include <sys/stat.h> #include <unistd.h> #include <assert.h> +#include <time.h> #include "playlist.h" #include "codec.h" #include "streamer.h" @@ -608,8 +609,9 @@ pl_set_current (playItem_t *it) { streamer_reset (0); } if (it) { - pl_item_copy (&playlist_current, it); it->played = 1; + it->started_timestamp = time (NULL); + pl_item_copy (&playlist_current, it); } codec_unlock (); if (it) { @@ -39,6 +39,7 @@ typedef struct playItem_s { int endoffset; // offset from end of file where music data ends (mp3) int shufflerating; // sort order for shuffle mode float playtime; // total playtime + time_t started_timestamp; // result of calling time(NULL) const char *filetype; // e.g. MP3 or OGG struct playItem_s *next[PL_MAX_ITERATORS]; // next item in linked list struct playItem_s *prev[PL_MAX_ITERATORS]; // prev item in linked list diff --git a/plugins/lastfm/lastfm.c b/plugins/lastfm/lastfm.c index 27d188d9..2d805ff6 100644 --- a/plugins/lastfm/lastfm.c +++ b/plugins/lastfm/lastfm.c @@ -355,7 +355,7 @@ lastfm_songstarted (DB_event_song_t *ev, uintptr_t data) { } char req[4096]; - snprintf (req, sizeof (req), "s=%s&a=%s&t=%s&b=%s&l=%d&n=%s&m=%s&", lfm_sess, a, t, b, (int)l, n, m); + snprintf (req, sizeof (req), "s=%s&a=%s&t=%s&b=%s&l=%d&n=%s&m=%s", lfm_sess, a, t, b, (int)l, n, m); fprintf (stderr, "sending nowplaying to lfm:\n%s\n", req); int status = curl_req_send (lfm_nowplaying_url, req); if (!status) { @@ -383,7 +383,38 @@ lastfm_songfinished (DB_event_song_t *ev, uintptr_t data) { } else { printf ("file %s doesn't have enough tags to submit to last.fm\n", ev->song->fname); + return 0; + } + + // check submission rules + +#if 0 + // must be played for >=240sec of half the total time + if (ev->song->playtime < 240 && ev->song->playtime < ev->song->duration/2) { + return 0; + } + + // duration must be >= 30 sec + if (ev->song->duration < 30) { + return 0; + } + + if (auth () < 0) { + return; } +#endif + + char req[4096]; + snprintf (req, sizeof (req), "s=%s&a[0]=%s&t[0]=%s&i[0]=%d&o[0]=P&r[0]=&b[0]=%s&l[0]=%d&n[0]=%s&m[0]=%s", lfm_sess, a, t, ev->song->started_timestamp, b, (int)l, n, m); + fprintf (stderr, "sending submission to lfm:\n%s\n", req); + int status = curl_req_send (lfm_submission_url, req); + if (!status) { + if (strncmp (lfm_reply, "OK", 2)) { + fprintf (stderr, "submission failed, response:\n%s\n", lfm_reply); + lfm_sess[0] = 0; + } + } + curl_req_cleanup (); return 0; } |