From 424271d5dffef1d8565e2ca287f3b9e405cb3e37 Mon Sep 17 00:00:00 2001 From: Krateng Date: Fri, 31 May 2019 16:02:39 +0200 Subject: [PATCH] Scrobbler sends more accurate times when loop-listening to a track --- rules/predefined/krateng_kpopgirlgroups.tsv | 1 + scrobblers/chromium-generic/background.js | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/rules/predefined/krateng_kpopgirlgroups.tsv b/rules/predefined/krateng_kpopgirlgroups.tsv index 98b0634..e07c332 100644 --- a/rules/predefined/krateng_kpopgirlgroups.tsv +++ b/rules/predefined/krateng_kpopgirlgroups.tsv @@ -114,6 +114,7 @@ replacetitle 음오아예 (Um Oh Ah Yeh) (Um Oh Ah Yeh) Um Oh Ah Yeh replacetitle 따끔 (a little bit) A Little Bit # Hello Venus +replaceartist HELLOVENUS Hello Venus replaceartist Hello/Venus Hello Venus # BESTie diff --git a/scrobblers/chromium-generic/background.js b/scrobblers/chromium-generic/background.js index 85d7143..9806105 100644 --- a/scrobblers/chromium-generic/background.js +++ b/scrobblers/chromium-generic/background.js @@ -202,7 +202,8 @@ class Controller { // Already played full song while (this.alreadyPlayed > this.currentLength) { this.alreadyPlayed = this.alreadyPlayed - this.currentLength - scrobble(this.currentArtist,this.currentTitle,this.currentLength) + var secondsago = this.alreadyPlayed + scrobble(this.currentArtist,this.currentTitle,this.currentLength,secondsago) } this.setUpdate() @@ -248,7 +249,8 @@ class Controller { // Already played full song while (this.alreadyPlayed > this.currentLength) { this.alreadyPlayed = this.alreadyPlayed - this.currentLength - scrobble(this.currentArtist,this.currentTitle,this.currentLength) + var secondsago = this.alreadyPlayed + scrobble(this.currentArtist,this.currentTitle,this.currentLength,secondsago) } this.currentlyPlaying = false @@ -282,17 +284,22 @@ class Controller { -function scrobble(artist,title,seconds) { - console.log("Scrobbling " + artist + " - " + title + "; " + seconds + " seconds playtime") - artiststring = encodeURIComponent(artist) - titlestring = encodeURIComponent(title) +function scrobble(artist,title,seconds,secondsago=0) { + console.log("Scrobbling " + artist + " - " + title + "; " + seconds + " seconds playtime, " + secondsago + " seconds ago") + var artiststring = encodeURIComponent(artist) + var titlestring = encodeURIComponent(title) + var d = new Date() + var time = Math.floor(d.getTime()/1000) - secondsago + //console.log("Time: " + time) + var requestbody = "artist=" + artiststring + "&title=" + titlestring + "&duration=" + seconds + "&time=" + time chrome.storage.local.get("apikey",function(result) { APIKEY = result["apikey"] chrome.storage.local.get("serverurl",function(result) { URL = result["serverurl"] var xhttp = new XMLHttpRequest(); xhttp.open("POST",URL + "/api/newscrobble",true); - xhttp.send("artist=" + artiststring + "&title=" + titlestring + "&duration=" + seconds + "&key=" + APIKEY) + xhttp.send(requestbody + "&key=" + APIKEY) + //console.log("Sent: " + requestbody) }); });