- Copy the code above (I recommend clicking the 'Raw' button to get at it more easily)
- Open all your music
- Zoom out as far as you can.
- Open up the Menu > Tools > Developer > JavaScript Console
- Paste in the code, and hit Enter.
Last active
August 29, 2015 14:06
-
-
Save jimmed/cec53862bd832f337e12 to your computer and use it in GitHub Desktop.
Duplicate finder for google play music
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
// Configuration! | |
var numericKeys = ['track', 'play-count']; | |
var matchKeys = ['title','album','artist']; | |
var caseSensitive = false; | |
// Don't change anything below here... | |
var hasJquery = typeof $ !== 'undefined' && $.jQuery; | |
if(!hasJquery) { | |
console.info('Waiting for jQuery to load...'); | |
(function(){var d=document;var h=d.getElementsByTagName('head')[0];var s=d.createElement('script');s.src='//code.jquery.com/jquery-2.1.0.min.js';h.appendChild(s);}()); | |
} | |
setTimeout(function() { | |
hasJquery = typeof $ !== 'undefined' && $.jQuery; | |
console.info('Finding duplicates...'); | |
function getSongsFromView() { | |
var songs = []; | |
$('.song-row').each(function(i, x) { | |
var song = { id: $(x).data('id'), row: $(x) }; | |
$('[data-col]', x).each(function(i, x) { | |
var $x = $(x); | |
var val = $x.text().trim(); | |
var key = $x.data('col'); | |
if(numericKeys.indexOf(key) > -1) { | |
val = parseInt(val, 10); | |
if(isNaN(val)) { | |
val = 0; | |
} | |
} | |
song[key] = val; | |
}); | |
songs.push(song); | |
}); | |
return songs; | |
} | |
function getDuplicates(songs, keys, caseSensitive) { | |
var seen = []; | |
keys = keys && keys.length ? keys : ['title']; | |
return songs.reduce(function(dupes, curr) { | |
seen.forEach(function(prev) { | |
if(songsMatchOn(curr, prev, keys)) { | |
curr._duplicateOf = prev; | |
dupes.push(curr); | |
} | |
}); | |
seen.push(curr); | |
return dupes; | |
}, []); | |
} | |
function songsMatchOn(a, b, keys, caseSensitive) { | |
return keys.every(function(key) { | |
if(caseSensitive || typeof a[key] !== 'string' || typeof b[key] !== 'string') { | |
return a[key] === b[key]; | |
} | |
return a[key].toLowerCase() === b[key].toLowerCase(); | |
}); | |
} | |
function enqueueClick(song, index) { | |
var target = $('[data-col="title"]', song.row).eq(0)[0]; | |
var myEvent = document.createEvent('MouseEvents'); | |
myEvent.initMouseEvent('click', true, true, target, 0, 0, 0, 1, 1, index > 0, false, false, false, 0, null); | |
target.dispatchEvent(myEvent); | |
} | |
var visibleSongs = getSongsFromView(); | |
var dupes = getDuplicates(visibleSongs, matchKeys, caseSensitive); | |
if(dupes.length) { | |
console.group('Found', dupes.length, 'duplicates, matching on ', matchKeys.join('/')); | |
dupes.forEach(function(song, index) { | |
console.log(index, song); | |
enqueueClick(song, index); | |
}); | |
console.groupEnd(); | |
} else { | |
console.info('No duplicates found!'); | |
} | |
}, hasJquery ? 1 : 10000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment