1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Added bandcamp to scrobbler

This commit is contained in:
Krateng 2019-06-25 16:05:36 +02:00
parent da76b6105e
commit 2cbe67f149
4 changed files with 38 additions and 5 deletions

View File

@ -68,7 +68,7 @@ If you didn't install Maloja from the package (and therefore don't have it in `/
### Native API ### Native API
If you use Plex Web or Youtube Music on Chromium, you can use the included extension (also available on the [Chrome Web Store](https://chrome.google.com/webstore/detail/maloja-scrobbler/cfnbifdmgbnaalphodcbandoopgbfeeh)). Make sure to enter the random key Maloja generates on first startup in the extension settings. If you use Plex Web, Spotify, Bandcamp or Youtube Music on Chromium, you can use the included extension (also available on the [Chrome Web Store](https://chrome.google.com/webstore/detail/maloja-scrobbler/cfnbifdmgbnaalphodcbandoopgbfeeh)). Make sure to enter the random key Maloja generates on first startup in the extension settings.
If you want to implement your own method of scrobbling, it's very simple: You only need one POST request to `/api/newscrobble` with the keys `artist`, `title` and `key` - either as form-data or json. If you want to implement your own method of scrobbling, it's very simple: You only need one POST request to `/api/newscrobble` with the keys `artist`, `title` and `key` - either as form-data or json.

View File

@ -28,6 +28,12 @@ pages = {
"https://open.spotify.com" "https://open.spotify.com"
], ],
"script":"spotify.js" "script":"spotify.js"
},
"Bandcamp":{
"patterns":[
"bandcamp.com"
],
"script":"bandcamp.js"
} }
} }
@ -51,7 +57,7 @@ function onTabUpdated(tabId, changeInfo, tab) {
patterns = pages[page]["patterns"]; patterns = pages[page]["patterns"];
//console.log("Page was managed by a " + page + " manager") //console.log("Page was managed by a " + page + " manager")
for (var i=0;i<patterns.length;i++) { for (var i=0;i<patterns.length;i++) {
if (tab.url.startsWith(patterns[i])) { if (tab.url.includes(patterns[i])) {
//console.log("Still on same page!") //console.log("Still on same page!")
tabManagers[tabId].update(); tabManagers[tabId].update();
@ -67,7 +73,7 @@ function onTabUpdated(tabId, changeInfo, tab) {
if (pages.hasOwnProperty(key)) { if (pages.hasOwnProperty(key)) {
patterns = pages[key]["patterns"]; patterns = pages[key]["patterns"];
for (var i=0;i<patterns.length;i++) { for (var i=0;i<patterns.length;i++) {
if (tab.url.startsWith(patterns[i])) { if (tab.url.includes(patterns[i])) {
console.log("New page on tab " + tabId + " will be handled by new " + key + " manager!"); console.log("New page on tab " + tabId + " will be handled by new " + key + " manager!");
tabManagers[tabId] = new Controller(tabId,key); tabManagers[tabId] = new Controller(tabId,key);
updateTabNum(); updateTabNum();

View File

@ -0,0 +1,15 @@
maloja_scrobbler_selector_playbar = "//div[contains(@class,'trackView')]"
maloja_scrobbler_selector_metadata = "."
// need to select everything as bar / metadata block because artist isn't shown in the inline player
maloja_scrobbler_selector_title = ".//span[@class='title']/text()"
maloja_scrobbler_selector_artist = ".//span[contains(@itemprop,'byArtist')]/a/text()"
maloja_scrobbler_selector_duration = ".//span[@class='time_total']/text()"
maloja_scrobbler_selector_control = ".//td[@class='play_cell']/a[@role='button']/div[contains(@class,'playbutton')]/@class"
maloja_scrobbler_label_playing = "playbutton playing"
maloja_scrobbler_label_paused = "playbutton"

View File

@ -65,12 +65,24 @@ else {
control = bar.xpath(maloja_scrobbler_selector_control, XPathResult.STRING_TYPE); control = bar.xpath(maloja_scrobbler_selector_control, XPathResult.STRING_TYPE);
if (control == "Play") { try {
label_playing = maloja_scrobbler_label_playing
}
catch {
label_playing = "Pause"
}
try {
label_paused = maloja_scrobbler_label_paused
}
catch {
label_paused = "Play"
}
if (control == label_paused) {
console.log("Not playing right now"); console.log("Not playing right now");
chrome.runtime.sendMessage({type:"stopPlayback",time:Math.floor(Date.now()),artist:artist,title:title}); chrome.runtime.sendMessage({type:"stopPlayback",time:Math.floor(Date.now()),artist:artist,title:title});
//stopPlayback() //stopPlayback()
} }
else if (control == "Pause") { else if (control == label_playing) {
console.log("Playing " + artist + " - " + title + " (" + durationSeconds + " sec)"); console.log("Playing " + artist + " - " + title + " (" + durationSeconds + " sec)");
chrome.runtime.sendMessage({type:"startPlayback",time:Math.floor(Date.now()),artist:artist,title:title,duration:durationSeconds}); chrome.runtime.sendMessage({type:"startPlayback",time:Math.floor(Date.now()),artist:artist,title:title,duration:durationSeconds});
//startPlayback(artist,title,durationSeconds) //startPlayback(artist,title,durationSeconds)