2012-03-28 22:49:43 +00:00
|
|
|
// ==UserScript==
|
|
|
|
// @name Import Bandcamp releases into MB
|
2015-05-25 16:13:40 +00:00
|
|
|
// @version 2015.05.25.0
|
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
|
2015-01-18 13:13:32 +00:00
|
|
|
// @require https://raw.github.com/murdos/musicbrainz-userscripts/master/lib/logger.js
|
2012-03-28 22:49:43 +00:00
|
|
|
// ==/UserScript==
|
|
|
|
|
|
|
|
|
2015-05-25 16:13:40 +00:00
|
|
|
if (!unsafeWindow) unsafeWindow = window;
|
2015-05-16 12:41:23 +00:00
|
|
|
|
2015-05-25 16:13:40 +00:00
|
|
|
var BandcampImport = {
|
2012-03-28 22:49:43 +00:00
|
|
|
|
2015-05-25 16:13:40 +00:00
|
|
|
// Analyze Bandcamp data and return a release object
|
|
|
|
retrieveReleaseInfo: function () {
|
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
|
|
|
|
2015-05-25 16:13:40 +00:00
|
|
|
var release = {
|
|
|
|
discs: [],
|
|
|
|
artist_credit: [],
|
|
|
|
title: '',
|
|
|
|
year: 0,
|
|
|
|
month: 0,
|
|
|
|
day: 0,
|
|
|
|
parent_album: '',
|
|
|
|
labels: [],
|
|
|
|
format: 'Digital Media',
|
|
|
|
country: 'XW',
|
|
|
|
type: '',
|
|
|
|
status: 'official',
|
|
|
|
packaging: 'None',
|
|
|
|
language: 'eng',
|
|
|
|
script: 'Latn',
|
|
|
|
urls: []
|
|
|
|
};
|
|
|
|
|
2012-03-28 22:49:43 +00:00
|
|
|
// Release artist credit
|
2015-05-25 16:13:40 +00:00
|
|
|
release.artist_credit = [{
|
|
|
|
artist_name: bandcampAlbumData.artist
|
|
|
|
}];
|
2012-03-28 22:49:43 +00:00
|
|
|
|
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
|
2015-05-25 16:13:40 +00:00
|
|
|
var date = this.convdate(bandcampAlbumData.current.release_date);
|
2014-10-08 21:24:41 +00:00
|
|
|
if (date) {
|
|
|
|
if (!(date.year > 2008 || (date.year == 2008 && date.month >= 9))) {
|
|
|
|
// use publish date if release date is before Bandcamp launch (2008-09)
|
2015-05-25 16:13:40 +00:00
|
|
|
var pdate = this.convdate(bandcampAlbumData.current.publish_date);
|
|
|
|
if (pdate) {
|
|
|
|
date = pdate;
|
2014-10-08 21:24:41 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-25 16:13:40 +00:00
|
|
|
release.year = date.year;
|
|
|
|
release.month = date.month;
|
|
|
|
release.day = date.day;
|
2012-12-12 11:15:06 +00:00
|
|
|
}
|
2012-12-12 10:48:28 +00:00
|
|
|
|
2015-05-25 16:13:40 +00:00
|
|
|
if (bandcampEmbedData.album_title) {
|
|
|
|
release.parent_album = bandcampEmbedData.album_title;
|
2014-02-21 17:42:25 +00:00
|
|
|
}
|
|
|
|
|
2012-03-28 22:49:43 +00:00
|
|
|
// FIXME: implement a mapping between bandcamp release types and MB ones
|
|
|
|
release.type = bandcampAlbumData.current.type;
|
2014-02-21 18:21:53 +00:00
|
|
|
// map Bandcamp single tracks to singles
|
2015-05-25 16:13:40 +00:00
|
|
|
if (release.type == "track") {
|
|
|
|
release.type = "single";
|
|
|
|
}
|
2012-12-12 10:48:28 +00:00
|
|
|
|
2014-02-21 17:46:29 +00:00
|
|
|
// Tracks
|
2015-05-25 16:13:40 +00:00
|
|
|
var disc = {
|
|
|
|
tracks: [],
|
|
|
|
format: release.format
|
|
|
|
};
|
2012-03-28 22:49:43 +00:00
|
|
|
release.discs.push(disc);
|
2015-05-25 16:13:40 +00:00
|
|
|
$.each(bandcampAlbumData.trackinfo, function (index, bctrack) {
|
|
|
|
var track = {
|
|
|
|
'title': bctrack.title,
|
|
|
|
'duration': Math.round(bctrack.duration * 1000),
|
|
|
|
'artist_credit': []
|
|
|
|
};
|
|
|
|
disc.tracks.push(track);
|
2012-03-28 22:49:43 +00:00
|
|
|
});
|
|
|
|
|
2014-02-21 19:05:25 +00:00
|
|
|
// URLs
|
2015-05-25 16:13:40 +00:00
|
|
|
var link_type = {
|
|
|
|
purchase_for_download: 74,
|
|
|
|
download_for_free: 75,
|
|
|
|
stream_for_free: 85,
|
|
|
|
license: 301
|
|
|
|
};
|
2014-02-21 19:05:25 +00:00
|
|
|
// Download for free vs. for purchase
|
|
|
|
if (bandcampAlbumData.current.download_pref !== null) {
|
2015-05-25 16:13:40 +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_type.download_for_free
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (bandcampAlbumData.current.download_pref === 2) {
|
|
|
|
release.urls.push({
|
|
|
|
'url': window.location.href,
|
|
|
|
'link_type': link_type.purchase_for_download
|
|
|
|
});
|
|
|
|
}
|
2014-02-21 19:05:25 +00:00
|
|
|
}
|
|
|
|
// Check if the release is streamable
|
|
|
|
if (bandcampAlbumData.hasAudio) {
|
2015-05-25 16:13:40 +00:00
|
|
|
release.urls.push({
|
|
|
|
'url': window.location.href,
|
|
|
|
'link_type': link_type.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) {
|
2015-05-25 16:13:40 +00:00
|
|
|
release.urls.push({
|
|
|
|
'url': $("div#license a.cc-icons").attr("href"),
|
|
|
|
'link_type': link_type.license
|
|
|
|
});
|
2014-02-21 19:05:25 +00:00
|
|
|
}
|
2015-05-20 12:01:35 +00:00
|
|
|
// Check if album has a back link to a label
|
2015-05-25 16:13:40 +00:00
|
|
|
var label = $("a.back-to-label-link span.back-to-label-name").text();
|
|
|
|
if (label) {
|
2015-05-20 12:01:35 +00:00
|
|
|
release.labels.push({
|
|
|
|
'name': label,
|
|
|
|
'mbid': '',
|
|
|
|
'catno': 'none'
|
|
|
|
});
|
|
|
|
}
|
2014-02-21 17:46:29 +00:00
|
|
|
return release;
|
2015-05-25 16:13:40 +00:00
|
|
|
},
|
2012-03-28 22:49:43 +00:00
|
|
|
|
2015-05-25 16:13:40 +00:00
|
|
|
// Insert links in page
|
|
|
|
insertLink: function (release) {
|
|
|
|
if (release.type == "single" && typeof release.parent_album != "undefined") {
|
|
|
|
return false;
|
2014-02-21 17:46:29 +00:00
|
|
|
}
|
2012-03-28 22:49:43 +00:00
|
|
|
// 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);
|
|
|
|
// Build form
|
|
|
|
var innerHTML = MBReleaseImportHelper.buildFormHTML(parameters);
|
2015-05-25 16:13:40 +00:00
|
|
|
// Append MB import link
|
2012-03-28 22:49:43 +00:00
|
|
|
$('h2.trackTitle').append(innerHTML);
|
2015-05-25 16:13:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// helper to convert bandcamp date to MB date
|
|
|
|
convdate: function (date) {
|
|
|
|
if (typeof date != "undefined" && date !== "") {
|
|
|
|
var d = new Date(date);
|
|
|
|
return {
|
|
|
|
"year": d.getUTCFullYear(),
|
|
|
|
"month": d.getUTCMonth() + 1,
|
|
|
|
"day": d.getUTCDate()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
|
|
|
|
var release = BandcampImport.retrieveReleaseInfo();
|
|
|
|
LOGGER.info("Parsed release: ", release);
|
|
|
|
BandcampImport.insertLink(release);
|
2012-03-28 22:49:43 +00:00
|
|
|
|
2015-05-25 16:13:40 +00:00
|
|
|
// append a comma after each tag to ease cut'n'paste to MB
|
|
|
|
$("div.tralbum-tags a:not(:last-child)").after(",");
|
2012-03-28 22:49:43 +00:00
|
|
|
|
2015-05-25 16:13:40 +00:00
|
|
|
// append a link to the full size image
|
|
|
|
var fullsizeimageurl = $("div#tralbumArt a").attr("href").replace('_10', '_0');
|
|
|
|
$("div#tralbumArt a").after("<div id='bci_link'><a class='custom-color' href='" + fullsizeimageurl +
|
|
|
|
"' title='Link to the original image (Bandcamp importer)'>Original image</a></div>");
|
|
|
|
|
|
|
|
});
|