2015-06-13 09:38:19 +00:00
|
|
|
// ==UserScript==
|
|
|
|
// @name Import Juno Download releases to MusicBrainz
|
|
|
|
// @namespace https://github.com/murdos/musicbrainz-userscripts/
|
|
|
|
// @description One-click importing of releases from junodownload.com/products pages into MusicBrainz
|
2018-02-18 17:16:45 +00:00
|
|
|
// @version 2018.2.18.1
|
2015-06-13 09:38:19 +00:00
|
|
|
// @downloadURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/juno_download_importer.user.js
|
|
|
|
// @updateURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/juno_download_importer.user.js
|
|
|
|
// @include http*://www.junodownload.com/products/*
|
|
|
|
// @include http*://secure.junodownload.com/products/*
|
|
|
|
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
|
2015-06-17 22:29:08 +00:00
|
|
|
// @require lib/mbimport.js
|
2015-06-13 09:38:19 +00:00
|
|
|
// @require lib/logger.js
|
2015-06-15 07:52:59 +00:00
|
|
|
// @require lib/mbimportstyle.js
|
2015-07-10 12:28:43 +00:00
|
|
|
// @icon https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/assets/images/Musicbrainz_import_logo.png
|
2015-06-13 09:38:19 +00:00
|
|
|
// ==/UserScript==
|
|
|
|
|
|
|
|
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant
|
|
|
|
this.$ = this.jQuery = jQuery.noConflict(true);
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
$(document).ready(function() {
|
|
|
|
MBImportStyle();
|
|
|
|
let release_url = window.location.href.replace('/?.*$/', '').replace(/#.*$/, '');
|
|
|
|
let release = retrieveReleaseInfo(release_url);
|
|
|
|
insertLink(release, release_url);
|
2015-06-13 09:38:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function parseReleaseDate(rdate) {
|
2018-11-20 22:18:49 +00:00
|
|
|
let months = {
|
|
|
|
January: 1,
|
|
|
|
February: 2,
|
|
|
|
March: 3,
|
|
|
|
April: 4,
|
|
|
|
May: 5,
|
|
|
|
June: 6,
|
|
|
|
July: 7,
|
|
|
|
August: 8,
|
|
|
|
September: 9,
|
|
|
|
October: 10,
|
|
|
|
November: 11,
|
|
|
|
December: 12
|
|
|
|
};
|
|
|
|
|
|
|
|
let m = rdate.match(/(\d{1,2}) ([a-z]+), (\d{4})/i);
|
|
|
|
if (m) {
|
|
|
|
return {
|
|
|
|
year: m[3],
|
|
|
|
month: months[m[2]],
|
|
|
|
day: m[1]
|
|
|
|
};
|
2015-06-13 09:38:19 +00:00
|
|
|
}
|
2018-11-20 22:18:49 +00:00
|
|
|
return false;
|
2015-06-13 09:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function retrieveReleaseInfo(release_url) {
|
2018-11-20 22:18:49 +00:00
|
|
|
// Release defaults
|
|
|
|
let release = {
|
|
|
|
artist_credit: [],
|
|
|
|
title: $('#product_heading_title')
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
year: 0,
|
|
|
|
month: 0,
|
|
|
|
day: 0,
|
|
|
|
format: 'Digital Media',
|
|
|
|
packaging: 'None',
|
|
|
|
country: 'XW',
|
|
|
|
status: 'official',
|
|
|
|
language: 'eng',
|
|
|
|
script: 'Latn',
|
|
|
|
type: '',
|
|
|
|
urls: [],
|
|
|
|
labels: [],
|
|
|
|
discs: []
|
|
|
|
};
|
|
|
|
|
|
|
|
// Release date
|
|
|
|
let parsed_releaseDate = parseReleaseDate(
|
|
|
|
$('#product_info_released_on')
|
|
|
|
.text()
|
|
|
|
.trim()
|
|
|
|
);
|
|
|
|
if (parsed_releaseDate) {
|
|
|
|
release.year = parsed_releaseDate.year;
|
|
|
|
release.month = parsed_releaseDate.month;
|
|
|
|
release.day = parsed_releaseDate.day;
|
2015-06-13 09:38:19 +00:00
|
|
|
}
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
// URLs
|
|
|
|
release.urls.push({
|
|
|
|
url: release_url,
|
|
|
|
link_type: MBImport.URL_TYPES.purchase_for_download
|
|
|
|
});
|
|
|
|
|
|
|
|
release.labels.push({
|
|
|
|
name: $('#product_heading_label')
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
catno: $('#product_info_cat_no')
|
|
|
|
.text()
|
|
|
|
.trim()
|
|
|
|
});
|
|
|
|
|
|
|
|
// Tracks
|
|
|
|
let tracks = [];
|
|
|
|
$(".product_tracklist_records[itemprop='tracks']").each(function() {
|
|
|
|
let artists = [];
|
|
|
|
let trackno =
|
|
|
|
$(this)
|
|
|
|
.find('.product_tracklist_heading_records_sn')
|
|
|
|
.text()
|
|
|
|
.trim() - 1;
|
|
|
|
let trackname = $(this)
|
|
|
|
.find('.product_tracklist_heading_records_title')
|
|
|
|
.text()
|
|
|
|
.trim();
|
|
|
|
let tracklength = $(this)
|
|
|
|
.find('.product_tracklist_heading_records_length')
|
|
|
|
.text()
|
|
|
|
.trim();
|
|
|
|
let m = trackname.match(/^([^-]+) - (.*)$/);
|
|
|
|
if (m) {
|
|
|
|
artists = [m[1]];
|
|
|
|
trackname = m[2];
|
|
|
|
}
|
|
|
|
tracks.push({
|
|
|
|
artist_credit: MBImport.makeArtistCredits(artists),
|
|
|
|
title: trackname,
|
|
|
|
duration: tracklength
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
let parsed_release_artist = $('#product_heading_artist')
|
|
|
|
.text()
|
|
|
|
.trim();
|
|
|
|
if (parsed_release_artist == 'VARIOUS') {
|
|
|
|
release.artist_credit = [MBImport.specialArtist('various_artists')];
|
|
|
|
} else {
|
|
|
|
release.artist_credit = MBImport.makeArtistCredits([parsed_release_artist]);
|
2015-06-13 09:38:19 +00:00
|
|
|
}
|
2018-11-20 22:18:49 +00:00
|
|
|
release.discs.push({
|
|
|
|
tracks: tracks,
|
|
|
|
format: release.format
|
|
|
|
});
|
2015-06-13 09:38:19 +00:00
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
LOGGER.info('Parsed release: ', release);
|
|
|
|
return release;
|
2015-06-13 09:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Insert button into page under label information
|
|
|
|
function insertLink(release, release_url) {
|
2018-11-20 22:18:49 +00:00
|
|
|
let edit_note = MBImport.makeEditNote(release_url, 'Juno Download');
|
|
|
|
let parameters = MBImport.buildFormParameters(release, edit_note);
|
2015-06-13 09:38:19 +00:00
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
let mbUI = $(`<div id="mb_buttons">${MBImport.buildFormHTML(parameters)}${MBImport.buildSearchButton(release)}</div>`).hide();
|
2015-06-16 13:34:02 +00:00
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
$('div.sociald').before(mbUI);
|
|
|
|
$('#mb_buttons').css({ background: '#759d44', border: '2px solid #ddd', 'text-align': 'center' });
|
|
|
|
$('form.musicbrainz_import button').css({ width: '80%' });
|
2015-06-16 13:34:02 +00:00
|
|
|
mbUI.slideDown();
|
2015-06-13 09:38:19 +00:00
|
|
|
}
|