summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--deadbeef.h1
-rw-r--r--playlist.c4
-rw-r--r--playlist.h1
-rw-r--r--plugins/lastfm/lastfm.c33
4 files changed, 37 insertions, 2 deletions
diff --git a/deadbeef.h b/deadbeef.h
index 1db005b6..2dfefda9 100644
--- a/deadbeef.h
+++ b/deadbeef.h
@@ -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;
diff --git a/playlist.c b/playlist.c
index f6c34f1f..5ee1a818 100644
--- a/playlist.c
+++ b/playlist.c
@@ -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) {
diff --git a/playlist.h b/playlist.h
index 7e2df4c2..b7304b14 100644
--- a/playlist.h
+++ b/playlist.h
@@ -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;
}