Skip to content

Commit

Permalink
[lastfm] Also scrobble after regular daap streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
ejurgensen committed Sep 2, 2016
1 parent 7f0d34d commit d66a130
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/httpd.c
Expand Up @@ -54,12 +54,16 @@
#include "db.h"
#include "conffile.h"
#include "misc.h"
#include "worker.h"
#include "httpd.h"
#include "httpd_rsp.h"
#include "httpd_daap.h"
#include "httpd_dacp.h"
#include "httpd_streaming.h"
#include "transcode.h"
#ifdef LASTFM
# include "lastfm.h"
#endif

/*
* HTTP client quirks by User-Agent, from mt-daapd
Expand Down Expand Up @@ -167,15 +171,38 @@ stream_end(struct stream_ctx *st, int failed)
free(st);
}

/* Callback from the worker thread (async operation as it may block) */
static void
stream_up_playcount(struct stream_ctx *st)
playcount_inc_cb(void *arg)
{
int *id = arg;

db_file_inc_playcount(*id);
}

#ifdef LASTFM
/* Callback from the worker thread (async operation as it may block) */
static void
scrobble_cb(void *arg)
{
int *id = arg;

lastfm_scrobble(*id);
}
#endif

static void
stream_end_register(struct stream_ctx *st)
{
if (!st->marked
&& (st->stream_size > ((st->size * 50) / 100))
&& (st->offset > ((st->size * 80) / 100)))
{
st->marked = 1;
db_file_inc_playcount(st->id);
worker_execute(playcount_inc_cb, &st->id, sizeof(int), 0);
#ifdef LASTFM
worker_execute(scrobble_cb, &st->id, sizeof(int), 1);
#endif
}
}

Expand Down Expand Up @@ -269,7 +296,7 @@ stream_chunk_xcode_cb(int fd, short event, void *arg)

st->offset += ret;

stream_up_playcount(st);
stream_end_register(st);

return;

Expand Down Expand Up @@ -335,7 +362,7 @@ stream_chunk_raw_cb(int fd, short event, void *arg)

st->offset += ret;

stream_up_playcount(st);
stream_end_register(st);
}

static void
Expand Down

0 comments on commit d66a130

Please sign in to comment.