From b6dd45bb67dc7fb64a2849448a5a7395bb49d356 Mon Sep 17 00:00:00 2001 From: Andreas Smas Date: Thu, 8 Sep 2016 21:52:35 +0200 Subject: [PATCH] videoscrobble: Pass video origin as third argument to scrobble callbacks --- .../videoscrobbling/videoscrobbling_example.js | 13 +++++++++---- res/ecmascript/modules/movian/videoscrobbler.js | 11 ++++++----- src/arch/rpi/rpi_tv.c | 3 ++- src/ecmascript/es_scrobble.c | 9 +++++++-- src/fileaccess/fa_video.c | 10 ++++++---- src/ipc/libcec.c | 3 ++- src/video/video_playback.c | 5 +++-- src/video/video_playback.h | 6 ++++-- 8 files changed, 39 insertions(+), 21 deletions(-) diff --git a/plugin_examples/videoscrobbling/videoscrobbling_example.js b/plugin_examples/videoscrobbling/videoscrobbling_example.js index b875c9c8c4..180e4ef35f 100644 --- a/plugin_examples/videoscrobbling/videoscrobbling_example.js +++ b/plugin_examples/videoscrobbling/videoscrobbling_example.js @@ -40,6 +40,9 @@ This can be used to query current position, etc during pause/resume + Also the origin item (the item that the video was started from, on the + "previous page" so to say) is also available as a third argument + */ @@ -47,22 +50,24 @@ var videoscrobbler = require('movian/videoscrobbler'); var vs = new videoscrobbler.VideoScrobbler(); -vs.onstart = function(data, prop) { +vs.onstart = function(data, prop, origin) { print("Started playback session: " + data.id + " at position " + prop.currenttime + " (seconds)"); print(JSON.stringify(data, null, 4)); + print("The filename is: " + origin.filename); + require('movian/prop').print(origin); } -vs.onstop = function(data, prop) { +vs.onstop = function(data, prop, origin) { print("Stopped playback session: " + data.id + " at position " + prop.currenttime + " (seconds)"); print(JSON.stringify(data, null, 4)); } -vs.onpause = function(data, prop) { +vs.onpause = function(data, prop, origin) { print("Paused playback session: " + data.id + " at position " + prop.currenttime + " (seconds)"); print(JSON.stringify(data, null, 4)); } -vs.onresume = function(data, prop) { +vs.onresume = function(data, prop, origin) { print("Resumed playback session: " + data.id + " at position " + prop.currenttime + " (seconds)"); print(JSON.stringify(data, null, 4)); } diff --git a/res/ecmascript/modules/movian/videoscrobbler.js b/res/ecmascript/modules/movian/videoscrobbler.js index e9024381cb..02d352ba52 100644 --- a/res/ecmascript/modules/movian/videoscrobbler.js +++ b/res/ecmascript/modules/movian/videoscrobbler.js @@ -4,15 +4,16 @@ var P = require('movian/prop'); exports.VideoScrobbler = function() { this.paused = false; - this.hook = hook.register('videoscrobble', function(event, data, prop) { + this.hook = hook.register('videoscrobble', function(event, data, prop, origin) { prop = P.makeProp(prop); + origin = P.makeProp(origin); this.paused = prop.playstatus == 'pause'; switch(event) { case 'start': if(typeof(this.onstart) === 'function') - this.onstart(data, prop); + this.onstart(data, prop, origin); P.subscribeValue(prop.playstatus, function(val) { var paused = val === 'pause'; @@ -22,10 +23,10 @@ exports.VideoScrobbler = function() { this.paused = paused; if(paused) { if(typeof(this.onpause) === 'function') - this.onpause(data, prop); + this.onpause(data, prop, origin); } else { if(typeof(this.onresume) === 'function') - this.onresume(data, prop); + this.onresume(data, prop, origin); } }.bind(this), { autoDestroy: true @@ -34,7 +35,7 @@ exports.VideoScrobbler = function() { case 'stop': if(typeof(this.onstop) === 'function') - this.onstop(data, prop); + this.onstop(data, prop, origin); break; } diff --git a/src/arch/rpi/rpi_tv.c b/src/arch/rpi/rpi_tv.c index 19343ee4a8..f6c7259ed6 100644 --- a/src/arch/rpi/rpi_tv.c +++ b/src/arch/rpi/rpi_tv.c @@ -201,7 +201,8 @@ static int respond; static void -rpi_tv_vpi(vpi_op_t op, struct htsmsg *info, struct prop *p) +rpi_tv_vpi(vpi_op_t op, struct htsmsg *info, struct prop *p, + struct prop *origin) { if(!respond) return; diff --git a/src/ecmascript/es_scrobble.c b/src/ecmascript/es_scrobble.c index 7817c96ca6..9a5bc63170 100644 --- a/src/ecmascript/es_scrobble.c +++ b/src/ecmascript/es_scrobble.c @@ -27,6 +27,7 @@ typedef struct video_scrobble_aux { vpi_op_t op; struct htsmsg *info; struct prop *p; + struct prop *origin; } video_scrobble_aux_t; @@ -56,7 +57,8 @@ video_scrobble_push_args(duk_context *duk, void *opaque) } es_stprop_push(duk, vsa->p); - return 3; + es_stprop_push(duk, vsa->origin); + return 4; } @@ -67,6 +69,7 @@ scrobble_video_task(void *aux) es_hook_invoke("videoscrobble", video_scrobble_push_args, vsa); htsmsg_release(vsa->info); prop_ref_dec(vsa->p); + prop_ref_dec(vsa->origin); free(vsa); } @@ -75,12 +78,14 @@ scrobble_video_task(void *aux) * */ static void -es_scrobble_video(vpi_op_t op, struct htsmsg *info, struct prop *p) +es_scrobble_video(vpi_op_t op, struct htsmsg *info, struct prop *p, + struct prop *origin) { video_scrobble_aux_t *vsa = malloc(sizeof(video_scrobble_aux_t)); vsa->op = op; vsa->info = htsmsg_copy(info); vsa->p = prop_ref_inc(p); + vsa->origin = prop_follow(origin); task_run(scrobble_video_task, vsa); } diff --git a/src/fileaccess/fa_video.c b/src/fileaccess/fa_video.c index 3b2a765056..96c24b359d 100644 --- a/src/fileaccess/fa_video.c +++ b/src/fileaccess/fa_video.c @@ -169,7 +169,8 @@ video_player_loop(AVFormatContext *fctx, media_codec_t **cwvec, fa_handle_t *fh, int resume_mode, const char *title, - htsmsg_t *vpi) + htsmsg_t *vpi, + prop_t *origin) { media_buf_t *mb = NULL; media_queue_t *mq = NULL; @@ -203,7 +204,7 @@ video_player_loop(AVFormatContext *fctx, media_codec_t **cwvec, if(fctx->duration != AV_NOPTS_VALUE) htsmsg_add_dbl(vpi, "duration", fctx->duration / 1000000.0f); - video_playback_info_invoke(VPI_START, vpi, mp->mp_prop_root); + video_playback_info_invoke(VPI_START, vpi, mp->mp_prop_root, origin); const int64_t offset = fctx->start_time != PTS_UNSET ? fctx->start_time : 0; @@ -885,9 +886,10 @@ be_file_playvideo_fh(const char *url, media_pipe_t *mp, event_t *e; e = video_player_loop(fctx, cwvec, mp, va.flags, errbuf, errlen, va.canonical_url, freetype_context, si, ci, - cwvec_size, fh, va.resume_mode, va.title, vpi); + cwvec_size, fh, va.resume_mode, va.title, vpi, + va.origin); - video_playback_info_invoke(VPI_STOP, vpi, mp->mp_prop_root); + video_playback_info_invoke(VPI_STOP, vpi, mp->mp_prop_root, va.origin); htsmsg_release(vpi); seek_index_destroy(si); diff --git a/src/ipc/libcec.c b/src/ipc/libcec.c index 9a02f87276..6e9845194f 100644 --- a/src/ipc/libcec.c +++ b/src/ipc/libcec.c @@ -303,7 +303,8 @@ activate_self(void *aux) static void -libcec_vpi(vpi_op_t op, struct htsmsg *info, struct prop *p) +libcec_vpi(vpi_op_t op, struct htsmsg *info, struct prop *p, + struct prop *origin) { if(!conn) return; diff --git a/src/video/video_playback.c b/src/video/video_playback.c index 7fda76185c..7186b25f7c 100644 --- a/src/video/video_playback.c +++ b/src/video/video_playback.c @@ -1035,9 +1035,10 @@ register_video_playback_info_handler(video_playback_info_handler_t *vpih) void -video_playback_info_invoke(vpi_op_t op, struct htsmsg *vpi, struct prop *p) +video_playback_info_invoke(vpi_op_t op, struct htsmsg *vpi, struct prop *p, + struct prop *origin) { video_playback_info_handler_t *vpih; LIST_FOREACH(vpih, &vpi_handlers, link) - vpih->invoke(op, vpi, p); + vpih->invoke(op, vpi, p, origin); } diff --git a/src/video/video_playback.h b/src/video/video_playback.h index 860257f6dd..2f69d9810d 100644 --- a/src/video/video_playback.h +++ b/src/video/video_playback.h @@ -52,13 +52,15 @@ typedef enum { } vpi_op_t; typedef struct video_playback_info_handler { - void (*invoke)(vpi_op_t op, struct htsmsg *info, struct prop *mp_root); + void (*invoke)(vpi_op_t op, struct htsmsg *info, struct prop *mp_root, + struct prop *origin); LIST_ENTRY(video_playback_info_handler) link; } video_playback_info_handler_t; void register_video_playback_info_handler(video_playback_info_handler_t *vpih); -void video_playback_info_invoke(vpi_op_t op, struct htsmsg *vpi, struct prop *p); +void video_playback_info_invoke(vpi_op_t op, struct htsmsg *vpi, + struct prop *p, struct prop *origin); #define VPI_REGISTER(handler) \ static video_playback_info_handler_t handler ## _strct = { handler}; \