From ef34bc26d7a51fe883f62d90347a4f2183c231c2 Mon Sep 17 00:00:00 2001 From: Jason Salaz Date: Fri, 26 Sep 2014 01:43:17 -0600 Subject: [PATCH 1/2] Beatport Importer Userscript v1 This script currently supports importing; * Release Title * Release Label * Release Catalog Number (if available) * Release Date * Tracklist --- beatport_importer.user.js | 94 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 beatport_importer.user.js diff --git a/beatport_importer.user.js b/beatport_importer.user.js new file mode 100644 index 0000000..97556d0 --- /dev/null +++ b/beatport_importer.user.js @@ -0,0 +1,94 @@ +// ==UserScript== +// @name MusicBrainz: Import from Beatport +// @version 2014.09.21.0 +// @downloadURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/beatport_importer.user.js +// @updateURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/beatport_importer.user.js +// @include http*://www.beatport.com/release/* +// @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js +// @require https://raw.githubusercontent.com/phstc/jquery-dateFormat/master/src/dateFormat.js +// @require https://raw.githubusercontent.com/phstc/jquery-dateFormat/master/src/jquery.dateFormat.js +// @require https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/lib/import_functions.js +// ==/UserScript== + +if (!unsafeWindow) unsafeWindow = window; + +$(document).ready(function(){ + + var release = retrieveReleaseInfo(); + insertLink(release); + +}); + +function retrieveReleaseInfo() { + var release = {}; + + // Release information global to all Beatport releases + release.packaging = 'None'; + release.country = "XW"; + release.status = 'official'; + release.urls = []; + release.urls.push( { 'url': window.location.href } ); + + var releaseDate = $( "td.meta-data-label:contains('Release Date')" ).next().text().split("-"); + release.year = releaseDate[0]; + release.month = releaseDate[1]; + release.day = releaseDate[2]; + + release.labels = []; + release.labels.push( + { + name: $( "td.meta-data-label:contains('Labels')" ).next().text(), + catno: $( "td.meta-data-label:contains('Catalog #')" ).next().text() + } + ); + + // Tracks + var tracks = []; + unsafeWindow.$( "span[data-json]" ).each( + function ( index, tagSoup ) { + var t = $.parseJSON($(tagSoup).attr('data-json')); + release.title = t.release.name; + + var artist = []; + t.artists.forEach( + function ( artistObject, index, arr ) { + artist.push({ + 'artist_name': artistObject.name + }); + } + ); + release.artist_credit = artist; + tracks.push({ + 'artist_credit': artist, + 'title': t.title, + 'duration': t.length + }); + } + ); + mylog(tracks); + release.discs = []; + release.discs.push( { + 'tracks': tracks, + 'format': "Digital Media" + } ); + + mylog(release); + return release; +} + +// Insert button into page under label information +function insertLink(release) { + var edit_note = 'Imported from ' + window.location.href; + var parameters = MBReleaseImportHelper.buildFormParameters(release, edit_note); + + var innerHTML = MBReleaseImportHelper.buildFormHTML(parameters); + + $("table.meta-data tbody").append(innerHTML); +} + +function mylog(obj) { + var DEBUG = true; + if (DEBUG && unsafeWindow.console) { + unsafeWindow.console.log(obj); + } +} From 380dbdb0d354086f79e3c0a6c38d2cfd02c4b143 Mon Sep 17 00:00:00 2001 From: Jason Salaz Date: Fri, 26 Sep 2014 01:47:48 -0600 Subject: [PATCH 2/2] Updating date in @version to reflect actual completion date --- beatport_importer.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beatport_importer.user.js b/beatport_importer.user.js index 97556d0..7975747 100644 --- a/beatport_importer.user.js +++ b/beatport_importer.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name MusicBrainz: Import from Beatport -// @version 2014.09.21.0 +// @version 2014.09.26.0 // @downloadURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/beatport_importer.user.js // @updateURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/beatport_importer.user.js // @include http*://www.beatport.com/release/*