Skip to content

Commit

Permalink
Merge pull request #1 from david-sabata/master
Browse files Browse the repository at this point in the history
update?
  • Loading branch information
j4cknife committed Aug 19, 2014
2 parents aca76ce + 77829b5 commit 8d184f1
Show file tree
Hide file tree
Showing 71 changed files with 4,177 additions and 2,224 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
nbproject
node_modules
.DS_Store
.idea
*.iml
*.zip
17 changes: 17 additions & 0 deletions .jshintrc
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
}
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- "0.10"
48 changes: 48 additions & 0 deletions Gruntfile.js
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']);
};
20 changes: 20 additions & 0 deletions LICENSE.txt
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.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Last.fm Scrobbler for Chrome

![build status](https://api.travis-ci.org/david-sabata/web-scrobbler.svg)

Last.fm Scrobbler for Chrome was created for people who listen to music
online through their browser, and would like to keep an updated playback
history using [last.fm](http://www.last.fm/)'s scrobbling service.
Expand All @@ -17,3 +19,7 @@ browser and "Load unpacked extension".

## Development
Check the [wiki pages](../../wiki) to understand development of connectors.

## License

See [LICENSE.txt](LICENSE.txt)
9 changes: 0 additions & 9 deletions background-ga.js

This file was deleted.

112 changes: 112 additions & 0 deletions connectors/archive.js
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
});
}
});
}
}
});
4 changes: 2 additions & 2 deletions connectors/baidu.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var pause;
$(function(){
$(CONTAINER_SELECTOR).live('DOMSubtreeModified', function(e) {

if ($(CONTAINER_SELECTOR)[0].href.length > 0 && $(".songname")[0].href.length > 1 && $(".songname")[0].href !== last_url) {
if ($(CONTAINER_SELECTOR)[0].href.length > 0 && $(".songname")[0].href.length > 1 && $(".songname")[0].href !== last_url && $(".album-name a").text() != "--") {

updateNowPlaying();
//console.log("Last.fm Scrobbler: starting Baidu Music connector");
Expand Down Expand Up @@ -148,4 +148,4 @@ chrome.runtime.onMessage.addListener(
break;
}
}
);
);
13 changes: 11 additions & 2 deletions connectors/bandcamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ function parseArtist()
return artist;
}

function parseAlbum() {
if (isAlbum()) {
return $('h2.trackTitle').text().trim();
}
else { // isTrack
return $('[itemprop="inAlbum"] [itemprop="name"]').text();
}
}

function parseTitle()
{
Expand Down Expand Up @@ -78,6 +86,7 @@ $(durationPart).bind('DOMSubtreeModified',function(e){

var artist = parseArtist();
var track = parseTitle();
var album = parseAlbum();

var dashIndex = track.indexOf('-');
if (artist == 'Various Artists' && dashIndex >= 0)
Expand All @@ -93,10 +102,10 @@ $(durationPart).bind('DOMSubtreeModified',function(e){
{
lastTrack = track;

//console.log("BandCampScrobbler: scrobbling '" + track + "' by " + artist);
//console.log("BandCampScrobbler: 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});
chrome.runtime.sendMessage({type: 'nowPlaying', artist: response.artist, track: response.track, duration: duration.total, album: album});
}
else
{
Expand Down
Loading

0 comments on commit 8d184f1

Please sign in to comment.