diff --git a/README.md b/README.md index 1265c10..6317837 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ If you didn't install Maloja from the package (and therefore don't have it in `/ ### 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. diff --git a/scrobblers/chromium-generic/background.js b/scrobblers/chromium-generic/background.js index 9806105..a215562 100644 --- a/scrobblers/chromium-generic/background.js +++ b/scrobblers/chromium-generic/background.js @@ -28,6 +28,12 @@ pages = { "https://open.spotify.com" ], "script":"spotify.js" + }, + "Bandcamp":{ + "patterns":[ + "bandcamp.com" + ], + "script":"bandcamp.js" } } @@ -51,7 +57,7 @@ function onTabUpdated(tabId, changeInfo, tab) { patterns = pages[page]["patterns"]; //console.log("Page was managed by a " + page + " manager") 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!") tabManagers[tabId].update(); @@ -67,7 +73,7 @@ function onTabUpdated(tabId, changeInfo, tab) { if (pages.hasOwnProperty(key)) { patterns = pages[key]["patterns"]; 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!"); tabManagers[tabId] = new Controller(tabId,key); updateTabNum(); diff --git a/scrobblers/chromium-generic/sites/bandcamp.js b/scrobblers/chromium-generic/sites/bandcamp.js new file mode 100644 index 0000000..b4b2f55 --- /dev/null +++ b/scrobblers/chromium-generic/sites/bandcamp.js @@ -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" diff --git a/scrobblers/chromium-generic/sitescript.js b/scrobblers/chromium-generic/sitescript.js index 0f5adb5..f24969d 100644 --- a/scrobblers/chromium-generic/sitescript.js +++ b/scrobblers/chromium-generic/sitescript.js @@ -65,12 +65,24 @@ else { 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"); chrome.runtime.sendMessage({type:"stopPlayback",time:Math.floor(Date.now()),artist:artist,title:title}); //stopPlayback() } - else if (control == "Pause") { + else if (control == label_playing) { console.log("Playing " + artist + " - " + title + " (" + durationSeconds + " sec)"); chrome.runtime.sendMessage({type:"startPlayback",time:Math.floor(Date.now()),artist:artist,title:title,duration:durationSeconds}); //startPlayback(artist,title,durationSeconds)