Skip to content

Commit

Permalink
Initial release of the Deezer Scrobbler. The duration issue seems to …
Browse files Browse the repository at this point in the history
…be fixed.
  • Loading branch information
damienalexandre committed Mar 5, 2012
1 parent 5d043f3 commit 7d9839c
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 8 deletions.
111 changes: 111 additions & 0 deletions deezer.js
@@ -0,0 +1,111 @@
/**
* Chrome-Last.fm-Scrobbler Deezer.com Connector by @damienalexandre
*
* The difficulty here is that the song duration can appear a long time after the
* song start playing.
* We use the title change to know when a song is played.
*/

var currentDeezerTimeout = null;

$(document).ready(function() {

sendTrack(); // We maybe have a song playing right away.

$("title").bind('DOMSubtreeModified', function(e) {

console.log("Dom changed detected");
console.log(e);
currentDeezerTimeout = window.setTimeout(sendTrack, 1000); // As the duration may be not available. And song can be zapped fast.
});

$(window).unload(function() {
cancel();
return true;
});
});

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) {

console.log('responses from extension');
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);
}
}


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;
}

function cancel()
{
// reset the background scrobbler song data
chrome.extension.sendRequest({type: 'reset'});
}

/**
* From 61.js
*
* Maybe this kind of common method should be in the Core
*
* @param durationString
*/
function parseDuration(durationString){

console.log(durationString);
try {
var match = durationString.match(/\d+:\d+/g);

if (match)
{
mins = match[0].substring(0, match[0].indexOf(':'));
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;
}
}
16 changes: 10 additions & 6 deletions 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"]
Expand Down Expand Up @@ -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"]
}
]
}
6 changes: 4 additions & 2 deletions options.html
Expand Up @@ -47,7 +47,8 @@ <h4><a href="http://scrobbler.davidsabata.cz">For details and changelog visit ou
<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>
Expand Down Expand Up @@ -80,7 +81,8 @@ <h4><a href="http://scrobbler.davidsabata.cz">For details and changelog visit ou
<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>
Expand Down

0 comments on commit 7d9839c

Please sign in to comment.