forked from web-scrobbler/web-scrobbler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from david-sabata/master
update?
- Loading branch information
Showing
71 changed files
with
4,177 additions
and
2,224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[package.json] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
nbproject | ||
node_modules | ||
.DS_Store | ||
.idea | ||
*.iml | ||
*.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"browser": true, | ||
"esnext": true, | ||
"globals": { | ||
"$": false, | ||
"console": false, | ||
"chrome": false, | ||
"require": false, | ||
"define": false | ||
}, | ||
"globalstrict": true, | ||
"quotmark": "single", | ||
"smarttabs": true, | ||
"trailing": true, | ||
"undef": true, | ||
"unused": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
language: node_js | ||
node_js: | ||
- "0.10" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
|
||
/* global module, require */ | ||
module.exports = function(grunt) { | ||
|
||
var jsFiles = ['Gruntfile.js', 'popup.js', 'core/background/*', 'core/content/*', 'options/options.js', 'connectors/archive.js']; // intentionally does not contain all files yet | ||
|
||
grunt.initConfig({ | ||
jshint: { | ||
all: jsFiles, | ||
options: { | ||
jshintrc: true, | ||
reporter: require('jshint-stylish') | ||
} | ||
}, | ||
compress: { | ||
main: { | ||
options: { | ||
archive: 'web-scrobbler.zip', | ||
pretty: true | ||
}, | ||
expand: true, | ||
src: ['*.*', 'connectors/**', 'options/**', 'vendor/**'] | ||
} | ||
}, | ||
lintspaces: { | ||
all: { | ||
src: [ | ||
jsFiles | ||
], | ||
|
||
options: { | ||
editorconfig: '.editorconfig', | ||
ignores: [ | ||
'js-comments' | ||
] | ||
} | ||
} | ||
} | ||
}); | ||
|
||
|
||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-contrib-compress'); | ||
grunt.loadNpmTasks('grunt-lintspaces'); | ||
grunt.registerTask('lint', ['jshint']); | ||
grunt.registerTask('default', ['lint', 'lintspaces']); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
Copyright © 2014 David Šabata | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the “Software”), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Chrome-Last.fm-Scrobbler archive.org Connector by Malachi Soord | ||
* (based on George Pollard's bandcamp connctor) | ||
* v0.1 | ||
*/ | ||
'use strict'; | ||
|
||
var lastTrack = null; | ||
|
||
$(function () { | ||
// bind page unload function to discard current "now listening" | ||
cancel(); | ||
}); | ||
|
||
var durationElapsed = '#jw6_controlbar_elapsed'; | ||
var durationTotal = '#jw6_controlbar_duration'; | ||
var durationRegex = /(\d+):(\d+)/; | ||
|
||
function parseDuration(elapsed, total) { | ||
try { | ||
var mEla = durationRegex.exec(elapsed); | ||
var mTot = durationRegex.exec(total); | ||
return { | ||
current: parseInt(mEla[1], 10) * 60 + parseInt(mEla[2], 10), | ||
total: parseInt(mTot[1], 10) * 60 + parseInt(mTot[2], 10) | ||
}; | ||
} catch (err) { | ||
return 0; | ||
} | ||
} | ||
|
||
function parseArtist() { | ||
return $('span.key:contains("Artist/Composer:"), span.key:contains("Band/Artist:")').next().text(); | ||
} | ||
|
||
function parseTitle() { | ||
|
||
// Get title directly from player | ||
var title = $('.playing > .ttl').text(); | ||
|
||
// Some titles are stored as artist - track # - title so strip out non-title elements | ||
var parts = title.split('-'); | ||
if (parts.length === 3 && parts[0].trim() === parseArtist()) { | ||
title = parts[2].trim(); | ||
} | ||
|
||
return title; | ||
} | ||
|
||
function parseAlbum() { | ||
var album = $('.x-archive-meta-title').text(); | ||
|
||
// Remove artist from album | ||
var parts = album.split('-'); | ||
if (parts.length > 0 && parts[0].trim() === parseArtist()) { | ||
album = album.substr(album.indexOf('-') + 1).trim(); | ||
} | ||
|
||
return album; | ||
} | ||
|
||
function cancel() { | ||
$(window).unload(function () { | ||
// reset the background scrobbler song data | ||
chrome.runtime.sendMessage({ | ||
type: 'reset' | ||
}); | ||
return true; | ||
}); | ||
} | ||
|
||
// console.log('Archive.org: loaded'); | ||
|
||
$(durationElapsed).live('DOMSubtreeModified', function () { | ||
|
||
var duration = parseDuration($(durationElapsed).text(), $(durationTotal).text()); | ||
|
||
// console.log('duration - ' + duration.current + ' / ' + duration.total); | ||
|
||
if (duration.current > 0) { // it's playing | ||
|
||
var artist = parseArtist(); | ||
var track = parseTitle(); | ||
var album = parseAlbum(); | ||
|
||
if (lastTrack !== track) { | ||
lastTrack = track; | ||
|
||
console.log('Archive.org: scrobbling - Artist: ' + artist + '; Album: ' + album + '; Track: ' + track + '; duration: ' + duration.total); | ||
chrome.runtime.sendMessage({ | ||
type: 'validate', | ||
artist: artist, | ||
track: track | ||
}, function (response) { | ||
if (response !== false) { | ||
chrome.runtime.sendMessage({ | ||
type: 'nowPlaying', | ||
artist: response.artist, | ||
track: response.track, | ||
duration: duration.total, | ||
album: album | ||
}); | ||
} else { | ||
chrome.runtime.sendMessage({ | ||
type: 'nowPlaying', | ||
duration: duration.total | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.