Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: damienalexandre/Chrome-Last.fm-Scrobbler
base: 5d043f30be
...
head fork: damienalexandre/Chrome-Last.fm-Scrobbler
compare: cb16a7b8b9
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 141 additions and 8 deletions.
  1. +127 −0 deezer.js
  2. +10 −6 manifest.json
  3. +4 −2 options.html
View
127 deezer.js
@@ -0,0 +1,127 @@
+/**
+ * Chrome-Last.fm-Scrobbler Deezer.com Connector by @damienalexandre
+ *
+ * v1.0, 5 march 2012
+ *
+ * The difficulty here is that the song duration can appear a long time after the
+ * song starts playing.
+ * We use the title change to know when a song is played.
+ *
+ * @todo Handle the song "pause"? (do we have to cancel the scrobble?)
+ */
+
+var currentDeezerTimeout = null;
+
+$(document).ready(function() {
+
+ sendTrack(); // We maybe have a song playing right away. There is no retry if this call fails.
+
+ $("title").bind('DOMSubtreeModified', function()
+ {
+ if (currentDeezerTimeout) // Handle song fast zapping
+ {
+ window.clearTimeout(currentDeezerTimeout);
+ }
+
+ currentDeezerTimeout = window.setTimeout(sendTrack, 1000); // As the duration may be not available.
+ });
+
+ $(window).unload(function()
+ {
+ cancel();
+ return true;
+ });
+});
+
+/**
+ * Handle the chrome.extension
+ * and can retry itself too.
+ */
+function sendTrack()
+{
+ if (currentDeezerTimeout)
+ {
+ window.clearTimeout(currentDeezerTimeout);
+ }
+
+ var deezerSong = getCurrentTrack();
+
+ if (deezerSong && deezerSong.duration > 0)
+ {
+ chrome.extension.sendRequest({type: 'validate', artist: deezerSong.artist, track: deezerSong.track}, function(response)
+ {
+ if (response != false)
+ {
+ var song = response; // contains valid artist/track now
+
+ chrome.extension.sendRequest({type: 'nowPlaying', artist: song.artist, track: song.track, duration: deezerSong.duration});
+ }
+ else
+ {
+ chrome.extension.sendRequest({type: 'nowPlaying', duration: deezerSong.duration});
+ displayMsg('Not recognized');
+ }
+ });
+ }
+ else if (currentDeezerTimeout)
+ {
+ // Retry to fetch the song infos later
+ currentDeezerTimeout = window.setTimeout(sendTrack, 1000);
+ }
+}
+
+/**
+ * Try to get the song infos (track, artist, duration)
+ * @return object|boolean
+ */
+function getCurrentTrack()
+{
+ if ($('#h_play').is(":hidden")) { // Play button hidden, the song is playing
+ return {
+ track: $('#current-track').html(),
+ artist: $('#current-artist').html(),
+ duration: parseDuration($('#end-track').html())
+ }
+ }
+
+ return false;
+}
+
+/**
+ * Binded on the unload
+ */
+function cancel()
+{
+ // reset the background scrobbler song data
+ chrome.extension.sendRequest({type: 'reset'});
+}
+
+/**
+ * Maybe this kind of common method should be in the Core
+ *
+ * @param durationString Like "13;37".
+ * @return int The duration string translated to seconds
+ */
+function parseDuration(durationString)
+{
+ try
+ {
+ var match = durationString.match(/\d+:\d+/g);
+
+ if (match)
+ {
+ var mins = match[0].substring(0, match[0].indexOf(':'));
+ var seconds = match[0].substring(match[0].indexOf(':')+1);
+ return parseInt(mins*60, 10) + parseInt(seconds, 10);
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ catch(err)
+ {
+ throw err;
+ return 0;
+ }
+}
View
16 manifest.json
@@ -1,27 +1,27 @@
{
"name": "Last.fm Scrobbler",
"version": "1.7",
-
- "description": "Scrobble music all around the web!",
+
+ "description": "Scrobble music all around the web!",
"icons": {
"128": "icon128.png"
},
-
+
"background_page": "background.html",
"options_page": "options.html",
-
+
"permissions": [
"tabs",
"notifications",
"http://ws.audioscrobbler.com/2.0/",
"http://gdata.youtube.com/feeds/api/videos/"
],
-
+
"page_action": {
"chromeBroken": "remove this line after issue #86449 is resolved"
},
- "content_scripts": [
+ "content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["dummy.js"]
@@ -75,6 +75,10 @@
"matches": ["*://www.pandora.com/*"],
"js": ["jquery-1.6.1.min.js", "jquery.dump.js", "pandora.js"],
"run_at" : "document_start"
+ },
+ {
+ "matches": ["*://www.deezer.com/*"],
+ "js": ["jquery-1.6.1.min.js", "jquery.dump.js", "deezer.js"]
}
]
}
View
6 options.html
@@ -47,7 +47,8 @@
<li>FFtunes.com</li>
<li>Fizy.com</li>
<li>BandCamp.com</li>
- <li>Pandora.com (new interface)</li>
+ <li>Pandora.com (new interface)</li>
+ <li>Deezer.com</li>
</ul>
</p>
<p>
@@ -80,7 +81,8 @@
<li><a href="https://github.com/moski">Moski Doski</a> - Thesixtyone.com support</li>
<li><a href="http://last.fm/user/Macint/">Peter McEvoy</a> - <a href="http://ghostly.com/discovery/play">Ghostly Discovery</a> support</li>
<li><a href="https://github.com/porges">George Pollard</a> - BandCamp support</li>
- <li><a href="http://jperr.com">Jordan Perr</a> - Pandora support</li>
+ <li><a href="http://jperr.com">Jordan Perr</a> - Pandora support</li>
+ <li><a href="http://damienalexandre.fr/">Damien Alexandre</a> - Deezer support</li>
</ul>
</p>
</div>

No commit comments for this range

Something went wrong with that request. Please try again.