2012-03-28 22:49:43 +00:00
|
|
|
// ==UserScript==
|
|
|
|
// @name Import Bandcamp releases into MB
|
2014-02-22 09:33:26 +00:00
|
|
|
// @version 2014.02.22.1
|
2012-03-28 22:49:43 +00:00
|
|
|
// @namespace http://userscripts.org/users/22504
|
2014-02-22 09:33:26 +00:00
|
|
|
// @downloadURL https://raw.github.com/murdos/musicbrainz-userscripts/master/bandcamp_importer.user.js
|
|
|
|
// @updateURL https://raw.github.com/murdos/musicbrainz-userscripts/master/bandcamp_importer.user.js
|
2014-01-02 13:20:19 +00:00
|
|
|
// @include http*://*.bandcamp.com/album/*
|
|
|
|
// @include http*://*.bandcamp.com/track/*
|
2013-03-04 10:38:13 +00:00
|
|
|
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js
|
2012-03-28 22:51:26 +00:00
|
|
|
// @require https://raw.github.com/murdos/musicbrainz-userscripts/master/lib/import_functions.js
|
2012-03-28 22:49:43 +00:00
|
|
|
// ==/UserScript==
|
|
|
|
|
2012-03-28 22:50:21 +00:00
|
|
|
if (!unsafeWindow) unsafeWindow = window;
|
|
|
|
|
2012-03-28 22:49:43 +00:00
|
|
|
$(document).ready(function(){
|
|
|
|
|
|
|
|
var release = retrieveReleaseInfo();
|
|
|
|
insertLink(release);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// Analyze Bandcamp data and return a release object
|
|
|
|
function retrieveReleaseInfo() {
|
|
|
|
var release = new Object();
|
2014-02-21 17:46:29 +00:00
|
|
|
release.discs = [];
|
2012-03-28 22:49:43 +00:00
|
|
|
|
|
|
|
var bandcampAlbumData = unsafeWindow.TralbumData;
|
2014-02-21 18:21:53 +00:00
|
|
|
var bandcampEmbedData = unsafeWindow.EmbedData;
|
2012-03-28 22:49:43 +00:00
|
|
|
|
|
|
|
// Release artist credit
|
|
|
|
release.artist_credit = [ { artist_name: bandcampAlbumData.artist } ];
|
|
|
|
|
2014-02-21 17:46:29 +00:00
|
|
|
// Grab release title
|
|
|
|
release.title = bandcampAlbumData.current.title;
|
2012-03-28 22:49:43 +00:00
|
|
|
|
|
|
|
// Grab release event information
|
2014-09-26 09:46:03 +00:00
|
|
|
var releasedate = $('.tralbumData meta[itemprop="datePublished"]').attr("content");
|
2012-03-28 22:49:43 +00:00
|
|
|
|
2014-02-21 18:21:53 +00:00
|
|
|
if(bandcampEmbedData.album_title) {
|
|
|
|
release.parent_album = bandcampEmbedData.album_title;
|
2012-12-12 11:15:06 +00:00
|
|
|
}
|
2012-12-12 10:48:28 +00:00
|
|
|
|
2012-03-28 22:49:43 +00:00
|
|
|
if (typeof releasedate != "undefined" && releasedate != "") {
|
2014-09-26 09:46:03 +00:00
|
|
|
release.year = releasedate.substring(0, 4);
|
|
|
|
release.month = releasedate.substring(4, 6);
|
|
|
|
release.day = releasedate.substring(6, 8);
|
2014-02-21 17:42:25 +00:00
|
|
|
}
|
|
|
|
|
2012-03-28 22:49:43 +00:00
|
|
|
release.labels = new Array();
|
|
|
|
release.format = "Digital Media";
|
|
|
|
release.country = "XW"; // Worldwide
|
|
|
|
// FIXME: implement a mapping between bandcamp release types and MB ones
|
|
|
|
release.type = bandcampAlbumData.current.type;
|
|
|
|
release.status = 'official';
|
2014-09-26 09:47:44 +00:00
|
|
|
release.packaging = 'none';
|
|
|
|
release.language = 'eng';
|
|
|
|
release.script = 'Latn';
|
2012-03-28 22:49:43 +00:00
|
|
|
|
2014-02-21 18:21:53 +00:00
|
|
|
// map Bandcamp single tracks to singles
|
|
|
|
if(release.type == "track")
|
|
|
|
{ release.type = "single"; }
|
2012-12-12 10:48:28 +00:00
|
|
|
|
2014-02-21 17:46:29 +00:00
|
|
|
// Tracks
|
2012-03-28 22:49:43 +00:00
|
|
|
var disc = new Object();
|
|
|
|
disc.tracks = new Array();
|
|
|
|
disc.format = release.format;
|
|
|
|
release.discs.push(disc);
|
|
|
|
$.each(bandcampAlbumData.trackinfo, function(index, bctrack) {
|
|
|
|
var track = {
|
|
|
|
'title': bctrack.title,
|
2012-03-28 22:50:21 +00:00
|
|
|
'duration': Math.round(bctrack.duration*1000),
|
2012-03-28 22:49:43 +00:00
|
|
|
'artist_credit': []
|
|
|
|
}
|
|
|
|
disc.tracks.push(track);
|
|
|
|
});
|
|
|
|
|
2014-02-21 19:05:25 +00:00
|
|
|
// URLs
|
|
|
|
// link_type mapping:
|
|
|
|
// - 74: purchase for download
|
|
|
|
// - 75: download for free
|
|
|
|
// - 85: stream {video} for free
|
2014-02-21 19:05:25 +00:00
|
|
|
// - 301: license
|
2014-09-26 09:51:15 +00:00
|
|
|
LINK_PURCHASE_FOR_DOWNLOAD = 74
|
|
|
|
LINK_DOWNLOAD_FOR_FREE = 75
|
|
|
|
LINK_STREAM_FOR_FREE = 85
|
|
|
|
LINK_LICENSE = 301
|
2014-02-21 19:05:25 +00:00
|
|
|
release.urls = new Array();
|
|
|
|
// Download for free vs. for purchase
|
|
|
|
if (bandcampAlbumData.current.download_pref !== null) {
|
2014-09-26 09:51:15 +00:00
|
|
|
if (bandcampAlbumData.freeDownloadPage !== null || bandcampAlbumData.current.download_pref === 1 || (
|
|
|
|
bandcampAlbumData.current.download_pref === 2 && bandcampAlbumData.current.minimum_price === 0)) {
|
|
|
|
release.urls.push({
|
|
|
|
'url': window.location.href,
|
|
|
|
'link_type': LINK_DOWNLOAD_FOR_FREE
|
|
|
|
});
|
2014-02-21 19:05:25 +00:00
|
|
|
}
|
2014-09-26 09:51:15 +00:00
|
|
|
if (bandcampAlbumData.current.download_pref === 2) {
|
|
|
|
// - 74: purchase for download
|
|
|
|
release.urls.push({
|
|
|
|
'url': window.location.href,
|
|
|
|
'link_type': LINK_PURCHASE_FOR_DOWNLOAD
|
|
|
|
});
|
2014-02-21 19:05:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check if the release is streamable
|
|
|
|
if (bandcampAlbumData.hasAudio) {
|
2014-09-26 09:51:15 +00:00
|
|
|
release.urls.push({
|
|
|
|
'url': window.location.href,
|
|
|
|
'link_type': LINK_STREAM_FOR_FREE
|
|
|
|
});
|
2014-02-21 19:05:25 +00:00
|
|
|
}
|
2014-02-21 19:05:25 +00:00
|
|
|
// Check if release is Creative Commons licensed
|
|
|
|
if ($("div#license a.cc-icons").length > 0) {
|
2014-09-26 09:51:15 +00:00
|
|
|
release.urls.push({
|
|
|
|
'url': $("div#license a.cc-icons").attr("href"),
|
|
|
|
'link_type': LINK_LICENSE
|
|
|
|
});
|
2014-02-21 19:05:25 +00:00
|
|
|
}
|
2014-02-21 19:05:25 +00:00
|
|
|
|
2012-03-28 22:49:43 +00:00
|
|
|
mylog(release);
|
2014-02-21 17:46:29 +00:00
|
|
|
return release;
|
2012-03-28 22:49:43 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert links in page
|
|
|
|
function insertLink(release) {
|
|
|
|
|
2014-02-21 17:46:29 +00:00
|
|
|
if(release.type == "single" && typeof release.parent_album != "undefined") {
|
|
|
|
mylog("This is part of an album, not continuing.");
|
|
|
|
return false;
|
|
|
|
}
|
2012-12-12 10:48:28 +00:00
|
|
|
|
2012-03-28 22:49:43 +00:00
|
|
|
/*
|
2014-02-21 17:46:29 +00:00
|
|
|
var mbUI = document.createElement('div');
|
2014-02-21 17:42:25 +00:00
|
|
|
mbUI.innerHTML = "<h3>MusicBrainz</h3>";
|
2014-02-21 17:46:29 +00:00
|
|
|
mbUI.className = "section";
|
2012-03-28 22:49:43 +00:00
|
|
|
|
|
|
|
|
2014-02-21 17:46:29 +00:00
|
|
|
var mbContentBlock = document.createElement('div');
|
2012-03-28 22:49:43 +00:00
|
|
|
mbContentBlock.className = "section_content";
|
|
|
|
mbUI.appendChild(mbContentBlock);
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Form parameters
|
|
|
|
var edit_note = 'Imported from ' + window.location.href;
|
2014-02-21 17:46:29 +00:00
|
|
|
var parameters = MBReleaseImportHelper.buildFormParameters(release, edit_note);
|
2012-03-28 22:49:43 +00:00
|
|
|
|
2014-02-21 17:46:29 +00:00
|
|
|
// Build form
|
|
|
|
var innerHTML = MBReleaseImportHelper.buildFormHTML(parameters);
|
2012-03-28 22:49:43 +00:00
|
|
|
// Append search link
|
2014-02-21 17:46:29 +00:00
|
|
|
//innerHTML += ' <small>(' + MBReleaseImportHelper.buildSearchLink(release) + ')</small>';
|
2012-03-28 22:49:43 +00:00
|
|
|
|
|
|
|
$('h2.trackTitle').append(innerHTML);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function mylog(obj) {
|
|
|
|
var DEBUG = true;
|
|
|
|
if (DEBUG && unsafeWindow.console) {
|
|
|
|
unsafeWindow.console.log(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|