mirror of
https://github.com/murdos/musicbrainz-userscripts
synced 2024-12-13 20:02:27 +00:00
Applied prettier and eslint tools on existing code
None of these changes are manual changes made a human
This commit is contained in:
parent
6c721d7c96
commit
14a32dab62
28 changed files with 6205 additions and 5745 deletions
47
README.md
47
README.md
|
@ -1,28 +1,28 @@
|
||||||
# MusicBrainz UserScripts
|
# MusicBrainz UserScripts
|
||||||
|
|
||||||
* [Display shortcut for relationships on MusicBrainz](#mb_relationship_shortcuts)
|
- [Display shortcut for relationships on MusicBrainz](#mb_relationship_shortcuts)
|
||||||
* [Import Bandcamp releases to MusicBrainz](#bandcamp_importer)
|
- [Import Bandcamp releases to MusicBrainz](#bandcamp_importer)
|
||||||
* [Import Bandcamp releases to MusicBrainz Album Link Helper](#bandcamp_importer_helper)
|
- [Import Bandcamp releases to MusicBrainz Album Link Helper](#bandcamp_importer_helper)
|
||||||
* [Import Beatport Pro releases to MusicBrainz](#beatport_pro_importer)
|
- [Import Beatport Pro releases to MusicBrainz](#beatport_pro_importer)
|
||||||
* [Import Beatport releases to MusicBrainz](#beatport_importer)
|
- [Import Beatport releases to MusicBrainz](#beatport_importer)
|
||||||
* [Import CD Baby releases to MusicBrainz](#cdbaby_importer)
|
- [Import CD Baby releases to MusicBrainz](#cdbaby_importer)
|
||||||
* [Import CD1D releases to MusicBrainz](#cd1d_importer)
|
- [Import CD1D releases to MusicBrainz](#cd1d_importer)
|
||||||
* [Import DG/Decca releases to MusicBrainz](#dgdecca_importer)
|
- [Import DG/Decca releases to MusicBrainz](#dgdecca_importer)
|
||||||
* [Import Discogs releases to MusicBrainz](#discogs_importer)
|
- [Import Discogs releases to MusicBrainz](#discogs_importer)
|
||||||
* [Import Encyclopedisque releases to MusicBrainz](#encyclopedisque_importer)
|
- [Import Encyclopedisque releases to MusicBrainz](#encyclopedisque_importer)
|
||||||
* [Import FMA releases to MusicBrainz](#fma_importer)
|
- [Import FMA releases to MusicBrainz](#fma_importer)
|
||||||
* [Import Juno Download releases to MusicBrainz](#juno_download_importer)
|
- [Import Juno Download releases to MusicBrainz](#juno_download_importer)
|
||||||
* [Import Last.fm releases to MusicBrainz](#lastfm_importer)
|
- [Import Last.fm releases to MusicBrainz](#lastfm_importer)
|
||||||
* [Import Loot releases to MusicBrainz](#loot_importer)
|
- [Import Loot releases to MusicBrainz](#loot_importer)
|
||||||
* [Import Metal Archives releases into MusicBrainz](#metalarchives_importer)
|
- [Import Metal Archives releases into MusicBrainz](#metalarchives_importer)
|
||||||
* [Import Qobuz releases to MusicBrainz](#qobuz_importer)
|
- [Import Qobuz releases to MusicBrainz](#qobuz_importer)
|
||||||
* [Import Takealot releases to MusicBrainz](#takealot_importer)
|
- [Import Takealot releases to MusicBrainz](#takealot_importer)
|
||||||
* [MusicBrainz: Batch-add "performance of" relationships](#batch-add-recording-relationships)
|
- [MusicBrainz: Batch-add "performance of" relationships](#batch-add-recording-relationships)
|
||||||
* [MusicBrainz: Expand/collapse release groups](#expand-collapse-release-groups)
|
- [MusicBrainz: Expand/collapse release groups](#expand-collapse-release-groups)
|
||||||
* [MusicBrainz: Fast cancel edits](#fast-cancel-edits)
|
- [MusicBrainz: Fast cancel edits](#fast-cancel-edits)
|
||||||
* [MusicBrainz: Set recording comments for a release](#set-recording-comments)
|
- [MusicBrainz: Set recording comments for a release](#set-recording-comments)
|
||||||
* [Musicbrainz DiscIds Detector](#mb_discids_detector)
|
- [Musicbrainz DiscIds Detector](#mb_discids_detector)
|
||||||
* [Musicbrainz UI enhancements](#mb_ui_enhancements)
|
- [Musicbrainz UI enhancements](#mb_ui_enhancements)
|
||||||
|
|
||||||
## <a name="mb_relationship_shortcuts"></a> Display shortcut for relationships on MusicBrainz
|
## <a name="mb_relationship_shortcuts"></a> Display shortcut for relationships on MusicBrainz
|
||||||
|
|
||||||
|
@ -184,4 +184,3 @@ Various UI enhancements for Musicbrainz
|
||||||
|
|
||||||
[![Source](https://github.com/jerone/UserScripts/blob/master/_resources/Source-button.png)](https://github.com/murdos/musicbrainz-userscripts/blob/master/mb_ui_enhancements.user.js)
|
[![Source](https://github.com/jerone/UserScripts/blob/master/_resources/Source-button.png)](https://github.com/murdos/musicbrainz-userscripts/blob/master/mb_ui_enhancements.user.js)
|
||||||
[![Install](https://raw.github.com/jerone/UserScripts/master/_resources/Install-button.png)](https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/mb_ui_enhancements.user.js)
|
[![Install](https://raw.github.com/jerone/UserScripts/master/_resources/Install-button.png)](https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/mb_ui_enhancements.user.js)
|
||||||
|
|
||||||
|
|
|
@ -14,313 +14,335 @@
|
||||||
// @icon https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/assets/images/Musicbrainz_import_logo.png
|
// @icon https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/assets/images/Musicbrainz_import_logo.png
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
|
|
||||||
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant
|
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant
|
||||||
this.$ = this.jQuery = jQuery.noConflict(true);
|
this.$ = this.jQuery = jQuery.noConflict(true);
|
||||||
|
|
||||||
if (!unsafeWindow) unsafeWindow = window;
|
if (!unsafeWindow) unsafeWindow = window;
|
||||||
|
|
||||||
String.prototype.fix_bandcamp_url = function () {
|
String.prototype.fix_bandcamp_url = function() {
|
||||||
return this.replace('http://', 'https://');
|
return this.replace('http://', 'https://');
|
||||||
};
|
};
|
||||||
|
|
||||||
var BandcampImport = {
|
var BandcampImport = {
|
||||||
|
// Analyze Bandcamp data and return a release object
|
||||||
|
retrieveReleaseInfo: function() {
|
||||||
|
let bandcampAlbumData = unsafeWindow.TralbumData;
|
||||||
|
let bandcampEmbedData = unsafeWindow.EmbedData;
|
||||||
|
|
||||||
|
let release = {
|
||||||
// Analyze Bandcamp data and return a release object
|
discs: [],
|
||||||
retrieveReleaseInfo: function () {
|
artist_credit: [],
|
||||||
|
title: '',
|
||||||
var bandcampAlbumData = unsafeWindow.TralbumData;
|
year: 0,
|
||||||
var bandcampEmbedData = unsafeWindow.EmbedData;
|
month: 0,
|
||||||
|
day: 0,
|
||||||
var release = {
|
parent_album_url: '',
|
||||||
discs: [],
|
labels: [],
|
||||||
artist_credit: [],
|
format: 'Digital Media',
|
||||||
title: '',
|
country: 'XW',
|
||||||
year: 0,
|
type: '',
|
||||||
month: 0,
|
status: 'official',
|
||||||
day: 0,
|
packaging: 'None',
|
||||||
parent_album_url: '',
|
language: 'eng',
|
||||||
labels: [],
|
script: 'Latn',
|
||||||
format: 'Digital Media',
|
urls: [],
|
||||||
country: 'XW',
|
url: bandcampAlbumData.url.fix_bandcamp_url()
|
||||||
type: '',
|
|
||||||
status: 'official',
|
|
||||||
packaging: 'None',
|
|
||||||
language: 'eng',
|
|
||||||
script: 'Latn',
|
|
||||||
urls: [],
|
|
||||||
url: bandcampAlbumData.url.fix_bandcamp_url()
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Grab release title
|
|
||||||
release.title = bandcampAlbumData.current.title;
|
|
||||||
|
|
||||||
// Grab release event information
|
|
||||||
var date = this.convdate(bandcampAlbumData.current.release_date);
|
|
||||||
if (date) {
|
|
||||||
if (!(date.year > 2008 || (date.year == 2008 && date.month >= 9))) {
|
|
||||||
// use publish date if release date is before Bandcamp launch (2008-09)
|
|
||||||
var pdate = this.convdate(bandcampAlbumData.current.publish_date);
|
|
||||||
if (pdate) {
|
|
||||||
date = pdate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
release.year = date.year;
|
|
||||||
release.month = date.month;
|
|
||||||
release.day = date.day;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: implement a mapping between bandcamp release types and MB ones
|
|
||||||
if (bandcampAlbumData.current.type == "track") {
|
|
||||||
// map Bandcamp single tracks to singles
|
|
||||||
release.type = "single";
|
|
||||||
// if track belongs to an album, get its url.
|
|
||||||
if (bandcampEmbedData.album_embed_data) {
|
|
||||||
release.parent_album_url = bandcampEmbedData.album_embed_data.linkback.fix_bandcamp_url();
|
|
||||||
release.type = 'track'; // <-- no import
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tracks
|
|
||||||
var disc = {
|
|
||||||
tracks: [],
|
|
||||||
format: release.format
|
|
||||||
};
|
|
||||||
release.discs.push(disc);
|
|
||||||
|
|
||||||
// attempt to detect multiple artists tracks
|
|
||||||
// bandcamp formats them as 'artist - tracktitle'
|
|
||||||
// only set to true if ALL tracks are formatted like this
|
|
||||||
// and if string doesn't start with a number (ie. 02 - title)
|
|
||||||
var various_artists = true;
|
|
||||||
for (var i=0; i < bandcampAlbumData.trackinfo.length; i++) {
|
|
||||||
if (!bandcampAlbumData.trackinfo[i].title.match(/ - /)
|
|
||||||
|| bandcampAlbumData.trackinfo[i].title.match(/^\d+ - /)) {
|
|
||||||
various_artists = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Release artist credit
|
|
||||||
if (bandcampAlbumData.artist.match(/^various(?: artists)?$/i)
|
|
||||||
&& various_artists) {
|
|
||||||
release.artist_credit = [ MBImport.specialArtist('various_artists') ];
|
|
||||||
} else {
|
|
||||||
release.artist_credit = MBImport.makeArtistCredits([bandcampAlbumData.artist]);
|
|
||||||
}
|
|
||||||
|
|
||||||
var tracks_streamable = 0;
|
|
||||||
$.each(bandcampAlbumData.trackinfo, function (index, bctrack) {
|
|
||||||
var title = bctrack.title;
|
|
||||||
var artist = [];
|
|
||||||
if (various_artists) {
|
|
||||||
var m = bctrack.title.match(/^(.+) - (.+)$/);
|
|
||||||
if (m) {
|
|
||||||
title = m[2];
|
|
||||||
artist = [m[1]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (bctrack.file) tracks_streamable++;
|
|
||||||
var track = {
|
|
||||||
'title': title,
|
|
||||||
'duration': Math.round(bctrack.duration * 1000),
|
|
||||||
'artist_credit': MBImport.makeArtistCredits(artist)
|
|
||||||
};
|
|
||||||
disc.tracks.push(track);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check for hidden tracks (more tracks in the download than shown for streaming ie.)
|
|
||||||
var showntracks = bandcampAlbumData.trackinfo.length;
|
|
||||||
var numtracks = -1;
|
|
||||||
var nostream = false;
|
|
||||||
// album description indicates number of tracks in the download
|
|
||||||
var match = /^\d+ track album$/.exec($("meta[property='og:description']").attr("content"));
|
|
||||||
if (match) {
|
|
||||||
numtracks = parseInt(match, 10);
|
|
||||||
}
|
|
||||||
if (numtracks > 0 && numtracks > showntracks) {
|
|
||||||
// display a warning if tracks in download differs from tracks shown
|
|
||||||
$('h2.trackTitle').append(
|
|
||||||
'<p style="font-size:70%; font-style: italic; margin: 0.1em 0;">' +
|
|
||||||
'Warning: ' + numtracks + ' vs ' + showntracks + ' tracks' +
|
|
||||||
'</p>'
|
|
||||||
);
|
|
||||||
|
|
||||||
// append unknown tracks to the release
|
|
||||||
for (var i = 0; i < numtracks - showntracks; i++) {
|
|
||||||
var track = {
|
|
||||||
'title': '[unknown]',
|
|
||||||
'duration': null,
|
|
||||||
'artist_credit': []
|
|
||||||
};
|
};
|
||||||
disc.tracks.push(track);
|
|
||||||
}
|
|
||||||
// disable stream link as only part of the album can be streamed
|
|
||||||
nostream = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// URLs
|
// Grab release title
|
||||||
var link_type = MBImport.URL_TYPES;
|
release.title = bandcampAlbumData.current.title;
|
||||||
// Download for free vs. for purchase
|
|
||||||
if (bandcampAlbumData.current.download_pref !== null) {
|
// Grab release event information
|
||||||
if (bandcampAlbumData.freeDownloadPage !== null || bandcampAlbumData.current.download_pref === 1 || (
|
let date = this.convdate(bandcampAlbumData.current.release_date);
|
||||||
bandcampAlbumData.current.download_pref === 2 && bandcampAlbumData.current.minimum_price === 0)) {
|
if (date) {
|
||||||
release.urls.push({
|
if (!(date.year > 2008 || (date.year == 2008 && date.month >= 9))) {
|
||||||
'url': release.url,
|
// use publish date if release date is before Bandcamp launch (2008-09)
|
||||||
'link_type': link_type.download_for_free
|
let pdate = this.convdate(bandcampAlbumData.current.publish_date);
|
||||||
|
if (pdate) {
|
||||||
|
date = pdate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
release.year = date.year;
|
||||||
|
release.month = date.month;
|
||||||
|
release.day = date.day;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: implement a mapping between bandcamp release types and MB ones
|
||||||
|
if (bandcampAlbumData.current.type == 'track') {
|
||||||
|
// map Bandcamp single tracks to singles
|
||||||
|
release.type = 'single';
|
||||||
|
// if track belongs to an album, get its url.
|
||||||
|
if (bandcampEmbedData.album_embed_data) {
|
||||||
|
release.parent_album_url = bandcampEmbedData.album_embed_data.linkback.fix_bandcamp_url();
|
||||||
|
release.type = 'track'; // <-- no import
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tracks
|
||||||
|
let disc = {
|
||||||
|
tracks: [],
|
||||||
|
format: release.format
|
||||||
|
};
|
||||||
|
release.discs.push(disc);
|
||||||
|
|
||||||
|
// attempt to detect multiple artists tracks
|
||||||
|
// bandcamp formats them as 'artist - tracktitle'
|
||||||
|
// only set to true if ALL tracks are formatted like this
|
||||||
|
// and if string doesn't start with a number (ie. 02 - title)
|
||||||
|
let various_artists = true;
|
||||||
|
for (var i = 0; i < bandcampAlbumData.trackinfo.length; i++) {
|
||||||
|
if (!bandcampAlbumData.trackinfo[i].title.match(/ - /) || bandcampAlbumData.trackinfo[i].title.match(/^\d+ - /)) {
|
||||||
|
various_artists = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release artist credit
|
||||||
|
if (bandcampAlbumData.artist.match(/^various(?: artists)?$/i) && various_artists) {
|
||||||
|
release.artist_credit = [MBImport.specialArtist('various_artists')];
|
||||||
|
} else {
|
||||||
|
release.artist_credit = MBImport.makeArtistCredits([bandcampAlbumData.artist]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let tracks_streamable = 0;
|
||||||
|
$.each(bandcampAlbumData.trackinfo, function(index, bctrack) {
|
||||||
|
let title = bctrack.title;
|
||||||
|
let artist = [];
|
||||||
|
if (various_artists) {
|
||||||
|
let m = bctrack.title.match(/^(.+) - (.+)$/);
|
||||||
|
if (m) {
|
||||||
|
title = m[2];
|
||||||
|
artist = [m[1]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bctrack.file) tracks_streamable++;
|
||||||
|
let track = {
|
||||||
|
title: title,
|
||||||
|
duration: Math.round(bctrack.duration * 1000),
|
||||||
|
artist_credit: MBImport.makeArtistCredits(artist)
|
||||||
|
};
|
||||||
|
disc.tracks.push(track);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
if (bandcampAlbumData.current.download_pref === 2) {
|
|
||||||
release.urls.push({
|
|
||||||
'url': release.url,
|
|
||||||
'link_type': link_type.purchase_for_download
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Check if the release is streamable
|
|
||||||
if (bandcampAlbumData.hasAudio && !nostream && disc.tracks.length > 0 && disc.tracks.length == tracks_streamable) {
|
|
||||||
release.urls.push({
|
|
||||||
'url': release.url,
|
|
||||||
'link_type': link_type.stream_for_free
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// Check if release is Creative Commons licensed
|
|
||||||
if ($("div#license a.cc-icons").length > 0) {
|
|
||||||
release.urls.push({
|
|
||||||
'url': $("div#license a.cc-icons").attr("href"),
|
|
||||||
'link_type': link_type.license
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// Check if album has a back link to a label
|
|
||||||
var label = $("a.back-to-label-link span.back-to-label-name").text();
|
|
||||||
if (label) {
|
|
||||||
release.labels.push({
|
|
||||||
'name': label,
|
|
||||||
'mbid': '',
|
|
||||||
'catno': 'none'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return release;
|
// Check for hidden tracks (more tracks in the download than shown for streaming ie.)
|
||||||
},
|
let showntracks = bandcampAlbumData.trackinfo.length;
|
||||||
|
let numtracks = -1;
|
||||||
|
let nostream = false;
|
||||||
|
// album description indicates number of tracks in the download
|
||||||
|
let match = /^\d+ track album$/.exec($("meta[property='og:description']").attr('content'));
|
||||||
|
if (match) {
|
||||||
|
numtracks = parseInt(match, 10);
|
||||||
|
}
|
||||||
|
if (numtracks > 0 && numtracks > showntracks) {
|
||||||
|
// display a warning if tracks in download differs from tracks shown
|
||||||
|
$('h2.trackTitle').append(
|
||||||
|
`${'<p style="font-size:70%; font-style: italic; margin: 0.1em 0;">' + 'Warning: '}${numtracks} vs ${showntracks} tracks` +
|
||||||
|
`</p>`
|
||||||
|
);
|
||||||
|
|
||||||
// Insert links in page
|
// append unknown tracks to the release
|
||||||
insertLink: function (release) {
|
for (var i = 0; i < numtracks - showntracks; i++) {
|
||||||
if (release.type == "track") {
|
let track = {
|
||||||
// only import album or single, tracks belong to an album
|
title: '[unknown]',
|
||||||
return false;
|
duration: null,
|
||||||
|
artist_credit: []
|
||||||
|
};
|
||||||
|
disc.tracks.push(track);
|
||||||
|
}
|
||||||
|
// disable stream link as only part of the album can be streamed
|
||||||
|
nostream = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// URLs
|
||||||
|
let link_type = MBImport.URL_TYPES;
|
||||||
|
// Download for free vs. for purchase
|
||||||
|
if (bandcampAlbumData.current.download_pref !== null) {
|
||||||
|
if (
|
||||||
|
bandcampAlbumData.freeDownloadPage !== null ||
|
||||||
|
bandcampAlbumData.current.download_pref === 1 ||
|
||||||
|
(bandcampAlbumData.current.download_pref === 2 && bandcampAlbumData.current.minimum_price === 0)
|
||||||
|
) {
|
||||||
|
release.urls.push({
|
||||||
|
url: release.url,
|
||||||
|
link_type: link_type.download_for_free
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (bandcampAlbumData.current.download_pref === 2) {
|
||||||
|
release.urls.push({
|
||||||
|
url: release.url,
|
||||||
|
link_type: link_type.purchase_for_download
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check if the release is streamable
|
||||||
|
if (bandcampAlbumData.hasAudio && !nostream && disc.tracks.length > 0 && disc.tracks.length == tracks_streamable) {
|
||||||
|
release.urls.push({
|
||||||
|
url: release.url,
|
||||||
|
link_type: link_type.stream_for_free
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Check if release is Creative Commons licensed
|
||||||
|
if ($('div#license a.cc-icons').length > 0) {
|
||||||
|
release.urls.push({
|
||||||
|
url: $('div#license a.cc-icons').attr('href'),
|
||||||
|
link_type: link_type.license
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Check if album has a back link to a label
|
||||||
|
let label = $('a.back-to-label-link span.back-to-label-name').text();
|
||||||
|
if (label) {
|
||||||
|
release.labels.push({
|
||||||
|
name: label,
|
||||||
|
mbid: '',
|
||||||
|
catno: 'none'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return release;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Insert links in page
|
||||||
|
insertLink: function(release) {
|
||||||
|
if (release.type == 'track') {
|
||||||
|
// only import album or single, tracks belong to an album
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Form parameters
|
||||||
|
let edit_note = MBImport.makeEditNote(release.url, 'Bandcamp');
|
||||||
|
let parameters = MBImport.buildFormParameters(release, edit_note);
|
||||||
|
// Build form
|
||||||
|
let mbUI = $(`<div id="mb_buttons">${MBImport.buildFormHTML(parameters)}${MBImport.buildSearchButton(release)}</div>`).hide();
|
||||||
|
|
||||||
|
// Append MB import link
|
||||||
|
$('#name-section').append(mbUI);
|
||||||
|
$('#mb_buttons').css({ 'margin-top': '6px' });
|
||||||
|
$('form.musicbrainz_import').css({ display: 'inline-block' });
|
||||||
|
mbUI.slideDown();
|
||||||
|
},
|
||||||
|
|
||||||
|
// helper to convert bandcamp date to MB date
|
||||||
|
convdate: function(date) {
|
||||||
|
if (typeof date != 'undefined' && date !== '') {
|
||||||
|
let d = new Date(date);
|
||||||
|
return {
|
||||||
|
year: d.getUTCFullYear(),
|
||||||
|
month: d.getUTCMonth() + 1,
|
||||||
|
day: d.getUTCDate()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
// Form parameters
|
|
||||||
var edit_note = MBImport.makeEditNote(release.url, 'Bandcamp');
|
|
||||||
var parameters = MBImport.buildFormParameters(release, edit_note);
|
|
||||||
// Build form
|
|
||||||
var mbUI = $('<div id="mb_buttons">'
|
|
||||||
+ MBImport.buildFormHTML(parameters)
|
|
||||||
+ MBImport.buildSearchButton(release)
|
|
||||||
+ '</div>').hide();
|
|
||||||
|
|
||||||
// Append MB import link
|
|
||||||
$('#name-section').append(mbUI);
|
|
||||||
$('#mb_buttons').css({'margin-top': '6px'});
|
|
||||||
$('form.musicbrainz_import').css({display: 'inline-block'});
|
|
||||||
mbUI.slideDown();
|
|
||||||
},
|
|
||||||
|
|
||||||
// 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 () {
|
$(document).ready(function() {
|
||||||
/* keep the following line as first, it is required to skip
|
/* keep the following line as first, it is required to skip
|
||||||
* pages which aren't actually a bandcamp page, since we support
|
* pages which aren't actually a bandcamp page, since we support
|
||||||
* bandcamp pages under third-party domains.
|
* bandcamp pages under third-party domains.
|
||||||
* see @include
|
* see @include
|
||||||
*/
|
*/
|
||||||
if (!unsafeWindow.TralbumData) return;
|
if (!unsafeWindow.TralbumData) return;
|
||||||
/***/
|
/***/
|
||||||
|
|
||||||
MBImportStyle();
|
MBImportStyle();
|
||||||
|
|
||||||
var mblinks = new MBLinks('BCI_MBLINKS_CACHE');
|
let mblinks = new MBLinks('BCI_MBLINKS_CACHE');
|
||||||
|
|
||||||
var release = BandcampImport.retrieveReleaseInfo();
|
let release = BandcampImport.retrieveReleaseInfo();
|
||||||
|
|
||||||
// add MB artist link
|
// add MB artist link
|
||||||
var root_url = release.url.match(/^(https?:\/\/[^\/]+)/)[1].split('?')[0];
|
let root_url = release.url.match(/^(https?:\/\/[^\/]+)/)[1].split('?')[0];
|
||||||
var label_url = "";
|
let label_url = '';
|
||||||
mblinks.searchAndDisplayMbLink(root_url, 'artist', function (link) { $('div#name-section span[itemprop="byArtist"]').before(link); } );
|
mblinks.searchAndDisplayMbLink(root_url, 'artist', function(link) {
|
||||||
mblinks.searchAndDisplayMbLink(root_url, 'label', function (link) { $('p#band-name-location span.title').append(link); }, 'label:' + root_url );
|
$('div#name-section span[itemprop="byArtist"]').before(link);
|
||||||
var labelback = $("a.back-to-label-link");
|
});
|
||||||
if (labelback) {
|
mblinks.searchAndDisplayMbLink(
|
||||||
var labelbacklink = labelback.attr('href');
|
root_url,
|
||||||
if (labelbacklink) {
|
'label',
|
||||||
label_url = labelbacklink.match(/^(https?:\/\/[^\/]+)/)[1].split('?')[0].fix_bandcamp_url();
|
function(link) {
|
||||||
mblinks.searchAndDisplayMbLink(label_url, 'label', function (link) { $('a.back-to-label-link span.back-link-text').append(link); }, 'label:' + label_url );
|
$('p#band-name-location span.title').append(link);
|
||||||
|
},
|
||||||
|
`label:${root_url}`
|
||||||
|
);
|
||||||
|
let labelback = $('a.back-to-label-link');
|
||||||
|
if (labelback) {
|
||||||
|
let labelbacklink = labelback.attr('href');
|
||||||
|
if (labelbacklink) {
|
||||||
|
label_url = labelbacklink
|
||||||
|
.match(/^(https?:\/\/[^\/]+)/)[1]
|
||||||
|
.split('?')[0]
|
||||||
|
.fix_bandcamp_url();
|
||||||
|
mblinks.searchAndDisplayMbLink(
|
||||||
|
label_url,
|
||||||
|
'label',
|
||||||
|
function(link) {
|
||||||
|
$('a.back-to-label-link span.back-link-text').append(link);
|
||||||
|
},
|
||||||
|
`label:${label_url}`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (release.artist_credit.length == 1) {
|
if (release.artist_credit.length == 1) {
|
||||||
// try to get artist's mbid from cache
|
// try to get artist's mbid from cache
|
||||||
var artist_mbid = mblinks.resolveMBID(root_url);
|
let artist_mbid = mblinks.resolveMBID(root_url);
|
||||||
if (artist_mbid) {
|
if (artist_mbid) {
|
||||||
release.artist_credit[0].mbid = artist_mbid;
|
release.artist_credit[0].mbid = artist_mbid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// try to get label mbid from cache
|
// try to get label mbid from cache
|
||||||
var label_mbid = "";
|
let label_mbid = '';
|
||||||
var label_name = "";
|
let label_name = '';
|
||||||
if (label_url) {
|
if (label_url) {
|
||||||
label_mbid = mblinks.resolveMBID('label:' + label_url);
|
label_mbid = mblinks.resolveMBID(`label:${label_url}`);
|
||||||
label_name = $('a.back-to-label-link span.back-link-text ').contents().get(2).textContent;
|
label_name = $('a.back-to-label-link span.back-link-text ')
|
||||||
} else {
|
.contents()
|
||||||
label_mbid = mblinks.resolveMBID('label:' + root_url);
|
.get(2).textContent;
|
||||||
if (label_mbid) label_name = $('p#band-name-location span.title').text().trim();
|
} else {
|
||||||
}
|
label_mbid = mblinks.resolveMBID(`label:${root_url}`);
|
||||||
if (label_mbid || label_name) {
|
if (label_mbid)
|
||||||
if (release.labels.length == 0) {
|
label_name = $('p#band-name-location span.title')
|
||||||
release.labels.push({
|
.text()
|
||||||
'name': '',
|
.trim();
|
||||||
'mbid': '',
|
}
|
||||||
'catno': 'none'
|
if (label_mbid || label_name) {
|
||||||
});
|
if (release.labels.length == 0) {
|
||||||
|
release.labels.push({
|
||||||
|
name: '',
|
||||||
|
mbid: '',
|
||||||
|
catno: 'none'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
release.labels[0].name = label_name;
|
||||||
|
release.labels[0].mbid = label_mbid;
|
||||||
}
|
}
|
||||||
release.labels[0].name = label_name;
|
|
||||||
release.labels[0].mbid = label_mbid;
|
|
||||||
}
|
|
||||||
|
|
||||||
BandcampImport.insertLink(release);
|
BandcampImport.insertLink(release);
|
||||||
LOGGER.info("Parsed release: ", release);
|
LOGGER.info('Parsed release: ', release);
|
||||||
|
|
||||||
if (release.type == 'track') {
|
if (release.type == 'track') {
|
||||||
// add MB links to parent album
|
// add MB links to parent album
|
||||||
mblinks.searchAndDisplayMbLink(release.parent_album_url, 'release', function (link) { $('div#name-section span[itemprop="inAlbum"] a:first').before(link); } );
|
mblinks.searchAndDisplayMbLink(release.parent_album_url, 'release', function(link) {
|
||||||
} else {
|
$('div#name-section span[itemprop="inAlbum"] a:first').before(link);
|
||||||
// add MB release links to album or single
|
});
|
||||||
mblinks.searchAndDisplayMbLink(release.url, 'release', function (link) { $('div#name-section span[itemprop="byArtist"]').after(link); } );
|
} else {
|
||||||
}
|
// add MB release links to album or single
|
||||||
|
mblinks.searchAndDisplayMbLink(release.url, 'release', function(link) {
|
||||||
|
$('div#name-section span[itemprop="byArtist"]').after(link);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// append a comma after each tag to ease cut'n'paste to MB
|
// append a comma after each tag to ease cut'n'paste to MB
|
||||||
$("div.tralbum-tags a:not(:last-child).tag").after(", ");
|
$('div.tralbum-tags a:not(:last-child).tag').after(', ');
|
||||||
|
|
||||||
// append a link to the full size image
|
// append a link to the full size image
|
||||||
var fullsizeimageurl = $("div#tralbumArt a").attr("href").replace('_10', '_0');
|
let fullsizeimageurl = $('div#tralbumArt a')
|
||||||
$("div#tralbumArt").after("<div id='bci_link'><a class='custom-color' href='" + fullsizeimageurl +
|
.attr('href')
|
||||||
"' title='Open original image in a new tab (Bandcamp importer)' target='_blank'>Original image</a></div>");
|
.replace('_10', '_0');
|
||||||
|
$('div#tralbumArt').after(
|
||||||
$("div#bci_link").css({ 'padding-top': '0.5em', 'text-align': 'right' });
|
`<div id='bci_link'><a class='custom-color' href='${fullsizeimageurl}' title='Open original image in a new tab (Bandcamp importer)' target='_blank'>Original image</a></div>`
|
||||||
$("div#bci_link a").css({ 'font-weight': 'bold' });
|
);
|
||||||
|
|
||||||
|
$('div#bci_link').css({ 'padding-top': '0.5em', 'text-align': 'right' });
|
||||||
|
$('div#bci_link a').css({ 'font-weight': 'bold' });
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,12 +18,13 @@ this.$ = this.jQuery = jQuery.noConflict(true);
|
||||||
|
|
||||||
if (!unsafeWindow) unsafeWindow = window;
|
if (!unsafeWindow) unsafeWindow = window;
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function() {
|
||||||
// Display a link to the correct album bandcamp url (ie. main page or releases page)
|
// Display a link to the correct album bandcamp url (ie. main page or releases page)
|
||||||
var bandcampAlbumData = unsafeWindow.TralbumData;
|
let bandcampAlbumData = unsafeWindow.TralbumData;
|
||||||
if (bandcampAlbumData && bandcampAlbumData.url) {
|
if (bandcampAlbumData && bandcampAlbumData.url) {
|
||||||
var innerHTML = '<div id="bci_helper" style="padding-top: 5px;">' + '<a href="' + bandcampAlbumData.url +
|
let innerHTML = `${'<div id="bci_helper" style="padding-top: 5px;">' + '<a href="'}${
|
||||||
'" title="Load album page and display Import to MB button">Album page (MB import)</a></div>';
|
bandcampAlbumData.url
|
||||||
$('#name-section').append(innerHTML);
|
}" title="Load album page and display Import to MB button">Album page (MB import)</a></div>`;
|
||||||
}
|
$('#name-section').append(innerHTML);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -17,119 +17,121 @@ this.$ = this.jQuery = jQuery.noConflict(true);
|
||||||
|
|
||||||
if (!unsafeWindow) unsafeWindow = window;
|
if (!unsafeWindow) unsafeWindow = window;
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function() {
|
||||||
MBImportStyle();
|
MBImportStyle();
|
||||||
|
|
||||||
var release_url = window.location.href.replace('/\?.*$/', '').replace(/#.*$/, '');
|
let release_url = window.location.href.replace('/?.*$/', '').replace(/#.*$/, '');
|
||||||
var release = retrieveReleaseInfo(release_url);
|
let release = retrieveReleaseInfo(release_url);
|
||||||
insertLink(release, release_url);
|
insertLink(release, release_url);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function retrieveReleaseInfo(release_url) {
|
function retrieveReleaseInfo(release_url) {
|
||||||
function contains_or(selector, list) {
|
function contains_or(selector, list) {
|
||||||
selectors = [];
|
selectors = [];
|
||||||
$.each(list, function(ind, value) {
|
$.each(list, function(ind, value) {
|
||||||
selectors.push(selector + ':contains("' + value.replace('"', '\\"') + '")');
|
selectors.push(`${selector}:contains("${value.replace('"', '\\"')}")`);
|
||||||
|
});
|
||||||
|
return selectors.join(',');
|
||||||
|
}
|
||||||
|
let release_date_strings = [
|
||||||
|
'Release Date',
|
||||||
|
'Fecha de lanzamiento',
|
||||||
|
'Date de sortie',
|
||||||
|
'Erscheinungsdatum',
|
||||||
|
'Data de lançamento',
|
||||||
|
'Releasedatum',
|
||||||
|
'Data di uscita',
|
||||||
|
'リリース予定日'
|
||||||
|
];
|
||||||
|
let labels_strings = ['Labels', 'Sello', 'Gravadoras', 'Label', 'Etichetta', 'Editora', 'レーベル'];
|
||||||
|
let catalog_strings = ['Catalog', 'Catálogo', 'Catalogue', 'Katalog', 'Catalogus', 'Catalogo', 'カタログ'];
|
||||||
|
let release = {};
|
||||||
|
|
||||||
|
// Release information global to all Beatport releases
|
||||||
|
release.packaging = 'None';
|
||||||
|
release.country = 'XW';
|
||||||
|
release.status = 'official';
|
||||||
|
release.urls = [];
|
||||||
|
release.urls.push({
|
||||||
|
url: release_url,
|
||||||
|
link_type: MBImport.URL_TYPES.purchase_for_download
|
||||||
});
|
});
|
||||||
return selectors.join(',');
|
|
||||||
}
|
|
||||||
var release_date_strings = [
|
|
||||||
'Release Date', 'Fecha de lanzamiento', 'Date de sortie', 'Erscheinungsdatum', 'Data de lançamento', 'Releasedatum', "Data di uscita", "リリース予定日"
|
|
||||||
];
|
|
||||||
var labels_strings = [
|
|
||||||
'Labels', 'Sello', 'Gravadoras', "Label", "Etichetta", "Editora", "レーベル"
|
|
||||||
];
|
|
||||||
var catalog_strings = [
|
|
||||||
'Catalog', 'Catálogo', 'Catalogue', 'Katalog', 'Catalogus', "Catalogo", "カタログ"
|
|
||||||
];
|
|
||||||
var release = {};
|
|
||||||
|
|
||||||
// Release information global to all Beatport releases
|
let releaseDate = $(contains_or('td.meta-data-label', release_date_strings))
|
||||||
release.packaging = 'None';
|
.next()
|
||||||
release.country = "XW";
|
.text()
|
||||||
release.status = 'official';
|
.split('-');
|
||||||
release.urls = [];
|
release.year = releaseDate[0];
|
||||||
release.urls.push({
|
release.month = releaseDate[1];
|
||||||
'url': release_url,
|
release.day = releaseDate[2];
|
||||||
'link_type': MBImport.URL_TYPES.purchase_for_download
|
|
||||||
});
|
|
||||||
|
|
||||||
var releaseDate = $(contains_or("td.meta-data-label", release_date_strings)).next().text().split("-");
|
release.labels = [];
|
||||||
release.year = releaseDate[0];
|
release.labels.push({
|
||||||
release.month = releaseDate[1];
|
name: $(contains_or('td.meta-data-label', labels_strings))
|
||||||
release.day = releaseDate[2];
|
.next()
|
||||||
|
.text(),
|
||||||
|
catno: $(contains_or('td.meta-data-label', catalog_strings))
|
||||||
|
.next()
|
||||||
|
.text()
|
||||||
|
});
|
||||||
|
|
||||||
release.labels = [];
|
let release_artists = [];
|
||||||
release.labels.push(
|
|
||||||
{
|
|
||||||
name: $(contains_or("td.meta-data-label", labels_strings)).next().text(),
|
|
||||||
catno: $(contains_or("td.meta-data-label", catalog_strings)).next().text()
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
var release_artists = [];
|
// Tracks
|
||||||
|
let tracks = [];
|
||||||
|
unsafeWindow.$('span[data-json]').each(function(index, tagSoup) {
|
||||||
|
let t = $.parseJSON($(tagSoup).attr('data-json'));
|
||||||
|
release.title = t.release.name;
|
||||||
|
|
||||||
// Tracks
|
let artists = [];
|
||||||
var tracks = [];
|
t.artists.forEach(function(artist) {
|
||||||
unsafeWindow.$( "span[data-json]" ).each(
|
artists.push(artist.name);
|
||||||
function ( index, tagSoup ) {
|
release_artists.push(artist.name);
|
||||||
var t = $.parseJSON($(tagSoup).attr('data-json'));
|
});
|
||||||
release.title = t.release.name;
|
let title = t.name;
|
||||||
|
if (t.mixName && t.mixName !== 'Original Mix' && t.mixName !== 'Original') {
|
||||||
var artists = [];
|
title += ` (${t.mixName})`;
|
||||||
t.artists.forEach(
|
|
||||||
function (artist) {
|
|
||||||
artists.push(artist.name);
|
|
||||||
release_artists.push(artist.name);
|
|
||||||
}
|
}
|
||||||
);
|
tracks.push({
|
||||||
var title = t.name;
|
artist_credit: MBImport.makeArtistCredits(artists),
|
||||||
if (t.mixName && t.mixName !== 'Original Mix' && t.mixName !== 'Original') {
|
title: title,
|
||||||
title += ' (' + t.mixName + ')';
|
duration: t.lengthMs
|
||||||
}
|
});
|
||||||
tracks.push({
|
});
|
||||||
'artist_credit': MBImport.makeArtistCredits(artists),
|
|
||||||
'title': title,
|
let unique_artists = [];
|
||||||
'duration': t.lengthMs
|
$.each(release_artists, function(i, el) {
|
||||||
});
|
if ($.inArray(el, unique_artists) === -1) {
|
||||||
|
unique_artists.push(el);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (unique_artists.length > 4) {
|
||||||
|
release.artist_credit = [MBImport.specialArtist('various_artists')];
|
||||||
|
} else {
|
||||||
|
release.artist_credit = MBImport.makeArtistCredits(unique_artists);
|
||||||
}
|
}
|
||||||
);
|
release.discs = [];
|
||||||
|
release.discs.push({
|
||||||
|
tracks: tracks,
|
||||||
|
format: 'Digital Media'
|
||||||
|
});
|
||||||
|
|
||||||
var unique_artists = [];
|
LOGGER.info('Parsed release: ', release);
|
||||||
$.each(release_artists, function(i, el){
|
return release;
|
||||||
if ($.inArray(el, unique_artists) === -1) {
|
|
||||||
unique_artists.push(el);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (unique_artists.length > 4) {
|
|
||||||
release.artist_credit = [ MBImport.specialArtist('various_artists') ];
|
|
||||||
} else {
|
|
||||||
release.artist_credit = MBImport.makeArtistCredits(unique_artists);
|
|
||||||
}
|
|
||||||
release.discs = [];
|
|
||||||
release.discs.push( {
|
|
||||||
'tracks': tracks,
|
|
||||||
'format': "Digital Media"
|
|
||||||
} );
|
|
||||||
|
|
||||||
LOGGER.info("Parsed release: ", release);
|
|
||||||
return release;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert button into page under label information
|
// Insert button into page under label information
|
||||||
function insertLink(release, release_url) {
|
function insertLink(release, release_url) {
|
||||||
var edit_note = MBImport.makeEditNote(release_url, 'Beatport Classic');
|
let edit_note = MBImport.makeEditNote(release_url, 'Beatport Classic');
|
||||||
var parameters = MBImport.buildFormParameters(release, edit_note);
|
let parameters = MBImport.buildFormParameters(release, edit_note);
|
||||||
|
|
||||||
var mbUI = $('<div class="musicbrainz-import">'
|
let mbUI = $(
|
||||||
+ MBImport.buildFormHTML(parameters)
|
`<div class="musicbrainz-import">${MBImport.buildFormHTML(parameters)}${MBImport.buildSearchButton(release)}</div>`
|
||||||
+ MBImport.buildSearchButton(release)
|
).hide();
|
||||||
+ '</div>').hide();
|
|
||||||
|
|
||||||
$(".release-detail-metadata").append(mbUI);
|
$('.release-detail-metadata').append(mbUI);
|
||||||
$('form.musicbrainz_import').css({'display': 'inline-block', 'margin': '1px'});
|
$('form.musicbrainz_import').css({ display: 'inline-block', margin: '1px' });
|
||||||
$('form.musicbrainz_import img').css({'display': 'inline-block'});
|
$('form.musicbrainz_import img').css({ display: 'inline-block' });
|
||||||
mbUI.slideDown();
|
mbUI.slideDown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,117 +20,112 @@ this.$ = this.jQuery = jQuery.noConflict(true);
|
||||||
|
|
||||||
if (!unsafeWindow) unsafeWindow = window;
|
if (!unsafeWindow) unsafeWindow = window;
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function() {
|
||||||
MBImportStyle();
|
MBImportStyle();
|
||||||
|
|
||||||
var release_url = window.location.href.replace('/\?.*$/', '').replace(/#.*$/, '');
|
let release_url = window.location.href.replace('/?.*$/', '').replace(/#.*$/, '');
|
||||||
var release = retrieveReleaseInfo(release_url);
|
let release = retrieveReleaseInfo(release_url);
|
||||||
insertLink(release, release_url);
|
insertLink(release, release_url);
|
||||||
});
|
});
|
||||||
|
|
||||||
function retrieveReleaseInfo(release_url) {
|
function retrieveReleaseInfo(release_url) {
|
||||||
var releaseDate = ProductDetail.date.published.split("-");
|
let releaseDate = ProductDetail.date.published.split('-');
|
||||||
|
|
||||||
// Release information global to all Beatport releases
|
// Release information global to all Beatport releases
|
||||||
var release = {
|
let release = {
|
||||||
artist_credit: [],
|
artist_credit: [],
|
||||||
title: ProductDetail.name,
|
title: ProductDetail.name,
|
||||||
year: releaseDate[0],
|
year: releaseDate[0],
|
||||||
month: releaseDate[1],
|
month: releaseDate[1],
|
||||||
day: releaseDate[2],
|
day: releaseDate[2],
|
||||||
format: 'Digital Media',
|
format: 'Digital Media',
|
||||||
packaging: 'None',
|
packaging: 'None',
|
||||||
country: 'XW',
|
country: 'XW',
|
||||||
status: 'official',
|
status: 'official',
|
||||||
language: 'eng',
|
language: 'eng',
|
||||||
script: 'Latn',
|
script: 'Latn',
|
||||||
type: '',
|
type: '',
|
||||||
urls: [],
|
urls: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
discs: []
|
discs: []
|
||||||
};
|
};
|
||||||
|
|
||||||
// URLs
|
// URLs
|
||||||
release.urls.push({
|
release.urls.push({
|
||||||
'url': release_url,
|
url: release_url,
|
||||||
'link_type': MBImport.URL_TYPES.purchase_for_download
|
link_type: MBImport.URL_TYPES.purchase_for_download
|
||||||
});
|
});
|
||||||
|
|
||||||
release.labels.push(
|
release.labels.push({
|
||||||
{
|
name: ProductDetail.label.name,
|
||||||
name: ProductDetail.label.name,
|
catno: ProductDetail.catalog
|
||||||
catno: ProductDetail.catalog
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Tracks
|
// Tracks
|
||||||
var tracks = [];
|
let tracks = [];
|
||||||
var the_tracks = unsafeWindow.Playables.tracks;
|
let the_tracks = unsafeWindow.Playables.tracks;
|
||||||
var seen_tracks = {}; // to shoot duplicates ...
|
let seen_tracks = {}; // to shoot duplicates ...
|
||||||
var release_artists = [];
|
let release_artists = [];
|
||||||
$.each(the_tracks,
|
$.each(the_tracks, function(idx, track) {
|
||||||
function (idx, track) {
|
if (track.release.id !== ProductDetail.id) {
|
||||||
if (track.release.id !== ProductDetail.id) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (seen_tracks[track.id]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
seen_tracks[track.id] = true;
|
|
||||||
|
|
||||||
var artists = [];
|
|
||||||
$.each(track.artists,
|
|
||||||
function (idx2, artist) {
|
|
||||||
artists.push(artist.name);
|
|
||||||
release_artists.push(artist.name);
|
|
||||||
}
|
}
|
||||||
);
|
if (seen_tracks[track.id]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
seen_tracks[track.id] = true;
|
||||||
|
|
||||||
var title = track.name;
|
let artists = [];
|
||||||
if (track.mix && track.mix !== 'Original Mix') {
|
$.each(track.artists, function(idx2, artist) {
|
||||||
title += ' (' + track.mix + ')';
|
artists.push(artist.name);
|
||||||
}
|
release_artists.push(artist.name);
|
||||||
tracks.push({
|
});
|
||||||
'artist_credit': MBImport.makeArtistCredits(artists),
|
|
||||||
'title': title,
|
let title = track.name;
|
||||||
'duration': track.duration.minutes
|
if (track.mix && track.mix !== 'Original Mix') {
|
||||||
});
|
title += ` (${track.mix})`;
|
||||||
|
}
|
||||||
|
tracks.push({
|
||||||
|
artist_credit: MBImport.makeArtistCredits(artists),
|
||||||
|
title: title,
|
||||||
|
duration: track.duration.minutes
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
let unique_artists = [];
|
||||||
|
$.each(release_artists, function(i, el) {
|
||||||
|
if ($.inArray(el, unique_artists) === -1) {
|
||||||
|
unique_artists.push(el);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (unique_artists.length > 4) {
|
||||||
|
release.artist_credit = [MBImport.specialArtist('various_artists')];
|
||||||
|
} else {
|
||||||
|
release.artist_credit = MBImport.makeArtistCredits(unique_artists);
|
||||||
}
|
}
|
||||||
);
|
release.discs.push({
|
||||||
|
tracks: tracks,
|
||||||
|
format: release.format
|
||||||
|
});
|
||||||
|
|
||||||
var unique_artists = [];
|
LOGGER.info('Parsed release: ', release);
|
||||||
$.each(release_artists, function(i, el){
|
return release;
|
||||||
if ($.inArray(el, unique_artists) === -1) {
|
|
||||||
unique_artists.push(el);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (unique_artists.length > 4) {
|
|
||||||
release.artist_credit = [ MBImport.specialArtist('various_artists') ];
|
|
||||||
} else {
|
|
||||||
release.artist_credit = MBImport.makeArtistCredits(unique_artists);
|
|
||||||
}
|
|
||||||
release.discs.push( {
|
|
||||||
'tracks': tracks,
|
|
||||||
'format': release.format
|
|
||||||
} );
|
|
||||||
|
|
||||||
LOGGER.info("Parsed release: ", release);
|
|
||||||
return release;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert button into page under label information
|
// Insert button into page under label information
|
||||||
function insertLink(release, release_url) {
|
function insertLink(release, release_url) {
|
||||||
var edit_note = MBImport.makeEditNote(release_url, 'Beatport');
|
let edit_note = MBImport.makeEditNote(release_url, 'Beatport');
|
||||||
var parameters = MBImport.buildFormParameters(release, edit_note);
|
let parameters = MBImport.buildFormParameters(release, edit_note);
|
||||||
|
|
||||||
var mbUI = $('<li class="interior-release-chart-content-item musicbrainz-import">'
|
let mbUI = $(
|
||||||
+ MBImport.buildFormHTML(parameters)
|
`<li class="interior-release-chart-content-item musicbrainz-import">${MBImport.buildFormHTML(
|
||||||
+ MBImport.buildSearchButton(release)
|
parameters
|
||||||
+ '</li>').hide();
|
)}${MBImport.buildSearchButton(release)}</li>`
|
||||||
|
).hide();
|
||||||
|
|
||||||
$(".interior-release-chart-content-list").append(mbUI);
|
$('.interior-release-chart-content-list').append(mbUI);
|
||||||
$('form.musicbrainz_import').css({'display': 'inline-block', 'margin-left': '5px'});
|
$('form.musicbrainz_import').css({ display: 'inline-block', 'margin-left': '5px' });
|
||||||
$('form.musicbrainz_import button').css({'width': '120px'});
|
$('form.musicbrainz_import button').css({ width: '120px' });
|
||||||
mbUI.slideDown();
|
mbUI.slideDown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,245 +25,260 @@ if (!unsafeWindow) unsafeWindow = window;
|
||||||
this.$ = this.jQuery = jQuery.noConflict(true);
|
this.$ = this.jQuery = jQuery.noConflict(true);
|
||||||
|
|
||||||
var CD1DImporter = {
|
var CD1DImporter = {
|
||||||
|
getFormats: function() {
|
||||||
getFormats: function () {
|
// get a list of existing formats, return id of the fragment and name
|
||||||
// get a list of existing formats, return id of the fragment and name
|
let formats = $('#container-1 ul li.ui-state-default').map(function() {
|
||||||
var formats = $('#container-1 ul li.ui-state-default').map(function () {
|
return {
|
||||||
return {
|
id: $(this)
|
||||||
id: $(this).find('a:first').attr('href').split('#')[1].split('-'),
|
.find('a:first')
|
||||||
name: $(this).find('span:first').text()
|
.attr('href')
|
||||||
};
|
.split('#')[1]
|
||||||
});
|
.split('-'),
|
||||||
// remove "parent" formats : ie. digital when mp3 and flac are present
|
name: $(this)
|
||||||
for (var i = 0; i < formats.length; i++) {
|
.find('span:first')
|
||||||
for (var j = i + 1; j < formats.length; j++) {
|
.text()
|
||||||
if (formats[j].id.length > 1) {
|
};
|
||||||
if (formats[i].id[1] == formats[j].id[1]) {
|
});
|
||||||
// same prefix (ie. fragment-33123 and fragment-33123-1-2)
|
// remove "parent" formats : ie. digital when mp3 and flac are present
|
||||||
if (formats[i].id.length < formats[j].id.length) {
|
for (var i = 0; i < formats.length; i++) {
|
||||||
formats[i].toremove = true;
|
for (let j = i + 1; j < formats.length; j++) {
|
||||||
} else if (formats[i].id.length > formats[j].id.length) {
|
if (formats[j].id.length > 1) {
|
||||||
formats[j].toremove = true;
|
if (formats[i].id[1] == formats[j].id[1]) {
|
||||||
|
// same prefix (ie. fragment-33123 and fragment-33123-1-2)
|
||||||
|
if (formats[i].id.length < formats[j].id.length) {
|
||||||
|
formats[i].toremove = true;
|
||||||
|
} else if (formats[i].id.length > formats[j].id.length) {
|
||||||
|
formats[j].toremove = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
let cleanformats = [];
|
||||||
}
|
for (var i = 0; i < formats.length; i++) {
|
||||||
var cleanformats = [];
|
if (!formats[i].toremove) {
|
||||||
for (var i = 0; i < formats.length; i++) {
|
cleanformats.push({
|
||||||
if (!formats[i].toremove) {
|
id: formats[i].id.join('-'),
|
||||||
cleanformats.push({
|
name: formats[i].name
|
||||||
id: formats[i].id.join('-'),
|
});
|
||||||
name: formats[i].name
|
}
|
||||||
|
}
|
||||||
|
return cleanformats;
|
||||||
|
},
|
||||||
|
|
||||||
|
getTracks: function(id) {
|
||||||
|
// extract discs & tracks
|
||||||
|
let tracklists = `div#${id} div.tracklist table.tracklist-content`;
|
||||||
|
let discs = [];
|
||||||
|
$(tracklists).each(function() {
|
||||||
|
disc = $(this)
|
||||||
|
.find('tbody tr')
|
||||||
|
.map(function() {
|
||||||
|
// $(this) is used more than once; cache it for performance.
|
||||||
|
let row = $(this);
|
||||||
|
|
||||||
|
// For each row that's "mapped", return an object that
|
||||||
|
// describes the first and second <td> in the row.
|
||||||
|
let duration = row
|
||||||
|
.find('td.tracklist-content-length')
|
||||||
|
.text()
|
||||||
|
.replace('"', '')
|
||||||
|
.replace("' ", ':');
|
||||||
|
|
||||||
|
// drop track number prefix (A A2 C3 01 05 etc...)
|
||||||
|
let title = row
|
||||||
|
.find('td.tracklist-content-title')
|
||||||
|
.text()
|
||||||
|
.replace(/^[0-9A-F][0-9]* /, '');
|
||||||
|
return {
|
||||||
|
title: title,
|
||||||
|
duration: MBImport.hmsToMilliSeconds(duration)
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.get();
|
||||||
|
discs.push(disc);
|
||||||
});
|
});
|
||||||
}
|
return discs;
|
||||||
}
|
},
|
||||||
return cleanformats;
|
|
||||||
},
|
|
||||||
|
|
||||||
getTracks: function (id) {
|
getArtists: function() {
|
||||||
// extract discs & tracks
|
// get artists
|
||||||
var tracklists = 'div#' + id + ' div.tracklist table.tracklist-content';
|
let artists = $('div.infos-releasegrp div.list-artist a')
|
||||||
var discs = [];
|
.map(function() {
|
||||||
$(tracklists).each(function () {
|
return $(this).text();
|
||||||
disc = $(this).find('tbody tr').map(function () {
|
})
|
||||||
// $(this) is used more than once; cache it for performance.
|
.get();
|
||||||
var row = $(this);
|
return MBImport.makeArtistCredits(artists);
|
||||||
|
},
|
||||||
|
|
||||||
// For each row that's "mapped", return an object that
|
getAlbum: function() {
|
||||||
// describes the first and second <td> in the row.
|
// get release title
|
||||||
var duration = row.find('td.tracklist-content-length').text().replace('"', '').replace('\' ', ':')
|
return $('h1').text();
|
||||||
|
},
|
||||||
|
|
||||||
// drop track number prefix (A A2 C3 01 05 etc...)
|
fromCurrentTime: function(offset_in_seconds) {
|
||||||
var title = row.find('td.tracklist-content-title').text().replace(/^[0-9A-F][0-9]* /, '');
|
let millis = Date.now();
|
||||||
|
if (!isNaN(offset_in_seconds)) {
|
||||||
|
millis += offset_in_seconds * 1000;
|
||||||
|
}
|
||||||
|
let date = new Date(millis);
|
||||||
|
let dd = date.getDate();
|
||||||
|
let mm = date.getMonth() + 1; //January is 0!
|
||||||
|
let yyyy = date.getFullYear();
|
||||||
return {
|
return {
|
||||||
title: title,
|
year: yyyy,
|
||||||
duration: MBImport.hmsToMilliSeconds(duration)
|
month: mm,
|
||||||
|
day: dd
|
||||||
};
|
};
|
||||||
}).get();
|
},
|
||||||
discs.push(disc);
|
|
||||||
});
|
|
||||||
return discs;
|
|
||||||
},
|
|
||||||
|
|
||||||
getArtists: function () {
|
getReleaseDate: function() {
|
||||||
// get artists
|
// get release date and convert it to object
|
||||||
var artists = $('div.infos-releasegrp div.list-artist a').map(function () {
|
let text = $('div.infos-releasegrp div.row-date').text();
|
||||||
return $(this).text();
|
if (text == 'yesterday' || text == 'hier') {
|
||||||
}).get();
|
return this.fromCurrentTime(-24 * 60 * 60);
|
||||||
return MBImport.makeArtistCredits(artists);
|
}
|
||||||
},
|
if (text == 'today' || text == "aujourd'hui") {
|
||||||
|
return this.fromCurrentTime(0);
|
||||||
getAlbum: function () {
|
}
|
||||||
// get release title
|
let date = text
|
||||||
return $('h1').text();
|
.replace('janvier', '01')
|
||||||
},
|
.replace('février', '02')
|
||||||
|
.replace('mars', '03')
|
||||||
fromCurrentTime: function (offset_in_seconds) {
|
.replace('avril', '04')
|
||||||
var millis = Date.now();
|
.replace('mai', '05')
|
||||||
if (!isNaN(offset_in_seconds)) {
|
.replace('juin', '06')
|
||||||
millis += offset_in_seconds * 1000;
|
.replace('juillet', '07')
|
||||||
}
|
.replace('août', '08')
|
||||||
var date = new Date(millis);
|
.replace('septembre', '09')
|
||||||
var dd = date.getDate();
|
.replace('octobre', '10')
|
||||||
var mm = date.getMonth() + 1; //January is 0!
|
.replace('novembre', '11')
|
||||||
var yyyy = date.getFullYear();
|
.replace('décembre', '12')
|
||||||
return {
|
.replace('January', '01')
|
||||||
'year': yyyy,
|
.replace('February', '02')
|
||||||
'month': mm,
|
.replace('March', '03')
|
||||||
'day': dd
|
.replace('April', '04')
|
||||||
};
|
.replace('May', '05')
|
||||||
},
|
.replace('June', '06')
|
||||||
|
.replace('July', '07')
|
||||||
getReleaseDate: function () {
|
.replace('August', '08')
|
||||||
// get release date and convert it to object
|
.replace('September', '09')
|
||||||
var text = $('div.infos-releasegrp div.row-date').text();
|
.replace('October', '10')
|
||||||
if (text == 'yesterday' || text == 'hier') {
|
.replace('November', '11')
|
||||||
return this.fromCurrentTime(-24 * 60 * 60);
|
.replace('December', '12')
|
||||||
}
|
.split(' ');
|
||||||
if (text == 'today' || text == 'aujourd\'hui') {
|
|
||||||
return this.fromCurrentTime(0);
|
|
||||||
}
|
|
||||||
var date = text
|
|
||||||
.replace('janvier', '01')
|
|
||||||
.replace('février', '02')
|
|
||||||
.replace('mars', '03')
|
|
||||||
.replace('avril', '04')
|
|
||||||
.replace('mai', '05')
|
|
||||||
.replace('juin', '06')
|
|
||||||
.replace('juillet', '07')
|
|
||||||
.replace('août', '08')
|
|
||||||
.replace('septembre', '09')
|
|
||||||
.replace('octobre', '10')
|
|
||||||
.replace('novembre', '11')
|
|
||||||
.replace('décembre', '12')
|
|
||||||
.replace('January', '01')
|
|
||||||
.replace('February', '02')
|
|
||||||
.replace('March', '03')
|
|
||||||
.replace('April', '04')
|
|
||||||
.replace('May', '05')
|
|
||||||
.replace('June', '06')
|
|
||||||
.replace('July', '07')
|
|
||||||
.replace('August', '08')
|
|
||||||
.replace('September', '09')
|
|
||||||
.replace('October', '10')
|
|
||||||
.replace('November', '11')
|
|
||||||
.replace('December', '12')
|
|
||||||
.split(' ');
|
|
||||||
return {
|
|
||||||
'year': parseInt(date[2], 10),
|
|
||||||
'month': parseInt(date[1], 10),
|
|
||||||
'day': parseInt(date[0], 10)
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
currentURL: function () {
|
|
||||||
return window.location.href.replace(/\/[a-z]{2}\/album\//i, '/album/').split('#')[0];
|
|
||||||
},
|
|
||||||
|
|
||||||
retrieveReleaseInfo: function (format) {
|
|
||||||
// Analyze CD1D data and return a release object
|
|
||||||
var release = {
|
|
||||||
artist_credit: this.getArtists(),
|
|
||||||
title: this.getAlbum(),
|
|
||||||
country: "", // Worldwide
|
|
||||||
type: '',
|
|
||||||
status: 'official',
|
|
||||||
language: 'eng',
|
|
||||||
script: 'latn',
|
|
||||||
barcode: '',
|
|
||||||
urls: [],
|
|
||||||
discs: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
// Grab release event information
|
|
||||||
var releasedate = this.getReleaseDate();
|
|
||||||
release.year = releasedate.year;
|
|
||||||
release.month = releasedate.month;
|
|
||||||
release.day = releasedate.day;
|
|
||||||
|
|
||||||
var link_type = MBImport.URL_TYPES;
|
|
||||||
|
|
||||||
if (format.name.match(/vinyl|lp/i)) {
|
|
||||||
release.country = 'FR';
|
|
||||||
release.format = "Vinyl";
|
|
||||||
release.urls.push({
|
|
||||||
'url': this.currentURL(),
|
|
||||||
'link_type': link_type.purchase_for_mail_order
|
|
||||||
});
|
|
||||||
} else if (format.name.match(/cd/i)) {
|
|
||||||
release.country = 'FR';
|
|
||||||
release.format = 'CD';
|
|
||||||
release.urls.push({
|
|
||||||
'url': this.currentURL(),
|
|
||||||
'link_type': link_type.purchase_for_mail_order
|
|
||||||
});
|
|
||||||
} else if (format.name.match(/digital|mp3|flac|ogg|wav/i)) {
|
|
||||||
release.country = 'XW';
|
|
||||||
release.packaging = 'None';
|
|
||||||
release.format = "Digital Media";
|
|
||||||
release.urls.push({
|
|
||||||
'url': this.currentURL(),
|
|
||||||
'link_type': link_type.purchase_for_download
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
release.labels = $('div.infos-details div.row-structure').map(function () {
|
|
||||||
return {
|
return {
|
||||||
name: $(this).text(),
|
year: parseInt(date[2], 10),
|
||||||
mbid: '',
|
month: parseInt(date[1], 10),
|
||||||
catno: 'none'
|
day: parseInt(date[0], 10)
|
||||||
};
|
};
|
||||||
})
|
},
|
||||||
.get();
|
|
||||||
|
|
||||||
// Tracks
|
currentURL: function() {
|
||||||
$.each(this.getTracks(format.id), function (ndisc, disc) {
|
return window.location.href.replace(/\/[a-z]{2}\/album\//i, '/album/').split('#')[0];
|
||||||
var thisdisc = {
|
},
|
||||||
tracks: [],
|
|
||||||
format: release.format
|
retrieveReleaseInfo: function(format) {
|
||||||
};
|
// Analyze CD1D data and return a release object
|
||||||
release.discs.push(thisdisc);
|
let release = {
|
||||||
$.each(this, function (ntrack, track) {
|
artist_credit: this.getArtists(),
|
||||||
thisdisc.tracks.push({
|
title: this.getAlbum(),
|
||||||
'title': track.title,
|
country: '', // Worldwide
|
||||||
'duration': track.duration,
|
type: '',
|
||||||
'artist_credit': []
|
status: 'official',
|
||||||
|
language: 'eng',
|
||||||
|
script: 'latn',
|
||||||
|
barcode: '',
|
||||||
|
urls: [],
|
||||||
|
discs: []
|
||||||
|
};
|
||||||
|
|
||||||
|
// Grab release event information
|
||||||
|
let releasedate = this.getReleaseDate();
|
||||||
|
release.year = releasedate.year;
|
||||||
|
release.month = releasedate.month;
|
||||||
|
release.day = releasedate.day;
|
||||||
|
|
||||||
|
let link_type = MBImport.URL_TYPES;
|
||||||
|
|
||||||
|
if (format.name.match(/vinyl|lp/i)) {
|
||||||
|
release.country = 'FR';
|
||||||
|
release.format = 'Vinyl';
|
||||||
|
release.urls.push({
|
||||||
|
url: this.currentURL(),
|
||||||
|
link_type: link_type.purchase_for_mail_order
|
||||||
|
});
|
||||||
|
} else if (format.name.match(/cd/i)) {
|
||||||
|
release.country = 'FR';
|
||||||
|
release.format = 'CD';
|
||||||
|
release.urls.push({
|
||||||
|
url: this.currentURL(),
|
||||||
|
link_type: link_type.purchase_for_mail_order
|
||||||
|
});
|
||||||
|
} else if (format.name.match(/digital|mp3|flac|ogg|wav/i)) {
|
||||||
|
release.country = 'XW';
|
||||||
|
release.packaging = 'None';
|
||||||
|
release.format = 'Digital Media';
|
||||||
|
release.urls.push({
|
||||||
|
url: this.currentURL(),
|
||||||
|
link_type: link_type.purchase_for_download
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
release.labels = $('div.infos-details div.row-structure')
|
||||||
|
.map(function() {
|
||||||
|
return {
|
||||||
|
name: $(this).text(),
|
||||||
|
mbid: '',
|
||||||
|
catno: 'none'
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.get();
|
||||||
|
|
||||||
|
// Tracks
|
||||||
|
$.each(this.getTracks(format.id), function(ndisc, disc) {
|
||||||
|
let thisdisc = {
|
||||||
|
tracks: [],
|
||||||
|
format: release.format
|
||||||
|
};
|
||||||
|
release.discs.push(thisdisc);
|
||||||
|
$.each(this, function(ntrack, track) {
|
||||||
|
thisdisc.tracks.push({
|
||||||
|
title: track.title,
|
||||||
|
duration: track.duration,
|
||||||
|
artist_credit: []
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
LOGGER.info("Parsed release: ", format.name, release);
|
LOGGER.info('Parsed release: ', format.name, release);
|
||||||
return release;
|
return release;
|
||||||
},
|
},
|
||||||
|
|
||||||
insertLink: function (release, where, formatname) {
|
insertLink: function(release, where, formatname) {
|
||||||
// Insert links in page
|
// Insert links in page
|
||||||
|
|
||||||
// Form parameters
|
// Form parameters
|
||||||
var edit_note = MBImport.makeEditNote(this.currentURL(), 'CD1D', formatname);
|
let edit_note = MBImport.makeEditNote(this.currentURL(), 'CD1D', formatname);
|
||||||
var parameters = MBImport.buildFormParameters(release, edit_note);
|
let parameters = MBImport.buildFormParameters(release, edit_note);
|
||||||
|
|
||||||
// Build form
|
// Build form
|
||||||
var mbUI = $('<div id="mb_buttons">'
|
let mbUI = $(`<div id="mb_buttons">${MBImport.buildFormHTML(parameters)}${MBImport.buildSearchButton(release)}</div>`).hide();
|
||||||
+ MBImport.buildFormHTML(parameters)
|
$(where).append(mbUI);
|
||||||
+ MBImport.buildSearchButton(release)
|
$('#mb_buttons').css({ 'margin-top': '6px' });
|
||||||
+ '</div>').hide();
|
$('form.musicbrainz_import').css({ display: 'inline-block', 'margin-right': '5px' });
|
||||||
$(where).append(mbUI);
|
mbUI.slideDown();
|
||||||
$('#mb_buttons').css({'margin-top': '6px'});
|
}
|
||||||
$('form.musicbrainz_import').css({display: 'inline-block', 'margin-right': '5px'});
|
|
||||||
mbUI.slideDown();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function() {
|
||||||
MBImportStyle();
|
MBImportStyle();
|
||||||
/* CD1D uses same page with hidden tabs for all formats */
|
/* CD1D uses same page with hidden tabs for all formats */
|
||||||
var formats = CD1DImporter.getFormats();
|
let formats = CD1DImporter.getFormats();
|
||||||
//LOGGER.info('Formats:', formats);
|
//LOGGER.info('Formats:', formats);
|
||||||
|
|
||||||
for (var i = 0; i < formats.length; i++) {
|
for (let i = 0; i < formats.length; i++) {
|
||||||
var release = CD1DImporter.retrieveReleaseInfo(formats[i]);
|
let release = CD1DImporter.retrieveReleaseInfo(formats[i]);
|
||||||
CD1DImporter.insertLink(release, 'div#' + formats[i].id, formats[i].name);
|
CD1DImporter.insertLink(release, `div#${formats[i].id}`, formats[i].name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,157 +18,165 @@ this.$ = this.jQuery = jQuery.noConflict(true);
|
||||||
|
|
||||||
if (!unsafeWindow) unsafeWindow = window;
|
if (!unsafeWindow) unsafeWindow = window;
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function() {
|
||||||
MBImportStyle();
|
MBImportStyle();
|
||||||
var release_url = window.location.href.replace('/\?.*$/', '').replace(/#.*$/, '');
|
let release_url = window.location.href.replace('/?.*$/', '').replace(/#.*$/, '');
|
||||||
release_url = release_url.replace(/^(?:https?:\/\/)?(?:store\.)?(?:cdbaby\.com)\//, "http://store.cdbaby.com/");
|
release_url = release_url.replace(/^(?:https?:\/\/)?(?:store\.)?(?:cdbaby\.com)\//, 'http://store.cdbaby.com/');
|
||||||
|
|
||||||
var release;
|
let release;
|
||||||
var buttons = "";
|
let buttons = '';
|
||||||
$("div.album-page-buy-button-container a").each(function() {
|
$('div.album-page-buy-button-container a').each(function() {
|
||||||
var format = $(this).attr("title").trim();
|
let format = $(this)
|
||||||
release = retrieveReleaseInfo(release_url, format);
|
.attr('title')
|
||||||
buttons += getImportButton(release, release_url, format);
|
.trim();
|
||||||
});
|
release = retrieveReleaseInfo(release_url, format);
|
||||||
|
buttons += getImportButton(release, release_url, format);
|
||||||
if (release) {
|
});
|
||||||
insertImportLinks(release, buttons);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (release) {
|
||||||
|
insertImportLinks(release, buttons);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function retrieveReleaseInfo(release_url, format) {
|
function retrieveReleaseInfo(release_url, format) {
|
||||||
|
// Release defaults
|
||||||
// Release defaults
|
let release = {
|
||||||
var release = {
|
artist_credit: '',
|
||||||
artist_credit: '',
|
title: $("h1 span[itemprop='name']")
|
||||||
title: $("h1 span[itemprop='name']").text().trim(),
|
.text()
|
||||||
year: 0,
|
.trim(),
|
||||||
month: 0,
|
year: 0,
|
||||||
day: 0,
|
month: 0,
|
||||||
format: '',
|
day: 0,
|
||||||
packaging: '',
|
format: '',
|
||||||
country: '',
|
packaging: '',
|
||||||
status: 'official',
|
country: '',
|
||||||
language: 'eng',
|
status: 'official',
|
||||||
script: 'Latn',
|
language: 'eng',
|
||||||
type: '',
|
script: 'Latn',
|
||||||
urls: [],
|
type: '',
|
||||||
labels: [],
|
urls: [],
|
||||||
discs: [],
|
labels: [],
|
||||||
};
|
discs: []
|
||||||
|
|
||||||
var link_type = MBImport.URL_TYPES;
|
|
||||||
|
|
||||||
release.urls = [];
|
|
||||||
if (format.match(/^vinyl/i)) {
|
|
||||||
release.country = 'US';
|
|
||||||
release.format = "Vinyl";
|
|
||||||
release.urls.push({
|
|
||||||
'url': release_url,
|
|
||||||
'link_type': link_type.purchase_for_mail_order
|
|
||||||
});
|
|
||||||
} else if (format.match(/^cd/i)) {
|
|
||||||
release.country = 'US';
|
|
||||||
release.format = 'CD';
|
|
||||||
release.urls.push({
|
|
||||||
'url': release_url,
|
|
||||||
'link_type': link_type.purchase_for_mail_order
|
|
||||||
});
|
|
||||||
} else if (format.match(/^download/i)) {
|
|
||||||
release.country = 'XW';
|
|
||||||
release.packaging = 'None';
|
|
||||||
release.format = "Digital Media";
|
|
||||||
release.urls.push({
|
|
||||||
'url': release_url,
|
|
||||||
'link_type': link_type.purchase_for_download
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Release artist
|
|
||||||
var artist = $("h2 span[itemprop='byArtist'] a").text().trim();
|
|
||||||
var various_artists = (artist == 'Various');
|
|
||||||
if (various_artists) {
|
|
||||||
release.artist_credit = [ MBImport.specialArtist('various_artists') ];
|
|
||||||
} else {
|
|
||||||
release.artist_credit = MBImport.makeArtistCredits([artist]);
|
|
||||||
}
|
|
||||||
|
|
||||||
release.year = $("span[itemprop='datePublished']").text().trim()
|
|
||||||
|
|
||||||
// Tracks
|
|
||||||
var tracks = [];
|
|
||||||
var trackcount = 0
|
|
||||||
$("table.track-table tr[itemprop='track']").each(function() {
|
|
||||||
var artists = [];
|
|
||||||
var trackno = tracks.length + 1;
|
|
||||||
if (trackno == 1 && tracks.length) {
|
|
||||||
// multiple "discs"
|
|
||||||
release.discs.push( {
|
|
||||||
'tracks': tracks,
|
|
||||||
'format': release.format
|
|
||||||
} );
|
|
||||||
tracks = [];
|
|
||||||
}
|
|
||||||
var trackname = $(this).find("meta[itemprop='name']").attr('content').trim();
|
|
||||||
var tracklength = $(this).find("meta[itemprop='duration']").attr('content').trim();
|
|
||||||
|
|
||||||
var track_artists = [];
|
|
||||||
// FIXME various artists releases ...
|
|
||||||
$(this).find("div.track-artist").each(
|
|
||||||
function () {
|
|
||||||
var artistname = $(this).text().trim();
|
|
||||||
if (artistname) {
|
|
||||||
track_artists.push(artistname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
var ac = {
|
|
||||||
'artist_credit': '',
|
|
||||||
'title': trackname,
|
|
||||||
'duration': MBImport.ISO8601toMilliSeconds(tracklength)
|
|
||||||
};
|
};
|
||||||
if (!track_artists.length && various_artists) {
|
|
||||||
ac.artist_credit = [ MBImport.specialArtist('unknown') ];
|
let link_type = MBImport.URL_TYPES;
|
||||||
} else {
|
|
||||||
ac.artist_credit = MBImport.makeArtistCredits(track_artists);
|
release.urls = [];
|
||||||
|
if (format.match(/^vinyl/i)) {
|
||||||
|
release.country = 'US';
|
||||||
|
release.format = 'Vinyl';
|
||||||
|
release.urls.push({
|
||||||
|
url: release_url,
|
||||||
|
link_type: link_type.purchase_for_mail_order
|
||||||
|
});
|
||||||
|
} else if (format.match(/^cd/i)) {
|
||||||
|
release.country = 'US';
|
||||||
|
release.format = 'CD';
|
||||||
|
release.urls.push({
|
||||||
|
url: release_url,
|
||||||
|
link_type: link_type.purchase_for_mail_order
|
||||||
|
});
|
||||||
|
} else if (format.match(/^download/i)) {
|
||||||
|
release.country = 'XW';
|
||||||
|
release.packaging = 'None';
|
||||||
|
release.format = 'Digital Media';
|
||||||
|
release.urls.push({
|
||||||
|
url: release_url,
|
||||||
|
link_type: link_type.purchase_for_download
|
||||||
|
});
|
||||||
}
|
}
|
||||||
tracks.push(ac);
|
|
||||||
});
|
|
||||||
|
|
||||||
release.discs.push( {
|
// Release artist
|
||||||
'tracks': tracks,
|
let artist = $("h2 span[itemprop='byArtist'] a")
|
||||||
'format': release.format
|
.text()
|
||||||
} );
|
.trim();
|
||||||
|
let various_artists = artist == 'Various';
|
||||||
|
if (various_artists) {
|
||||||
|
release.artist_credit = [MBImport.specialArtist('various_artists')];
|
||||||
|
} else {
|
||||||
|
release.artist_credit = MBImport.makeArtistCredits([artist]);
|
||||||
|
}
|
||||||
|
|
||||||
LOGGER.info("Parsed release: ", release);
|
release.year = $("span[itemprop='datePublished']")
|
||||||
return release;
|
.text()
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
// Tracks
|
||||||
|
let tracks = [];
|
||||||
|
let trackcount = 0;
|
||||||
|
$("table.track-table tr[itemprop='track']").each(function() {
|
||||||
|
let artists = [];
|
||||||
|
let trackno = tracks.length + 1;
|
||||||
|
if (trackno == 1 && tracks.length) {
|
||||||
|
// multiple "discs"
|
||||||
|
release.discs.push({
|
||||||
|
tracks: tracks,
|
||||||
|
format: release.format
|
||||||
|
});
|
||||||
|
tracks = [];
|
||||||
|
}
|
||||||
|
let trackname = $(this)
|
||||||
|
.find("meta[itemprop='name']")
|
||||||
|
.attr('content')
|
||||||
|
.trim();
|
||||||
|
let tracklength = $(this)
|
||||||
|
.find("meta[itemprop='duration']")
|
||||||
|
.attr('content')
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
let track_artists = [];
|
||||||
|
// FIXME various artists releases ...
|
||||||
|
$(this)
|
||||||
|
.find('div.track-artist')
|
||||||
|
.each(function() {
|
||||||
|
let artistname = $(this)
|
||||||
|
.text()
|
||||||
|
.trim();
|
||||||
|
if (artistname) {
|
||||||
|
track_artists.push(artistname);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let ac = {
|
||||||
|
artist_credit: '',
|
||||||
|
title: trackname,
|
||||||
|
duration: MBImport.ISO8601toMilliSeconds(tracklength)
|
||||||
|
};
|
||||||
|
if (!track_artists.length && various_artists) {
|
||||||
|
ac.artist_credit = [MBImport.specialArtist('unknown')];
|
||||||
|
} else {
|
||||||
|
ac.artist_credit = MBImport.makeArtistCredits(track_artists);
|
||||||
|
}
|
||||||
|
tracks.push(ac);
|
||||||
|
});
|
||||||
|
|
||||||
|
release.discs.push({
|
||||||
|
tracks: tracks,
|
||||||
|
format: release.format
|
||||||
|
});
|
||||||
|
|
||||||
|
LOGGER.info('Parsed release: ', release);
|
||||||
|
return release;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getImportButton(release, release_url, format) {
|
function getImportButton(release, release_url, format) {
|
||||||
var edit_note = MBImport.makeEditNote(release_url, "CD Baby", format);
|
let edit_note = MBImport.makeEditNote(release_url, 'CD Baby', format);
|
||||||
var parameters = MBImport.buildFormParameters(release, edit_note);
|
let parameters = MBImport.buildFormParameters(release, edit_note);
|
||||||
return MBImport.buildFormHTML(parameters).replace('<span>Import into MB</span>', '<span>Import ' + format + '</span>');
|
return MBImport.buildFormHTML(parameters).replace('<span>Import into MB</span>', `<span>Import ${format}</span>`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertImportLinks(release, buttons) {
|
function insertImportLinks(release, buttons) {
|
||||||
$("div.right-container-top-right").prepend(
|
$('div.right-container-top-right').prepend($(`<div id="mb_buttons">${buttons}${MBImport.buildSearchButton(release)}</div>`).hide());
|
||||||
$('<div id="mb_buttons">'
|
$('#mb_buttons').css({
|
||||||
+ buttons
|
'margin-bottom': '5px',
|
||||||
+ MBImport.buildSearchButton(release)
|
padding: '2%',
|
||||||
+ '</div>').hide()
|
'background-color': '#fff'
|
||||||
);
|
});
|
||||||
$('#mb_buttons').css({
|
|
||||||
'margin-bottom': '5px',
|
|
||||||
'padding': '2%',
|
|
||||||
'background-color': '#fff'
|
|
||||||
});
|
|
||||||
|
|
||||||
$('form.musicbrainz_import').css({
|
$('form.musicbrainz_import').css({
|
||||||
'margin-bottom': '5px'
|
'margin-bottom': '5px'
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#mb_buttons').slideDown();
|
$('#mb_buttons').slideDown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,54 +1,59 @@
|
||||||
/* global $ MBImport */
|
/* global $ MBImport */
|
||||||
'use strict';
|
'use strict';
|
||||||
var meta = function() {
|
var meta = function() {
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Import DG/Decca releases to MusicBrainz
|
// @name Import DG/Decca releases to MusicBrainz
|
||||||
// @namespace https://github.com/murdos/musicbrainz-userscripts
|
// @namespace https://github.com/murdos/musicbrainz-userscripts
|
||||||
// @author loujine
|
// @author loujine
|
||||||
// @version 2018.2.18.1
|
// @version 2018.2.18.1
|
||||||
// @downloadURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/dgdecca_importer.user.js
|
// @downloadURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/dgdecca_importer.user.js
|
||||||
// @updateURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/dgdecca_importer.user.js
|
// @updateURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/dgdecca_importer.user.js
|
||||||
// @icon https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/assets/images/Musicbrainz_import_logo.png
|
// @icon https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/assets/images/Musicbrainz_import_logo.png
|
||||||
// @description Add a button to import DG/Decca releases to MusicBrainz
|
// @description Add a button to import DG/Decca releases to MusicBrainz
|
||||||
// @compatible firefox+greasemonkey
|
// @compatible firefox+greasemonkey
|
||||||
// @licence CC BY-NC-SA 3.0 (https://creativecommons.org/licenses/by-nc-sa/3.0/)
|
// @licence CC BY-NC-SA 3.0 (https://creativecommons.org/licenses/by-nc-sa/3.0/)
|
||||||
// @include http*://*deutschegrammophon.com/*/cat/*
|
// @include http*://*deutschegrammophon.com/*/cat/*
|
||||||
// @include http*://*deccaclassics.com/*/cat/*
|
// @include http*://*deccaclassics.com/*/cat/*
|
||||||
// @require lib/mbimport.js
|
// @require lib/mbimport.js
|
||||||
// @require lib/mbimportstyle.js
|
// @require lib/mbimportstyle.js
|
||||||
// @grant none
|
// @grant none
|
||||||
// @run-at document-end
|
// @run-at document-end
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
};
|
};
|
||||||
if (meta && meta.toString && (meta = meta.toString())) {
|
if (meta && meta.toString && (meta = meta.toString())) {
|
||||||
var meta = {'name': meta.match(/@name\s+(.+)/)[1],
|
var meta = { name: meta.match(/@name\s+(.+)/)[1], version: meta.match(/@version\s+(.+)/)[1] };
|
||||||
'version': meta.match(/@version\s+(.+)/)[1]};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var siteURL = document.URL.split('/')[2].replace('www.', '');
|
var siteURL = document.URL.split('/')[2].replace('www.', '');
|
||||||
|
|
||||||
var months = {
|
var months = {
|
||||||
'Jan.': 1, 'Feb.': 2, 'Mar.': 3, 'Apr.': 4,
|
'Jan.': 1,
|
||||||
'May': 5, 'Jun.': 6, 'Jul.': 7, 'Aug.': 8,
|
'Feb.': 2,
|
||||||
'Sep.': 9, 'Oct.': 10, 'Nov.': 11, 'Dec.': 12
|
'Mar.': 3,
|
||||||
|
'Apr.': 4,
|
||||||
|
May: 5,
|
||||||
|
'Jun.': 6,
|
||||||
|
'Jul.': 7,
|
||||||
|
'Aug.': 8,
|
||||||
|
'Sep.': 9,
|
||||||
|
'Oct.': 10,
|
||||||
|
'Nov.': 11,
|
||||||
|
'Dec.': 12
|
||||||
};
|
};
|
||||||
var labels = {
|
var labels = {
|
||||||
'deutschegrammophon.com': {
|
'deutschegrammophon.com': {
|
||||||
'name': 'Deutsche Grammophon',
|
name: 'Deutsche Grammophon',
|
||||||
'mbid': '5a584032-dcef-41bb-9f8b-19540116fb1c',
|
mbid: '5a584032-dcef-41bb-9f8b-19540116fb1c',
|
||||||
'catno': document.URL.split('/')[5]
|
catno: document.URL.split('/')[5]
|
||||||
},
|
},
|
||||||
'deccaclassics.com': {
|
'deccaclassics.com': {
|
||||||
'name': 'Decca Classics',
|
name: 'Decca Classics',
|
||||||
'mbid': '89a9993d-1dad-4445-a3d7-1d8df04f7e7b',
|
mbid: '89a9993d-1dad-4445-a3d7-1d8df04f7e7b',
|
||||||
'catno': document.URL.split('/')[5]
|
catno: document.URL.split('/')[5]
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
var editNote = ('Imported from '
|
var editNote = `Imported from ${document.URL}\n —\n` + `GM script: "${meta.name}" (${meta.version})\n\n`;
|
||||||
+ document.URL
|
|
||||||
+ '\n —\n'
|
|
||||||
+ 'GM script: "' + meta.name + '" (' + meta.version + ')\n\n');
|
|
||||||
|
|
||||||
function _clean(s) {
|
function _clean(s) {
|
||||||
return s
|
return s
|
||||||
|
@ -74,47 +79,52 @@ function _clean(s) {
|
||||||
.replace(' - ', ': ')
|
.replace(' - ', ': ')
|
||||||
.replace(' | ', ': ')
|
.replace(' | ', ': ')
|
||||||
.replace('K.', 'K. ') // Mozart
|
.replace('K.', 'K. ') // Mozart
|
||||||
.replace('S.', 'S. ') // Liszt
|
.replace('S.', 'S. '); // Liszt
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function extract_release_data() {
|
function extract_release_data() {
|
||||||
console.log('extract_release_data');
|
console.log('extract_release_data');
|
||||||
|
|
||||||
function _setTitle() {
|
function _setTitle() {
|
||||||
var title = $('h4')[0].textContent;
|
let title = $('h4')[0].textContent;
|
||||||
if ($('div.works').length) {
|
if ($('div.works').length) {
|
||||||
title += ' ' + $('div.works')[0].innerHTML.replace(/<br><br>/g, ' / ').replace(/<br>/g, ' ');
|
title += ` ${$('div.works')[0]
|
||||||
|
.innerHTML.replace(/<br><br>/g, ' / ')
|
||||||
|
.replace(/<br>/g, ' ')}`;
|
||||||
}
|
}
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
function _setReleasePerformers() {
|
function _setReleasePerformers() {
|
||||||
var list = $('div.artists')[0].innerHTML.split('<br>').map(function (artist) {
|
let list = $('div.artists')[0]
|
||||||
return {
|
.innerHTML.split('<br>')
|
||||||
'credited_name': artist,
|
.map(function(artist) {
|
||||||
'artist_name': artist,
|
return {
|
||||||
'artist_mbid': '',
|
credited_name: artist,
|
||||||
'joinphrase': ', '
|
artist_name: artist,
|
||||||
};
|
artist_mbid: '',
|
||||||
});
|
joinphrase: ', '
|
||||||
|
};
|
||||||
|
});
|
||||||
list[list.length - 1]['joinphrase'] = '';
|
list[list.length - 1]['joinphrase'] = '';
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _setReleaseArtists() {
|
function _setReleaseArtists() {
|
||||||
var composer = document.getElementsByTagName('h4')[0].textContent;
|
let composer = document.getElementsByTagName('h4')[0].textContent;
|
||||||
var list = [{
|
let list = [
|
||||||
'credited_name': composer,
|
{
|
||||||
'artist_name': composer,
|
credited_name: composer,
|
||||||
'artist_mbid': '',
|
artist_name: composer,
|
||||||
'joinphrase': '; '
|
artist_mbid: '',
|
||||||
}];
|
joinphrase: '; '
|
||||||
|
}
|
||||||
|
];
|
||||||
return list.concat(_setReleasePerformers());
|
return list.concat(_setReleasePerformers());
|
||||||
}
|
}
|
||||||
|
|
||||||
function _indices(array, element) {
|
function _indices(array, element) {
|
||||||
var indices = [];
|
let indices = [];
|
||||||
var idx = array.indexOf(element);
|
let idx = array.indexOf(element);
|
||||||
while (idx != -1) {
|
while (idx != -1) {
|
||||||
indices.push(idx);
|
indices.push(idx);
|
||||||
idx = array.indexOf(element, idx + 1);
|
idx = array.indexOf(element, idx + 1);
|
||||||
|
@ -122,14 +132,14 @@ function extract_release_data() {
|
||||||
return indices;
|
return indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
var date = document.getElementsByClassName('date')[0].textContent;
|
let date = document.getElementsByClassName('date')[0].textContent;
|
||||||
date = date.replace('Int. Release ', '').split(' ');
|
date = date.replace('Int. Release ', '').split(' ');
|
||||||
var nodes = [];
|
let nodes = [];
|
||||||
var tracklist_node = document.getElementById('tracklist');
|
let tracklist_node = document.getElementById('tracklist');
|
||||||
|
|
||||||
$('.item,.hier0,.hier1,.hier2,.hier3').each(function (idx, node) {
|
$('.item,.hier0,.hier1,.hier2,.hier3').each(function(idx, node) {
|
||||||
var idx;
|
var idx;
|
||||||
var d = {};
|
let d = {};
|
||||||
if (node.classList.contains('hier0')) {
|
if (node.classList.contains('hier0')) {
|
||||||
d['level'] = 0;
|
d['level'] = 0;
|
||||||
} else if (node.classList.contains('hier1')) {
|
} else if (node.classList.contains('hier1')) {
|
||||||
|
@ -155,9 +165,9 @@ function extract_release_data() {
|
||||||
console.log(nodes, tracklist_node);
|
console.log(nodes, tracklist_node);
|
||||||
|
|
||||||
// complete track titles
|
// complete track titles
|
||||||
var header0, header1, header2, idx;
|
let header0, header1, header2, idx;
|
||||||
nodes.forEach(function (node, idx) {
|
nodes.forEach(function(node, idx) {
|
||||||
var level = node['level'],
|
let level = node['level'],
|
||||||
type = node['type'],
|
type = node['type'],
|
||||||
content = node['title'];
|
content = node['title'];
|
||||||
if (type === 'work') {
|
if (type === 'work') {
|
||||||
|
@ -172,30 +182,30 @@ function extract_release_data() {
|
||||||
if (level === 0) {
|
if (level === 0) {
|
||||||
nodes[idx]['title'] = content;
|
nodes[idx]['title'] = content;
|
||||||
} else if (level === 1) {
|
} else if (level === 1) {
|
||||||
nodes[idx]['title'] = header0 + ': ' + content;
|
nodes[idx]['title'] = `${header0}: ${content}`;
|
||||||
} else if (level === 2) {
|
} else if (level === 2) {
|
||||||
nodes[idx]['title'] = header0 + ', ' + header1 + ': ' + content;
|
nodes[idx]['title'] = `${header0}, ${header1}: ${content}`;
|
||||||
} else if (level === 3) {
|
} else if (level === 3) {
|
||||||
nodes[idx]['title'] = header0 + ', ' + header1 + ', ' + header2 + ': ' + content;
|
nodes[idx]['title'] = `${header0}, ${header1}, ${header2}: ${content}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var discs = [],
|
let discs = [],
|
||||||
tracks = [],
|
tracks = [],
|
||||||
medium_title = '';
|
medium_title = '';
|
||||||
nodes.forEach(function (item, idx) {
|
nodes.forEach(function(item, idx) {
|
||||||
if (item.type === 'track') {
|
if (item.type === 'track') {
|
||||||
var track = extract_track_data(item.node);
|
let track = extract_track_data(item.node);
|
||||||
track.title = _clean(item.title);
|
track.title = _clean(item.title);
|
||||||
tracks.push(track);
|
tracks.push(track);
|
||||||
}
|
}
|
||||||
if (item.type === 'medium') {
|
if (item.type === 'medium') {
|
||||||
if (idx > 0) {
|
if (idx > 0) {
|
||||||
discs.push({
|
discs.push({
|
||||||
'title': '', // medium_title,
|
title: '', // medium_title,
|
||||||
'format': 'CD',
|
format: 'CD',
|
||||||
'tracks': tracks
|
tracks: tracks
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
medium_title = item.title;
|
medium_title = item.title;
|
||||||
|
@ -204,118 +214,118 @@ function extract_release_data() {
|
||||||
});
|
});
|
||||||
// push last medium
|
// push last medium
|
||||||
discs.push({
|
discs.push({
|
||||||
'title': '', // nodes[0].title,
|
title: '', // nodes[0].title,
|
||||||
'format': 'CD',
|
format: 'CD',
|
||||||
'tracks': tracks
|
tracks: tracks
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'title': _setTitle(),
|
title: _setTitle(),
|
||||||
'artist_credit': _setReleaseArtists(),
|
artist_credit: _setReleaseArtists(),
|
||||||
'type': 'Album',
|
type: 'Album',
|
||||||
'status': 'Official',
|
status: 'Official',
|
||||||
'language': 'eng', // 'English',
|
language: 'eng', // 'English',
|
||||||
'script': 'Latn', // 'Latin',
|
script: 'Latn', // 'Latin',
|
||||||
'packaging': '',
|
packaging: '',
|
||||||
'country': '',
|
country: '',
|
||||||
'year': date[2],
|
year: date[2],
|
||||||
'month': months[date[1]],
|
month: months[date[1]],
|
||||||
'day': date[0],
|
day: date[0],
|
||||||
'labels': [labels[siteURL]],
|
labels: [labels[siteURL]],
|
||||||
'barcode': document.getElementById('upc').value.replace('00', ''), // too many 0s
|
barcode: document.getElementById('upc').value.replace('00', ''), // too many 0s
|
||||||
'urls': [{
|
urls: [
|
||||||
'link_type': 288, // 'discography'
|
{
|
||||||
'url': document.URL
|
link_type: 288, // 'discography'
|
||||||
}],
|
url: document.URL
|
||||||
'discs': discs
|
}
|
||||||
|
],
|
||||||
|
discs: discs
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function extract_track_data(node) {
|
function extract_track_data(node) {
|
||||||
function _setTrackArtists(artistString) {
|
function _setTrackArtists(artistString) {
|
||||||
console.log('artistString', artistString);
|
console.log('artistString', artistString);
|
||||||
var artists;
|
let artists;
|
||||||
if (artistString.includes(' | ')) {
|
if (artistString.includes(' | ')) {
|
||||||
artists = artistString.split(' | ').map(function (artist) {
|
artists = artistString.split(' | ').map(function(artist) {
|
||||||
return {
|
return {
|
||||||
'credited_name': artist.split(',')[0],
|
credited_name: artist.split(',')[0],
|
||||||
'artist_name': artist.split(',')[0],
|
artist_name: artist.split(',')[0],
|
||||||
'artist_mbid': '',
|
artist_mbid: '',
|
||||||
'joinphrase': ', '
|
joinphrase: ', '
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
artists = artistString.split(', ').map(function (artist, idx) {
|
artists = artistString.split(', ').map(function(artist, idx) {
|
||||||
var mbid = '';
|
let mbid = '';
|
||||||
var url = '/ws/js/artist/?q=' + artist + '&fmt=json&limit=1';
|
let url = `/ws/js/artist/?q=${artist}&fmt=json&limit=1`;
|
||||||
return {
|
return {
|
||||||
'credited_name': artist,
|
credited_name: artist,
|
||||||
'artist_name': artist,
|
artist_name: artist,
|
||||||
'artist_mbid': mbid,
|
artist_mbid: mbid,
|
||||||
'joinphrase': ', '
|
joinphrase: ', '
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
artists[artists.length - 1]['joinphrase'] = '';
|
artists[artists.length - 1]['joinphrase'] = '';
|
||||||
return artists
|
return artists;
|
||||||
}
|
}
|
||||||
|
|
||||||
var schema = {};
|
let schema = {};
|
||||||
if (node.querySelectorAll('meta').length) {
|
if (node.querySelectorAll('meta').length) {
|
||||||
// https://schema.org/MusicRecording info available
|
// https://schema.org/MusicRecording info available
|
||||||
for (var item of node.querySelectorAll('meta')) {
|
for (let item of node.querySelectorAll('meta')) {
|
||||||
var attrs = item.attributes;
|
let attrs = item.attributes;
|
||||||
schema[attrs.itemprop.value] = attrs.content.value;
|
schema[attrs.itemprop.value] = attrs.content.value;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('no meta data on ', node);
|
console.log('no meta data on ', node);
|
||||||
schema.name = node.querySelectorAll('div.track-text > a.fancy')[0].textContent;
|
schema.name = node.querySelectorAll('div.track-text > a.fancy')[0].textContent;
|
||||||
schema.byArtist = $(node).parent().nextAll('div.container-container').children('.artists-container')[0].textContent;
|
schema.byArtist = $(node)
|
||||||
var previousComposers = $(node).parent().prevAll('div.container-container').children('.first-composer-container');
|
.parent()
|
||||||
schema.creator = previousComposers[previousComposers.length-1].textContent;
|
.nextAll('div.container-container')
|
||||||
|
.children('.artists-container')[0].textContent;
|
||||||
|
let previousComposers = $(node)
|
||||||
|
.parent()
|
||||||
|
.prevAll('div.container-container')
|
||||||
|
.children('.first-composer-container');
|
||||||
|
schema.creator = previousComposers[previousComposers.length - 1].textContent;
|
||||||
}
|
}
|
||||||
console.info('schema', schema);
|
console.info('schema', schema);
|
||||||
return {
|
return {
|
||||||
'number': parseInt(node.querySelectorAll('div.track-no')[0].textContent),
|
number: parseInt(node.querySelectorAll('div.track-no')[0].textContent),
|
||||||
'title': _clean(schema.name),
|
title: _clean(schema.name),
|
||||||
'duration': node.querySelectorAll('div.track-time')[0].textContent,
|
duration: node.querySelectorAll('div.track-time')[0].textContent,
|
||||||
'artist_credit': _setTrackArtists(schema.byArtist), // CSG
|
artist_credit: _setTrackArtists(schema.byArtist), // CSG
|
||||||
'performer': schema.byArtist,
|
performer: schema.byArtist,
|
||||||
'composer': schema.creator,
|
composer: schema.creator,
|
||||||
'url': node.querySelectorAll('div.track-text > a.fancy')[0].href
|
url: node.querySelectorAll('div.track-text > a.fancy')[0].href
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Insert links in page
|
// Insert links in page
|
||||||
function insertMBSection(release) {
|
function insertMBSection(release) {
|
||||||
var mbUI = $('<div class="section musicbrainz"><h3>MusicBrainz</h3></div>');
|
let mbUI = $('<div class="section musicbrainz"><h3>MusicBrainz</h3></div>');
|
||||||
var mbContentBlock = $('<div class="section_content"></div>');
|
let mbContentBlock = $('<div class="section_content"></div>');
|
||||||
mbUI.append(mbContentBlock);
|
mbUI.append(mbContentBlock);
|
||||||
|
|
||||||
// Form parameters
|
// Form parameters
|
||||||
var parameters = MBImport.buildFormParameters(release, editNote);
|
let parameters = MBImport.buildFormParameters(release, editNote);
|
||||||
|
|
||||||
// Build form + search button
|
// Build form + search button
|
||||||
var innerHTML = '<div id="mb_buttons">'
|
let innerHTML = `<div id="mb_buttons">${MBImport.buildFormHTML(parameters)}${MBImport.buildSearchButton(release)}</div>`;
|
||||||
+ MBImport.buildFormHTML(parameters)
|
|
||||||
+ MBImport.buildSearchButton(release)
|
|
||||||
+ '</div>';
|
|
||||||
mbContentBlock.append(innerHTML);
|
mbContentBlock.append(innerHTML);
|
||||||
|
|
||||||
$('div#product-text').append(mbUI[0]);
|
$('div#product-text').append(mbUI[0]);
|
||||||
|
|
||||||
$('#mb_buttons').css({
|
$('#mb_buttons').css({
|
||||||
display: 'inline-block',
|
display: 'inline-block',
|
||||||
width: '100%'
|
width: '100%'
|
||||||
});
|
});
|
||||||
$('form.musicbrainz_import').css({width: '49%', display: 'inline-block'});
|
$('form.musicbrainz_import').css({ width: '49%', display: 'inline-block' });
|
||||||
$('form.musicbrainz_import_search').css({'float': 'right'})
|
$('form.musicbrainz_import_search').css({ float: 'right' });
|
||||||
$('form.musicbrainz_import > button').css(
|
$('form.musicbrainz_import > button').css({ width: '100%', 'box-sizing': 'border-box' });
|
||||||
{width: '100%', 'box-sizing': 'border-box'}
|
|
||||||
);
|
|
||||||
|
|
||||||
mbUI.slideDown();
|
mbUI.slideDown();
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -21,7 +21,7 @@ $(document).ready(function() {
|
||||||
MBImportStyle();
|
MBImportStyle();
|
||||||
|
|
||||||
if (window.location.href.match(/encyclopedisque\.fr\/disque\/(\d+)/)) {
|
if (window.location.href.match(/encyclopedisque\.fr\/disque\/(\d+)/)) {
|
||||||
var release = parseEncyclopedisquePage();
|
let release = parseEncyclopedisquePage();
|
||||||
setupImportUI(release);
|
setupImportUI(release);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,57 +32,64 @@ $(document).ready(function() {
|
||||||
// Encyclopedisque functions
|
// Encyclopedisque functions
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
function setupImportUI(release) {
|
function setupImportUI(release) {
|
||||||
|
|
||||||
// Form parameters
|
// Form parameters
|
||||||
var edit_note = MBImport.makeEditNote(window.location.href, 'Encyclopedisque');
|
let edit_note = MBImport.makeEditNote(window.location.href, 'Encyclopedisque');
|
||||||
var parameters = MBImport.buildFormParameters(release, edit_note);
|
let parameters = MBImport.buildFormParameters(release, edit_note);
|
||||||
|
|
||||||
// Build form
|
// Build form
|
||||||
var mbUI = $(MBImport.buildFormHTML(parameters) + MBImport.buildSearchButton(release)).hide();
|
let mbUI = $(MBImport.buildFormHTML(parameters) + MBImport.buildSearchButton(release)).hide();
|
||||||
$('#recherchebox').append(mbUI);
|
$('#recherchebox').append(mbUI);
|
||||||
$('form.musicbrainz_import button').css({width: '100%'});
|
$('form.musicbrainz_import button').css({ width: '100%' });
|
||||||
mbUI.slideDown();
|
mbUI.slideDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertMBLinks() {
|
function insertMBLinks() {
|
||||||
|
let current_url = window.location.href;
|
||||||
var current_url = window.location.href;
|
|
||||||
if (current_url.match(/\/disque\//)) {
|
if (current_url.match(/\/disque\//)) {
|
||||||
mblinks.searchAndDisplayMbLink(current_url, 'release', function (link) { $('h2 span').before(link); } );
|
mblinks.searchAndDisplayMbLink(current_url, 'release', function(link) {
|
||||||
|
$('h2 span').before(link);
|
||||||
|
});
|
||||||
} else if (current_url.match(/\/artiste\//)) {
|
} else if (current_url.match(/\/artiste\//)) {
|
||||||
mblinks.searchAndDisplayMbLink(current_url, 'artist', function (link) { $('h2').prepend(link); } );
|
mblinks.searchAndDisplayMbLink(current_url, 'artist', function(link) {
|
||||||
|
$('h2').prepend(link);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$('div.v7P, div.v12P').find('a[href*="/disque/"]').each(function() {
|
$('div.v7P, div.v12P')
|
||||||
var $link = $(this);
|
.find('a[href*="/disque/"]')
|
||||||
var external_url = window.location.origin + $link.attr('href');
|
.each(function() {
|
||||||
mblinks.searchAndDisplayMbLink(external_url, 'release', function (link) { $link.after(link).after('<br />') } );
|
let $link = $(this);
|
||||||
});
|
let external_url = window.location.origin + $link.attr('href');
|
||||||
|
mblinks.searchAndDisplayMbLink(external_url, 'release', function(link) {
|
||||||
$('h2, div.main').find('a[href*="/artiste/"]').each(function() {
|
$link.after(link).after('<br />');
|
||||||
var $link = $(this);
|
});
|
||||||
var external_url = window.location.origin + $link.attr('href');
|
});
|
||||||
mblinks.searchAndDisplayMbLink(external_url, 'artist', function (link) { $link.before(link); } );
|
|
||||||
});
|
|
||||||
|
|
||||||
|
$('h2, div.main')
|
||||||
|
.find('a[href*="/artiste/"]')
|
||||||
|
.each(function() {
|
||||||
|
let $link = $(this);
|
||||||
|
let external_url = window.location.origin + $link.attr('href');
|
||||||
|
mblinks.searchAndDisplayMbLink(external_url, 'artist', function(link) {
|
||||||
|
$link.before(link);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Analyze Encyclopedisque data and prepare to release object
|
// Analyze Encyclopedisque data and prepare to release object
|
||||||
function parseEncyclopedisquePage() {
|
function parseEncyclopedisquePage() {
|
||||||
|
|
||||||
release = new Object();
|
release = new Object();
|
||||||
|
|
||||||
var infoHeader = document.body.querySelector("#contenu > h2:nth-of-type(1)");
|
let infoHeader = document.body.querySelector('#contenu > h2:nth-of-type(1)');
|
||||||
|
|
||||||
// Release artist credit
|
// Release artist credit
|
||||||
release.artist_credit = new Array();
|
release.artist_credit = new Array();
|
||||||
var artist_name = infoHeader.querySelector("div.floatright:nth-of-type(1)").textContent.trim();
|
let artist_name = infoHeader.querySelector('div.floatright:nth-of-type(1)').textContent.trim();
|
||||||
release.artist_credit.push( { 'artist_name': artist_name } );
|
release.artist_credit.push({ artist_name: artist_name });
|
||||||
|
|
||||||
// Release title
|
// Release title
|
||||||
release.title = infoHeader.querySelector("span:nth-of-type(1)").textContent.trim();
|
release.title = infoHeader.querySelector('span:nth-of-type(1)').textContent.trim();
|
||||||
|
|
||||||
// Default status is official, will change if "tirage promo" is found (see below)
|
// Default status is official, will change if "tirage promo" is found (see below)
|
||||||
release.status = 'official';
|
release.status = 'official';
|
||||||
|
@ -91,60 +98,83 @@ function parseEncyclopedisquePage() {
|
||||||
release.language = 'fra';
|
release.language = 'fra';
|
||||||
release.script = 'Latn';
|
release.script = 'Latn';
|
||||||
|
|
||||||
var disc = {'position': 1, 'tracks': [] };
|
let disc = { position: 1, tracks: [] };
|
||||||
release.discs = [ disc ];
|
release.discs = [disc];
|
||||||
|
|
||||||
// Release URL
|
// Release URL
|
||||||
release.urls = new Array();
|
release.urls = new Array();
|
||||||
release.urls.push( { 'url': window.location.href, 'link_type': MBImport.URL_TYPES.other_databases } );
|
release.urls.push({ url: window.location.href, link_type: MBImport.URL_TYPES.other_databases });
|
||||||
|
|
||||||
// Parse other infos
|
// Parse other infos
|
||||||
var releaseInfos = document.body.querySelectorAll("div.main tr");
|
let releaseInfos = document.body.querySelectorAll('div.main tr');
|
||||||
var lastVinylFace = '';
|
let lastVinylFace = '';
|
||||||
var lastInfoType;
|
let lastInfoType;
|
||||||
for (var i = 0; i < releaseInfos.length; i++) {
|
for (let i = 0; i < releaseInfos.length; i++) {
|
||||||
var infoType = releaseInfos[i].querySelector("td:nth-of-type(1)").textContent.trim();
|
let infoType = releaseInfos[i].querySelector('td:nth-of-type(1)').textContent.trim();
|
||||||
|
|
||||||
// Release date
|
// Release date
|
||||||
if (infoType == "Sortie :") {
|
if (infoType == 'Sortie :') {
|
||||||
var infoValue = releaseInfos[i].querySelector("td:nth-of-type(2)").textContent.trim();
|
var infoValue = releaseInfos[i].querySelector('td:nth-of-type(2)').textContent.trim();
|
||||||
var re = /\s*(janvier|février|mars|avril|mai|juin|juillet|août|septembre|octobre|novembre|décembre)?\s*([\d\?]{4})?\s*(?:chez)?\s*((?:\S+\s?)*)\s*\(?([^\)]*)?\)?/;
|
let re = /\s*(janvier|février|mars|avril|mai|juin|juillet|août|septembre|octobre|novembre|décembre)?\s*([\d\?]{4})?\s*(?:chez)?\s*((?:\S+\s?)*)\s*\(?([^\)]*)?\)?/;
|
||||||
m = infoValue.match(re);
|
m = infoValue.match(re);
|
||||||
month = m[1];
|
month = m[1];
|
||||||
if (month != undefined) {
|
if (month != undefined) {
|
||||||
switch (month)
|
switch (month) {
|
||||||
{
|
case 'janvier':
|
||||||
case "janvier": release.month = 1; break;
|
release.month = 1;
|
||||||
case "février": release.month = 2; break;
|
break;
|
||||||
case "mars": release.month = 3; break;
|
case 'février':
|
||||||
case "avril": release.month = 4; break;
|
release.month = 2;
|
||||||
case "mai": release.month = 5; break;
|
break;
|
||||||
case "juin": release.month = 6; break;
|
case 'mars':
|
||||||
case "juillet": release.month = 7; break;
|
release.month = 3;
|
||||||
case "août": release.month = 8; break;
|
break;
|
||||||
case "septembre": release.month = 9; break;
|
case 'avril':
|
||||||
case "octobre": release.month = 10; break;
|
release.month = 4;
|
||||||
case "novembre": release.month = 11; break;
|
break;
|
||||||
case "décembre": release.month = 12; break;
|
case 'mai':
|
||||||
|
release.month = 5;
|
||||||
|
break;
|
||||||
|
case 'juin':
|
||||||
|
release.month = 6;
|
||||||
|
break;
|
||||||
|
case 'juillet':
|
||||||
|
release.month = 7;
|
||||||
|
break;
|
||||||
|
case 'août':
|
||||||
|
release.month = 8;
|
||||||
|
break;
|
||||||
|
case 'septembre':
|
||||||
|
release.month = 9;
|
||||||
|
break;
|
||||||
|
case 'octobre':
|
||||||
|
release.month = 10;
|
||||||
|
break;
|
||||||
|
case 'novembre':
|
||||||
|
release.month = 11;
|
||||||
|
break;
|
||||||
|
case 'décembre':
|
||||||
|
release.month = 12;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
release.year = m[2];
|
release.year = m[2];
|
||||||
release.labels = [];
|
release.labels = [];
|
||||||
var labels = m[3];
|
let labels = m[3];
|
||||||
if (labels != undefined) {
|
if (labels != undefined) {
|
||||||
$.each(labels.split("/"), function(index, label) {
|
$.each(labels.split('/'), function(index, label) {
|
||||||
release.labels.push({ 'name': label.trim(), 'catno': m[4] });
|
release.labels.push({ name: label.trim(), catno: m[4] });
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
release.labels.push({ 'catno': m[4] });
|
release.labels.push({ catno: m[4] });
|
||||||
}
|
}
|
||||||
} else if (infoType.match(/^Face [A-Z]/) || (infoType == '' && lastInfoType.match(/^Face [A-Z]/))) {
|
} else if (infoType.match(/^Face [A-Z]/) || (infoType == '' && lastInfoType.match(/^Face [A-Z]/))) {
|
||||||
// Tracks
|
// Tracks
|
||||||
var track = new Object();
|
let track = new Object();
|
||||||
|
|
||||||
// First part of tracknumber (A, B, ...)
|
// First part of tracknumber (A, B, ...)
|
||||||
var tnum_part1 = '';
|
let tnum_part1 = '';
|
||||||
if (m = infoType.match(/^Face ([A-Z])/)) {
|
if ((m = infoType.match(/^Face ([A-Z])/))) {
|
||||||
lastVinylFace = m[1];
|
lastVinylFace = m[1];
|
||||||
tnum_part1 = m[1];
|
tnum_part1 = m[1];
|
||||||
} else {
|
} else {
|
||||||
|
@ -152,43 +182,60 @@ function parseEncyclopedisquePage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track title
|
// Track title
|
||||||
if (releaseInfos[i].querySelector("td:nth-of-type(2) em") == null) {
|
if (releaseInfos[i].querySelector('td:nth-of-type(2) em') == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var title = releaseInfos[i].querySelector("td:nth-of-type(2) em").textContent.trim();
|
let title = releaseInfos[i].querySelector('td:nth-of-type(2) em').textContent.trim();
|
||||||
|
|
||||||
// 2nd part of tracknumber (1, 2, ...)
|
// 2nd part of tracknumber (1, 2, ...)
|
||||||
var tnum_part2 = '';
|
let tnum_part2 = '';
|
||||||
if (m = infoType.match(/^Face [A-Z](\d+)/)) {
|
if ((m = infoType.match(/^Face [A-Z](\d+)/))) {
|
||||||
tnum_part2 = m[1];
|
tnum_part2 = m[1];
|
||||||
} else if (m = title.match(/^(\d+)\.\s+(.*)$/)) {
|
} else if ((m = title.match(/^(\d+)\.\s+(.*)$/))) {
|
||||||
tnum_part2 = m[1];
|
tnum_part2 = m[1];
|
||||||
title = m[2];
|
title = m[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track length
|
// Track length
|
||||||
if (m = releaseInfos[i].querySelector("td:nth-of-type(2)").textContent.trim().match(/- (\d+)’(\d+)$/)) {
|
if (
|
||||||
track.duration = m[1] + ':' + m[2];
|
(m = releaseInfos[i]
|
||||||
|
.querySelector('td:nth-of-type(2)')
|
||||||
|
.textContent.trim()
|
||||||
|
.match(/- (\d+)’(\d+)$/))
|
||||||
|
) {
|
||||||
|
track.duration = `${m[1]}:${m[2]}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
track.number = tnum_part1 + tnum_part2;
|
track.number = tnum_part1 + tnum_part2;
|
||||||
track.title = title;
|
track.title = title;
|
||||||
disc.tracks.push(track);
|
disc.tracks.push(track);
|
||||||
} else if (infoType == "Format :") {
|
} else if (infoType == 'Format :') {
|
||||||
// Format => medium format, release-group type, release status
|
// Format => medium format, release-group type, release status
|
||||||
var infoValue = releaseInfos[i].querySelector("td:nth-of-type(2)").textContent.trim();
|
var infoValue = releaseInfos[i].querySelector('td:nth-of-type(2)').textContent.trim();
|
||||||
var values = infoValue.split(" / ");
|
let values = infoValue.split(' / ');
|
||||||
values.forEach(function(value) {
|
values.forEach(function(value) {
|
||||||
if (value.indexOf('45 tours') > -1) { disc.format = '7" Vinyl'; }
|
if (value.indexOf('45 tours') > -1) {
|
||||||
if (value.indexOf('33 tours') > -1) { disc.format = '12" Vinyl'; }
|
disc.format = '7" Vinyl';
|
||||||
if (value.indexOf('LP') > -1) { release.type = 'album'; }
|
}
|
||||||
if (value.indexOf('EP') > -1) { release.type = 'ep'; }
|
if (value.indexOf('33 tours') > -1) {
|
||||||
if (value.indexOf('SP') > -1) { release.type = 'single'; }
|
disc.format = '12" Vinyl';
|
||||||
if (value.indexOf('tirage promo') > -1) { release.status = 'promotion'; }
|
}
|
||||||
|
if (value.indexOf('LP') > -1) {
|
||||||
|
release.type = 'album';
|
||||||
|
}
|
||||||
|
if (value.indexOf('EP') > -1) {
|
||||||
|
release.type = 'ep';
|
||||||
|
}
|
||||||
|
if (value.indexOf('SP') > -1) {
|
||||||
|
release.type = 'single';
|
||||||
|
}
|
||||||
|
if (value.indexOf('tirage promo') > -1) {
|
||||||
|
release.status = 'promotion';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else if (infoType == "Pays :") {
|
} else if (infoType == 'Pays :') {
|
||||||
// Country
|
// Country
|
||||||
var infoValue = releaseInfos[i].querySelector("td:nth-of-type(2)").textContent.trim();
|
var infoValue = releaseInfos[i].querySelector('td:nth-of-type(2)').textContent.trim();
|
||||||
if (infoValue == 'France') {
|
if (infoValue == 'France') {
|
||||||
release.country = 'FR';
|
release.country = 'FR';
|
||||||
} else if (infoValue == 'Royaume-uni') {
|
} else if (infoValue == 'Royaume-uni') {
|
||||||
|
@ -211,7 +258,7 @@ function parseEncyclopedisquePage() {
|
||||||
release.no_barcode = '1';
|
release.no_barcode = '1';
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.info("Parsed release: ", release);
|
LOGGER.info('Parsed release: ', release);
|
||||||
|
|
||||||
return release;
|
return release;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ var MBID_REGEX = /[0-9a-z]{8}\-[0-9a-z]{4}\-[0-9a-z]{4}\-[0-9a-z]{4}\-[0-9a-z]{1
|
||||||
|
|
||||||
var releasesOrReleaseGroups = document.querySelectorAll("#content table.tbl > tbody > tr > td a[href^='/release']");
|
var releasesOrReleaseGroups = document.querySelectorAll("#content table.tbl > tbody > tr > td a[href^='/release']");
|
||||||
for (var r = 0; r < releasesOrReleaseGroups.length; r++) {
|
for (var r = 0; r < releasesOrReleaseGroups.length; r++) {
|
||||||
if (releasesOrReleaseGroups[r].getAttribute("href").match(/\/release-group\//)) {
|
if (releasesOrReleaseGroups[r].getAttribute('href').match(/\/release-group\//)) {
|
||||||
inject_release_group_button(releasesOrReleaseGroups[r].parentNode);
|
inject_release_group_button(releasesOrReleaseGroups[r].parentNode);
|
||||||
} else {
|
} else {
|
||||||
inject_release_button(releasesOrReleaseGroups[r].parentNode);
|
inject_release_button(releasesOrReleaseGroups[r].parentNode);
|
||||||
|
@ -49,23 +49,24 @@ for (var r = 0; r < releasesOrReleaseGroups.length; r++) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function inject_release_group_button(parent) {
|
function inject_release_group_button(parent) {
|
||||||
var mbid = parent.querySelector("a").href.match(MBID_REGEX),
|
let mbid = parent.querySelector('a').href.match(MBID_REGEX),
|
||||||
table = document.createElement("table");
|
table = document.createElement('table');
|
||||||
|
|
||||||
table.style.marginTop = "1em";
|
table.style.marginTop = '1em';
|
||||||
table.style.marginLeft = "1em";
|
table.style.marginLeft = '1em';
|
||||||
table.style.paddingLeft = "1em";
|
table.style.paddingLeft = '1em';
|
||||||
|
|
||||||
var button = create_button(
|
let button = create_button(
|
||||||
"/ws/2/release?release-group=" + mbid + "&limit=100&inc=media&fmt=json",
|
`/ws/2/release?release-group=${mbid}&limit=100&inc=media&fmt=json`,
|
||||||
function(toggled) {
|
function(toggled) {
|
||||||
if (toggled) parent.appendChild(table); else parent.removeChild(table);
|
if (toggled) parent.appendChild(table);
|
||||||
|
else parent.removeChild(table);
|
||||||
},
|
},
|
||||||
function(json) {
|
function(json) {
|
||||||
parse_release_group(json, mbid, parent, table);
|
parse_release_group(json, mbid, parent, table);
|
||||||
},
|
},
|
||||||
function(status) {
|
function(status) {
|
||||||
table.innerHTML = '<tr><td style="color: #f00;">Error loading release group (HTTP status ' + status + ')</td></tr>';
|
table.innerHTML = `<tr><td style="color: #f00;">Error loading release group (HTTP status ${status})</td></tr>`;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -73,23 +74,24 @@ function inject_release_group_button(parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function inject_release_button(parent, _table_parent, _table, _mbid) {
|
function inject_release_button(parent, _table_parent, _table, _mbid) {
|
||||||
var mbid = _mbid || parent.querySelector("a").href.match(MBID_REGEX),
|
let mbid = _mbid || parent.querySelector('a').href.match(MBID_REGEX),
|
||||||
table = _table || document.createElement("table");
|
table = _table || document.createElement('table');
|
||||||
|
|
||||||
table.style.marginTop = "1em";
|
table.style.marginTop = '1em';
|
||||||
table.style.marginLeft = "1em";
|
table.style.marginLeft = '1em';
|
||||||
table.style.paddingLeft = "1em";
|
table.style.paddingLeft = '1em';
|
||||||
|
|
||||||
var button = create_button(
|
let button = create_button(
|
||||||
"/ws/2/release/" + mbid + "?inc=media+recordings+artist-credits&fmt=json",
|
`/ws/2/release/${mbid}?inc=media+recordings+artist-credits&fmt=json`,
|
||||||
function(toggled) {
|
function(toggled) {
|
||||||
if (toggled) parent.appendChild(table); else parent.removeChild(table);
|
if (toggled) parent.appendChild(table);
|
||||||
|
else parent.removeChild(table);
|
||||||
},
|
},
|
||||||
function(json) {
|
function(json) {
|
||||||
parse_release(json, table);
|
parse_release(json, table);
|
||||||
},
|
},
|
||||||
function(status) {
|
function(status) {
|
||||||
table.innerHTML = '<tr><td style="color: #f00;">Error loading release (HTTP status ' + status + ')</td></tr>';
|
table.innerHTML = `<tr><td style="color: #f00;">Error loading release (HTTP status ${status})</td></tr>`;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -97,76 +99,92 @@ function inject_release_button(parent, _table_parent, _table, _mbid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_button(url, dom_callback, success_callback, error_callback) {
|
function create_button(url, dom_callback, success_callback, error_callback) {
|
||||||
var button = document.createElement("span"), toggled = false;
|
let button = document.createElement('span'),
|
||||||
|
toggled = false;
|
||||||
|
|
||||||
button.innerHTML = "▶";
|
button.innerHTML = '▶';
|
||||||
button.style.cursor = "pointer";
|
button.style.cursor = 'pointer';
|
||||||
button.style.marginRight = "4px";
|
button.style.marginRight = '4px';
|
||||||
button.style.color = "#777";
|
button.style.color = '#777';
|
||||||
|
|
||||||
button.addEventListener("mousedown", function() {
|
button.addEventListener(
|
||||||
toggled = !toggled;
|
'mousedown',
|
||||||
if (toggled)
|
function() {
|
||||||
button.innerHTML = "▼";
|
toggled = !toggled;
|
||||||
else button.innerHTML = "▶";
|
if (toggled) button.innerHTML = '▼';
|
||||||
dom_callback(toggled);
|
else button.innerHTML = '▶';
|
||||||
}, false);
|
dom_callback(toggled);
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
button.addEventListener("mousedown", function() {
|
button.addEventListener(
|
||||||
var this_event = arguments.callee;
|
'mousedown',
|
||||||
button.removeEventListener("mousedown", this_event, false);
|
function() {
|
||||||
var req = new XMLHttpRequest();
|
let this_event = arguments.callee;
|
||||||
|
button.removeEventListener('mousedown', this_event, false);
|
||||||
|
let req = new XMLHttpRequest();
|
||||||
|
|
||||||
req.onreadystatechange = function() {
|
req.onreadystatechange = function() {
|
||||||
if (req.readyState != 4) return;
|
if (req.readyState != 4) return;
|
||||||
|
|
||||||
if (req.status == 200 && req.responseText) {
|
if (req.status == 200 && req.responseText) {
|
||||||
success_callback(JSON.parse(req.responseText));
|
success_callback(JSON.parse(req.responseText));
|
||||||
} else {
|
} else {
|
||||||
button.addEventListener("mousedown", function() {
|
button.addEventListener(
|
||||||
button.removeEventListener("mousedown", arguments.callee, false);
|
'mousedown',
|
||||||
button.addEventListener("mousedown", this_event, false);
|
function() {
|
||||||
}, false);
|
button.removeEventListener('mousedown', arguments.callee, false);
|
||||||
error_callback(req.status);
|
button.addEventListener('mousedown', this_event, false);
|
||||||
}
|
},
|
||||||
};
|
false
|
||||||
|
);
|
||||||
|
error_callback(req.status);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
req.open("GET", url, true);
|
req.open('GET', url, true);
|
||||||
req.send(null);
|
req.send(null);
|
||||||
|
},
|
||||||
}, false);
|
false
|
||||||
|
);
|
||||||
|
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
function format_time(ms) {
|
function format_time(ms) {
|
||||||
var ts = ms / 1000, s = Math.round(ts % 60);
|
let ts = ms / 1000,
|
||||||
return (Math.floor(ts / 60) + ":" + (s >= 10 ? s : "0" + s));
|
s = Math.round(ts % 60);
|
||||||
|
return `${Math.floor(ts / 60)}:${s >= 10 ? s : `0${s}`}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_release_group(json, mbid, parent, table) {
|
function parse_release_group(json, mbid, parent, table) {
|
||||||
var releases = json.releases;
|
let releases = json.releases;
|
||||||
table.innerHTML = "";
|
table.innerHTML = '';
|
||||||
|
|
||||||
for (var i = 0; i < releases.length; i++) {
|
for (var i = 0; i < releases.length; i++) {
|
||||||
var release = releases[i], media = {}, tracks = [], formats = [];
|
let release = releases[i],
|
||||||
|
media = {},
|
||||||
|
tracks = [],
|
||||||
|
formats = [];
|
||||||
|
|
||||||
for (var j = 0; j < release.media.length; j++) {
|
for (let j = 0; j < release.media.length; j++) {
|
||||||
var medium = release.media[j], format = medium.format, count = medium["track-count"];
|
var medium = release.media[j],
|
||||||
if (format)
|
format = medium.format,
|
||||||
format in media ? (media[format] += 1) : (media[format] = 1);
|
count = medium['track-count'];
|
||||||
|
if (format) format in media ? (media[format] += 1) : (media[format] = 1);
|
||||||
tracks.push(count);
|
tracks.push(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (format in media) {
|
for (format in media) {
|
||||||
var count = media[format], txt;
|
var count = media[format],
|
||||||
if (count > 1)
|
txt;
|
||||||
formats.push(count.toString() + "×" + format);
|
if (count > 1) formats.push(`${count.toString()}×${format}`);
|
||||||
else formats.push(format);
|
else formats.push(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
release.tracks = tracks.join(" + ");
|
release.tracks = tracks.join(' + ');
|
||||||
release.formats = formats.join(" + ");
|
release.formats = formats.join(' + ');
|
||||||
}
|
}
|
||||||
|
|
||||||
releases.sort(function(a, b) {
|
releases.sort(function(a, b) {
|
||||||
|
@ -175,82 +193,77 @@ function parse_release_group(json, mbid, parent, table) {
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
for (var i = 0; i < releases.length; i++) {(function(release) {
|
for (var i = 0; i < releases.length; i++) {
|
||||||
var track_tr = document.createElement("tr"),
|
(function(release) {
|
||||||
track_td = document.createElement("td"),
|
let track_tr = document.createElement('tr'),
|
||||||
track_table = document.createElement("table"),
|
track_td = document.createElement('td'),
|
||||||
format_td = document.createElement("td"),
|
track_table = document.createElement('table'),
|
||||||
tr = document.createElement("tr"),
|
format_td = document.createElement('td'),
|
||||||
td = document.createElement("td"),
|
tr = document.createElement('tr'),
|
||||||
a = createLink("/release/" + release.id, release.title);
|
td = document.createElement('td'),
|
||||||
|
a = createLink(`/release/${release.id}`, release.title);
|
||||||
|
|
||||||
track_td.colSpan = 6;
|
track_td.colSpan = 6;
|
||||||
track_table.style.width = "100%";
|
track_table.style.width = '100%';
|
||||||
track_table.style.marginLeft = "1em";
|
track_table.style.marginLeft = '1em';
|
||||||
track_tr.appendChild(track_td);
|
track_tr.appendChild(track_td);
|
||||||
inject_release_button(td, track_td, track_table, release.id);
|
inject_release_button(td, track_td, track_table, release.id);
|
||||||
td.appendChild(a);
|
td.appendChild(a);
|
||||||
if (release.disambiguation) {
|
if (release.disambiguation) {
|
||||||
td.appendChild(document.createTextNode(" (" + release.disambiguation + ")"));
|
td.appendChild(document.createTextNode(` (${release.disambiguation})`));
|
||||||
}
|
}
|
||||||
tr.appendChild(td);
|
tr.appendChild(td);
|
||||||
format_td.innerHTML = release.formats;
|
format_td.innerHTML = release.formats;
|
||||||
tr.appendChild(format_td);
|
tr.appendChild(format_td);
|
||||||
|
|
||||||
var columns = [
|
let columns = [release.tracks, release.date || '', release.country || '', release.status || ''];
|
||||||
release.tracks,
|
|
||||||
release.date || "",
|
|
||||||
release.country || "",
|
|
||||||
release.status || ""
|
|
||||||
];
|
|
||||||
|
|
||||||
for (var i = 0; i < columns.length; i++)
|
for (let i = 0; i < columns.length; i++) tr.appendChild(createElement('td', columns[i]));
|
||||||
tr.appendChild(createElement("td", columns[i]));
|
|
||||||
|
|
||||||
table.appendChild(tr);
|
table.appendChild(tr);
|
||||||
table.appendChild(track_tr);
|
table.appendChild(track_tr);
|
||||||
|
})(releases[i]);
|
||||||
|
}
|
||||||
|
|
||||||
})(releases[i]);}
|
let bottom_tr = document.createElement('tr'),
|
||||||
|
bottom_td = document.createElement('td');
|
||||||
var bottom_tr = document.createElement("tr"),
|
|
||||||
bottom_td = document.createElement("td");
|
|
||||||
|
|
||||||
bottom_td.colSpan = 6;
|
bottom_td.colSpan = 6;
|
||||||
bottom_td.style.padding = "1em";
|
bottom_td.style.padding = '1em';
|
||||||
|
|
||||||
bottom_td.appendChild(createLink("/release-group/" + mbid + "/edit", "edit"));
|
bottom_td.appendChild(createLink(`/release-group/${mbid}/edit`, 'edit'));
|
||||||
bottom_td.appendChild(document.createTextNode(" | "));
|
bottom_td.appendChild(document.createTextNode(' | '));
|
||||||
bottom_td.appendChild(createLink("/release/add?release-group=" + mbid, "add release"));
|
bottom_td.appendChild(createLink(`/release/add?release-group=${mbid}`, 'add release'));
|
||||||
bottom_td.appendChild(document.createTextNode(" | "));
|
bottom_td.appendChild(document.createTextNode(' | '));
|
||||||
bottom_td.appendChild(createLink("/release-group/" + mbid + "/edits", "editing history"));
|
bottom_td.appendChild(createLink(`/release-group/${mbid}/edits`, 'editing history'));
|
||||||
|
|
||||||
bottom_tr.appendChild(bottom_td);
|
bottom_tr.appendChild(bottom_td);
|
||||||
table.appendChild(bottom_tr);
|
table.appendChild(bottom_tr);
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_release(json, table) {
|
function parse_release(json, table) {
|
||||||
var media = json.media;
|
let media = json.media;
|
||||||
table.innerHTML = "";
|
table.innerHTML = '';
|
||||||
|
|
||||||
for (var i = 0; i < media.length; i++) {
|
for (let i = 0; i < media.length; i++) {
|
||||||
var medium = media[i],
|
let medium = media[i],
|
||||||
format = medium.format ? medium.format + " " + (i + 1) : "Medium " + (i + 1);
|
format = medium.format ? `${medium.format} ${i + 1}` : `Medium ${i + 1}`;
|
||||||
|
|
||||||
table.innerHTML += '<tr class="subh"><td colspan="4">' + format + "</td></tr>";
|
table.innerHTML += `<tr class="subh"><td colspan="4">${format}</td></tr>`;
|
||||||
|
|
||||||
for (var j = 0; j < medium.tracks.length; j++) {
|
for (let j = 0; j < medium.tracks.length; j++) {
|
||||||
var track = medium.tracks[j], recording = track.recording,
|
let track = medium.tracks[j],
|
||||||
disambiguation = recording.disambiguation ? " (" + recording.disambiguation + ")" : "",
|
recording = track.recording,
|
||||||
length = track.length ? format_time(track.length) : "?:??"
|
disambiguation = recording.disambiguation ? ` (${recording.disambiguation})` : '',
|
||||||
artist_credit = track["artist-credit"] || track.recording["artist-credit"],
|
length = track.length ? format_time(track.length) : '?:??';
|
||||||
tr = document.createElement("tr");
|
(artist_credit = track['artist-credit'] || track.recording['artist-credit']), (tr = document.createElement('tr'));
|
||||||
|
|
||||||
tr.appendChild(createElement("td", j + 1));
|
tr.appendChild(createElement('td', j + 1));
|
||||||
var title_td = createElement("td", disambiguation);
|
let title_td = createElement('td', disambiguation);
|
||||||
title_td.insertBefore(createLink("/recording/" + recording.id, recording.title), title_td.firstChild);
|
title_td.insertBefore(createLink(`/recording/${recording.id}`, recording.title), title_td.firstChild);
|
||||||
tr.appendChild(title_td);
|
tr.appendChild(title_td);
|
||||||
tr.appendChild(createElement("td", length));
|
tr.appendChild(createElement('td', length));
|
||||||
var ac_td = document.createElement("td");
|
let ac_td = document.createElement('td');
|
||||||
ac_td.appendChild(createAC(artist_credit));
|
ac_td.appendChild(createAC(artist_credit));
|
||||||
tr.appendChild(ac_td);
|
tr.appendChild(ac_td);
|
||||||
|
|
||||||
|
@ -258,46 +271,46 @@ function parse_release(json, table) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var bottom_tr = document.createElement("tr"),
|
let bottom_tr = document.createElement('tr'),
|
||||||
bottom_td = document.createElement("td");
|
bottom_td = document.createElement('td');
|
||||||
|
|
||||||
bottom_td.colSpan = 4;
|
bottom_td.colSpan = 4;
|
||||||
bottom_td.style.padding = "1em";
|
bottom_td.style.padding = '1em';
|
||||||
|
|
||||||
bottom_td.appendChild(createLink("/release/" + json.id + "/edit", "edit"));
|
bottom_td.appendChild(createLink(`/release/${json.id}/edit`, 'edit'));
|
||||||
bottom_td.appendChild(document.createTextNode(" | "));
|
bottom_td.appendChild(document.createTextNode(' | '));
|
||||||
bottom_td.appendChild(createLink("/release/" + json.id + "/edit-relationships", "edit relationships"));
|
bottom_td.appendChild(createLink(`/release/${json.id}/edit-relationships`, 'edit relationships'));
|
||||||
bottom_td.appendChild(document.createTextNode(" | "));
|
bottom_td.appendChild(document.createTextNode(' | '));
|
||||||
bottom_td.appendChild(createLink("/release/" + json.id + "/edits", "editing history"));
|
bottom_td.appendChild(createLink(`/release/${json.id}/edits`, 'editing history'));
|
||||||
|
|
||||||
bottom_tr.appendChild(bottom_td);
|
bottom_tr.appendChild(bottom_td);
|
||||||
table.appendChild(bottom_tr);
|
table.appendChild(bottom_tr);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createAC(obj) {
|
function createAC(obj) {
|
||||||
var span = document.createElement("span");
|
let span = document.createElement('span');
|
||||||
|
|
||||||
for (var i = 0; i < obj.length; i++) {
|
for (let i = 0; i < obj.length; i++) {
|
||||||
var credit = obj[i], artist = credit.artist,
|
let credit = obj[i],
|
||||||
link = createLink("/artist/" + artist.id, credit.name || artist.name);
|
artist = credit.artist,
|
||||||
|
link = createLink(`/artist/${artist.id}`, credit.name || artist.name);
|
||||||
|
|
||||||
link.setAttribute("title", artist["sort-name"]);
|
link.setAttribute('title', artist['sort-name']);
|
||||||
span.appendChild(link);
|
span.appendChild(link);
|
||||||
|
|
||||||
if (credit.joinphrase)
|
if (credit.joinphrase) span.appendChild(document.createTextNode(credit.joinphrase));
|
||||||
span.appendChild(document.createTextNode(credit.joinphrase));
|
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createElement(name, text) {
|
function createElement(name, text) {
|
||||||
var element = document.createElement(name);
|
let element = document.createElement(name);
|
||||||
element.textContent = text;
|
element.textContent = text;
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createLink(href, text) {
|
function createLink(href, text) {
|
||||||
var element = createElement("a", text);
|
let element = createElement('a', text);
|
||||||
element.href = href;
|
element.href = href;
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,66 +62,63 @@
|
||||||
|
|
||||||
//**************************************************************************//
|
//**************************************************************************//
|
||||||
|
|
||||||
var scr = document.createElement("script");
|
var scr = document.createElement('script');
|
||||||
scr.textContent = "(" + fastCancelScript + ")();";
|
scr.textContent = `(${fastCancelScript})();`;
|
||||||
document.body.appendChild(scr);
|
document.body.appendChild(scr);
|
||||||
|
|
||||||
function fastCancelScript() {
|
function fastCancelScript() {
|
||||||
var totalCancels = 0;
|
let totalCancels = 0;
|
||||||
|
|
||||||
var $status = $("<div></div>")
|
let $status = $('<div></div>')
|
||||||
.css({
|
.css({
|
||||||
"position": "fixed",
|
position: 'fixed',
|
||||||
"right": "0",
|
right: '0',
|
||||||
"bottom": "0",
|
bottom: '0',
|
||||||
"background": "#FFBA58",
|
background: '#FFBA58',
|
||||||
"border-top": "1px #000 solid",
|
'border-top': '1px #000 solid',
|
||||||
"border-left": "1px #000 solid",
|
'border-left': '1px #000 solid',
|
||||||
"padding": "0.5em"
|
padding: '0.5em'
|
||||||
})
|
})
|
||||||
.appendTo("body")
|
.appendTo('body')
|
||||||
.hide();
|
.hide();
|
||||||
|
|
||||||
function updateStatus() {
|
function updateStatus() {
|
||||||
if (totalCancels === 0) {
|
if (totalCancels === 0) {
|
||||||
$status.hide();
|
$status.hide();
|
||||||
} else {
|
} else {
|
||||||
$status.text("Canceling " + totalCancels + " edit" +
|
$status.text(`Canceling ${totalCancels} edit${totalCancels > 1 ? 's' : ''}...`).show();
|
||||||
(totalCancels > 1 ? "s" : "") + "...").show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.body.addEventListener("click", function (event) {
|
document.body.addEventListener('click', function(event) {
|
||||||
if (event.target && event.target.tagName && event.target.tagName == "A" && event.target.classList.contains("negative")) {
|
if (event.target && event.target.tagName && event.target.tagName == 'A' && event.target.classList.contains('negative')) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
totalCancels += 1;
|
totalCancels += 1;
|
||||||
updateStatus();
|
updateStatus();
|
||||||
|
|
||||||
var $self = $(event.target),
|
let $self = $(event.target),
|
||||||
$edit = $self.parents("div.edit-list:eq(0)");
|
$edit = $self.parents('div.edit-list:eq(0)');
|
||||||
|
|
||||||
pushRequest(function () {
|
pushRequest(function() {
|
||||||
var editNote = $edit.find("div.add-edit-note textarea").val();
|
let editNote = $edit.find('div.add-edit-note textarea').val();
|
||||||
var data = { "confirm.edit_note": editNote };
|
let data = { 'confirm.edit_note': editNote };
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: 'POST',
|
||||||
url: $self.attr("href"),
|
url: $self.attr('href'),
|
||||||
data: data,
|
data: data,
|
||||||
error: function (request, status, error) {
|
error: function(request, status, error) {
|
||||||
$self
|
$self
|
||||||
.css({
|
.css({
|
||||||
"background": "red",
|
background: 'red',
|
||||||
"color": "yellow",
|
color: 'yellow',
|
||||||
"cursor": "help"
|
cursor: 'help'
|
||||||
})
|
})
|
||||||
.attr("title", "Error cancelling this edit: “" + error + "”");
|
.attr('title', `Error cancelling this edit: “${error}”`);
|
||||||
$edit
|
$edit.css({ border: '6px solid red' }).show();
|
||||||
.css({border: "6px solid red"})
|
|
||||||
.show();
|
|
||||||
},
|
},
|
||||||
complete: function () {
|
complete: function() {
|
||||||
$edit.remove();
|
$edit.remove();
|
||||||
totalCancels -= 1;
|
totalCancels -= 1;
|
||||||
updateStatus();
|
updateStatus();
|
||||||
|
@ -132,15 +129,15 @@ function fastCancelScript() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("div#edits > form[action$='/edit/enter_votes']").on("submit", function(event) {
|
$("div#edits > form[action$='/edit/enter_votes']").on('submit', function(event) {
|
||||||
if (totalCancels > 0) {
|
if (totalCancels > 0) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
alert("Please wait, " + (totalCancels > 1 ? totalCancels + " edits are" : "an edit is") + " being cancelled in the background.");
|
alert(`Please wait, ${totalCancels > 1 ? `${totalCancels} edits are` : 'an edit is'} being cancelled in the background.`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var pushRequest = (function () {
|
var pushRequest = (function() {
|
||||||
var queue = [],
|
let queue = [],
|
||||||
last = 0,
|
last = 0,
|
||||||
active = false,
|
active = false,
|
||||||
rate = 2000;
|
rate = 2000;
|
||||||
|
@ -155,19 +152,19 @@ function fastCancelScript() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return function (req) {
|
return function(req) {
|
||||||
queue.push(req);
|
queue.push(req);
|
||||||
|
|
||||||
if (!active) {
|
if (!active) {
|
||||||
active = true;
|
active = true;
|
||||||
var now = new Date().getTime();
|
let now = new Date().getTime();
|
||||||
if (now - last >= rate) {
|
if (now - last >= rate) {
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
var timeout = rate - now + last;
|
let timeout = rate - now + last;
|
||||||
setTimeout(next, timeout);
|
setTimeout(next, timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}());
|
})();
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -19,128 +19,144 @@ this.$ = this.jQuery = jQuery.noConflict(true);
|
||||||
|
|
||||||
if (!unsafeWindow) unsafeWindow = window;
|
if (!unsafeWindow) unsafeWindow = window;
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function() {
|
||||||
MBImportStyle();
|
MBImportStyle();
|
||||||
var release_url = window.location.href.replace('/\?.*$/', '').replace(/#.*$/, '');
|
let release_url = window.location.href.replace('/?.*$/', '').replace(/#.*$/, '');
|
||||||
var release = retrieveReleaseInfo(release_url);
|
let release = retrieveReleaseInfo(release_url);
|
||||||
insertLink(release, release_url);
|
insertLink(release, release_url);
|
||||||
});
|
});
|
||||||
|
|
||||||
function parseReleaseDate(rdate) {
|
function parseReleaseDate(rdate) {
|
||||||
var months = {
|
let months = {
|
||||||
"January": 1,
|
January: 1,
|
||||||
"February": 2,
|
February: 2,
|
||||||
"March": 3,
|
March: 3,
|
||||||
"April": 4,
|
April: 4,
|
||||||
"May": 5,
|
May: 5,
|
||||||
"June": 6,
|
June: 6,
|
||||||
"July": 7,
|
July: 7,
|
||||||
"August": 8,
|
August: 8,
|
||||||
"September": 9,
|
September: 9,
|
||||||
"October": 10,
|
October: 10,
|
||||||
"November": 11,
|
November: 11,
|
||||||
"December": 12
|
December: 12
|
||||||
};
|
};
|
||||||
|
|
||||||
var m = rdate.match(/(\d{1,2}) ([a-z]+), (\d{4})/i);
|
let m = rdate.match(/(\d{1,2}) ([a-z]+), (\d{4})/i);
|
||||||
if (m) {
|
if (m) {
|
||||||
return {
|
return {
|
||||||
year: m[3],
|
year: m[3],
|
||||||
month: months[m[2]],
|
month: months[m[2]],
|
||||||
day: m[1]
|
day: m[1]
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
return false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function retrieveReleaseInfo(release_url) {
|
function retrieveReleaseInfo(release_url) {
|
||||||
|
// 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 defaults
|
// Release date
|
||||||
var release = {
|
let parsed_releaseDate = parseReleaseDate(
|
||||||
artist_credit: [],
|
$('#product_info_released_on')
|
||||||
title: $("#product_heading_title").text().trim(),
|
.text()
|
||||||
year: 0,
|
.trim()
|
||||||
month: 0,
|
);
|
||||||
day: 0,
|
if (parsed_releaseDate) {
|
||||||
format: 'Digital Media',
|
release.year = parsed_releaseDate.year;
|
||||||
packaging: 'None',
|
release.month = parsed_releaseDate.month;
|
||||||
country: 'XW',
|
release.day = parsed_releaseDate.day;
|
||||||
status: 'official',
|
|
||||||
language: 'eng',
|
|
||||||
script: 'Latn',
|
|
||||||
type: '',
|
|
||||||
urls: [],
|
|
||||||
labels: [],
|
|
||||||
discs: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
// Release date
|
|
||||||
var 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
// URLs
|
||||||
var tracks = [];
|
release.urls.push({
|
||||||
$(".product_tracklist_records[itemprop='tracks']").each(function() {
|
url: release_url,
|
||||||
var artists = [];
|
link_type: MBImport.URL_TYPES.purchase_for_download
|
||||||
var trackno = $(this).find(".product_tracklist_heading_records_sn").text().trim() - 1;
|
});
|
||||||
var trackname = $(this).find(".product_tracklist_heading_records_title").text().trim();
|
|
||||||
var tracklength = $(this).find(".product_tracklist_heading_records_length").text().trim();
|
release.labels.push({
|
||||||
var m = trackname.match(/^([^-]+) - (.*)$/);
|
name: $('#product_heading_label')
|
||||||
if (m) {
|
.text()
|
||||||
artists = [m[1]];
|
.trim(),
|
||||||
trackname = m[2];
|
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]);
|
||||||
}
|
}
|
||||||
tracks.push({
|
release.discs.push({
|
||||||
'artist_credit': MBImport.makeArtistCredits(artists),
|
tracks: tracks,
|
||||||
'title': trackname,
|
format: release.format
|
||||||
'duration': tracklength
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
var parsed_release_artist = $("#product_heading_artist").text().trim();
|
LOGGER.info('Parsed release: ', release);
|
||||||
if (parsed_release_artist == 'VARIOUS') {
|
return release;
|
||||||
release.artist_credit = [ MBImport.specialArtist('various_artists') ];
|
|
||||||
} else {
|
|
||||||
release.artist_credit = MBImport.makeArtistCredits([ parsed_release_artist ]);
|
|
||||||
}
|
|
||||||
release.discs.push( {
|
|
||||||
'tracks': tracks,
|
|
||||||
'format': release.format
|
|
||||||
} );
|
|
||||||
|
|
||||||
LOGGER.info("Parsed release: ", release);
|
|
||||||
return release;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert button into page under label information
|
// Insert button into page under label information
|
||||||
function insertLink(release, release_url) {
|
function insertLink(release, release_url) {
|
||||||
var edit_note = MBImport.makeEditNote(release_url, 'Juno Download');
|
let edit_note = MBImport.makeEditNote(release_url, 'Juno Download');
|
||||||
var parameters = MBImport.buildFormParameters(release, edit_note);
|
let parameters = MBImport.buildFormParameters(release, edit_note);
|
||||||
|
|
||||||
var mbUI = $('<div id="mb_buttons">'
|
let mbUI = $(`<div id="mb_buttons">${MBImport.buildFormHTML(parameters)}${MBImport.buildSearchButton(release)}</div>`).hide();
|
||||||
+ MBImport.buildFormHTML(parameters)
|
|
||||||
+ MBImport.buildSearchButton(release)
|
|
||||||
+ '</div>').hide();
|
|
||||||
|
|
||||||
$("div.sociald").before(mbUI);
|
$('div.sociald').before(mbUI);
|
||||||
$('#mb_buttons').css({'background': '#759d44', 'border': '2px solid #ddd', 'text-align': 'center'});
|
$('#mb_buttons').css({ background: '#759d44', border: '2px solid #ddd', 'text-align': 'center' });
|
||||||
$('form.musicbrainz_import button').css({width: '80%'});
|
$('form.musicbrainz_import button').css({ width: '80%' });
|
||||||
mbUI.slideDown();
|
mbUI.slideDown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,111 +18,125 @@ this.$ = this.jQuery = jQuery.noConflict(true);
|
||||||
|
|
||||||
if (!unsafeWindow) unsafeWindow = window;
|
if (!unsafeWindow) unsafeWindow = window;
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function() {
|
||||||
MBImportStyle();
|
MBImportStyle();
|
||||||
var release_url = window.location.href.replace('/\?.*$/', '').replace(/#.*$/, '');
|
let release_url = window.location.href.replace('/?.*$/', '').replace(/#.*$/, '');
|
||||||
release_url = release_url.replace(/^(?:https?:\/\/)?(?:www\.)?(?:last\.fm|lastfm\.(?:com\.br|com\.tr|at|com|de|es|fr|it|jp|pl|pt|ru|se))\//, "http://www.last.fm/");
|
release_url = release_url.replace(
|
||||||
|
/^(?:https?:\/\/)?(?:www\.)?(?:last\.fm|lastfm\.(?:com\.br|com\.tr|at|com|de|es|fr|it|jp|pl|pt|ru|se))\//,
|
||||||
|
'http://www.last.fm/'
|
||||||
|
);
|
||||||
|
|
||||||
var release = retrieveReleaseInfo(release_url);
|
let release = retrieveReleaseInfo(release_url);
|
||||||
insertLink(release, release_url);
|
insertLink(release, release_url);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function retrieveReleaseInfo(release_url) {
|
function retrieveReleaseInfo(release_url) {
|
||||||
|
// Release defaults
|
||||||
|
let release = {
|
||||||
// Release defaults
|
artist_credit: '',
|
||||||
var release = {
|
title: $("h1[itemprop='name']")
|
||||||
artist_credit: '',
|
.text()
|
||||||
title: $("h1[itemprop='name']").text().trim(),
|
.trim(),
|
||||||
year: 0,
|
year: 0,
|
||||||
month: 0,
|
month: 0,
|
||||||
day: 0,
|
day: 0,
|
||||||
format: '',
|
format: '',
|
||||||
packaging: '',
|
packaging: '',
|
||||||
country: '',
|
country: '',
|
||||||
status: 'official',
|
status: 'official',
|
||||||
language: 'eng',
|
language: 'eng',
|
||||||
script: 'Latn',
|
script: 'Latn',
|
||||||
type: '',
|
type: '',
|
||||||
urls: [],
|
urls: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
discs: [],
|
discs: []
|
||||||
};
|
|
||||||
|
|
||||||
// Release artist
|
|
||||||
var artist = $("article span[itemprop='byArtist'] meta[itemprop='name']").attr('content').trim();
|
|
||||||
var various_artists = (artist == 'Various Artists');
|
|
||||||
if (various_artists) {
|
|
||||||
release.artist_credit = [ MBImport.specialArtist('various_artists') ];
|
|
||||||
} else {
|
|
||||||
release.artist_credit = MBImport.makeArtistCredits([artist]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tracks
|
|
||||||
var tracks = [];
|
|
||||||
$("#albumTracklist tr[itemprop='tracks']").each(function() {
|
|
||||||
var artists = [];
|
|
||||||
var trackno = parseInt($(this).find("td.positionCell").text(), 10);
|
|
||||||
if (trackno == 1 && tracks.length) {
|
|
||||||
// multiple "discs"
|
|
||||||
release.discs.push( {
|
|
||||||
'tracks': tracks,
|
|
||||||
'format': release.format
|
|
||||||
} );
|
|
||||||
tracks = [];
|
|
||||||
}
|
|
||||||
var trackname = $(this).find("td.subjectCell span[itemprop='name']").text().trim();
|
|
||||||
var tracklength = $(this).find("td.durationCell").text().trim();
|
|
||||||
|
|
||||||
// VA releases have an additional link to the lastfm artist page
|
|
||||||
var track_artists = [];
|
|
||||||
$(this).find("td.subjectCell > a:not(:last)").each(
|
|
||||||
function () {
|
|
||||||
track_artists.push($(this).text().trim());
|
|
||||||
}
|
|
||||||
);
|
|
||||||
var ac = {
|
|
||||||
'artist_credit': '',
|
|
||||||
'title': trackname,
|
|
||||||
'duration': tracklength
|
|
||||||
};
|
};
|
||||||
if (!track_artists.length && various_artists) {
|
|
||||||
ac.artist_credit = [ MBImport.specialArtist('unknown') ];
|
// Release artist
|
||||||
|
let artist = $("article span[itemprop='byArtist'] meta[itemprop='name']")
|
||||||
|
.attr('content')
|
||||||
|
.trim();
|
||||||
|
let various_artists = artist == 'Various Artists';
|
||||||
|
if (various_artists) {
|
||||||
|
release.artist_credit = [MBImport.specialArtist('various_artists')];
|
||||||
} else {
|
} else {
|
||||||
ac.artist_credit = MBImport.makeArtistCredits(track_artists);
|
release.artist_credit = MBImport.makeArtistCredits([artist]);
|
||||||
}
|
}
|
||||||
tracks.push(ac);
|
|
||||||
});
|
|
||||||
|
|
||||||
release.discs.push( {
|
// Tracks
|
||||||
'tracks': tracks,
|
let tracks = [];
|
||||||
'format': release.format
|
$("#albumTracklist tr[itemprop='tracks']").each(function() {
|
||||||
} );
|
let artists = [];
|
||||||
|
let trackno = parseInt(
|
||||||
|
$(this)
|
||||||
|
.find('td.positionCell')
|
||||||
|
.text(),
|
||||||
|
10
|
||||||
|
);
|
||||||
|
if (trackno == 1 && tracks.length) {
|
||||||
|
// multiple "discs"
|
||||||
|
release.discs.push({
|
||||||
|
tracks: tracks,
|
||||||
|
format: release.format
|
||||||
|
});
|
||||||
|
tracks = [];
|
||||||
|
}
|
||||||
|
let trackname = $(this)
|
||||||
|
.find("td.subjectCell span[itemprop='name']")
|
||||||
|
.text()
|
||||||
|
.trim();
|
||||||
|
let tracklength = $(this)
|
||||||
|
.find('td.durationCell')
|
||||||
|
.text()
|
||||||
|
.trim();
|
||||||
|
|
||||||
LOGGER.info("Parsed release: ", release);
|
// VA releases have an additional link to the lastfm artist page
|
||||||
return release;
|
let track_artists = [];
|
||||||
|
$(this)
|
||||||
|
.find('td.subjectCell > a:not(:last)')
|
||||||
|
.each(function() {
|
||||||
|
track_artists.push(
|
||||||
|
$(this)
|
||||||
|
.text()
|
||||||
|
.trim()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
let ac = {
|
||||||
|
artist_credit: '',
|
||||||
|
title: trackname,
|
||||||
|
duration: tracklength
|
||||||
|
};
|
||||||
|
if (!track_artists.length && various_artists) {
|
||||||
|
ac.artist_credit = [MBImport.specialArtist('unknown')];
|
||||||
|
} else {
|
||||||
|
ac.artist_credit = MBImport.makeArtistCredits(track_artists);
|
||||||
|
}
|
||||||
|
tracks.push(ac);
|
||||||
|
});
|
||||||
|
|
||||||
|
release.discs.push({
|
||||||
|
tracks: tracks,
|
||||||
|
format: release.format
|
||||||
|
});
|
||||||
|
|
||||||
|
LOGGER.info('Parsed release: ', release);
|
||||||
|
return release;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert button into page under label information
|
// Insert button into page under label information
|
||||||
function insertLink(release, release_url) {
|
function insertLink(release, release_url) {
|
||||||
var edit_note = MBImport.makeEditNote(release_url, 'Last.fm');
|
let edit_note = MBImport.makeEditNote(release_url, 'Last.fm');
|
||||||
var parameters = MBImport.buildFormParameters(release, edit_note);
|
let parameters = MBImport.buildFormParameters(release, edit_note);
|
||||||
|
|
||||||
$("div.g4").prepend(
|
$('div.g4').prepend($(`<div id="mb_buttons">${MBImport.buildFormHTML(parameters)}${MBImport.buildSearchButton(release)}</div>`).hide());
|
||||||
$('<div id="mb_buttons">'
|
|
||||||
+ MBImport.buildFormHTML(parameters)
|
|
||||||
+ MBImport.buildSearchButton(release)
|
|
||||||
+ '</div>').hide()
|
|
||||||
);
|
|
||||||
$('#mb_buttons').css({
|
$('#mb_buttons').css({
|
||||||
'margin-bottom': '5px',
|
'margin-bottom': '5px',
|
||||||
'padding': '2%',
|
padding: '2%',
|
||||||
'background-color': '#444'
|
'background-color': '#444'
|
||||||
});
|
});
|
||||||
$('form.musicbrainz_import').css({width: '48%', display:'inline-block'});
|
$('form.musicbrainz_import').css({ width: '48%', display: 'inline-block' });
|
||||||
$('form.musicbrainz_import_search').css({'float': 'right'})
|
$('form.musicbrainz_import_search').css({ float: 'right' });
|
||||||
$('form.musicbrainz_import > button').css({width: '100%', 'box-sizing': 'border-box'});
|
$('form.musicbrainz_import > button').css({ width: '100%', 'box-sizing': 'border-box' });
|
||||||
|
|
||||||
$('#mb_buttons').slideDown();
|
$('#mb_buttons').slideDown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,23 +3,22 @@
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
var LOGGER = (function() {
|
var LOGGER = (function() {
|
||||||
|
let LOG_LEVEL = 'info';
|
||||||
var LOG_LEVEL = 'info';
|
|
||||||
|
|
||||||
function fnDebug() {
|
function fnDebug() {
|
||||||
if (LOG_LEVEL == 'debug') {
|
if (LOG_LEVEL == 'debug') {
|
||||||
_log("DEBUG", arguments);
|
_log('DEBUG', arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function fnInfo() {
|
function fnInfo() {
|
||||||
if (LOG_LEVEL == 'debug' || LOG_LEVEL === 'info') {
|
if (LOG_LEVEL == 'debug' || LOG_LEVEL === 'info') {
|
||||||
_log("INFO", arguments);
|
_log('INFO', arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function fnError() {
|
function fnError() {
|
||||||
_log("ERROR", arguments);
|
_log('ERROR', arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
function fnSetLevel(level) {
|
function fnSetLevel(level) {
|
||||||
|
@ -31,16 +30,16 @@ var LOGGER = (function() {
|
||||||
function _log(level, args) {
|
function _log(level, args) {
|
||||||
// Prepends log level to things that will be logged
|
// Prepends log level to things that will be logged
|
||||||
args = Array.prototype.slice.call(args);
|
args = Array.prototype.slice.call(args);
|
||||||
args.unshift('['+level+']');
|
args.unshift(`[${level}]`);
|
||||||
// Determine if there's a logger (console.log) available
|
// Determine if there's a logger (console.log) available
|
||||||
var win = unsafeWindow || window;
|
let win = unsafeWindow || window;
|
||||||
var console = win.console;
|
let console = win.console;
|
||||||
if (console && console.log && console.log.apply) {
|
if (console && console.log && console.log.apply) {
|
||||||
try {
|
try {
|
||||||
console.log.apply(this, args);
|
console.log.apply(this, args);
|
||||||
} catch(e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// ---------------------------------- expose publics here ------------------------------------ //
|
// ---------------------------------- expose publics here ------------------------------------ //
|
||||||
|
|
||||||
|
@ -50,4 +49,4 @@ var LOGGER = (function() {
|
||||||
error: fnError,
|
error: fnError,
|
||||||
setLevel: fnSetLevel
|
setLevel: fnSetLevel
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
397
lib/mbimport.js
397
lib/mbimport.js
|
@ -58,62 +58,63 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var MBImport = (function() {
|
var MBImport = (function() {
|
||||||
|
|
||||||
// --------------------------------------- publics ----------------------------------------- //
|
// --------------------------------------- publics ----------------------------------------- //
|
||||||
|
|
||||||
var special_artists = {
|
let special_artists = {
|
||||||
various_artists: {
|
various_artists: {
|
||||||
name: 'Various Artists',
|
name: 'Various Artists',
|
||||||
mbid: '89ad4ac3-39f7-470e-963a-56509c546377'
|
mbid: '89ad4ac3-39f7-470e-963a-56509c546377'
|
||||||
},
|
},
|
||||||
unknown: {
|
unknown: {
|
||||||
name: '[unknown]',
|
name: '[unknown]',
|
||||||
mbid: '125ec42a-7229-4250-afc5-e057484327fe'
|
mbid: '125ec42a-7229-4250-afc5-e057484327fe'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var url_types = {
|
let url_types = {
|
||||||
purchase_for_download: 74,
|
purchase_for_download: 74,
|
||||||
download_for_free: 75,
|
download_for_free: 75,
|
||||||
discogs: 76,
|
discogs: 76,
|
||||||
purchase_for_mail_order: 79,
|
purchase_for_mail_order: 79,
|
||||||
other_databases: 82,
|
other_databases: 82,
|
||||||
stream_for_free: 85,
|
stream_for_free: 85,
|
||||||
license: 301
|
license: 301
|
||||||
}
|
};
|
||||||
|
|
||||||
function fnSpecialArtist(key, ac) {
|
function fnSpecialArtist(key, ac) {
|
||||||
var credited_name = "";
|
let credited_name = '';
|
||||||
var joinphrase = "";
|
let joinphrase = '';
|
||||||
if (typeof ac !== 'undefined') {
|
if (typeof ac !== 'undefined') {
|
||||||
joinphrase = ac.joinphrase;
|
joinphrase = ac.joinphrase;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
'artist_name': special_artists[key].name,
|
artist_name: special_artists[key].name,
|
||||||
'credited_name': credited_name,
|
credited_name: credited_name,
|
||||||
'joinphrase': joinphrase,
|
joinphrase: joinphrase,
|
||||||
'mbid': special_artists[key].mbid
|
mbid: special_artists[key].mbid
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// compute HTML of search link
|
// compute HTML of search link
|
||||||
function fnBuildSearchLink(release) {
|
function fnBuildSearchLink(release) {
|
||||||
var parameters = searchParams(release);
|
let parameters = searchParams(release);
|
||||||
var url_params = [];
|
let url_params = [];
|
||||||
parameters.forEach(function(parameter) {
|
parameters.forEach(function(parameter) {
|
||||||
var value = parameter.value + "";
|
let value = `${parameter.value}`;
|
||||||
url_params.push(encodeURI(parameter.name + '=' + value));
|
url_params.push(encodeURI(`${parameter.name}=${value}`));
|
||||||
});
|
});
|
||||||
return '<a class="musicbrainz_import" href="//musicbrainz.org/search?' + url_params.join('&') + '">Search in MusicBrainz</a>';
|
return `<a class="musicbrainz_import" href="//musicbrainz.org/search?${url_params.join('&')}">Search in MusicBrainz</a>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compute HTML of search button
|
// compute HTML of search button
|
||||||
function fnBuildSearchButton(release) {
|
function fnBuildSearchButton(release) {
|
||||||
var parameters = searchParams(release);
|
let parameters = searchParams(release);
|
||||||
var html = '<form class="musicbrainz_import musicbrainz_import_search" action="//musicbrainz.org/search" method="get" target="_blank" accept-charset="UTF-8" charset="' + document.characterSet + '">';
|
let html = `<form class="musicbrainz_import musicbrainz_import_search" action="//musicbrainz.org/search" method="get" target="_blank" accept-charset="UTF-8" charset="${
|
||||||
|
document.characterSet
|
||||||
|
}">`;
|
||||||
parameters.forEach(function(parameter) {
|
parameters.forEach(function(parameter) {
|
||||||
var value = parameter.value + "";
|
let value = `${parameter.value}`;
|
||||||
html += "<input type='hidden' value='" + value.replace(/'/g,"'") + "' name='" + parameter.name + "'/>";
|
html += `<input type='hidden' value='${value.replace(/'/g, ''')}' name='${parameter.name}'/>`;
|
||||||
});
|
});
|
||||||
html += '<button type="submit" title="Search for this release in MusicBrainz (open a new tab)"><span>Search in MB</span></button>';
|
html += '<button type="submit" title="Search for this release in MusicBrainz (open a new tab)"><span>Search in MB</span></button>';
|
||||||
html += '</form>';
|
html += '</form>';
|
||||||
|
@ -121,27 +122,25 @@ var MBImport = (function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function fnSearchUrlFor(type, what) {
|
function fnSearchUrlFor(type, what) {
|
||||||
type = type.replace('-', '_');
|
type = type.replace('-', '_');
|
||||||
|
|
||||||
var params = [
|
let params = [`query=${luceneEscape(what)}`, `type=${type}`, 'indexed=1'];
|
||||||
'query=' + luceneEscape(what),
|
return `//musicbrainz.org/search?${params.join('&')}`;
|
||||||
'type=' + type,
|
|
||||||
'indexed=1'
|
|
||||||
];
|
|
||||||
return '//musicbrainz.org/search?' + params.join('&');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// compute HTML of import form
|
// compute HTML of import form
|
||||||
function fnBuildFormHTML(parameters) {
|
function fnBuildFormHTML(parameters) {
|
||||||
|
|
||||||
// Build form
|
// Build form
|
||||||
var innerHTML = '<form class="musicbrainz_import musicbrainz_import_add" action="//musicbrainz.org/release/add" method="post" target="_blank" accept-charset="UTF-8" charset="' + document.characterSet + '">';
|
let innerHTML = `<form class="musicbrainz_import musicbrainz_import_add" action="//musicbrainz.org/release/add" method="post" target="_blank" accept-charset="UTF-8" charset="${
|
||||||
|
document.characterSet
|
||||||
|
}">`;
|
||||||
parameters.forEach(function(parameter) {
|
parameters.forEach(function(parameter) {
|
||||||
var value = parameter.value + "";
|
let value = `${parameter.value}`;
|
||||||
innerHTML += "<input type='hidden' value='" + value.replace(/'/g,"'") + "' name='" + parameter.name + "'/>";
|
innerHTML += `<input type='hidden' value='${value.replace(/'/g, ''')}' name='${parameter.name}'/>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
innerHTML += '<button type="submit" title="Import this release into MusicBrainz (open a new tab)"><img src="//musicbrainz.org/favicon.ico" /><span>Import into MB</span></button>';
|
innerHTML +=
|
||||||
|
'<button type="submit" title="Import this release into MusicBrainz (open a new tab)"><img src="//musicbrainz.org/favicon.ico" /><span>Import into MB</span></button>';
|
||||||
innerHTML += '</form>';
|
innerHTML += '</form>';
|
||||||
|
|
||||||
return innerHTML;
|
return innerHTML;
|
||||||
|
@ -150,14 +149,14 @@ var MBImport = (function() {
|
||||||
// build form POST parameters that MB is waiting
|
// build form POST parameters that MB is waiting
|
||||||
function fnBuildFormParameters(release, edit_note) {
|
function fnBuildFormParameters(release, edit_note) {
|
||||||
// Form parameters
|
// Form parameters
|
||||||
var parameters = new Array();
|
let parameters = new Array();
|
||||||
appendParameter(parameters, 'name', release.title);
|
appendParameter(parameters, 'name', release.title);
|
||||||
|
|
||||||
// Release Artist credits
|
// Release Artist credits
|
||||||
buildArtistCreditsFormParameters(parameters, "", release.artist_credit);
|
buildArtistCreditsFormParameters(parameters, '', release.artist_credit);
|
||||||
|
|
||||||
if (release["secondary_types"]) {
|
if (release['secondary_types']) {
|
||||||
for (var i=0; i < release.secondary_types.length; i++) {
|
for (var i = 0; i < release.secondary_types.length; i++) {
|
||||||
appendParameter(parameters, 'type', release.secondary_types[i]);
|
appendParameter(parameters, 'type', release.secondary_types[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,61 +170,67 @@ var MBImport = (function() {
|
||||||
|
|
||||||
// Date + country
|
// Date + country
|
||||||
appendParameter(parameters, 'country', release.country);
|
appendParameter(parameters, 'country', release.country);
|
||||||
if (!isNaN(release.year) && release.year != 0) { appendParameter(parameters, 'date.year', release.year); };
|
if (!isNaN(release.year) && release.year != 0) {
|
||||||
if (!isNaN(release.month) && release.month != 0) { appendParameter(parameters, 'date.month', release.month); };
|
appendParameter(parameters, 'date.year', release.year);
|
||||||
if (!isNaN(release.day) && release.day != 0) { appendParameter(parameters, 'date.day', release.day); };
|
}
|
||||||
|
if (!isNaN(release.month) && release.month != 0) {
|
||||||
|
appendParameter(parameters, 'date.month', release.month);
|
||||||
|
}
|
||||||
|
if (!isNaN(release.day) && release.day != 0) {
|
||||||
|
appendParameter(parameters, 'date.day', release.day);
|
||||||
|
}
|
||||||
|
|
||||||
// Barcode
|
// Barcode
|
||||||
appendParameter(parameters, 'barcode', release.barcode);
|
appendParameter(parameters, 'barcode', release.barcode);
|
||||||
|
|
||||||
// Label + catnos
|
// Label + catnos
|
||||||
for (var i=0; i < release.labels.length; i++) {
|
for (var i = 0; i < release.labels.length; i++) {
|
||||||
var label = release.labels[i];
|
let label = release.labels[i];
|
||||||
appendParameter(parameters, 'labels.'+i+'.name', label.name);
|
appendParameter(parameters, `labels.${i}.name`, label.name);
|
||||||
appendParameter(parameters, 'labels.'+i+'.mbid', label.mbid);
|
appendParameter(parameters, `labels.${i}.mbid`, label.mbid);
|
||||||
if (label.catno != "none") {
|
if (label.catno != 'none') {
|
||||||
appendParameter(parameters, 'labels.'+i+'.catalog_number', label.catno);
|
appendParameter(parameters, `labels.${i}.catalog_number`, label.catno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// URLs
|
// URLs
|
||||||
for (var i=0; i < release.urls.length; i++) {
|
for (var i = 0; i < release.urls.length; i++) {
|
||||||
var url = release.urls[i];
|
let url = release.urls[i];
|
||||||
appendParameter(parameters, 'urls.'+i+'.url', url.url);
|
appendParameter(parameters, `urls.${i}.url`, url.url);
|
||||||
appendParameter(parameters, 'urls.'+i+'.link_type', url.link_type);
|
appendParameter(parameters, `urls.${i}.link_type`, url.link_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mediums
|
// Mediums
|
||||||
var total_tracks = 0;
|
let total_tracks = 0;
|
||||||
var total_tracks_with_duration = 0;
|
let total_tracks_with_duration = 0;
|
||||||
var total_duration = 0;
|
let total_duration = 0;
|
||||||
for (var i=0; i < release.discs.length; i++) {
|
for (var i = 0; i < release.discs.length; i++) {
|
||||||
var disc = release.discs[i];
|
let disc = release.discs[i];
|
||||||
appendParameter(parameters, 'mediums.'+i+'.format', disc.format);
|
appendParameter(parameters, `mediums.${i}.format`, disc.format);
|
||||||
appendParameter(parameters, 'mediums.'+i+'.name', disc.title);
|
appendParameter(parameters, `mediums.${i}.name`, disc.title);
|
||||||
|
|
||||||
// Tracks
|
// Tracks
|
||||||
for (var j=0; j < disc.tracks.length; j++) {
|
for (let j = 0; j < disc.tracks.length; j++) {
|
||||||
var track = disc.tracks[j];
|
let track = disc.tracks[j];
|
||||||
total_tracks++;
|
total_tracks++;
|
||||||
appendParameter(parameters, 'mediums.'+i+'.track.'+j+'.number', track.number);
|
appendParameter(parameters, `mediums.${i}.track.${j}.number`, track.number);
|
||||||
appendParameter(parameters, 'mediums.'+i+'.track.'+j+'.name', track.title);
|
appendParameter(parameters, `mediums.${i}.track.${j}.name`, track.title);
|
||||||
var tracklength = "?:??";
|
let tracklength = '?:??';
|
||||||
var duration_ms = hmsToMilliSeconds(track.duration);
|
let duration_ms = hmsToMilliSeconds(track.duration);
|
||||||
if (!isNaN(duration_ms)) {
|
if (!isNaN(duration_ms)) {
|
||||||
tracklength = duration_ms;
|
tracklength = duration_ms;
|
||||||
total_tracks_with_duration++;
|
total_tracks_with_duration++;
|
||||||
total_duration += duration_ms;
|
total_duration += duration_ms;
|
||||||
}
|
}
|
||||||
appendParameter(parameters, 'mediums.'+i+'.track.'+j+'.length', tracklength);
|
appendParameter(parameters, `mediums.${i}.track.${j}.length`, tracklength);
|
||||||
|
|
||||||
buildArtistCreditsFormParameters(parameters, 'mediums.'+i+'.track.'+j+'.', track.artist_credit);
|
buildArtistCreditsFormParameters(parameters, `mediums.${i}.track.${j}.`, track.artist_credit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Guess release type if not given
|
// Guess release type if not given
|
||||||
if (!release.type && release.title && total_tracks == total_tracks_with_duration) {
|
if (!release.type && release.title && total_tracks == total_tracks_with_duration) {
|
||||||
release.type = fnGuessReleaseType(release.title, total_tracks, total_duration);
|
release.type = fnGuessReleaseType(release.title, total_tracks, total_duration);
|
||||||
}
|
}
|
||||||
appendParameter(parameters, 'type', release.type);
|
appendParameter(parameters, 'type', release.type);
|
||||||
|
|
||||||
|
@ -237,154 +242,156 @@ var MBImport = (function() {
|
||||||
|
|
||||||
// Convert a list of artists to a list of artist credits with joinphrases
|
// Convert a list of artists to a list of artist credits with joinphrases
|
||||||
function fnArtistCredits(artists_list) {
|
function fnArtistCredits(artists_list) {
|
||||||
var artists = artists_list.map(function(item) { return {artist_name: item}; });
|
let artists = artists_list.map(function(item) {
|
||||||
if (artists.length > 2) {
|
return { artist_name: item };
|
||||||
var last = artists.pop();
|
});
|
||||||
last.joinphrase = '';
|
if (artists.length > 2) {
|
||||||
var prev = artists.pop();
|
let last = artists.pop();
|
||||||
prev.joinphrase = ' & ';
|
last.joinphrase = '';
|
||||||
for (var i = 0; i < artists.length; i++) {
|
let prev = artists.pop();
|
||||||
artists[i].joinphrase = ', ';
|
prev.joinphrase = ' & ';
|
||||||
}
|
for (let i = 0; i < artists.length; i++) {
|
||||||
artists.push(prev);
|
artists[i].joinphrase = ', ';
|
||||||
artists.push(last);
|
|
||||||
} else if (artists.length == 2) {
|
|
||||||
artists[0].joinphrase = ' & ';
|
|
||||||
}
|
|
||||||
var credits = [];
|
|
||||||
// re-split artists if featuring or vs
|
|
||||||
artists.map(function (item) {
|
|
||||||
var c = item.artist_name.replace(/\s*\b(?:feat\.?|ft\.?|featuring)\s+/gi, ' feat. ');
|
|
||||||
c = c.replace(/\s*\(( feat. )([^\)]+)\)/g, '$1$2');
|
|
||||||
c = c.replace(/\s*\b(?:versus|vs\.?)\s+/gi, ' vs. ');
|
|
||||||
c = c.replace(/\s+/g, ' ');
|
|
||||||
var splitted = c.split(/( feat\. | vs\. )/);
|
|
||||||
if (splitted.length == 1) {
|
|
||||||
credits.push(item); // nothing to split
|
|
||||||
} else {
|
|
||||||
var new_items = [];
|
|
||||||
var n = 0;
|
|
||||||
for (var i = 0; i < splitted.length; i++) {
|
|
||||||
if (n && (splitted[i] == ' feat. ' || splitted[i] == ' vs. ')) {
|
|
||||||
new_items[n-1].joinphrase = splitted[i];
|
|
||||||
} else {
|
|
||||||
new_items[n++] = {
|
|
||||||
artist_name: splitted[i].trim(),
|
|
||||||
joinphrase: ''
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
artists.push(prev);
|
||||||
new_items[n-1].joinphrase = item.joinphrase;
|
artists.push(last);
|
||||||
new_items.map(function (newit) {
|
} else if (artists.length == 2) {
|
||||||
credits.push(newit)
|
artists[0].joinphrase = ' & ';
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
let credits = [];
|
||||||
return credits;
|
// re-split artists if featuring or vs
|
||||||
|
artists.map(function(item) {
|
||||||
|
let c = item.artist_name.replace(/\s*\b(?:feat\.?|ft\.?|featuring)\s+/gi, ' feat. ');
|
||||||
|
c = c.replace(/\s*\(( feat. )([^\)]+)\)/g, '$1$2');
|
||||||
|
c = c.replace(/\s*\b(?:versus|vs\.?)\s+/gi, ' vs. ');
|
||||||
|
c = c.replace(/\s+/g, ' ');
|
||||||
|
let splitted = c.split(/( feat\. | vs\. )/);
|
||||||
|
if (splitted.length == 1) {
|
||||||
|
credits.push(item); // nothing to split
|
||||||
|
} else {
|
||||||
|
let new_items = [];
|
||||||
|
let n = 0;
|
||||||
|
for (let i = 0; i < splitted.length; i++) {
|
||||||
|
if (n && (splitted[i] == ' feat. ' || splitted[i] == ' vs. ')) {
|
||||||
|
new_items[n - 1].joinphrase = splitted[i];
|
||||||
|
} else {
|
||||||
|
new_items[n++] = {
|
||||||
|
artist_name: splitted[i].trim(),
|
||||||
|
joinphrase: ''
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
new_items[n - 1].joinphrase = item.joinphrase;
|
||||||
|
new_items.map(function(newit) {
|
||||||
|
credits.push(newit);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return credits;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to guess release type using number of tracks, title and total duration (in millisecs)
|
// Try to guess release type using number of tracks, title and total duration (in millisecs)
|
||||||
function fnGuessReleaseType(title, num_tracks, duration_ms) {
|
function fnGuessReleaseType(title, num_tracks, duration_ms) {
|
||||||
if (num_tracks < 1) return '';
|
if (num_tracks < 1) return '';
|
||||||
var has_single = !!title.match(/\bsingle\b/i);
|
let has_single = !!title.match(/\bsingle\b/i);
|
||||||
var has_EP = !!title.match(/\bEP\b/i);
|
let has_EP = !!title.match(/\bEP\b/i);
|
||||||
if (has_single && has_EP) {
|
if (has_single && has_EP) {
|
||||||
has_single = false;
|
has_single = false;
|
||||||
has_EP = false;
|
has_EP = false;
|
||||||
}
|
}
|
||||||
var perhaps_single = ((has_single && num_tracks <= 4) || num_tracks <= 2);
|
let perhaps_single = (has_single && num_tracks <= 4) || num_tracks <= 2;
|
||||||
var perhaps_EP = has_EP || (num_tracks > 2 && num_tracks <= 6);
|
let perhaps_EP = has_EP || (num_tracks > 2 && num_tracks <= 6);
|
||||||
var perhaps_album = (num_tracks > 8);
|
let perhaps_album = num_tracks > 8;
|
||||||
if (isNaN(duration_ms)) {
|
if (isNaN(duration_ms)) {
|
||||||
// no duration, try to guess with title and number of tracks
|
// no duration, try to guess with title and number of tracks
|
||||||
if (perhaps_single && !perhaps_EP && !perhaps_album) return 'single';
|
if (perhaps_single && !perhaps_EP && !perhaps_album) return 'single';
|
||||||
if (!perhaps_single && perhaps_EP && !perhaps_album) return 'EP';
|
if (!perhaps_single && perhaps_EP && !perhaps_album) return 'EP';
|
||||||
if (!perhaps_single && !perhaps_EP && perhaps_album) return 'album';
|
if (!perhaps_single && !perhaps_EP && perhaps_album) return 'album';
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
let duration_mn = duration_ms / (60 * 1000);
|
||||||
|
if (perhaps_single && duration_mn >= 1 && duration_mn < 7) return 'single';
|
||||||
|
if (perhaps_EP && duration_mn > 7 && duration_mn <= 30) return 'EP';
|
||||||
|
if (perhaps_album && duration_mn > 30) return 'album';
|
||||||
return '';
|
return '';
|
||||||
}
|
|
||||||
var duration_mn = duration_ms / (60*1000);
|
|
||||||
if (perhaps_single && duration_mn >= 1 && duration_mn < 7) return 'single';
|
|
||||||
if (perhaps_EP && duration_mn > 7 && duration_mn <= 30) return 'EP';
|
|
||||||
if (perhaps_album && duration_mn > 30) return 'album';
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert HH:MM:SS or MM:SS to milliseconds
|
// convert HH:MM:SS or MM:SS to milliseconds
|
||||||
function hmsToMilliSeconds(str) {
|
function hmsToMilliSeconds(str) {
|
||||||
if (typeof str == 'undefined' || str === null || str === NaN || str === '') return NaN;
|
if (typeof str == 'undefined' || str === null || str === NaN || str === '') return NaN;
|
||||||
if (typeof str == 'number') return str;
|
if (typeof str == 'number') return str;
|
||||||
var t = str.split(':');
|
let t = str.split(':');
|
||||||
var s = 0;
|
let s = 0;
|
||||||
var m = 1;
|
let m = 1;
|
||||||
while (t.length > 0) {
|
while (t.length > 0) {
|
||||||
s += m * parseInt(t.pop(), 10);
|
s += m * parseInt(t.pop(), 10);
|
||||||
m *= 60;
|
m *= 60;
|
||||||
}
|
}
|
||||||
return s*1000;
|
return s * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert ISO8601 duration (limited to hours/minutes/seconds) to milliseconds
|
// convert ISO8601 duration (limited to hours/minutes/seconds) to milliseconds
|
||||||
// format looks like PT1H45M5.789S (note: floats can be used)
|
// format looks like PT1H45M5.789S (note: floats can be used)
|
||||||
// https://en.wikipedia.org/wiki/ISO_8601#Durations
|
// https://en.wikipedia.org/wiki/ISO_8601#Durations
|
||||||
function fnISO8601toMilliSeconds(str) {
|
function fnISO8601toMilliSeconds(str) {
|
||||||
var regex = /^PT(?:(\d*\.?\d*)H)?(?:(\d*\.?\d*)M)?(?:(\d*\.?\d*)S)?$/,
|
let regex = /^PT(?:(\d*\.?\d*)H)?(?:(\d*\.?\d*)M)?(?:(\d*\.?\d*)S)?$/,
|
||||||
m = str.replace(',', '.').match(regex);
|
m = str.replace(',', '.').match(regex);
|
||||||
if (!m) return NaN;
|
if (!m) return NaN;
|
||||||
return (3600 * parseFloat(m[1] || 0) + 60 * parseFloat(m[2] || 0) + parseFloat(m[3] || 0)) * 1000;
|
return (3600 * parseFloat(m[1] || 0) + 60 * parseFloat(m[2] || 0) + parseFloat(m[3] || 0)) * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
function fnMakeEditNote(release_url, importer_name, format) {
|
function fnMakeEditNote(release_url, importer_name, format) {
|
||||||
var home = 'https://github.com/murdos/musicbrainz-userscripts';
|
let home = 'https://github.com/murdos/musicbrainz-userscripts';
|
||||||
return 'Imported from ' + release_url + (format ? ' (' + format + ')' : '') +' using ' + importer_name + ' import script from ' + home;
|
return `Imported from ${release_url}${format ? ` (${format})` : ''} using ${importer_name} import script from ${home}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------- privates ----------------------------------------- //
|
// --------------------------------------- privates ----------------------------------------- //
|
||||||
|
|
||||||
function appendParameter(parameters, paramName, paramValue) {
|
function appendParameter(parameters, paramName, paramValue) {
|
||||||
if(!paramValue) return;
|
if (!paramValue) return;
|
||||||
parameters.push( { name: paramName, value: paramValue } );
|
parameters.push({ name: paramName, value: paramValue });
|
||||||
}
|
}
|
||||||
|
|
||||||
function luceneEscape(text) {
|
function luceneEscape(text) {
|
||||||
var newtext = text.replace(/[-[\]{}()*+?~:\\^!"\/]/g, "\\$&");
|
let newtext = text.replace(/[-[\]{}()*+?~:\\^!"\/]/g, '\\$&');
|
||||||
return newtext.replace("&&", "\&&").replace("||", "\||");
|
return newtext.replace('&&', '&&').replace('||', '||');
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildArtistCreditsFormParameters(parameters, paramPrefix, artist_credit) {
|
function buildArtistCreditsFormParameters(parameters, paramPrefix, artist_credit) {
|
||||||
if(!artist_credit) return;
|
if (!artist_credit) return;
|
||||||
for (var i=0; i < artist_credit.length; i++) {
|
for (let i = 0; i < artist_credit.length; i++) {
|
||||||
var ac = artist_credit[i];
|
let ac = artist_credit[i];
|
||||||
appendParameter(parameters, paramPrefix+'artist_credit.names.'+i+'.name', ac.credited_name);
|
appendParameter(parameters, `${paramPrefix}artist_credit.names.${i}.name`, ac.credited_name);
|
||||||
appendParameter(parameters, paramPrefix+'artist_credit.names.'+i+'.artist.name', ac.artist_name);
|
appendParameter(parameters, `${paramPrefix}artist_credit.names.${i}.artist.name`, ac.artist_name);
|
||||||
appendParameter(parameters, paramPrefix+'artist_credit.names.'+i+'.mbid', ac.mbid);
|
appendParameter(parameters, `${paramPrefix}artist_credit.names.${i}.mbid`, ac.mbid);
|
||||||
if (typeof ac.joinphrase != 'undefined' && ac.joinphrase != "") {
|
if (typeof ac.joinphrase != 'undefined' && ac.joinphrase != '') {
|
||||||
appendParameter(parameters, paramPrefix+'artist_credit.names.'+i+'.join_phrase', ac.joinphrase);
|
appendParameter(parameters, `${paramPrefix}artist_credit.names.${i}.join_phrase`, ac.joinphrase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchParams(release) {
|
function searchParams(release) {
|
||||||
var params = [];
|
let params = [];
|
||||||
|
|
||||||
var totaltracks = 0;
|
let totaltracks = 0;
|
||||||
for (var i=0; i < release.discs.length; i++) {
|
for (var i = 0; i < release.discs.length; i++) {
|
||||||
totaltracks += release.discs[i].tracks.length;
|
totaltracks += release.discs[i].tracks.length;
|
||||||
}
|
}
|
||||||
var release_artist = "";
|
let release_artist = '';
|
||||||
for (var i=0; i < release.artist_credit.length; i++) {
|
for (var i = 0; i < release.artist_credit.length; i++) {
|
||||||
var ac = release.artist_credit[i];
|
let ac = release.artist_credit[i];
|
||||||
release_artist += ac.artist_name;
|
release_artist += ac.artist_name;
|
||||||
if (typeof ac.joinphrase != 'undefined' && ac.joinphrase != "") {
|
if (typeof ac.joinphrase != 'undefined' && ac.joinphrase != '') {
|
||||||
release_artist += ac.joinphrase;
|
release_artist += ac.joinphrase;
|
||||||
} else {
|
} else {
|
||||||
if (i != release.artist_credit.length-1) release_artist += ", ";
|
if (i != release.artist_credit.length - 1) release_artist += ', ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var query = 'artist:(' + luceneEscape(release_artist) + ')'
|
let query =
|
||||||
+ ' release:(' + luceneEscape(release.title) + ')'
|
`artist:(${luceneEscape(release_artist)})` +
|
||||||
+ ' tracks:(' + totaltracks + ')'
|
` release:(${luceneEscape(release.title)})` +
|
||||||
+ (release.country ? ' country:' + release.country : '');
|
` tracks:(${totaltracks})${release.country ? ` country:${release.country}` : ''}`;
|
||||||
|
|
||||||
appendParameter(params, 'query', query);
|
appendParameter(params, 'query', query);
|
||||||
appendParameter(params, 'type', 'release');
|
appendParameter(params, 'type', 'release');
|
||||||
|
@ -395,18 +402,18 @@ var MBImport = (function() {
|
||||||
// ---------------------------------- expose publics here ------------------------------------ //
|
// ---------------------------------- expose publics here ------------------------------------ //
|
||||||
|
|
||||||
return {
|
return {
|
||||||
buildSearchLink: fnBuildSearchLink,
|
buildSearchLink: fnBuildSearchLink,
|
||||||
buildSearchButton: fnBuildSearchButton,
|
buildSearchButton: fnBuildSearchButton,
|
||||||
buildFormHTML: fnBuildFormHTML,
|
buildFormHTML: fnBuildFormHTML,
|
||||||
buildFormParameters: fnBuildFormParameters,
|
buildFormParameters: fnBuildFormParameters,
|
||||||
makeArtistCredits: fnArtistCredits,
|
makeArtistCredits: fnArtistCredits,
|
||||||
guessReleaseType: fnGuessReleaseType,
|
guessReleaseType: fnGuessReleaseType,
|
||||||
hmsToMilliSeconds: hmsToMilliSeconds,
|
hmsToMilliSeconds: hmsToMilliSeconds,
|
||||||
ISO8601toMilliSeconds: fnISO8601toMilliSeconds,
|
ISO8601toMilliSeconds: fnISO8601toMilliSeconds,
|
||||||
makeEditNote: fnMakeEditNote,
|
makeEditNote: fnMakeEditNote,
|
||||||
searchUrlFor: fnSearchUrlFor,
|
searchUrlFor: fnSearchUrlFor,
|
||||||
URL_TYPES: url_types,
|
URL_TYPES: url_types,
|
||||||
SPECIAL_ARTISTS: special_artists,
|
SPECIAL_ARTISTS: special_artists,
|
||||||
specialArtist: fnSpecialArtist
|
specialArtist: fnSpecialArtist
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
function _add_css(css) {
|
function _add_css(css) {
|
||||||
$("<style type='text/css'>"+css.replace(/\s+/g, ' ') + "</style>").appendTo("head");
|
$(`<style type='text/css'>${css.replace(/\s+/g, ' ')}</style>`).appendTo('head');
|
||||||
}
|
}
|
||||||
|
|
||||||
function MBImportStyle() {
|
function MBImportStyle() {
|
||||||
var css_import_button = " \
|
let css_import_button =
|
||||||
|
' \
|
||||||
.musicbrainz_import button { \
|
.musicbrainz_import button { \
|
||||||
-moz-border-radius:5px; \
|
-moz-border-radius:5px; \
|
||||||
-webkit-border-radius:5px; \
|
-webkit-border-radius:5px; \
|
||||||
|
@ -34,12 +35,13 @@ function MBImportStyle() {
|
||||||
min-height: 16px; \
|
min-height: 16px; \
|
||||||
display: inline-block; \
|
display: inline-block; \
|
||||||
} \
|
} \
|
||||||
";
|
';
|
||||||
_add_css(css_import_button);
|
_add_css(css_import_button);
|
||||||
}
|
}
|
||||||
|
|
||||||
function MBSearchItStyle() {
|
function MBSearchItStyle() {
|
||||||
var css_search_it = " \
|
let css_search_it =
|
||||||
|
' \
|
||||||
.mb_valign { \
|
.mb_valign { \
|
||||||
display: inline-block; \
|
display: inline-block; \
|
||||||
vertical-align: top; \
|
vertical-align: top; \
|
||||||
|
@ -68,6 +70,6 @@ function MBSearchItStyle() {
|
||||||
.mb_wrapper { \
|
.mb_wrapper { \
|
||||||
display: inline-block; \
|
display: inline-block; \
|
||||||
} \
|
} \
|
||||||
";
|
';
|
||||||
_add_css(css_search_it);
|
_add_css(css_search_it);
|
||||||
}
|
}
|
||||||
|
|
429
lib/mblinks.js
429
lib/mblinks.js
|
@ -16,222 +16,227 @@
|
||||||
// user_cache_key = textual key used to store cached data in local storage
|
// user_cache_key = textual key used to store cached data in local storage
|
||||||
// version = optionnal version, to force creation of a cache (ie. when format of keys changes)
|
// version = optionnal version, to force creation of a cache (ie. when format of keys changes)
|
||||||
// expiration = time in minutes before an entry is refreshed, value <= 0 disables cache reads, if undefined or false, use defaults
|
// expiration = time in minutes before an entry is refreshed, value <= 0 disables cache reads, if undefined or false, use defaults
|
||||||
var MBLinks = function (user_cache_key, version, expiration) {
|
var MBLinks = function(user_cache_key, version, expiration) {
|
||||||
this.supports_local_storage = function () {
|
this.supports_local_storage = (function() {
|
||||||
try {
|
try {
|
||||||
return !!localStorage.getItem;
|
return !!localStorage.getItem;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}();
|
|
||||||
|
|
||||||
this.ajax_requests = {
|
|
||||||
// properties: "key": {handler: function, next: property, context: {}}
|
|
||||||
first: "",
|
|
||||||
last: "",
|
|
||||||
empty: function() {return this.first == "";},
|
|
||||||
push: function(key, handler, context) {
|
|
||||||
if (key in this) {
|
|
||||||
this[key].handler = handler;
|
|
||||||
this[key].context = context;
|
|
||||||
}
|
}
|
||||||
else {
|
})();
|
||||||
this[key] = {handler: handler, next: "", context: context};
|
|
||||||
if (this.first == "") {
|
|
||||||
this.first = this.last = key;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this[this.last].next = key;
|
|
||||||
this.last = key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
shift: function() {
|
|
||||||
if (this.empty()) { return; }
|
|
||||||
var key = this.first;
|
|
||||||
var handler = this[key].handler;
|
|
||||||
var context = this[key].context;
|
|
||||||
this.first = this[key].next;
|
|
||||||
delete this[key]; // delete this property
|
|
||||||
return $.proxy(handler, context);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.cache = {};
|
|
||||||
this.expirationMinutes = ((typeof expiration != 'undefined' && expiration !== false) ? parseInt(expiration, 10) : 90*24*60); // default to 90 days
|
|
||||||
var cache_version = 2;
|
|
||||||
this.user_cache_key = user_cache_key;
|
|
||||||
this.cache_key = this.user_cache_key + '-v' + cache_version + (typeof version != 'undefined' ? '.' + version : '');
|
|
||||||
this.mb_server = '//musicbrainz.org';
|
|
||||||
// overrides link title and img src url (per type), see createMusicBrainzLink()
|
|
||||||
this.type_link_info = {
|
|
||||||
release_group: {
|
|
||||||
title: 'See this release group on MusicBrainz',
|
|
||||||
},
|
|
||||||
place: {
|
|
||||||
img_src: '<img src="'+ this.mb_server + '/static/images/entity/place.svg" height=16 width=16 />'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.initAjaxEngine = function () {
|
this.ajax_requests = {
|
||||||
var ajax_requests = this.ajax_requests;
|
// properties: "key": {handler: function, next: property, context: {}}
|
||||||
setInterval(function () {
|
first: '',
|
||||||
if (!ajax_requests.empty()) {
|
last: '',
|
||||||
var request = ajax_requests.shift();
|
empty: function() {
|
||||||
if (typeof request === "function") {
|
return this.first == '';
|
||||||
request();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
};
|
|
||||||
|
|
||||||
this.initCache = function () {
|
|
||||||
if (!this.supports_local_storage) return;
|
|
||||||
// Check if we already added links for this content
|
|
||||||
this.cache = JSON.parse(localStorage.getItem(this.cache_key) || '{}');
|
|
||||||
// remove old entries
|
|
||||||
this.clearCacheExpired();
|
|
||||||
// remove old cache versions
|
|
||||||
this.removeOldCacheVersions();
|
|
||||||
};
|
|
||||||
|
|
||||||
this.saveCache = function () {
|
|
||||||
if (!this.supports_local_storage) return;
|
|
||||||
try {
|
|
||||||
localStorage.setItem(this.cache_key, JSON.stringify(this.cache));
|
|
||||||
} catch (e) {
|
|
||||||
alert(e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.removeOldCacheVersions = function () {
|
|
||||||
var to_remove = [];
|
|
||||||
for (var i = 0, len = localStorage.length; i < len; ++i) {
|
|
||||||
var key = localStorage.key(i);
|
|
||||||
if (key.indexOf(this.user_cache_key) === 0) {
|
|
||||||
if (key != this.cache_key) { // we don't want to remove current cache
|
|
||||||
to_remove.push(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// remove old cache keys
|
|
||||||
for (var i = 0; i < to_remove.length; i++) {
|
|
||||||
localStorage.removeItem(to_remove[i]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.clearCacheExpired = function() {
|
|
||||||
//var old_cache_entries = Object.keys(this.cache).length;
|
|
||||||
//console.log("clearCacheExpired " + old_cache_entries);
|
|
||||||
var now = new Date().getTime();
|
|
||||||
var new_cache = {};
|
|
||||||
var that = this;
|
|
||||||
$.each(this.cache, function (key, value) {
|
|
||||||
if (that.is_cached(key)) {
|
|
||||||
new_cache[key] = that.cache[key];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
//var new_cache_entries = Object.keys(new_cache).length;
|
|
||||||
//console.log("Cleared cache entries: " + old_cache_entries + ' -> ' + new_cache_entries);
|
|
||||||
this.cache = new_cache;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.is_cached = function (key) {
|
|
||||||
return (this.cache[key] && this.expirationMinutes > 0 && new Date().getTime() < this.cache[key].timestamp + this.expirationMinutes*60*1000);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Search for ressource 'url' in local cache, and return the matching MBID if there's only matching MB entity.
|
|
||||||
// If the url is not known by the cache, no attempt will be made to request the MusicBrainz webservice, in order to keep this method synchronous.
|
|
||||||
this.resolveMBID = function (key) {
|
|
||||||
if (this.is_cached(key) && this.cache[key].urls.length == 1) {
|
|
||||||
return this.cache[key].urls[0].slice(-36);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.createMusicBrainzLink = function (mb_url, _type) {
|
|
||||||
var title = 'See this ' + _type + ' on MusicBrainz';
|
|
||||||
var img_url = this.mb_server + '/static/images/entity/' + _type + '.svg';
|
|
||||||
var img_src = '<img src="' + img_url + '" height=16 width=16 />';
|
|
||||||
// handle overrides
|
|
||||||
var ti = this.type_link_info[_type];
|
|
||||||
if (ti) {
|
|
||||||
if (ti.title) title = ti.title;
|
|
||||||
if (ti.img_url) img_url = ti.img_url;
|
|
||||||
if (ti.img_src) img_src = ti.img_src;
|
|
||||||
}
|
|
||||||
return '<a href="' + mb_url + '" title="' + title + '">' + img_src + '</a> ';
|
|
||||||
};
|
|
||||||
|
|
||||||
// Search for ressource 'url' on MB, for relation of type 'mb_type' (artist, release, label, release-group, ...)
|
|
||||||
// and call 'insert_func' function with matching MB links (a tag built in createMusicBrainzLink) for each
|
|
||||||
// entry found
|
|
||||||
this.searchAndDisplayMbLink = function (url, mb_type, insert_func, key) {
|
|
||||||
var mblinks = this;
|
|
||||||
var _type = mb_type.replace('-', '_'); // underscored type
|
|
||||||
|
|
||||||
if (!key) key = url;
|
|
||||||
if (this.is_cached(key)) {
|
|
||||||
$.each(mblinks.cache[key].urls, function (idx, mb_url) {
|
|
||||||
insert_func(mblinks.createMusicBrainzLink(mb_url, _type));
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// webservice query url
|
|
||||||
var query = mblinks.mb_server + '/ws/2/url?resource=' + encodeURIComponent(url) + '&inc=' + mb_type + '-rels';
|
|
||||||
|
|
||||||
// Merge with previous context if there's already a pending ajax request
|
|
||||||
var handlers = [];
|
|
||||||
if (query in mblinks.ajax_requests) {
|
|
||||||
handlers = mblinks.ajax_requests[query].context.handlers;
|
|
||||||
}
|
|
||||||
handlers.push(insert_func);
|
|
||||||
|
|
||||||
mblinks.ajax_requests.push(
|
|
||||||
// key
|
|
||||||
query,
|
|
||||||
|
|
||||||
// handler
|
|
||||||
function () {
|
|
||||||
var ctx = this; // context from $.proxy()
|
|
||||||
var mbl = ctx.mblinks;
|
|
||||||
$.getJSON(ctx.query,
|
|
||||||
function (data) {
|
|
||||||
if ('relations' in data) {
|
|
||||||
mbl.cache[ctx.key] = {
|
|
||||||
timestamp: new Date().getTime(),
|
|
||||||
urls: []
|
|
||||||
};
|
|
||||||
$.each(data['relations'], function (idx, relation) {
|
|
||||||
if (ctx._type in relation) {
|
|
||||||
var mb_url = mbl.mb_server + '/' + ctx.mb_type + '/' + relation[ctx._type]['id'];
|
|
||||||
if ($.inArray(mb_url, mbl.cache[ctx.key].urls) == -1) { // prevent dupes
|
|
||||||
mbl.cache[ctx.key].urls.push(mb_url);
|
|
||||||
$.each(ctx.handlers, function(i, handler) {
|
|
||||||
handler(mbl.createMusicBrainzLink(mb_url, ctx._type))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
mbl.saveCache();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
push: function(key, handler, context) {
|
||||||
// context
|
if (key in this) {
|
||||||
{
|
this[key].handler = handler;
|
||||||
'key': key, // cache key
|
this[key].context = context;
|
||||||
'handlers': handlers, // list of handlers
|
} else {
|
||||||
'mb_type': mb_type, // musicbrainz type ie. release-group
|
this[key] = { handler: handler, next: '', context: context };
|
||||||
'_type': _type, // musicbrainz type '-' replaced, ie. release_group
|
if (this.first == '') {
|
||||||
'query': query, // json request url
|
this.first = this.last = key;
|
||||||
'mblinks': mblinks // MBLinks object
|
} else {
|
||||||
|
this[this.last].next = key;
|
||||||
|
this.last = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
shift: function() {
|
||||||
|
if (this.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let key = this.first;
|
||||||
|
let handler = this[key].handler;
|
||||||
|
let context = this[key].context;
|
||||||
|
this.first = this[key].next;
|
||||||
|
delete this[key]; // delete this property
|
||||||
|
return $.proxy(handler, context);
|
||||||
}
|
}
|
||||||
);
|
};
|
||||||
}
|
this.cache = {};
|
||||||
};
|
this.expirationMinutes = typeof expiration != 'undefined' && expiration !== false ? parseInt(expiration, 10) : 90 * 24 * 60; // default to 90 days
|
||||||
|
let cache_version = 2;
|
||||||
|
this.user_cache_key = user_cache_key;
|
||||||
|
this.cache_key = `${this.user_cache_key}-v${cache_version}${typeof version != 'undefined' ? `.${version}` : ''}`;
|
||||||
|
this.mb_server = '//musicbrainz.org';
|
||||||
|
// overrides link title and img src url (per type), see createMusicBrainzLink()
|
||||||
|
this.type_link_info = {
|
||||||
|
release_group: {
|
||||||
|
title: 'See this release group on MusicBrainz'
|
||||||
|
},
|
||||||
|
place: {
|
||||||
|
img_src: `<img src="${this.mb_server}/static/images/entity/place.svg" height=16 width=16 />`
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.initCache();
|
this.initAjaxEngine = function() {
|
||||||
this.initAjaxEngine();
|
let ajax_requests = this.ajax_requests;
|
||||||
|
setInterval(function() {
|
||||||
|
if (!ajax_requests.empty()) {
|
||||||
|
let request = ajax_requests.shift();
|
||||||
|
if (typeof request === 'function') {
|
||||||
|
request();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
};
|
||||||
|
|
||||||
return this;
|
this.initCache = function() {
|
||||||
|
if (!this.supports_local_storage) return;
|
||||||
|
// Check if we already added links for this content
|
||||||
|
this.cache = JSON.parse(localStorage.getItem(this.cache_key) || '{}');
|
||||||
|
// remove old entries
|
||||||
|
this.clearCacheExpired();
|
||||||
|
// remove old cache versions
|
||||||
|
this.removeOldCacheVersions();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.saveCache = function() {
|
||||||
|
if (!this.supports_local_storage) return;
|
||||||
|
try {
|
||||||
|
localStorage.setItem(this.cache_key, JSON.stringify(this.cache));
|
||||||
|
} catch (e) {
|
||||||
|
alert(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.removeOldCacheVersions = function() {
|
||||||
|
let to_remove = [];
|
||||||
|
for (var i = 0, len = localStorage.length; i < len; ++i) {
|
||||||
|
let key = localStorage.key(i);
|
||||||
|
if (key.indexOf(this.user_cache_key) === 0) {
|
||||||
|
if (key != this.cache_key) {
|
||||||
|
// we don't want to remove current cache
|
||||||
|
to_remove.push(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// remove old cache keys
|
||||||
|
for (var i = 0; i < to_remove.length; i++) {
|
||||||
|
localStorage.removeItem(to_remove[i]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.clearCacheExpired = function() {
|
||||||
|
//var old_cache_entries = Object.keys(this.cache).length;
|
||||||
|
//console.log("clearCacheExpired " + old_cache_entries);
|
||||||
|
let now = new Date().getTime();
|
||||||
|
let new_cache = {};
|
||||||
|
let that = this;
|
||||||
|
$.each(this.cache, function(key, value) {
|
||||||
|
if (that.is_cached(key)) {
|
||||||
|
new_cache[key] = that.cache[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//var new_cache_entries = Object.keys(new_cache).length;
|
||||||
|
//console.log("Cleared cache entries: " + old_cache_entries + ' -> ' + new_cache_entries);
|
||||||
|
this.cache = new_cache;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.is_cached = function(key) {
|
||||||
|
return (
|
||||||
|
this.cache[key] &&
|
||||||
|
this.expirationMinutes > 0 &&
|
||||||
|
new Date().getTime() < this.cache[key].timestamp + this.expirationMinutes * 60 * 1000
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Search for ressource 'url' in local cache, and return the matching MBID if there's only matching MB entity.
|
||||||
|
// If the url is not known by the cache, no attempt will be made to request the MusicBrainz webservice, in order to keep this method synchronous.
|
||||||
|
this.resolveMBID = function(key) {
|
||||||
|
if (this.is_cached(key) && this.cache[key].urls.length == 1) {
|
||||||
|
return this.cache[key].urls[0].slice(-36);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.createMusicBrainzLink = function(mb_url, _type) {
|
||||||
|
let title = `See this ${_type} on MusicBrainz`;
|
||||||
|
let img_url = `${this.mb_server}/static/images/entity/${_type}.svg`;
|
||||||
|
let img_src = `<img src="${img_url}" height=16 width=16 />`;
|
||||||
|
// handle overrides
|
||||||
|
let ti = this.type_link_info[_type];
|
||||||
|
if (ti) {
|
||||||
|
if (ti.title) title = ti.title;
|
||||||
|
if (ti.img_url) img_url = ti.img_url;
|
||||||
|
if (ti.img_src) img_src = ti.img_src;
|
||||||
|
}
|
||||||
|
return `<a href="${mb_url}" title="${title}">${img_src}</a> `;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Search for ressource 'url' on MB, for relation of type 'mb_type' (artist, release, label, release-group, ...)
|
||||||
|
// and call 'insert_func' function with matching MB links (a tag built in createMusicBrainzLink) for each
|
||||||
|
// entry found
|
||||||
|
this.searchAndDisplayMbLink = function(url, mb_type, insert_func, key) {
|
||||||
|
let mblinks = this;
|
||||||
|
let _type = mb_type.replace('-', '_'); // underscored type
|
||||||
|
|
||||||
|
if (!key) key = url;
|
||||||
|
if (this.is_cached(key)) {
|
||||||
|
$.each(mblinks.cache[key].urls, function(idx, mb_url) {
|
||||||
|
insert_func(mblinks.createMusicBrainzLink(mb_url, _type));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// webservice query url
|
||||||
|
let query = `${mblinks.mb_server}/ws/2/url?resource=${encodeURIComponent(url)}&inc=${mb_type}-rels`;
|
||||||
|
|
||||||
|
// Merge with previous context if there's already a pending ajax request
|
||||||
|
let handlers = [];
|
||||||
|
if (query in mblinks.ajax_requests) {
|
||||||
|
handlers = mblinks.ajax_requests[query].context.handlers;
|
||||||
|
}
|
||||||
|
handlers.push(insert_func);
|
||||||
|
|
||||||
|
mblinks.ajax_requests.push(
|
||||||
|
// key
|
||||||
|
query,
|
||||||
|
|
||||||
|
// handler
|
||||||
|
function() {
|
||||||
|
let ctx = this; // context from $.proxy()
|
||||||
|
let mbl = ctx.mblinks;
|
||||||
|
$.getJSON(ctx.query, function(data) {
|
||||||
|
if ('relations' in data) {
|
||||||
|
mbl.cache[ctx.key] = {
|
||||||
|
timestamp: new Date().getTime(),
|
||||||
|
urls: []
|
||||||
|
};
|
||||||
|
$.each(data['relations'], function(idx, relation) {
|
||||||
|
if (ctx._type in relation) {
|
||||||
|
let mb_url = `${mbl.mb_server}/${ctx.mb_type}/${relation[ctx._type]['id']}`;
|
||||||
|
if ($.inArray(mb_url, mbl.cache[ctx.key].urls) == -1) {
|
||||||
|
// prevent dupes
|
||||||
|
mbl.cache[ctx.key].urls.push(mb_url);
|
||||||
|
$.each(ctx.handlers, function(i, handler) {
|
||||||
|
handler(mbl.createMusicBrainzLink(mb_url, ctx._type));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mbl.saveCache();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// context
|
||||||
|
{
|
||||||
|
key: key, // cache key
|
||||||
|
handlers: handlers, // list of handlers
|
||||||
|
mb_type: mb_type, // musicbrainz type ie. release-group
|
||||||
|
_type: _type, // musicbrainz type '-' replaced, ie. release_group
|
||||||
|
query: query, // json request url
|
||||||
|
mblinks: mblinks // MBLinks object
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.initCache();
|
||||||
|
this.initAjaxEngine();
|
||||||
|
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -23,166 +23,193 @@ this.$ = this.jQuery = jQuery.noConflict(true);
|
||||||
|
|
||||||
LOGGER.setLevel('info');
|
LOGGER.setLevel('info');
|
||||||
|
|
||||||
var CHECK_IMAGE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/gD+AP7rGNSCAAAACXBIWXMAAABIAAAASABGyWs+AAAACXZwQWcAAAAQAAAAEABcxq3DAAADKklEQVQ4y32TS2hcZRiGn/8/Z87MNNc2zczEmptO0jSXagJtXCjWhhSEXpCI4EYENy6KG8FFBYtgEbzQ4k5QqNp2VyMtJVGpRU0tGDNoQxvrmCbkMslkSJrJXM6cOef8v4ukQqX4wbP5eL/327wv/M/Em+qNeFO9ASDEwzUPrM+fP8dqOhXqeGJ/f21ddCAYCsfRyFLJvru2mvnh9mTil8am1uJLQ8ceNOhoa+XC8HfMJm81x1q63glV179oBMLVhpQYEiQKzy0VNtZWLs9OT53s6X3qrxPHX+bSyNVNgyujV8lvrDXG2vZ/7oWig64nAY0hwZCCgIRwUGBJRSGbvp6cHH91R33078ODTyNOnXqPxcRl88ibX5wuBJuP5x2BVhop2PwuBA01kn2tJo4HtxfL5DIzZ7+/8MHrOx7tcMQ3I9dwnWKvF+kfTdlVEc/10f59A0HAgMEui90xgxvTLn8u+9SYhXUnNX60smr7z7Jx3wG8UOSZhUI4spJTrGwo0lssZxVSQlOdZGrJYyzpks4qlvLBWhWMHOgb7Mfsq4PfXOvx+bwgk/WxSwrfUwRNQSgAh7oCFB3N1xNllrMK04A5V7PLMOOvCSFMgFzJl6u2Jl8Gx9XkCppSWdEWNWiPGZy9XmIs6WJKKHuasq+p3qlkOwhz9B54dnbOkorOR0yG9gZJ3fP5cNTm4J4Akws+FyfKOK5GCFAatm/T4ObmB7RWxt74k9hrC0LVtLwwmw2FwyY8323hK2iLGnz2U4lMTiHvR04IGiqLxbrS7x/np3NJozoEmcTFTLTz2U7bivTcXNSsFxWHeyyGE2XGZ7x/j7WGyhA0W3e/LU58eiY1N+0IgLc++or1VLLb6hz6MmPGe/M2NFTBzIpH3lYoX6MQhC1NkzV/p2Jp5JX6eP+vn7wxsJnEXXUVnL6T59K7J/u2tR96365oey7nVQTKnsDzNFr5hETBq3ZmbrB47cS5M2+PdTbHmJpL89+OGbv3dLc81n/kWLih+yDhnTGtEcpeXXHSUz/OJ64M3/ojMS3BUw9rI2BsIUxBsLYyEJYC1nNuqawpARrwtwDgHxTwbTT5CxY9AAAALnpUWHRjcmVhdGUtZGF0ZQAAeNozMjCw0DWw0DUyCTEwsDIyszIw0jUwtTIwAABB3gURQfNnBAAAAC56VFh0bW9kaWZ5LWRhdGUAAHjaMzIwsNA1sNA1MggxNLMyNLYyNtM1MLUyMAAAQgUFF56jVzIAAAAASUVORK5CYII%3D";
|
var CHECK_IMAGE =
|
||||||
|
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/gD+AP7rGNSCAAAACXBIWXMAAABIAAAASABGyWs+AAAACXZwQWcAAAAQAAAAEABcxq3DAAADKklEQVQ4y32TS2hcZRiGn/8/Z87MNNc2zczEmptO0jSXagJtXCjWhhSEXpCI4EYENy6KG8FFBYtgEbzQ4k5QqNp2VyMtJVGpRU0tGDNoQxvrmCbkMslkSJrJXM6cOef8v4ukQqX4wbP5eL/327wv/M/Em+qNeFO9ASDEwzUPrM+fP8dqOhXqeGJ/f21ddCAYCsfRyFLJvru2mvnh9mTil8am1uJLQ8ceNOhoa+XC8HfMJm81x1q63glV179oBMLVhpQYEiQKzy0VNtZWLs9OT53s6X3qrxPHX+bSyNVNgyujV8lvrDXG2vZ/7oWig64nAY0hwZCCgIRwUGBJRSGbvp6cHH91R33078ODTyNOnXqPxcRl88ibX5wuBJuP5x2BVhop2PwuBA01kn2tJo4HtxfL5DIzZ7+/8MHrOx7tcMQ3I9dwnWKvF+kfTdlVEc/10f59A0HAgMEui90xgxvTLn8u+9SYhXUnNX60smr7z7Jx3wG8UOSZhUI4spJTrGwo0lssZxVSQlOdZGrJYyzpks4qlvLBWhWMHOgb7Mfsq4PfXOvx+bwgk/WxSwrfUwRNQSgAh7oCFB3N1xNllrMK04A5V7PLMOOvCSFMgFzJl6u2Jl8Gx9XkCppSWdEWNWiPGZy9XmIs6WJKKHuasq+p3qlkOwhz9B54dnbOkorOR0yG9gZJ3fP5cNTm4J4Akws+FyfKOK5GCFAatm/T4ObmB7RWxt74k9hrC0LVtLwwmw2FwyY8323hK2iLGnz2U4lMTiHvR04IGiqLxbrS7x/np3NJozoEmcTFTLTz2U7bivTcXNSsFxWHeyyGE2XGZ7x/j7WGyhA0W3e/LU58eiY1N+0IgLc++or1VLLb6hz6MmPGe/M2NFTBzIpH3lYoX6MQhC1NkzV/p2Jp5JX6eP+vn7wxsJnEXXUVnL6T59K7J/u2tR96365oey7nVQTKnsDzNFr5hETBq3ZmbrB47cS5M2+PdTbHmJpL89+OGbv3dLc81n/kWLih+yDhnTGtEcpeXXHSUz/OJ64M3/ojMS3BUw9rI2BsIUxBsLYyEJYC1nNuqawpARrwtwDgHxTwbTT5CxY9AAAALnpUWHRjcmVhdGUtZGF0ZQAAeNozMjCw0DWw0DUyCTEwsDIyszIw0jUwtTIwAABB3gURQfNnBAAAAC56VFh0bW9kaWZ5LWRhdGUAAHjaMzIwsNA1sNA1MggxNLMyNLYyNtM1MLUyMAAAQgUFF56jVzIAAAAASUVORK5CYII%3D';
|
||||||
$(document).ready(function () {
|
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
if (window.location.host.match(/apollo\.rip|redacted\.ch|passtheheadphones\.me|lztr\.(us|me)|mutracker\.org|notwhat\.cd/)) {
|
if (window.location.host.match(/apollo\.rip|redacted\.ch|passtheheadphones\.me|lztr\.(us|me)|mutracker\.org|notwhat\.cd/)) {
|
||||||
LOGGER.info("Gazelle site detected");
|
LOGGER.info('Gazelle site detected');
|
||||||
gazellePageHandler();
|
gazellePageHandler();
|
||||||
} else if (window.location.host.match(/avaxhome\.ws/)) {
|
} else if (window.location.host.match(/avaxhome\.ws/)) {
|
||||||
avaxHomePageHandler();
|
avaxHomePageHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function avaxHomePageHandler() {
|
function avaxHomePageHandler() {
|
||||||
|
|
||||||
// Find artist and release titles
|
// Find artist and release titles
|
||||||
var artistName = "";
|
let artistName = '';
|
||||||
var releaseName = "";
|
let releaseName = '';
|
||||||
var m = $('div.title h1').text().match(/(.*) (?:-|–) (.*)( \(\d{4}\))?/);
|
let m = $('div.title h1')
|
||||||
|
.text()
|
||||||
|
.match(/(.*) (?:-|–) (.*)( \(\d{4}\))?/);
|
||||||
if (m) {
|
if (m) {
|
||||||
artistName = m[1];
|
artistName = m[1];
|
||||||
releaseName = m[2];
|
releaseName = m[2];
|
||||||
}
|
}
|
||||||
if (artistName == "VA") artistName = "Various Artists";
|
if (artistName == 'VA') artistName = 'Various Artists';
|
||||||
|
|
||||||
// Find and analyze EAC log
|
// Find and analyze EAC log
|
||||||
$('div.spoiler').filter(function () {
|
$('div.spoiler')
|
||||||
return $(this).find('a').text().match(/(EAC|log)/i);
|
.filter(function() {
|
||||||
})
|
return $(this)
|
||||||
|
.find('a')
|
||||||
|
.text()
|
||||||
|
.match(/(EAC|log)/i);
|
||||||
|
})
|
||||||
.find('div')
|
.find('div')
|
||||||
.each(function () {
|
.each(function() {
|
||||||
|
let $eacLog = $(this);
|
||||||
var $eacLog = $(this);
|
let discs = analyze_log_files($eacLog);
|
||||||
var discs = analyze_log_files($eacLog);
|
|
||||||
|
|
||||||
// Check and display
|
// Check and display
|
||||||
check_and_display_discs(artistName, releaseName, discs,
|
check_and_display_discs(
|
||||||
function (mb_toc_numbers, discid, discNumber) {
|
artistName,
|
||||||
$eacLog.parents('div.spoiler').prevAll('div.center:first').append('<br /><strong>' + (discs.length > 1 ? 'Disc ' + discNumber + ': ' : '' ) + 'MB DiscId </strong><span id="' + discid + '" />');
|
releaseName,
|
||||||
|
discs,
|
||||||
|
function(mb_toc_numbers, discid, discNumber) {
|
||||||
|
$eacLog
|
||||||
|
.parents('div.spoiler')
|
||||||
|
.prevAll('div.center:first')
|
||||||
|
.append(
|
||||||
|
`<br /><strong>${discs.length > 1 ? `Disc ${discNumber}: ` : ''}MB DiscId </strong><span id="${discid}" />`
|
||||||
|
);
|
||||||
},
|
},
|
||||||
function (mb_toc_numbers, discid, discNumber, found) {
|
function(mb_toc_numbers, discid, discNumber, found) {
|
||||||
var url = computeAttachURL(mb_toc_numbers, artistName, releaseName);
|
let url = computeAttachURL(mb_toc_numbers, artistName, releaseName);
|
||||||
var html = '<a href="' + url + '">' + discid + '</a>';
|
let html = `<a href="${url}">${discid}</a>`;
|
||||||
if (found) {
|
if (found) {
|
||||||
html = html + '<img src="' + CHECK_IMAGE + '" />';
|
html = `${html}<img src="${CHECK_IMAGE}" />`;
|
||||||
}
|
}
|
||||||
$('#' + discid.replace('.', '\\.')).html(html);
|
$(`#${discid.replace('.', '\\.')}`).html(html);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function gazellePageHandler() {
|
function gazellePageHandler() {
|
||||||
|
let serverHost = window.location.host;
|
||||||
var serverHost = window.location.host;
|
|
||||||
|
|
||||||
// Determine Artist name and Release title
|
// Determine Artist name and Release title
|
||||||
var titleAndArtists = $("#content div.thin h2:eq(0)").text();
|
let titleAndArtists = $('#content div.thin h2:eq(0)').text();
|
||||||
var pattern = /(.*) - (.*) \[.*\] \[.*/;
|
let pattern = /(.*) - (.*) \[.*\] \[.*/;
|
||||||
var artistName, releaseName;
|
let artistName, releaseName;
|
||||||
if (m = titleAndArtists.match(pattern)) {
|
if ((m = titleAndArtists.match(pattern))) {
|
||||||
artistName = m[1];
|
artistName = m[1];
|
||||||
releaseName = m[2];
|
releaseName = m[2];
|
||||||
}
|
}
|
||||||
LOGGER.debug("artist:", artistName, "- releaseName:", releaseName);
|
LOGGER.debug('artist:', artistName, '- releaseName:', releaseName);
|
||||||
|
|
||||||
// Parse each torrent
|
// Parse each torrent
|
||||||
$('tr.group_torrent').filter(function () {
|
$('tr.group_torrent')
|
||||||
return $(this).attr("id");
|
.filter(function() {
|
||||||
}).each(function () {
|
return $(this).attr('id');
|
||||||
var torrentInfo = $(this).next();
|
})
|
||||||
|
.each(function() {
|
||||||
|
let torrentInfo = $(this).next();
|
||||||
|
|
||||||
$(torrentInfo).find('a')
|
$(torrentInfo)
|
||||||
// Only investigate the ones with a log
|
.find('a')
|
||||||
.filter(function (index) {
|
// Only investigate the ones with a log
|
||||||
return $(this).text().match(/View\s+Log/i);
|
.filter(function(index) {
|
||||||
})
|
return $(this)
|
||||||
.each(function () {
|
.text()
|
||||||
LOGGER.debug("Log link", this);
|
.match(/View\s+Log/i);
|
||||||
if ($(this).attr("onclick").match(/show_logs/)) {
|
})
|
||||||
if (window.location.host.match(/apollo/)) {
|
.each(function() {
|
||||||
LOGGER.debug("Apollo");
|
LOGGER.debug('Log link', this);
|
||||||
var logAction = 'viewlog';
|
if (
|
||||||
} else if (window.location.host.match(/redacted|passtheheadphones/)){
|
$(this)
|
||||||
LOGGER.debug("RED");
|
.attr('onclick')
|
||||||
var logAction = 'loglist';
|
.match(/show_logs/)
|
||||||
|
) {
|
||||||
|
if (window.location.host.match(/apollo/)) {
|
||||||
|
LOGGER.debug('Apollo');
|
||||||
|
var logAction = 'viewlog';
|
||||||
|
} else if (window.location.host.match(/redacted|passtheheadphones/)) {
|
||||||
|
LOGGER.debug('RED');
|
||||||
|
var logAction = 'loglist';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
// LzTR
|
||||||
// LzTR
|
else if (
|
||||||
else if ($(this).attr("onclick").match(/get_log/)) {
|
$(this)
|
||||||
LOGGER.debug("LzTR");
|
.attr('onclick')
|
||||||
var logAction = 'log_ajax';
|
.match(/get_log/)
|
||||||
}
|
) {
|
||||||
// NotWhat.CD
|
LOGGER.debug('LzTR');
|
||||||
else if ($(this).attr("onclick").match(/show_log/)) {
|
var logAction = 'log_ajax';
|
||||||
LOGGER.debug("NotWhat.CD");
|
}
|
||||||
var logAction = 'viewlog';
|
// NotWhat.CD
|
||||||
} else {
|
else if (
|
||||||
return true;
|
$(this)
|
||||||
}
|
.attr('onclick')
|
||||||
var targetContainer = $(this).parents(".linkbox");
|
.match(/show_log/)
|
||||||
var torrentId = /(show_logs|get_log|show_log)\('(\d+)/.exec($(this).attr('onclick'))[2];
|
) {
|
||||||
var logUrl = '/torrents.php?action=' + logAction + '&torrentid=' + torrentId;
|
LOGGER.debug('NotWhat.CD');
|
||||||
LOGGER.info("Log URL: ", logUrl);
|
var logAction = 'viewlog';
|
||||||
LOGGER.debug("targetContainer: ", targetContainer);
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
let targetContainer = $(this).parents('.linkbox');
|
||||||
|
let torrentId = /(show_logs|get_log|show_log)\('(\d+)/.exec($(this).attr('onclick'))[2];
|
||||||
|
let logUrl = `/torrents.php?action=${logAction}&torrentid=${torrentId}`;
|
||||||
|
LOGGER.info('Log URL: ', logUrl);
|
||||||
|
LOGGER.debug('targetContainer: ', targetContainer);
|
||||||
|
|
||||||
// Get log content
|
// Get log content
|
||||||
$.get(logUrl,
|
$.get(logUrl, function(data) {
|
||||||
function (data) {
|
LOGGER.debug('Log content', $(data).find('pre'));
|
||||||
LOGGER.debug("Log content", $(data).find('pre'));
|
let discs = analyze_log_files($(data).find('pre'));
|
||||||
var discs = analyze_log_files($(data).find('pre'));
|
LOGGER.debug('Number of disc found', discs.length);
|
||||||
LOGGER.debug("Number of disc found", discs.length);
|
check_and_display_discs(
|
||||||
check_and_display_discs(artistName, releaseName, discs,
|
artistName,
|
||||||
function (mb_toc_numbers, discid, discNumber) {
|
releaseName,
|
||||||
targetContainer.append('<br /><strong>' + (discs.length > 1 ? 'Disc ' + discNumber + ': ' : '' ) + 'MB DiscId: </strong><span id="' + torrentId + '_disc' + discNumber + '" />');
|
discs,
|
||||||
|
function(mb_toc_numbers, discid, discNumber) {
|
||||||
|
targetContainer.append(
|
||||||
|
`<br /><strong>${
|
||||||
|
discs.length > 1 ? `Disc ${discNumber}: ` : ''
|
||||||
|
}MB DiscId: </strong><span id="${torrentId}_disc${discNumber}" />`
|
||||||
|
);
|
||||||
},
|
},
|
||||||
function (mb_toc_numbers, discid, discNumber, found) {
|
function(mb_toc_numbers, discid, discNumber, found) {
|
||||||
var url = computeAttachURL(mb_toc_numbers, artistName, releaseName);
|
let url = computeAttachURL(mb_toc_numbers, artistName, releaseName);
|
||||||
var html = '<a href="' + url + '">' + discid + '</a>';
|
let html = `<a href="${url}">${discid}</a>`;
|
||||||
if (found) {
|
if (found) {
|
||||||
html = html + '<img src="' + CHECK_IMAGE + '" />';
|
html = `${html}<img src="${CHECK_IMAGE}" />`;
|
||||||
}
|
}
|
||||||
LOGGER.debug('#' + torrentId + '_disc' + discNumber);
|
LOGGER.debug(`#${torrentId}_disc${discNumber}`);
|
||||||
$('#' + torrentId + '_disc' + discNumber).html(html);
|
$(`#${torrentId}_disc${discNumber}`).html(html);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
);
|
});
|
||||||
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Common functions
|
// Common functions
|
||||||
|
|
||||||
function computeAttachURL(mb_toc_numbers, artistName, releaseName) {
|
function computeAttachURL(mb_toc_numbers, artistName, releaseName) {
|
||||||
var url = 'http://musicbrainz.org/cdtoc/attach'
|
let url = `${'http://musicbrainz.org/cdtoc/attach' + '?toc='}${mb_toc_numbers.join('%20')}&artist-name=${encodeURIComponent(
|
||||||
+ '?toc=' + mb_toc_numbers.join("%20")
|
artistName
|
||||||
+ '&artist-name=' + encodeURIComponent(artistName)
|
)}&release-name=${encodeURIComponent(releaseName)}`;
|
||||||
+ '&release-name=' + encodeURIComponent(releaseName);
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
function analyze_log_files(log_files) {
|
function analyze_log_files(log_files) {
|
||||||
var discs = [];
|
let discs = [];
|
||||||
$.each(log_files, function (i, log_file) {
|
$.each(log_files, function(i, log_file) {
|
||||||
var discsInLog = MBDiscid.log_input_to_entries($(log_file).text());
|
let discsInLog = MBDiscid.log_input_to_entries($(log_file).text());
|
||||||
for (var i = 0; i < discsInLog.length; i++) {
|
for (var i = 0; i < discsInLog.length; i++) {
|
||||||
discs.push(discsInLog[i]);
|
discs.push(discsInLog[i]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove dupes discs
|
// Remove dupes discs
|
||||||
var keys = new Object();
|
let keys = new Object();
|
||||||
var uniqueDiscs = new Array();
|
let uniqueDiscs = new Array();
|
||||||
for (var i = 0; i < discs.length; i++) {
|
for (let i = 0; i < discs.length; i++) {
|
||||||
var discid = MBDiscid.calculate_mb_discid(discs[i]);
|
let discid = MBDiscid.calculate_mb_discid(discs[i]);
|
||||||
if (discid in keys) {
|
if (discid in keys) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
@ -195,26 +222,24 @@ function analyze_log_files(log_files) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_and_display_discs(artistName, releaseName, discs, displayDiscHandler, displayResultHandler) {
|
function check_and_display_discs(artistName, releaseName, discs, displayDiscHandler, displayResultHandler) {
|
||||||
|
|
||||||
// For each disc, check if it's in MusicBrainz database
|
// For each disc, check if it's in MusicBrainz database
|
||||||
for (var i = 0; i < discs.length; i++) {
|
for (let i = 0; i < discs.length; i++) {
|
||||||
var entries = discs[i];
|
let entries = discs[i];
|
||||||
var discNumber = i + 1;
|
let discNumber = i + 1;
|
||||||
if (entries.length > 0) {
|
if (entries.length > 0) {
|
||||||
|
let mb_toc_numbers = MBDiscid.calculate_mb_toc_numbers(entries);
|
||||||
var mb_toc_numbers = MBDiscid.calculate_mb_toc_numbers(entries);
|
let discid = MBDiscid.calculate_mb_discid(entries);
|
||||||
var discid = MBDiscid.calculate_mb_discid(entries);
|
LOGGER.info(`Computed discid :${discid}`);
|
||||||
LOGGER.info("Computed discid :" + discid);
|
|
||||||
displayDiscHandler(mb_toc_numbers, discid, discNumber);
|
displayDiscHandler(mb_toc_numbers, discid, discNumber);
|
||||||
|
|
||||||
// Now check if this discid is known by MusicBrainz
|
// Now check if this discid is known by MusicBrainz
|
||||||
(function (discid, discNumber, mb_toc_numbers) {
|
(function(discid, discNumber, mb_toc_numbers) {
|
||||||
var query = $.getJSON('//musicbrainz.org/ws/2/discid/' + discid + '?cdstubs=no');
|
let query = $.getJSON(`//musicbrainz.org/ws/2/discid/${discid}?cdstubs=no`);
|
||||||
query.done(function (data) {
|
query.done(function(data) {
|
||||||
var existsInMusicbrainz = !('error' in data) && data.error != "Not found";
|
let existsInMusicbrainz = !('error' in data) && data.error != 'Not found';
|
||||||
displayResultHandler(mb_toc_numbers, discid, discNumber, existsInMusicbrainz);
|
displayResultHandler(mb_toc_numbers, discid, discNumber, existsInMusicbrainz);
|
||||||
});
|
});
|
||||||
query.fail(function () {
|
query.fail(function() {
|
||||||
// If discid is not found, the webservice returns a 404 http code
|
// If discid is not found, the webservice returns a 404 http code
|
||||||
displayResultHandler(mb_toc_numbers, discid, discNumber, false);
|
displayResultHandler(mb_toc_numbers, discid, discNumber, false);
|
||||||
});
|
});
|
||||||
|
@ -229,30 +254,29 @@ function check_and_display_discs(artistName, releaseName, discs, displayDiscHand
|
||||||
// Copyright 2010, kolen
|
// Copyright 2010, kolen
|
||||||
// Released under the MIT License
|
// Released under the MIT License
|
||||||
|
|
||||||
var MBDiscid = (function () {
|
var MBDiscid = (function() {
|
||||||
|
|
||||||
this.SECTORS_PER_SECOND = 75;
|
this.SECTORS_PER_SECOND = 75;
|
||||||
this.PREGAP = 150;
|
this.PREGAP = 150;
|
||||||
this.DATA_TRACK_GAP = 11400;
|
this.DATA_TRACK_GAP = 11400;
|
||||||
|
|
||||||
this.toc_entry_matcher = new RegExp(
|
this.toc_entry_matcher = new RegExp(
|
||||||
"^\\s*" +
|
'^\\s*' +
|
||||||
"(\\d+)" + // 1 - track number
|
'(\\d+)' + // 1 - track number
|
||||||
"\\s*\\|\\s*" +
|
'\\s*\\|\\s*' +
|
||||||
"([0-9:.]+)" + // 2 - time start
|
'([0-9:.]+)' + // 2 - time start
|
||||||
"\\s*\\|\\s*" +
|
'\\s*\\|\\s*' +
|
||||||
"([0-9:.]+)" + // 3 - time length
|
'([0-9:.]+)' + // 3 - time length
|
||||||
"\\s*\\|\\s*" +
|
'\\s*\\|\\s*' +
|
||||||
"(\\d+)" + // 4 - start sector
|
'(\\d+)' + // 4 - start sector
|
||||||
"\\s*\\|\\s*" +
|
'\\s*\\|\\s*' +
|
||||||
"(\\d+)" + // 5 - end sector
|
'(\\d+)' + // 5 - end sector
|
||||||
"\\s*$"
|
'\\s*$'
|
||||||
);
|
);
|
||||||
this.log_input_to_entries = function (text) {
|
this.log_input_to_entries = function(text) {
|
||||||
var discs = [];
|
let discs = [];
|
||||||
var entries = [];
|
var entries = [];
|
||||||
$.each(text.split("\n"), function (index, value) {
|
$.each(text.split('\n'), function(index, value) {
|
||||||
var m = toc_entry_matcher.exec(value);
|
let m = toc_entry_matcher.exec(value);
|
||||||
if (m) {
|
if (m) {
|
||||||
// New disc
|
// New disc
|
||||||
if (parseInt(m[1], 10) == 1) {
|
if (parseInt(m[1], 10) == 1) {
|
||||||
|
@ -268,11 +292,11 @@ var MBDiscid = (function () {
|
||||||
discs.push(entries);
|
discs.push(entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < discs.length; i++) {
|
for (let i = 0; i < discs.length; i++) {
|
||||||
var entries = discs[i];
|
var entries = discs[i];
|
||||||
var layout_type = get_layout_type(entries);
|
let layout_type = get_layout_type(entries);
|
||||||
var entries_audio;
|
var entries_audio;
|
||||||
if (layout_type == "with_data") {
|
if (layout_type == 'with_data') {
|
||||||
entries_audio = entries.slice(0, entries.length - 1);
|
entries_audio = entries.slice(0, entries.length - 1);
|
||||||
} else {
|
} else {
|
||||||
entries_audio = entries;
|
entries_audio = entries;
|
||||||
|
@ -282,15 +306,15 @@ var MBDiscid = (function () {
|
||||||
return discs;
|
return discs;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.get_layout_type = function (entries) {
|
this.get_layout_type = function(entries) {
|
||||||
var type = "standard";
|
let type = 'standard';
|
||||||
for (var i = 0; i < entries.length - 1; i++) {
|
for (let i = 0; i < entries.length - 1; i++) {
|
||||||
var gap = parseInt(entries[i + 1][4], 10) - parseInt(entries[i][5], 10) - 1;
|
let gap = parseInt(entries[i + 1][4], 10) - parseInt(entries[i][5], 10) - 1;
|
||||||
if (gap != 0) {
|
if (gap != 0) {
|
||||||
if (i == entries.length - 2 && gap == DATA_TRACK_GAP) {
|
if (i == entries.length - 2 && gap == DATA_TRACK_GAP) {
|
||||||
type = "with_data";
|
type = 'with_data';
|
||||||
} else {
|
} else {
|
||||||
type = "unknown";
|
type = 'unknown';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,84 +322,91 @@ var MBDiscid = (function () {
|
||||||
return type;
|
return type;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.calculate_mb_toc_numbers = function (entries) {
|
this.calculate_mb_toc_numbers = function(entries) {
|
||||||
if (entries.length == 0) {
|
if (entries.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var leadout_offset = parseInt(entries[entries.length - 1][5], 10) + PREGAP + 1;
|
let leadout_offset = parseInt(entries[entries.length - 1][5], 10) + PREGAP + 1;
|
||||||
|
|
||||||
var offsets = $.map(entries, function (entry) {
|
let offsets = $.map(entries, function(entry) {
|
||||||
return parseInt(entry[4], 10) + PREGAP;
|
return parseInt(entry[4], 10) + PREGAP;
|
||||||
})
|
});
|
||||||
return [1, entries.length, leadout_offset].concat(offsets);
|
return [1, entries.length, leadout_offset].concat(offsets);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.calculate_cddb_id = function (entries) {
|
this.calculate_cddb_id = function(entries) {
|
||||||
var sum_of_digits = function (n) {
|
let sum_of_digits = function(n) {
|
||||||
var sum = 0;
|
let sum = 0;
|
||||||
while (n > 0) {
|
while (n > 0) {
|
||||||
sum = sum + (n % 10);
|
sum = sum + (n % 10);
|
||||||
n = Math.floor(n / 10);
|
n = Math.floor(n / 10);
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
}
|
};
|
||||||
|
|
||||||
var decimalToHexString = function (number) {
|
let decimalToHexString = function(number) {
|
||||||
if (number < 0) {
|
if (number < 0) {
|
||||||
number = 0xFFFFFFFF + number + 1;
|
number = 0xffffffff + number + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return number.toString(16).toUpperCase();
|
return number.toString(16).toUpperCase();
|
||||||
}
|
};
|
||||||
|
|
||||||
var length_seconds = Math.floor((parseInt(entries[entries.length - 1][5], 10) - parseInt(entries[0][4], 10) + 1) / SECTORS_PER_SECOND);
|
let length_seconds = Math.floor(
|
||||||
var checksum = 0;
|
(parseInt(entries[entries.length - 1][5], 10) - parseInt(entries[0][4], 10) + 1) / SECTORS_PER_SECOND
|
||||||
$.each(entries, function (index, entry) {
|
);
|
||||||
|
let checksum = 0;
|
||||||
|
$.each(entries, function(index, entry) {
|
||||||
checksum += sum_of_digits(Math.floor((parseInt(entry[4], 10) + PREGAP) / SECTORS_PER_SECOND));
|
checksum += sum_of_digits(Math.floor((parseInt(entry[4], 10) + PREGAP) / SECTORS_PER_SECOND));
|
||||||
})
|
});
|
||||||
|
|
||||||
var xx = checksum % 255;
|
let xx = checksum % 255;
|
||||||
var discid_num = (xx << 24) | (length_seconds << 8) | entries.length;
|
let discid_num = (xx << 24) | (length_seconds << 8) | entries.length;
|
||||||
//return discid_num
|
//return discid_num
|
||||||
return decimalToHexString(discid_num);
|
return decimalToHexString(discid_num);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.calculate_mb_discid = function (entries) {
|
this.calculate_mb_discid = function(entries) {
|
||||||
|
let hex_left_pad = function(input, totalChars) {
|
||||||
var hex_left_pad = function (input, totalChars) {
|
input = `${parseInt(input, 10)
|
||||||
input = '' + parseInt(input, 10).toString(16).toUpperCase();
|
.toString(16)
|
||||||
var padWith = "0";
|
.toUpperCase()}`;
|
||||||
|
let padWith = '0';
|
||||||
if (input.length < totalChars) {
|
if (input.length < totalChars) {
|
||||||
while (input.length < totalChars) {
|
while (input.length < totalChars) {
|
||||||
input = padWith + input;
|
input = padWith + input;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
if (input.length > totalChars) { //if padWith was a multiple character string and num was overpadded
|
if (input.length > totalChars) {
|
||||||
input = input.substring((input.length - totalChars), totalChars);
|
//if padWith was a multiple character string and num was overpadded
|
||||||
|
input = input.substring(input.length - totalChars, totalChars);
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
};
|
};
|
||||||
|
|
||||||
var mb_toc_numbers = calculate_mb_toc_numbers(entries);
|
let mb_toc_numbers = calculate_mb_toc_numbers(entries);
|
||||||
var message = "";
|
let message = '';
|
||||||
var first_track = mb_toc_numbers[0];
|
let first_track = mb_toc_numbers[0];
|
||||||
var last_track = mb_toc_numbers[1];
|
let last_track = mb_toc_numbers[1];
|
||||||
var leadout_offset = mb_toc_numbers[2];
|
let leadout_offset = mb_toc_numbers[2];
|
||||||
message = message + hex_left_pad(first_track, 2);
|
message = message + hex_left_pad(first_track, 2);
|
||||||
message = message + hex_left_pad(last_track, 2);
|
message = message + hex_left_pad(last_track, 2);
|
||||||
message = message + hex_left_pad(leadout_offset, 8);
|
message = message + hex_left_pad(leadout_offset, 8);
|
||||||
for (var i = 0; i < 99; i++) {
|
for (let i = 0; i < 99; i++) {
|
||||||
var offset = (i + 3 < mb_toc_numbers.length) ? mb_toc_numbers[i + 3] : 0;
|
let offset = i + 3 < mb_toc_numbers.length ? mb_toc_numbers[i + 3] : 0;
|
||||||
message = message + hex_left_pad(offset, 8);
|
message = message + hex_left_pad(offset, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
b64pad = "=";
|
b64pad = '=';
|
||||||
var discid = b64_sha1(message);
|
let discid = b64_sha1(message);
|
||||||
discid = discid.replace(/\+/g, ".").replace(/\//g, "_").replace(/=/g, "-");
|
discid = discid
|
||||||
|
.replace(/\+/g, '.')
|
||||||
|
.replace(/\//g, '_')
|
||||||
|
.replace(/=/g, '-');
|
||||||
return discid;
|
return discid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -14,38 +14,38 @@
|
||||||
|
|
||||||
// Definitions: relations-type and corresponding icons we are going to treat
|
// Definitions: relations-type and corresponding icons we are going to treat
|
||||||
var relationsIconsURLs = {
|
var relationsIconsURLs = {
|
||||||
'url': {
|
url: {
|
||||||
"amazon asin": "https://musicbrainz.org/static/images/favicons/amazon-32.png",
|
'amazon asin': 'https://musicbrainz.org/static/images/favicons/amazon-32.png',
|
||||||
"discogs": "https://musicbrainz.org/static/images/favicons/discogs-32.png",
|
discogs: 'https://musicbrainz.org/static/images/favicons/discogs-32.png',
|
||||||
"wikidata": "https://musicbrainz.org/static/images/favicons/wikidata-32.png",
|
wikidata: 'https://musicbrainz.org/static/images/favicons/wikidata-32.png',
|
||||||
"imdb": "https://musicbrainz.org/static/images/favicons/imdb-32.png",
|
imdb: 'https://musicbrainz.org/static/images/favicons/imdb-32.png',
|
||||||
"creative commons licensed download": "http://creativecommons.org/favicon.ico",
|
'creative commons licensed download': 'http://creativecommons.org/favicon.ico',
|
||||||
"cover art link": "http://www.cdcovers.cc/favicon.ico",
|
'cover art link': 'http://www.cdcovers.cc/favicon.ico',
|
||||||
"secondhandsongs": "https://musicbrainz.org/static/images/favicons/secondhandsongs-32.png",
|
secondhandsongs: 'https://musicbrainz.org/static/images/favicons/secondhandsongs-32.png',
|
||||||
"lyrics": "http://www.nomy.nu/img/lyrics-icon.gif",
|
lyrics: 'http://www.nomy.nu/img/lyrics-icon.gif',
|
||||||
"allmusic": "https://musicbrainz.org/static/images/favicons/allmusic-16.png"
|
allmusic: 'https://musicbrainz.org/static/images/favicons/allmusic-16.png'
|
||||||
},
|
},
|
||||||
'release-group': {
|
'release-group': {
|
||||||
"single from": "http://www.amaesingtools.com/images/left_arrow_icon.gif"
|
'single from': 'http://www.amaesingtools.com/images/left_arrow_icon.gif'
|
||||||
},
|
},
|
||||||
'release': {
|
release: {
|
||||||
"part of set": "http://web.archive.org/web/20060709091901/http://wiki.musicbrainz.org/-/musicbrainz/img/moin-inter.png",
|
'part of set': 'http://web.archive.org/web/20060709091901/http://wiki.musicbrainz.org/-/musicbrainz/img/moin-inter.png',
|
||||||
"remaster": "http://web.archive.org/web/20060708200714/http://wiki.musicbrainz.org/-/musicbrainz/img/moin-www.png",
|
remaster: 'http://web.archive.org/web/20060708200714/http://wiki.musicbrainz.org/-/musicbrainz/img/moin-www.png'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var otherDatabasesIconURLs = {
|
var otherDatabasesIconURLs = {
|
||||||
"d-nb.info" : "https://musicbrainz.org/static/images/favicons/dnb-16.png",
|
'd-nb.info': 'https://musicbrainz.org/static/images/favicons/dnb-16.png',
|
||||||
"www.musik-sammler.de": "https://musicbrainz.org/static/images/favicons/musiksammler-32.png",
|
'www.musik-sammler.de': 'https://musicbrainz.org/static/images/favicons/musiksammler-32.png',
|
||||||
"www.worldcat.org": "https://musicbrainz.org/static/images/favicons/worldcat-32.png",
|
'www.worldcat.org': 'https://musicbrainz.org/static/images/favicons/worldcat-32.png',
|
||||||
"rateyourmusic.com": "https://musicbrainz.org/static/images/favicons/rateyourmusic-32.png"
|
'rateyourmusic.com': 'https://musicbrainz.org/static/images/favicons/rateyourmusic-32.png'
|
||||||
};
|
};
|
||||||
|
|
||||||
var incOptions = {
|
var incOptions = {
|
||||||
'release-group': [ 'release-group-rels', 'url-rels' ],
|
'release-group': ['release-group-rels', 'url-rels'],
|
||||||
'release': [ 'release-rels', 'url-rels', 'discids' ],
|
release: ['release-rels', 'url-rels', 'discids'],
|
||||||
'recording': [ 'work-rels' ],
|
recording: ['work-rels'],
|
||||||
'work': [ 'url-rels' ]
|
work: ['url-rels']
|
||||||
};
|
};
|
||||||
|
|
||||||
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant
|
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant
|
||||||
|
@ -53,20 +53,19 @@ this.$ = this.jQuery = jQuery.noConflict(true);
|
||||||
|
|
||||||
if (!unsafeWindow) unsafeWindow = window;
|
if (!unsafeWindow) unsafeWindow = window;
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function() {
|
||||||
|
|
||||||
// Get pageType (label or artist)
|
// Get pageType (label or artist)
|
||||||
var parent = {};
|
let parent = {};
|
||||||
var child = {};
|
let child = {};
|
||||||
if (m = window.location.href.match("\/artist\/(.{36})[^\/]*$")) {
|
if ((m = window.location.href.match('/artist/(.{36})[^/]*$'))) {
|
||||||
parent.type = 'artist';
|
parent.type = 'artist';
|
||||||
parent.mbid = m[1];
|
parent.mbid = m[1];
|
||||||
child.type = 'release-group';
|
child.type = 'release-group';
|
||||||
} else if (m = window.location.href.match("\/(release-group|label)\/(.{36})[^\/]*$")) {
|
} else if ((m = window.location.href.match('/(release-group|label)/(.{36})[^/]*$'))) {
|
||||||
parent.type = m[1];
|
parent.type = m[1];
|
||||||
parent.mbid = m[2];
|
parent.mbid = m[2];
|
||||||
child.type = 'release';
|
child.type = 'release';
|
||||||
} else if (m = window.location.href.match("\/artist/(.{36})\/(releases|recordings|works)")) {
|
} else if ((m = window.location.href.match('/artist/(.{36})/(releases|recordings|works)'))) {
|
||||||
parent.type = 'artist';
|
parent.type = 'artist';
|
||||||
parent.mbid = m[1];
|
parent.mbid = m[1];
|
||||||
child.type = m[2].replace(/s$/, '');
|
child.type = m[2].replace(/s$/, '');
|
||||||
|
@ -75,106 +74,132 @@ $(document).ready(function(){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var mbidRE = /(release|release-group|work)\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/;
|
let mbidRE = /(release|release-group|work)\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/;
|
||||||
|
|
||||||
// Determine target column
|
// Determine target column
|
||||||
var columnindex = 0;
|
let columnindex = 0;
|
||||||
$("table.tbl tbody tr[class!='subh']").each(function() {
|
$("table.tbl tbody tr[class!='subh']").each(function() {
|
||||||
$(this).children("td").each(function() {
|
$(this)
|
||||||
if ($(this).find("a").attr("href") !== undefined && $(this).find("a").attr("href").match(mbidRE)) { return false; }
|
.children('td')
|
||||||
columnindex++;
|
.each(function() {
|
||||||
});
|
if (
|
||||||
|
$(this)
|
||||||
|
.find('a')
|
||||||
|
.attr('href') !== undefined &&
|
||||||
|
$(this)
|
||||||
|
.find('a')
|
||||||
|
.attr('href')
|
||||||
|
.match(mbidRE)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
columnindex++;
|
||||||
|
});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set MBID to row in tables to get easiest fastest access
|
// Set MBID to row in tables to get easiest fastest access
|
||||||
$("table.tbl tr[class!='subh']").each(function() {
|
$("table.tbl tr[class!='subh']").each(function() {
|
||||||
var $tr = $(this);
|
let $tr = $(this);
|
||||||
|
|
||||||
$tr.children("th:eq("+columnindex+")").after("<th style='width: 150px;'>Relationships</th>");
|
$tr.children(`th:eq(${columnindex})`).after("<th style='width: 150px;'>Relationships</th>");
|
||||||
$tr.children("td:eq("+columnindex+")").after("<td class='relationships'></td>");
|
$tr.children(`td:eq(${columnindex})`).after("<td class='relationships'></td>");
|
||||||
|
|
||||||
$(this).find("a").each(function() {
|
$(this)
|
||||||
var href = $(this).attr("href");
|
.find('a')
|
||||||
if (m = href.match(mbidRE)) {
|
.each(function() {
|
||||||
$tr.attr("id", m[2]);
|
let href = $(this).attr('href');
|
||||||
return false;
|
if ((m = href.match(mbidRE))) {
|
||||||
}
|
$tr.attr('id', m[2]);
|
||||||
});
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Calculate offset for multi-page lists
|
// Calculate offset for multi-page lists
|
||||||
var page = 1;
|
let page = 1;
|
||||||
if (m = window.location.href.match("[\?&]page=([0-9]*)")) {
|
if ((m = window.location.href.match('[?&]page=([0-9]*)'))) {
|
||||||
page = m[1];
|
page = m[1];
|
||||||
}
|
}
|
||||||
var offset = (page - 1) * 100;
|
let offset = (page - 1) * 100;
|
||||||
|
|
||||||
// Call the MB webservice
|
// Call the MB webservice
|
||||||
var url = '/ws/2/' + child.type + '?' + parent.type + "=" + parent.mbid + '&inc=' + incOptions[child.type].join("+") + '&limit=100&offset=' + offset;
|
let url = `/ws/2/${child.type}?${parent.type}=${parent.mbid}&inc=${incOptions[child.type].join('+')}&limit=100&offset=${offset}`;
|
||||||
//console.log("MB WS url: " + url);
|
//console.log("MB WS url: " + url);
|
||||||
|
|
||||||
$.get(url, function(data, textStatus, jqXHR) {
|
$.get(url, function(data, textStatus, jqXHR) {
|
||||||
|
|
||||||
// Parse each child
|
// Parse each child
|
||||||
$(data).find(child.type).each(function() {
|
$(data)
|
||||||
var mbid = $(this).attr("id");
|
.find(child.type)
|
||||||
|
.each(function() {
|
||||||
|
let mbid = $(this).attr('id');
|
||||||
|
|
||||||
// URL relationships
|
// URL relationships
|
||||||
$(this).find("relation-list[target-type='url'] relation").each(function() {
|
$(this)
|
||||||
var reltype = $(this).attr("type");
|
.find("relation-list[target-type='url'] relation")
|
||||||
var target = $(this).children("target").text();
|
.each(function() {
|
||||||
if (relationsIconsURLs.url.hasOwnProperty(reltype)) {
|
let reltype = $(this).attr('type');
|
||||||
$("#" + mbid + " td.relationships").append(
|
let target = $(this)
|
||||||
"<a href='" + target.replace(/'/g,"'") + "'>" + "<img style='max-height: 16px;' src='" + relationsIconsURLs.url[reltype] + "' /> " + "</a>"
|
.children('target')
|
||||||
);
|
.text();
|
||||||
}
|
if (relationsIconsURLs.url.hasOwnProperty(reltype)) {
|
||||||
else for (var rel in otherDatabasesIconURLs) {
|
$(`#${mbid} td.relationships`).append(
|
||||||
if (target.indexOf(rel) != -1 ) {
|
`<a href='${target.replace(/'/g, ''')}'>` +
|
||||||
$("#" + mbid + " td.relationships").append(
|
`<img style='max-height: 16px;' src='${relationsIconsURLs.url[reltype]}' /> ` +
|
||||||
"<a href='" + target.replace(/'/g,"'") + "'>" + "<img style='max-height: 16px;' src='" + otherDatabasesIconURLs[rel] + "' /> " + "</a>"
|
`</a>`
|
||||||
);
|
);
|
||||||
}
|
} else
|
||||||
}
|
for (let rel in otherDatabasesIconURLs) {
|
||||||
});
|
if (target.indexOf(rel) != -1) {
|
||||||
|
$(`#${mbid} td.relationships`).append(
|
||||||
|
`<a href='${target.replace(/'/g, ''')}'>` +
|
||||||
|
`<img style='max-height: 16px;' src='${otherDatabasesIconURLs[rel]}' /> ` +
|
||||||
|
`</a>`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Other relationships
|
// Other relationships
|
||||||
$(this).find("relation-list[target-type!='url']").each(function() {
|
$(this)
|
||||||
var targettype = $(this).attr("target-type").replace("release_group", "release-group");
|
.find("relation-list[target-type!='url']")
|
||||||
var relations = {};
|
.each(function() {
|
||||||
|
let targettype = $(this)
|
||||||
|
.attr('target-type')
|
||||||
|
.replace('release_group', 'release-group');
|
||||||
|
let relations = {};
|
||||||
|
|
||||||
if (relationsIconsURLs[targettype] === undefined) {
|
if (relationsIconsURLs[targettype] === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$(this).children("relation").each(function() {
|
$(this)
|
||||||
var reltype = $(this).attr("type");
|
.children('relation')
|
||||||
var target = $(this).children("target").text();
|
.each(function() {
|
||||||
var url = (targettype == 'url') ? target : "/" + targettype + "/" + target;
|
let reltype = $(this).attr('type');
|
||||||
|
let target = $(this)
|
||||||
|
.children('target')
|
||||||
|
.text();
|
||||||
|
let url = targettype == 'url' ? target : `/${targettype}/${target}`;
|
||||||
|
|
||||||
if (relationsIconsURLs[targettype].hasOwnProperty(reltype)) {
|
if (relationsIconsURLs[targettype].hasOwnProperty(reltype)) {
|
||||||
|
if (!relations.hasOwnProperty(reltype)) relations[reltype] = [url];
|
||||||
|
else relations[reltype].push(url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (!relations.hasOwnProperty(reltype)) relations[reltype] = [url];
|
$.each(relations, function(reltype, urls) {
|
||||||
else relations[reltype].push(url);
|
let html = '';
|
||||||
}
|
if (urls.length < -1) {
|
||||||
});
|
html += `<img src='${relationsIconsURLs[targettype][reltype]}' />(${urls.length}) `;
|
||||||
|
} else {
|
||||||
$.each(relations, function(reltype, urls) {
|
$.each(urls, function(index, url) {
|
||||||
var html = "";
|
html += `<a href='${url}'><img src='${relationsIconsURLs[targettype][reltype]}' /></a> `;
|
||||||
if (urls.length < -1) {
|
});
|
||||||
html += "<img src='" + relationsIconsURLs[targettype][reltype] + "' />(" + urls.length + ") ";
|
}
|
||||||
} else {
|
$(`#${mbid} td.relationships`).append(html);
|
||||||
$.each(urls, function(index, url) {
|
|
||||||
html += "<a href='" + url + "'><img src='" + relationsIconsURLs[targettype][reltype] + "' /></a> ";
|
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
$("#" + mbid + " td.relationships").append(html);
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,114 +14,149 @@
|
||||||
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant
|
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant
|
||||||
this.$ = this.jQuery = jQuery.noConflict(true);
|
this.$ = this.jQuery = jQuery.noConflict(true);
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function() {
|
||||||
LASTFM_APIKEY = null;
|
LASTFM_APIKEY = null;
|
||||||
|
|
||||||
// Highlight table rows
|
// Highlight table rows
|
||||||
$('table.tbl tbody tr').hover(
|
$('table.tbl tbody tr').hover(
|
||||||
function () {
|
function() {
|
||||||
$(this).children('td').each(function(){
|
$(this)
|
||||||
var backgroundColor = $(this).css("backgroundColor");
|
.children('td')
|
||||||
if (backgroundColor != 'rgb(255, 255, 0)')
|
.each(function() {
|
||||||
$(this).css("backgroundColor", "#ffeea8");
|
let backgroundColor = $(this).css('backgroundColor');
|
||||||
});
|
if (backgroundColor != 'rgb(255, 255, 0)') $(this).css('backgroundColor', '#ffeea8');
|
||||||
|
});
|
||||||
},
|
},
|
||||||
function () {
|
function() {
|
||||||
$(this).children('td').each(function(){
|
$(this)
|
||||||
var backgroundColor = $(this).css("backgroundColor");
|
.children('td')
|
||||||
if (backgroundColor != 'rgb(255, 255, 0)')
|
.each(function() {
|
||||||
$(this).css("backgroundColor", "");
|
let backgroundColor = $(this).css('backgroundColor');
|
||||||
});
|
if (backgroundColor != 'rgb(255, 255, 0)') $(this).css('backgroundColor', '');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
var re;
|
let re;
|
||||||
|
|
||||||
// Top tracks from Lastfm
|
// Top tracks from Lastfm
|
||||||
re = new RegExp("musicbrainz\.org\/artist\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})$","i");
|
re = new RegExp('musicbrainz.org/artist/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})$', 'i');
|
||||||
if (LASTFM_APIKEY && window.location.href.match(re)) {
|
if (LASTFM_APIKEY && window.location.href.match(re)) {
|
||||||
$('h2.discography').before('<h2 class="toptracks">Top Last.fm recordings</h2><ul class="toptracks" />');
|
$('h2.discography').before('<h2 class="toptracks">Top Last.fm recordings</h2><ul class="toptracks" />');
|
||||||
var mbid = window.location.href.match(re)[1];
|
var mbid = window.location.href.match(re)[1];
|
||||||
var toptracks = $.getJSON('http://ws.audioscrobbler.com/2.0/?method=artist.gettoptracks&mbid='+mbid+'&api_key='+LASTFM_APIKEY+'&format=json', function(data) {
|
let toptracks = $.getJSON(
|
||||||
$.each(data.toptracks.track, function (index, track) {
|
`http://ws.audioscrobbler.com/2.0/?method=artist.gettoptracks&mbid=${mbid}&api_key=${LASTFM_APIKEY}&format=json`,
|
||||||
if (index >= 5) return true;
|
function(data) {
|
||||||
var url = track.mbid ? '/recording/'+track.mbid : track.url;
|
$.each(data.toptracks.track, function(index, track) {
|
||||||
$('ul.toptracks').append('<li><a href="'+url+'">'+track.name+'</a></li>');
|
if (index >= 5) return true;
|
||||||
});
|
let url = track.mbid ? `/recording/${track.mbid}` : track.url;
|
||||||
});
|
$('ul.toptracks').append(`<li><a href="${url}">${track.name}</a></li>`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix for http://tickets.musicbrainz.org/browse/MBS-750
|
// Fix for http://tickets.musicbrainz.org/browse/MBS-750
|
||||||
re = new RegExp("musicbrainz\.org\/release\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})","i");
|
re = new RegExp('musicbrainz.org/release/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})', 'i');
|
||||||
if (window.location.href.match(re)) {
|
if (window.location.href.match(re)) {
|
||||||
if ($("table.medium thead").length == 1) {
|
if ($('table.medium thead').length == 1) {
|
||||||
var text = $.trim($("table.medium thead").text());
|
let text = $.trim($('table.medium thead').text());
|
||||||
if (text.match(/ 1$/)) {
|
if (text.match(/ 1$/)) {
|
||||||
$("table.medium thead a").text(text.replace(/ 1$/, ''));
|
$('table.medium thead a').text(text.replace(/ 1$/, ''));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Better fix for http://tickets.musicbrainz.org/browse/MBS-1943
|
// Better fix for http://tickets.musicbrainz.org/browse/MBS-1943
|
||||||
re = new RegExp("musicbrainz\.org\/(artist|release-group|release|recording|work|label)\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})","i");
|
re = new RegExp(
|
||||||
|
'musicbrainz.org/(artist|release-group|release|recording|work|label)/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})',
|
||||||
|
'i'
|
||||||
|
);
|
||||||
if (window.location.href.match(re)) {
|
if (window.location.href.match(re)) {
|
||||||
$("#sidebar h2:contains('Rating')").before($("#sidebar h2:contains('External links')"));
|
$("#sidebar h2:contains('Rating')").before($("#sidebar h2:contains('External links')"));
|
||||||
var pageHasRGLinks = $("#sidebar h2:contains('Release group external links')").length > 0;
|
let pageHasRGLinks = $("#sidebar h2:contains('Release group external links')").length > 0;
|
||||||
$("#sidebar h2:contains('Rating')").before(
|
$("#sidebar h2:contains('Rating')").before(
|
||||||
$("#sidebar h2:contains('External links')").nextAll("ul.external_links").filter( function() {
|
$("#sidebar h2:contains('External links')")
|
||||||
return !pageHasRGLinks || $(this).nextAll("h2:contains('Release group external links')").length > 0;
|
.nextAll('ul.external_links')
|
||||||
}));
|
.filter(function() {
|
||||||
|
return !pageHasRGLinks || $(this).nextAll("h2:contains('Release group external links')").length > 0;
|
||||||
|
})
|
||||||
|
);
|
||||||
$("#sidebar h2:contains('Rating')").before($("#sidebar h2:contains('Release group external links')"));
|
$("#sidebar h2:contains('Rating')").before($("#sidebar h2:contains('Release group external links')"));
|
||||||
$("#sidebar h2:contains('Rating')").before($("#sidebar h2:contains('Release group external links')").nextAll("ul.external_links"));
|
$("#sidebar h2:contains('Rating')").before($("#sidebar h2:contains('Release group external links')").nextAll('ul.external_links'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the affiliate section
|
// Remove the affiliate section
|
||||||
re = new RegExp("musicbrainz\.org\/(artist|release-group|release|recording|work|label)\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})","i");
|
re = new RegExp(
|
||||||
|
'musicbrainz.org/(artist|release-group|release|recording|work|label)/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})',
|
||||||
|
'i'
|
||||||
|
);
|
||||||
if (window.location.href.match(re)) {
|
if (window.location.href.match(re)) {
|
||||||
$('#sidebar-affiliates').remove();
|
$('#sidebar-affiliates').remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Batch merge -> open in a new tab/windows
|
// Batch merge -> open in a new tab/windows
|
||||||
re = new RegExp("musicbrainz\.org\/artist\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/(recordings|releases|works)","i");
|
re = new RegExp(
|
||||||
|
'musicbrainz.org/artist/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/(recordings|releases|works)',
|
||||||
|
'i'
|
||||||
|
);
|
||||||
if (window.location.href.match(re)) {
|
if (window.location.href.match(re)) {
|
||||||
$("form").filter(function() {
|
$('form')
|
||||||
return $(this).prop("action").match("merge_queue");
|
.filter(function() {
|
||||||
}).attr("target", "_blank");
|
return $(this)
|
||||||
|
.prop('action')
|
||||||
|
.match('merge_queue');
|
||||||
|
})
|
||||||
|
.attr('target', '_blank');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modify link to edits: remove " - <Edit type>" from the link "Edit XXXX - <Edit type>"
|
// Modify link to edits: remove " - <Edit type>" from the link "Edit XXXX - <Edit type>"
|
||||||
re = new RegExp("musicbrainz\.org/.*/(open_)?edits","i");
|
re = new RegExp('musicbrainz.org/.*/(open_)?edits', 'i');
|
||||||
if (window.location.href.match(re)) {
|
if (window.location.href.match(re)) {
|
||||||
$("div.edit-description ~ h2").each(function() {
|
$('div.edit-description ~ h2').each(function() {
|
||||||
var parts = $(this).find("a").text().split(" - ");
|
let parts = $(this)
|
||||||
$(this).find("a").text(parts[0]);
|
.find('a')
|
||||||
$(this).append(" - " + parts[1]);
|
.text()
|
||||||
|
.split(' - ');
|
||||||
|
$(this)
|
||||||
|
.find('a')
|
||||||
|
.text(parts[0]);
|
||||||
|
$(this).append(` - ${parts[1]}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add direct link to cover art tab for Add cover art edits
|
// Add direct link to cover art tab for Add cover art edits
|
||||||
re = new RegExp("musicbrainz\.org/(.*/(open_)?edits|edit\/\d+)","i");
|
re = new RegExp('musicbrainz.org/(.*/(open_)?edits|edit/d+)', 'i');
|
||||||
if (window.location.href.match(re)) {
|
if (window.location.href.match(re)) {
|
||||||
$("div.edit-description ~ h2:contains('cover art')").each(function() {
|
$("div.edit-description ~ h2:contains('cover art')").each(function() {
|
||||||
$editdetails = $(this).parents('.edit-header').siblings('.edit-details');
|
$editdetails = $(this)
|
||||||
mbid = $editdetails.find("a[href*='musicbrainz.org/release/']").attr('href').match(/\/release\/(.{36})/)[1];
|
.parents('.edit-header')
|
||||||
$editdetails.find('tbody td.edit-cover-art').after("<tr><th span='2'><a href='/release/"+mbid+"/cover-art'>See all artworks for this release</a></th></tr>");
|
.siblings('.edit-details');
|
||||||
|
mbid = $editdetails
|
||||||
|
.find("a[href*='musicbrainz.org/release/']")
|
||||||
|
.attr('href')
|
||||||
|
.match(/\/release\/(.{36})/)[1];
|
||||||
|
$editdetails
|
||||||
|
.find('tbody td.edit-cover-art')
|
||||||
|
.after(`<tr><th span='2'><a href='/release/${mbid}/cover-art'>See all artworks for this release</a></th></tr>`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Embed Youtube videos
|
// Embed Youtube videos
|
||||||
re = new RegExp("musicbrainz\.org\/recording\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$","i");
|
re = new RegExp('musicbrainz.org/recording/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$', 'i');
|
||||||
if (window.location.href.match(re)) {
|
if (window.location.href.match(re)) {
|
||||||
var $youtube_link = $('#sidebar li.youtube-favicon a');
|
let $youtube_link = $('#sidebar li.youtube-favicon a');
|
||||||
if ($youtube_link.length > 0) {
|
if ($youtube_link.length > 0) {
|
||||||
var youtube_id = $youtube_link.prop("href").match(/http:\/\/www\.youtube\.com\/watch\?v=(.*)/)[1];
|
let youtube_id = $youtube_link.prop('href').match(/http:\/\/www\.youtube\.com\/watch\?v=(.*)/)[1];
|
||||||
$("table.details").width("60%");
|
$('table.details').width('60%');
|
||||||
$("h2:contains('Relationships')").after('<iframe width="360" height="275" frameborder="0" style="float: right;" src="https://www.youtube.com/embed/'+ youtube_id +'?rel=0" allowfullscreen=""></iframe>');
|
$("h2:contains('Relationships')").after(
|
||||||
|
`<iframe width="360" height="275" frameborder="0" style="float: right;" src="https://www.youtube.com/embed/${youtube_id}?rel=0" allowfullscreen=""></iframe>`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When attaching CDTOC, autoselect artist when there's only one result
|
// When attaching CDTOC, autoselect artist when there's only one result
|
||||||
re = new RegExp("musicbrainz\.org\/cdtoc\/attach.*&filter-artist.query=.*","i");
|
re = new RegExp('musicbrainz.org/cdtoc/attach.*&filter-artist.query=.*', 'i');
|
||||||
if (window.location.href.match(re)) {
|
if (window.location.href.match(re)) {
|
||||||
$artists = $('ul.radio-list li');
|
$artists = $('ul.radio-list li');
|
||||||
if ($artists.length == 1) {
|
if ($artists.length == 1) {
|
||||||
|
@ -130,41 +165,46 @@ $(document).ready(function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Highlight Year in ISRCs codes
|
// Highlight Year in ISRCs codes
|
||||||
re = new RegExp("musicbrainz\.org\/artist\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/recordings","i");
|
re = new RegExp('musicbrainz.org/artist/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/recordings', 'i');
|
||||||
if (window.location.href.match(re)) {
|
if (window.location.href.match(re)) {
|
||||||
var isrcColNo; // = ($("#content table.tbl thead th:eq(2)").text() == "Artist") ? 3 : 2;
|
let isrcColNo; // = ($("#content table.tbl thead th:eq(2)").text() == "Artist") ? 3 : 2;
|
||||||
$("#content table.tbl thead th").each(function(index, th) {
|
$('#content table.tbl thead th').each(function(index, th) {
|
||||||
if ($(th).text() == "ISRCs") {
|
if ($(th).text() == 'ISRCs') {
|
||||||
isrcColNo = index;
|
isrcColNo = index;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var reg = new RegExp("([A-Z]{2}[A-Z0-9]{3}[0-9]{7})");
|
let reg = new RegExp('([A-Z]{2}[A-Z0-9]{3}[0-9]{7})');
|
||||||
$("#content table.tbl tbody tr").each(function() {
|
$('#content table.tbl tbody tr').each(function() {
|
||||||
var $td = $(this).find("td:eq("+isrcColNo+")");
|
let $td = $(this).find(`td:eq(${isrcColNo})`);
|
||||||
var isrcs = $td.text().trim().split("\n<br>\n");
|
let isrcs = $td
|
||||||
var newHTML = "";
|
.text()
|
||||||
|
.trim()
|
||||||
|
.split('\n<br>\n');
|
||||||
|
let newHTML = '';
|
||||||
$.each(isrcs, function(index, isrc) {
|
$.each(isrcs, function(index, isrc) {
|
||||||
isrc = isrc.trim();
|
isrc = isrc.trim();
|
||||||
newHTML += "<a href='/isrc/" + isrc + "'><code>";
|
newHTML += `<a href='/isrc/${isrc}'><code>`;
|
||||||
newHTML += isrc.substring(0,5) + "<b>" + isrc.substring(5,7) + "</b>" + isrc.substring(7);
|
newHTML += `${isrc.substring(0, 5)}<b>${isrc.substring(5, 7)}</b>${isrc.substring(7)}`;
|
||||||
newHTML += "</code></a>";
|
newHTML += '</code></a>';
|
||||||
if (index != isrcs.length-1) { newHTML += "<br>" };
|
if (index != isrcs.length - 1) {
|
||||||
|
newHTML += '<br>';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
$td.html(newHTML);
|
$td.html(newHTML);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display ISRCs and recording comment on release tracklisting
|
// Display ISRCs and recording comment on release tracklisting
|
||||||
re = new RegExp("musicbrainz\.org\/release\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})#?$","i");
|
re = new RegExp('musicbrainz.org/release/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})#?$', 'i');
|
||||||
if (window.location.href.match(re)) {
|
if (window.location.href.match(re)) {
|
||||||
var ISRC_COLUMN_POSITION = 2;
|
let ISRC_COLUMN_POSITION = 2;
|
||||||
var mbid = window.location.href.match(re)[1];
|
var mbid = window.location.href.match(re)[1];
|
||||||
// Get tracks data from webservice
|
// Get tracks data from webservice
|
||||||
var wsurl = "/ws/2/release/" + mbid + "?inc=isrcs+recordings";
|
let wsurl = `/ws/2/release/${mbid}?inc=isrcs+recordings`;
|
||||||
$.getJSON(wsurl, function(data) {
|
$.getJSON(wsurl, function(data) {
|
||||||
// Store tracks data from webservice in a hash table
|
// Store tracks data from webservice in a hash table
|
||||||
var tracks = {};
|
let tracks = {};
|
||||||
$.each(data.media, function(index, medium) {
|
$.each(data.media, function(index, medium) {
|
||||||
$.each(medium.tracks, function(i, track) {
|
$.each(medium.tracks, function(i, track) {
|
||||||
tracks[track.id] = track;
|
tracks[track.id] = track;
|
||||||
|
@ -173,16 +213,20 @@ $(document).ready(function () {
|
||||||
// Different behavior depending on the number of mediums
|
// Different behavior depending on the number of mediums
|
||||||
if ($('table.medium').length <= 10) {
|
if ($('table.medium').length <= 10) {
|
||||||
// All mediums are already displayed: handle them now
|
// All mediums are already displayed: handle them now
|
||||||
$("table.medium").each(function() {
|
$('table.medium').each(function() {
|
||||||
handleMedium($(this), tracks)
|
handleMedium($(this), tracks);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Each medium will be handled when it's loaded
|
// Each medium will be handled when it's loaded
|
||||||
var HANDLED_ATTRIBUTE = 'ui_enh_isrcs_handled';
|
let HANDLED_ATTRIBUTE = 'ui_enh_isrcs_handled';
|
||||||
$('table.medium').attr(HANDLED_ATTRIBUTE, 'no');
|
$('table.medium').attr(HANDLED_ATTRIBUTE, 'no');
|
||||||
$('table.medium').bind("DOMNodeInserted", function(event) {
|
$('table.medium').bind('DOMNodeInserted', function(event) {
|
||||||
$target = $(event.target);
|
$target = $(event.target);
|
||||||
if ($target.prop('nodeName') == 'TBODY' && $target.parent().attr(HANDLED_ATTRIBUTE) == 'no' && $target.find('tr.subh').length > 0) {
|
if (
|
||||||
|
$target.prop('nodeName') == 'TBODY' &&
|
||||||
|
$target.parent().attr(HANDLED_ATTRIBUTE) == 'no' &&
|
||||||
|
$target.find('tr.subh').length > 0
|
||||||
|
) {
|
||||||
$medium = $target.parent();
|
$medium = $target.parent();
|
||||||
$medium.attr(HANDLED_ATTRIBUTE, 'pending');
|
$medium.attr(HANDLED_ATTRIBUTE, 'pending');
|
||||||
handleMedium($medium, tracks);
|
handleMedium($medium, tracks);
|
||||||
|
@ -194,48 +238,65 @@ $(document).ready(function () {
|
||||||
|
|
||||||
function handleMedium($medium, ws_tracks) {
|
function handleMedium($medium, ws_tracks) {
|
||||||
// Extend colspan for medium table header
|
// Extend colspan for medium table header
|
||||||
$medium.find("thead tr").each(function() {
|
$medium.find('thead tr').each(function() {
|
||||||
$(this).find("th:eq(0)").attr("colspan", $(this).find("th:eq(0)").attr("colspan")*1+1);
|
$(this)
|
||||||
|
.find('th:eq(0)')
|
||||||
|
.attr(
|
||||||
|
'colspan',
|
||||||
|
$(this)
|
||||||
|
.find('th:eq(0)')
|
||||||
|
.attr('colspan') *
|
||||||
|
1 +
|
||||||
|
1
|
||||||
|
);
|
||||||
});
|
});
|
||||||
// Table sub-header
|
// Table sub-header
|
||||||
$medium.find("tbody tr.subh th:nth-last-child("+ISRC_COLUMN_POSITION+")").before("<th style='width: 150px;' class='isrc c'> ISRC </th>");
|
$medium
|
||||||
|
.find(`tbody tr.subh th:nth-last-child(${ISRC_COLUMN_POSITION})`)
|
||||||
|
.before("<th style='width: 150px;' class='isrc c'> ISRC </th>");
|
||||||
|
|
||||||
// Handle each track
|
// Handle each track
|
||||||
$medium.find("tbody tr[id]").each(function(index, medium_track) {
|
$medium.find('tbody tr[id]').each(function(index, medium_track) {
|
||||||
track_mbid = $(medium_track).attr('id');
|
track_mbid = $(medium_track).attr('id');
|
||||||
var isrcsLinks = "";
|
let isrcsLinks = '';
|
||||||
if (ws_tracks.hasOwnProperty(track_mbid)) {
|
if (ws_tracks.hasOwnProperty(track_mbid)) {
|
||||||
track = ws_tracks[track_mbid];
|
track = ws_tracks[track_mbid];
|
||||||
var recording = track.recording;
|
let recording = track.recording;
|
||||||
// Recording comment
|
// Recording comment
|
||||||
if (recording.disambiguation != "") {
|
if (recording.disambiguation != '') {
|
||||||
var td_title_index = $("#"+track_mbid).find("td:eq(1)").hasClass("video") ? 2 : 1;
|
let td_title_index = $(`#${track_mbid}`)
|
||||||
$("#"+track_mbid).find("td:eq("+td_title_index+") a:eq(0)").after(' <span class="comment">(' + recording.disambiguation + ')</span>');
|
.find('td:eq(1)')
|
||||||
|
.hasClass('video')
|
||||||
|
? 2
|
||||||
|
: 1;
|
||||||
|
$(`#${track_mbid}`)
|
||||||
|
.find(`td:eq(${td_title_index}) a:eq(0)`)
|
||||||
|
.after(` <span class="comment">(${recording.disambiguation})</span>`);
|
||||||
}
|
}
|
||||||
// ISRCS
|
// ISRCS
|
||||||
if (recording.isrcs.length != 0) {
|
if (recording.isrcs.length != 0) {
|
||||||
var links = jQuery.map(recording.isrcs, function(isrc, i) {
|
let links = jQuery.map(recording.isrcs, function(isrc, i) {
|
||||||
return ("<a href='/isrc/" + isrc + "'>" + isrc + "</a>");
|
return `<a href='/isrc/${isrc}'>${isrc}</a>`;
|
||||||
});
|
});
|
||||||
isrcsLinks = links.join(", ");
|
isrcsLinks = links.join(', ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$('#'+track_mbid).find("td:nth-last-child("+ISRC_COLUMN_POSITION+")").before("<td class='isrc c'><small>"+isrcsLinks+"</small></td>");
|
$(`#${track_mbid}`)
|
||||||
|
.find(`td:nth-last-child(${ISRC_COLUMN_POSITION})`)
|
||||||
|
.before(`<td class='isrc c'><small>${isrcsLinks}</small></td>`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display "Edit relationships" link for release besides "Edit" link
|
// Display "Edit relationships" link for release besides "Edit" link
|
||||||
re = new RegExp("musicbrainz\.org\/release\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})","i");
|
re = new RegExp('musicbrainz.org/release/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})', 'i');
|
||||||
if (window.location.href.match(re)) {
|
if (window.location.href.match(re)) {
|
||||||
var mbid = window.location.href.match(re)[1];
|
var mbid = window.location.href.match(re)[1];
|
||||||
$('ul.tabs').append('<li><a href="/release/' + mbid + '/edit-relationships">Edit relationships</a></li>');
|
$('ul.tabs').append(`<li><a href="/release/${mbid}/edit-relationships">Edit relationships</a></li>`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discogs link rollover
|
// Discogs link rollover
|
||||||
// TODO...
|
// TODO...
|
||||||
|
|
||||||
// -------------- End of script ------------------------
|
// -------------- End of script ------------------------
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -13,205 +13,213 @@
|
||||||
// @icon https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/assets/images/Musicbrainz_import_logo.png
|
// @icon https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/assets/images/Musicbrainz_import_logo.png
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
|
|
||||||
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant
|
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant
|
||||||
this.$ = this.jQuery = jQuery.noConflict(true);
|
this.$ = this.jQuery = jQuery.noConflict(true);
|
||||||
|
|
||||||
if (!unsafeWindow) unsafeWindow = window;
|
if (!unsafeWindow) unsafeWindow = window;
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
MBImportStyle();
|
MBImportStyle();
|
||||||
|
|
||||||
var release_url = window.location.href.replace('/\?.*$/', '').replace(/#.*$/, '');
|
let release_url = window.location.href.replace('/?.*$/', '').replace(/#.*$/, '');
|
||||||
var release = retrieveReleaseInfo(release_url);
|
let release = retrieveReleaseInfo(release_url);
|
||||||
insertLink(release, release_url);
|
insertLink(release, release_url);
|
||||||
LOGGER.info("Parsed release: ", release);
|
LOGGER.info('Parsed release: ', release);
|
||||||
});
|
});
|
||||||
|
|
||||||
function setreleasedate(release, datestring) {
|
function setreleasedate(release, datestring) {
|
||||||
if (/^\d{4}$/.exec(datestring)) {
|
if (/^\d{4}$/.exec(datestring)) {
|
||||||
release.year = datestring;
|
release.year = datestring;
|
||||||
} else if (datestring.indexOf(',') != -1) {
|
} else if (datestring.indexOf(',') != -1) {
|
||||||
var commaindex = datestring.indexOf(',');
|
let commaindex = datestring.indexOf(',');
|
||||||
var d = new Date(datestring.substring(0, commaindex - 2) + datestring.substring(commaindex));
|
var d = new Date(datestring.substring(0, commaindex - 2) + datestring.substring(commaindex));
|
||||||
release.year = d.getFullYear();
|
release.year = d.getFullYear();
|
||||||
release.month = d.getMonth() + 1;
|
release.month = d.getMonth() + 1;
|
||||||
release.day = d.getDate();
|
release.day = d.getDate();
|
||||||
} else {
|
} else {
|
||||||
var d = new Date("2 " + datestring);
|
var d = new Date(`2 ${datestring}`);
|
||||||
release.year = d.getFullYear();
|
release.year = d.getFullYear();
|
||||||
release.month = d.getMonth() + 1;
|
release.month = d.getMonth() + 1;
|
||||||
}
|
}
|
||||||
return release;
|
return release;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGenericalData() {
|
function getGenericalData() {
|
||||||
var rdata = new Array();
|
let rdata = new Array();
|
||||||
var keydata = $('dl.float_left dt, dl.float_right dt').map(function() {
|
let keydata = $('dl.float_left dt, dl.float_right dt')
|
||||||
var s = $.trim($(this).text());
|
.map(function() {
|
||||||
return s.substring(0, s.length - 1);
|
let s = $.trim($(this).text());
|
||||||
}).get();
|
return s.substring(0, s.length - 1);
|
||||||
var valuedata = $('dl.float_left dd,dl.float_right dd').map(function() {
|
})
|
||||||
return $.trim($(this).text());
|
.get();
|
||||||
}).get();
|
let valuedata = $('dl.float_left dd,dl.float_right dd')
|
||||||
for (i = 0; i < keydata.length; i++) {
|
.map(function() {
|
||||||
rdata[keydata[i]] = valuedata[i];
|
return $.trim($(this).text());
|
||||||
}
|
})
|
||||||
return rdata;
|
.get();
|
||||||
|
for (i = 0; i < keydata.length; i++) {
|
||||||
|
rdata[keydata[i]] = valuedata[i];
|
||||||
|
}
|
||||||
|
return rdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getArtistsList() {
|
function getArtistsList() {
|
||||||
return $.map($('h2.band_name').text().split('/'), $.trim);
|
return $.map(
|
||||||
|
$('h2.band_name')
|
||||||
|
.text()
|
||||||
|
.split('/'),
|
||||||
|
$.trim
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function retrieveReleaseInfo(release_url) {
|
function retrieveReleaseInfo(release_url) {
|
||||||
|
let release = {
|
||||||
|
discs: [],
|
||||||
|
artist_credit: [],
|
||||||
|
title: '',
|
||||||
|
year: 0,
|
||||||
|
month: 0,
|
||||||
|
day: 0,
|
||||||
|
parent_album_url: '',
|
||||||
|
labels: [],
|
||||||
|
format: '',
|
||||||
|
country: '',
|
||||||
|
type: '',
|
||||||
|
status: 'official',
|
||||||
|
packaging: '',
|
||||||
|
language: '',
|
||||||
|
script: '',
|
||||||
|
urls: []
|
||||||
|
};
|
||||||
|
|
||||||
var release = {
|
let rdata = getGenericalData();
|
||||||
discs: [],
|
let artists = getArtistsList();
|
||||||
artist_credit: [],
|
let joinphrase = '';
|
||||||
title: '',
|
if (artists.length > 1) {
|
||||||
year: 0,
|
if (rdata['Type'] == 'Split') {
|
||||||
month: 0,
|
joinphrase = ' / ';
|
||||||
day: 0,
|
} else {
|
||||||
parent_album_url: '',
|
joinphrase = ' & ';
|
||||||
labels: [],
|
}
|
||||||
format: '',
|
}
|
||||||
country: '',
|
for (let i = 0; i < artists.length; i++) {
|
||||||
type: '',
|
release.artist_credit.push({
|
||||||
status: 'official',
|
artist_name: artists[i],
|
||||||
packaging: '',
|
credited_name: artists[i],
|
||||||
language: '',
|
joinphrase: i != artists.length - 1 ? joinphrase : ''
|
||||||
script: '',
|
});
|
||||||
urls: [],
|
}
|
||||||
};
|
release.title = $('h1.album_name').text();
|
||||||
|
|
||||||
var rdata = getGenericalData();
|
release = setreleasedate(release, rdata['Release date']);
|
||||||
var artists = getArtistsList();
|
if ('Label' in rdata) {
|
||||||
var joinphrase = "";
|
// TODO: add case for multiple labels if such a case exist
|
||||||
if (artists.length > 1) {
|
let label = rdata['Label'];
|
||||||
if (rdata["Type"] == "Split") {
|
let label_mbid = '';
|
||||||
joinphrase = " / ";
|
if (label == 'Independent') {
|
||||||
|
label = '[no label]';
|
||||||
|
label_mbid = '157afde4-4bf5-4039-8ad2-5a15acc85176';
|
||||||
|
}
|
||||||
|
let catno = rdata['Catalog ID'];
|
||||||
|
if (catno == undefined || catno == 'N/A') {
|
||||||
|
catno = '';
|
||||||
|
}
|
||||||
|
release.labels.push({
|
||||||
|
name: label,
|
||||||
|
catno: catno,
|
||||||
|
mbid: label_mbid
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
joinphrase = " & ";
|
if (rdata['Type'] in ReleaseTypes) {
|
||||||
|
let types = ReleaseTypes[rdata['Type']];
|
||||||
|
release.type = types[0];
|
||||||
|
// NOTE: secondary type may not be selected on MB editor, but it still works, a bug on MB side
|
||||||
|
release.secondary_types = types.slice(1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for (var i = 0; i < artists.length; i++) {
|
// FIXME: multiple vinyls ie. http://www.metal-archives.com/albums/Reverend_Bizarre/III%3A_So_Long_Suckers/415313
|
||||||
release.artist_credit.push({
|
if (rdata['Format'] in ReleaseFormat) {
|
||||||
artist_name: artists[i],
|
release.format = ReleaseFormat[rdata['Format']];
|
||||||
credited_name: artists[i],
|
}
|
||||||
joinphrase: i != artists.length - 1 ? joinphrase : ""
|
|
||||||
|
if ('Version desc.' in rdata) {
|
||||||
|
if (rdata['Version desc.'].indexOf('Digipak') != -1) {
|
||||||
|
release.packaging = 'Digipak';
|
||||||
|
}
|
||||||
|
if (release.format == 'CD' && rdata['Version desc.'] == 'CD-R') {
|
||||||
|
release.format = 'CD-R';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let identifiers = $('#album_tabs_notes > div:nth-child(2)')
|
||||||
|
.find('p:not([class])')
|
||||||
|
.contents();
|
||||||
|
for (let j = 0; j < identifiers.length; j++) {
|
||||||
|
if (identifiers[j].textContent.indexOf('Barcode:') != -1) {
|
||||||
|
release.barcode = $.trim(identifiers[j].textContent.substring(8));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// URLs
|
||||||
|
let link_type = MBImport.URL_TYPES;
|
||||||
|
release.urls.push({
|
||||||
|
url: release_url,
|
||||||
|
link_type: link_type.other_databases
|
||||||
});
|
});
|
||||||
}
|
|
||||||
release.title = $('h1.album_name').text();
|
|
||||||
|
|
||||||
release = setreleasedate(release, rdata["Release date"]);
|
let releaseNumber = 0;
|
||||||
if ("Label" in rdata) {
|
let disc = {
|
||||||
// TODO: add case for multiple labels if such a case exist
|
|
||||||
var label = rdata["Label"];
|
|
||||||
var label_mbid = "";
|
|
||||||
if (label == "Independent") {
|
|
||||||
label = "[no label]";
|
|
||||||
label_mbid = '157afde4-4bf5-4039-8ad2-5a15acc85176';
|
|
||||||
}
|
|
||||||
var catno = rdata["Catalog ID"];
|
|
||||||
if (catno == undefined || catno == "N/A") {
|
|
||||||
catno = "";
|
|
||||||
}
|
|
||||||
release.labels.push({
|
|
||||||
name: label,
|
|
||||||
catno: catno,
|
|
||||||
mbid: label_mbid
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rdata["Type"] in ReleaseTypes) {
|
|
||||||
var types = ReleaseTypes[rdata["Type"]];
|
|
||||||
release.type = types[0];
|
|
||||||
// NOTE: secondary type may not be selected on MB editor, but it still works, a bug on MB side
|
|
||||||
release.secondary_types = types.slice(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: multiple vinyls ie. http://www.metal-archives.com/albums/Reverend_Bizarre/III%3A_So_Long_Suckers/415313
|
|
||||||
if (rdata["Format"] in ReleaseFormat) {
|
|
||||||
release.format = ReleaseFormat[rdata["Format"]];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("Version desc." in rdata) {
|
|
||||||
if (rdata["Version desc."].indexOf("Digipak") != -1) {
|
|
||||||
release.packaging = "Digipak";
|
|
||||||
}
|
|
||||||
if (release.format == "CD" && rdata["Version desc."] == "CD-R") {
|
|
||||||
release.format = "CD-R";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var identifiers = $("#album_tabs_notes > div:nth-child(2)").find("p:not([class])").contents();
|
|
||||||
for (var j = 0; j < identifiers.length; j++) {
|
|
||||||
if (identifiers[j].textContent.indexOf("Barcode:") != -1) {
|
|
||||||
release.barcode = $.trim(identifiers[j].textContent.substring(8));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// URLs
|
|
||||||
var link_type = MBImport.URL_TYPES;
|
|
||||||
release.urls.push({
|
|
||||||
url: release_url,
|
|
||||||
link_type: link_type.other_databases
|
|
||||||
});
|
|
||||||
|
|
||||||
var releaseNumber = 0;
|
|
||||||
var disc = {
|
|
||||||
tracks: [],
|
|
||||||
format: release.format
|
|
||||||
};
|
|
||||||
release.discs.push(disc);
|
|
||||||
|
|
||||||
var tracksline = $('table.table_lyrics tr.even,table.table_lyrics tr.odd');
|
|
||||||
|
|
||||||
tracksline.each(function(index, element) {
|
|
||||||
var trackNumber = $.trim(element.children[0].textContent).replace('.', "");
|
|
||||||
if (trackNumber == "1" && trackNumber != index + 1) {
|
|
||||||
releaseNumber++;
|
|
||||||
release.discs.push({
|
|
||||||
tracks: [],
|
tracks: [],
|
||||||
format: release.format
|
format: release.format
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: handling of split and compilation artists (artist - title)
|
|
||||||
var track = {
|
|
||||||
'number': trackNumber,
|
|
||||||
'title': $.trim(element.children[1].textContent.replace(/\s+/g, ' ')),
|
|
||||||
'duration': $.trim(element.children[2].textContent),
|
|
||||||
'artist_credit': [release.artist_credit]
|
|
||||||
};
|
};
|
||||||
release.discs[releaseNumber].tracks.push(track);
|
release.discs.push(disc);
|
||||||
});
|
|
||||||
return release;
|
let tracksline = $('table.table_lyrics tr.even,table.table_lyrics tr.odd');
|
||||||
|
|
||||||
|
tracksline.each(function(index, element) {
|
||||||
|
let trackNumber = $.trim(element.children[0].textContent).replace('.', '');
|
||||||
|
if (trackNumber == '1' && trackNumber != index + 1) {
|
||||||
|
releaseNumber++;
|
||||||
|
release.discs.push({
|
||||||
|
tracks: [],
|
||||||
|
format: release.format
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: handling of split and compilation artists (artist - title)
|
||||||
|
let track = {
|
||||||
|
number: trackNumber,
|
||||||
|
title: $.trim(element.children[1].textContent.replace(/\s+/g, ' ')),
|
||||||
|
duration: $.trim(element.children[2].textContent),
|
||||||
|
artist_credit: [release.artist_credit]
|
||||||
|
};
|
||||||
|
release.discs[releaseNumber].tracks.push(track);
|
||||||
|
});
|
||||||
|
return release;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert button into page under label information
|
// Insert button into page under label information
|
||||||
function insertLink(release, release_url) {
|
function insertLink(release, release_url) {
|
||||||
var edit_note = MBImport.makeEditNote(release_url, 'Metal Archives');
|
let edit_note = MBImport.makeEditNote(release_url, 'Metal Archives');
|
||||||
var parameters = MBImport.buildFormParameters(release, edit_note);
|
let parameters = MBImport.buildFormParameters(release, edit_note);
|
||||||
|
|
||||||
var mbUI = $('<div id="musicbrainz-import">' + MBImport.buildFormHTML(parameters) + MBImport.buildSearchButton(release) + '</div>').hide();
|
let mbUI = $(`<div id="musicbrainz-import">${MBImport.buildFormHTML(parameters)}${MBImport.buildSearchButton(release)}</div>`).hide();
|
||||||
|
|
||||||
$('h2.band_name').after(mbUI);
|
$('h2.band_name').after(mbUI);
|
||||||
$('#musicbrainz-import form').css({
|
$('#musicbrainz-import form').css({
|
||||||
'padding': '0'
|
padding: '0'
|
||||||
});
|
});
|
||||||
$('form.musicbrainz_import').css({
|
$('form.musicbrainz_import').css({
|
||||||
'display': 'inline-block',
|
display: 'inline-block',
|
||||||
'margin': '1px'
|
margin: '1px'
|
||||||
});
|
});
|
||||||
$('form.musicbrainz_import img').css({
|
$('form.musicbrainz_import img').css({
|
||||||
'display': 'inline-block'
|
display: 'inline-block'
|
||||||
});
|
});
|
||||||
|
|
||||||
mbUI.slideDown();
|
mbUI.slideDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -236,28 +244,28 @@ Split video
|
||||||
|
|
||||||
//ReleaseTypes[MAtype]=["primary type","secondary type on mb"];
|
//ReleaseTypes[MAtype]=["primary type","secondary type on mb"];
|
||||||
var ReleaseTypes = {
|
var ReleaseTypes = {
|
||||||
"Full-length": ["album"],
|
'Full-length': ['album'],
|
||||||
"Live album": ["album", "live"],
|
'Live album': ['album', 'live'],
|
||||||
"Demo": ["album", "demo"],
|
Demo: ['album', 'demo'],
|
||||||
"Single": ["single"],
|
Single: ['single'],
|
||||||
"EP": ["ep"],
|
EP: ['ep'],
|
||||||
"Compilation": ["album", "compilation"],
|
Compilation: ['album', 'compilation'],
|
||||||
"Split": ["album"],
|
Split: ['album'],
|
||||||
"Collaboration": [""],
|
Collaboration: ['']
|
||||||
};
|
};
|
||||||
|
|
||||||
//ReleaseFormat[MAformat]="MBformat";
|
//ReleaseFormat[MAformat]="MBformat";
|
||||||
var ReleaseFormat = {
|
var ReleaseFormat = {
|
||||||
"CD": "CD",
|
CD: 'CD',
|
||||||
"2CD": "CD",
|
'2CD': 'CD',
|
||||||
"Vinyl": "Vinyl",
|
Vinyl: 'Vinyl',
|
||||||
"7\" vinyl": "7\" Vinyl",
|
'7" vinyl': '7" Vinyl',
|
||||||
"7\" vinyl (33⅓ RPM)": "7\" Vinyl",
|
'7" vinyl (33⅓ RPM)': '7" Vinyl',
|
||||||
"10\" vinyl (33⅓ RPM)": "10\" Vinyl",
|
'10" vinyl (33⅓ RPM)': '10" Vinyl',
|
||||||
"10\" vinyl": "10\" Vinyl",
|
'10" vinyl': '10" Vinyl',
|
||||||
"12\" vinyl": "12\" Vinyl",
|
'12" vinyl': '12" Vinyl',
|
||||||
"2 12\" vinyls": "12\" Vinyl",
|
'2 12" vinyls': '12" Vinyl',
|
||||||
"12\" vinyl (33⅓ RPM)": "12\" Vinyl",
|
'12" vinyl (33⅓ RPM)': '12" Vinyl',
|
||||||
"Cassette": "Cassette",
|
Cassette: 'Cassette',
|
||||||
"Digital": "Digital Media",
|
Digital: 'Digital Media'
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,170 +22,178 @@ if (!unsafeWindow) unsafeWindow = window;
|
||||||
var DEBUG = false;
|
var DEBUG = false;
|
||||||
//DEBUG = true;
|
//DEBUG = true;
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
LOGGER.setLevel('debug');
|
LOGGER.setLevel('debug');
|
||||||
}
|
}
|
||||||
|
|
||||||
// list of qobuz artist id which should be mapped to Various Artists
|
// list of qobuz artist id which should be mapped to Various Artists
|
||||||
var various_artists_ids = [ 26887, 145383, 353325, 183869, 997899 ];
|
var various_artists_ids = [26887, 145383, 353325, 183869, 997899];
|
||||||
|
|
||||||
function parseRelease(data) {
|
function parseRelease(data) {
|
||||||
var release = {};
|
let release = {};
|
||||||
|
|
||||||
release.script = 'Latn';
|
release.script = 'Latn';
|
||||||
release.url = 'https://www.qobuz.com' + data.relative_url; // no lang
|
release.url = `https://www.qobuz.com${data.relative_url}`; // no lang
|
||||||
|
|
||||||
release.title = data.title;
|
release.title = data.title;
|
||||||
release.artist_credit = MBImport.makeArtistCredits([data.artist.name]); // FIXME: various artists
|
release.artist_credit = MBImport.makeArtistCredits([data.artist.name]); // FIXME: various artists
|
||||||
if ($.inArray(data.artist.id, various_artists_ids) != -1) {
|
if ($.inArray(data.artist.id, various_artists_ids) != -1) {
|
||||||
release.artist_credit = [ MBImport.specialArtist('various_artists') ];
|
release.artist_credit = [MBImport.specialArtist('various_artists')];
|
||||||
}
|
|
||||||
|
|
||||||
// Release information global to all Beatport releases
|
|
||||||
release.packaging = 'None';
|
|
||||||
release.barcode = data.upc;
|
|
||||||
release.country = "XW";
|
|
||||||
if (i18n_global && i18n_global.zone) {
|
|
||||||
release.country = i18n_global.zone;
|
|
||||||
}
|
|
||||||
release.status = 'official';
|
|
||||||
release.urls = [];
|
|
||||||
release.urls.push({
|
|
||||||
'url': release.url,
|
|
||||||
'link_type': MBImport.URL_TYPES.purchase_for_download
|
|
||||||
});
|
|
||||||
|
|
||||||
// release timestamps are using France time + daylight saving (GMT+1 or GMT+2),
|
|
||||||
// add 3 hours to get the day of release (matching the one displayed)
|
|
||||||
var releaseDate = new Date((parseInt(data.released_at, 10) + 3*3600) * 1000);
|
|
||||||
release.year = releaseDate.getUTCFullYear();
|
|
||||||
release.month = releaseDate.getUTCMonth() + 1;
|
|
||||||
release.day = releaseDate.getUTCDate();
|
|
||||||
|
|
||||||
release.labels = [];
|
|
||||||
$.each(data.label.name.split(' - '), function(index, label) {
|
|
||||||
release.labels.push({
|
|
||||||
name: label,
|
|
||||||
catno: "[none]" // no catno on qobuz ?
|
|
||||||
});
|
|
||||||
});
|
|
||||||
release.isrcs = [];
|
|
||||||
release.comment = "Digital download";
|
|
||||||
release.discs = [];
|
|
||||||
var tracks = [], old_media_num = 1;
|
|
||||||
$.each(data.tracks.items, function(index, trackobj) {
|
|
||||||
release.isrcs.push(trackobj.isrc);
|
|
||||||
if (trackobj.media_number != old_media_num) {
|
|
||||||
release.discs.push({
|
|
||||||
'tracks': tracks,
|
|
||||||
'format': "Digital Media"
|
|
||||||
});
|
|
||||||
old_media_num = trackobj.media_number;
|
|
||||||
tracks = [];
|
|
||||||
}
|
}
|
||||||
var track = {};
|
|
||||||
track.title = trackobj.title.replace('"','\"');
|
|
||||||
track.duration = trackobj.duration * 1000;
|
|
||||||
var performers = (typeof trackobj.performers !== 'undefined') && trackobj.performers.split('\r - ').map(function(v) {
|
|
||||||
var list = v.split(', ');
|
|
||||||
var name = list.shift();
|
|
||||||
return [name, list];
|
|
||||||
}) || [trackobj.performer.name, ['Primary']];
|
|
||||||
var artists = [];
|
|
||||||
var featured_artists = [];
|
|
||||||
$.each(performers, function(index, performer) {
|
|
||||||
if ($.inArray('Featured Artist', performer[1]) != -1) {
|
|
||||||
featured_artists.push(performer[0]);
|
|
||||||
}
|
|
||||||
else if ($.inArray('Main Performer', performer[1]) != -1
|
|
||||||
|| $.inArray('Primary', performer[1]) != -1
|
|
||||||
|| $.inArray('interprète', performer[1]) != -1
|
|
||||||
|| $.inArray('Performer', performer[1]) != -1
|
|
||||||
|| $.inArray('Main Artist', performer[1]) != -1
|
|
||||||
) {
|
|
||||||
artists.push(performer[0]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
track.artist_credit = MBImport.makeArtistCredits(artists);
|
|
||||||
if (featured_artists.length) {
|
|
||||||
if (track.artist_credit.length) {
|
|
||||||
track.artist_credit[track.artist_credit.length-1].joinphrase = ' feat. ';
|
|
||||||
}
|
|
||||||
$.merge(track.artist_credit, MBImport.makeArtistCredits(featured_artists));
|
|
||||||
}
|
|
||||||
tracks.push(track);
|
|
||||||
});
|
|
||||||
release.discs.push({
|
|
||||||
'tracks': tracks,
|
|
||||||
'format': "Digital Media"
|
|
||||||
});
|
|
||||||
|
|
||||||
LOGGER.info("Parsed release: ", release);
|
// Release information global to all Beatport releases
|
||||||
return release;
|
release.packaging = 'None';
|
||||||
|
release.barcode = data.upc;
|
||||||
|
release.country = 'XW';
|
||||||
|
if (i18n_global && i18n_global.zone) {
|
||||||
|
release.country = i18n_global.zone;
|
||||||
|
}
|
||||||
|
release.status = 'official';
|
||||||
|
release.urls = [];
|
||||||
|
release.urls.push({
|
||||||
|
url: release.url,
|
||||||
|
link_type: MBImport.URL_TYPES.purchase_for_download
|
||||||
|
});
|
||||||
|
|
||||||
|
// release timestamps are using France time + daylight saving (GMT+1 or GMT+2),
|
||||||
|
// add 3 hours to get the day of release (matching the one displayed)
|
||||||
|
let releaseDate = new Date((parseInt(data.released_at, 10) + 3 * 3600) * 1000);
|
||||||
|
release.year = releaseDate.getUTCFullYear();
|
||||||
|
release.month = releaseDate.getUTCMonth() + 1;
|
||||||
|
release.day = releaseDate.getUTCDate();
|
||||||
|
|
||||||
|
release.labels = [];
|
||||||
|
$.each(data.label.name.split(' - '), function(index, label) {
|
||||||
|
release.labels.push({
|
||||||
|
name: label,
|
||||||
|
catno: '[none]' // no catno on qobuz ?
|
||||||
|
});
|
||||||
|
});
|
||||||
|
release.isrcs = [];
|
||||||
|
release.comment = 'Digital download';
|
||||||
|
release.discs = [];
|
||||||
|
let tracks = [],
|
||||||
|
old_media_num = 1;
|
||||||
|
$.each(data.tracks.items, function(index, trackobj) {
|
||||||
|
release.isrcs.push(trackobj.isrc);
|
||||||
|
if (trackobj.media_number != old_media_num) {
|
||||||
|
release.discs.push({
|
||||||
|
tracks: tracks,
|
||||||
|
format: 'Digital Media'
|
||||||
|
});
|
||||||
|
old_media_num = trackobj.media_number;
|
||||||
|
tracks = [];
|
||||||
|
}
|
||||||
|
let track = {};
|
||||||
|
track.title = trackobj.title.replace('"', '"');
|
||||||
|
track.duration = trackobj.duration * 1000;
|
||||||
|
let performers = (typeof trackobj.performers !== 'undefined' &&
|
||||||
|
trackobj.performers.split('\r - ').map(function(v) {
|
||||||
|
let list = v.split(', ');
|
||||||
|
let name = list.shift();
|
||||||
|
return [name, list];
|
||||||
|
})) || [trackobj.performer.name, ['Primary']];
|
||||||
|
let artists = [];
|
||||||
|
let featured_artists = [];
|
||||||
|
$.each(performers, function(index, performer) {
|
||||||
|
if ($.inArray('Featured Artist', performer[1]) != -1) {
|
||||||
|
featured_artists.push(performer[0]);
|
||||||
|
} else if (
|
||||||
|
$.inArray('Main Performer', performer[1]) != -1 ||
|
||||||
|
$.inArray('Primary', performer[1]) != -1 ||
|
||||||
|
$.inArray('interprète', performer[1]) != -1 ||
|
||||||
|
$.inArray('Performer', performer[1]) != -1 ||
|
||||||
|
$.inArray('Main Artist', performer[1]) != -1
|
||||||
|
) {
|
||||||
|
artists.push(performer[0]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
track.artist_credit = MBImport.makeArtistCredits(artists);
|
||||||
|
if (featured_artists.length) {
|
||||||
|
if (track.artist_credit.length) {
|
||||||
|
track.artist_credit[track.artist_credit.length - 1].joinphrase = ' feat. ';
|
||||||
|
}
|
||||||
|
$.merge(track.artist_credit, MBImport.makeArtistCredits(featured_artists));
|
||||||
|
}
|
||||||
|
tracks.push(track);
|
||||||
|
});
|
||||||
|
release.discs.push({
|
||||||
|
tracks: tracks,
|
||||||
|
format: 'Digital Media'
|
||||||
|
});
|
||||||
|
|
||||||
|
LOGGER.info('Parsed release: ', release);
|
||||||
|
return release;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert button into page under label information
|
// Insert button into page under label information
|
||||||
function insertLink(release) {
|
function insertLink(release) {
|
||||||
var edit_note = MBImport.makeEditNote(release.url, 'Qobuz');
|
let edit_note = MBImport.makeEditNote(release.url, 'Qobuz');
|
||||||
var parameters = MBImport.buildFormParameters(release, edit_note);
|
let parameters = MBImport.buildFormParameters(release, edit_note);
|
||||||
|
|
||||||
var mbUI = $('<p class="musicbrainz_import">').append(MBImport.buildFormHTML(parameters) + MBImport.buildSearchButton(release)).hide();
|
let mbUI = $('<p class="musicbrainz_import">')
|
||||||
mbUI.append($('<button id="isrcs" type="submit" title="Show list of ISRCs">Show ISRCs</button>'));
|
.append(MBImport.buildFormHTML(parameters) + MBImport.buildSearchButton(release))
|
||||||
var isrclist = $('<p><textarea id="isrclist" style="display:none">' + release.isrcs.join("\n") + '</textarea></p>');
|
.hide();
|
||||||
|
mbUI.append($('<button id="isrcs" type="submit" title="Show list of ISRCs">Show ISRCs</button>'));
|
||||||
|
let isrclist = $(`<p><textarea id="isrclist" style="display:none">${release.isrcs.join('\n')}</textarea></p>`);
|
||||||
|
|
||||||
$("#info div.meta").append(mbUI).append(isrclist);
|
$('#info div.meta')
|
||||||
$('form.musicbrainz_import').css({
|
.append(mbUI)
|
||||||
'display': 'inline-block',
|
.append(isrclist);
|
||||||
'margin': '1px'
|
$('form.musicbrainz_import').css({
|
||||||
});
|
display: 'inline-block',
|
||||||
$('form.musicbrainz_import img').css({
|
margin: '1px'
|
||||||
'display': 'inline-block',
|
});
|
||||||
'width': '16px',
|
$('form.musicbrainz_import img').css({
|
||||||
'height': '16px'
|
display: 'inline-block',
|
||||||
});
|
width: '16px',
|
||||||
mbUI.slideDown();
|
height: '16px'
|
||||||
|
});
|
||||||
|
mbUI.slideDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hook all XMLHttpRequest to use the data fetched by the official web-player.
|
// Hook all XMLHttpRequest to use the data fetched by the official web-player.
|
||||||
(function() {
|
(function() {
|
||||||
const send = XMLHttpRequest.prototype.send
|
const send = XMLHttpRequest.prototype.send;
|
||||||
XMLHttpRequest.prototype.send = function() {
|
XMLHttpRequest.prototype.send = function() {
|
||||||
this.addEventListener('load', function() {
|
this.addEventListener('load', function() {
|
||||||
var wsUrl = 'https://www.qobuz.com/api.json/0.2/album/get?album_id=';
|
let wsUrl = 'https://www.qobuz.com/api.json/0.2/album/get?album_id=';
|
||||||
var repUrl = arguments[0].originalTarget.responseURL;
|
let repUrl = arguments[0].originalTarget.responseURL;
|
||||||
if (repUrl.startsWith(wsUrl)) {
|
if (repUrl.startsWith(wsUrl)) {
|
||||||
var data = JSON.parse(this.responseText);
|
let data = JSON.parse(this.responseText);
|
||||||
var release = parseRelease(data);
|
let release = parseRelease(data);
|
||||||
insertLink(release);
|
insertLink(release);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
return send.apply(this, arguments)
|
return send.apply(this, arguments);
|
||||||
}
|
};
|
||||||
})()
|
})();
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
MBImportStyle();
|
||||||
|
|
||||||
MBImportStyle();
|
// replace image zoom link by the maximum size image link
|
||||||
|
let maximgurl = $('#product-cover-link')
|
||||||
// replace image zoom link by the maximum size image link
|
.attr('href')
|
||||||
var maximgurl = $("#product-cover-link").attr("href").replace('_600', '_max');
|
.replace('_600', '_max');
|
||||||
var maximg = new Image();
|
let maximg = new Image();
|
||||||
maximg.onerror = function (evt) {
|
maximg.onerror = function(evt) {
|
||||||
LOGGER.debug("No max image");
|
LOGGER.debug('No max image');
|
||||||
};
|
};
|
||||||
maximg.onload = function (evt) {
|
maximg.onload = function(evt) {
|
||||||
$("#product-cover-link").attr("href", maximgurl);
|
$('#product-cover-link').attr('href', maximgurl);
|
||||||
$("#product-cover-link").attr("title", $("#product-cover-link").attr("title") + ' (Qobuz importer: ' + maximg.width + 'x' + maximg.height + ' image)');
|
$('#product-cover-link').attr(
|
||||||
};
|
'title',
|
||||||
maximg.src = maximgurl;
|
`${$('#product-cover-link').attr('title')} (Qobuz importer: ${maximg.width}x${maximg.height} image)`
|
||||||
|
);
|
||||||
|
};
|
||||||
|
maximg.src = maximgurl;
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('click', '#isrcs', function (){
|
$(document).on('click', '#isrcs', function() {
|
||||||
$('#isrclist').toggle();
|
$('#isrclist').toggle();
|
||||||
if ($('#isrclist').is(':visible')) {
|
if ($('#isrclist').is(':visible')) {
|
||||||
$('#isrclist').select();
|
$('#isrclist').select();
|
||||||
$(this).text('Hide ISRCs');
|
$(this).text('Hide ISRCs');
|
||||||
}
|
} else $(this).text('Show ISRCs');
|
||||||
else $(this).text('Show ISRCs');
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
|
@ -41,19 +41,23 @@
|
||||||
// authorization.
|
// authorization.
|
||||||
// ==/License==
|
// ==/License==
|
||||||
|
|
||||||
var scr = document.createElement("script");
|
var scr = document.createElement('script');
|
||||||
scr.textContent = "$(" + setRecordingComments + ");";
|
scr.textContent = `$(${setRecordingComments});`;
|
||||||
document.body.appendChild(scr);
|
document.body.appendChild(scr);
|
||||||
|
|
||||||
function setRecordingComments() {
|
function setRecordingComments() {
|
||||||
var $tracks;
|
let $tracks;
|
||||||
var $inputs = $();
|
let $inputs = $();
|
||||||
var EDIT_RECORDING_EDIT = 72;
|
let EDIT_RECORDING_EDIT = 72;
|
||||||
|
|
||||||
$("head").append($("<style></style>").text("input.recording-comment { background: inherit; border: 1px #999 solid; width: 32em; margin-left: 0.5em; }"));
|
$('head').append(
|
||||||
|
$('<style></style>').text(
|
||||||
|
'input.recording-comment { background: inherit; border: 1px #999 solid; width: 32em; margin-left: 0.5em; }'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
var delay = setInterval(function () {
|
var delay = setInterval(function() {
|
||||||
$tracks = $(".medium tbody tr[id]");
|
$tracks = $('.medium tbody tr[id]');
|
||||||
|
|
||||||
if ($tracks.length) {
|
if ($tracks.length) {
|
||||||
clearInterval(delay);
|
clearInterval(delay);
|
||||||
|
@ -61,10 +65,14 @@ function setRecordingComments() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tracks.each(function () {
|
$tracks.each(function() {
|
||||||
var $td = $(this).children("td:not(.pos):not(.video):not(.rating):not(.treleases)").has("a[href^=\\/recording\\/]"),
|
let $td = $(this)
|
||||||
node = $td.children("td > .mp, td > .name-variation, td > a[href^=\\/recording\\/]").filter(":first"),
|
.children('td:not(.pos):not(.video):not(.rating):not(.treleases)')
|
||||||
$input = $("<input />").addClass("recording-comment").insertAfter(node);
|
.has('a[href^=\\/recording\\/]'),
|
||||||
|
node = $td.children('td > .mp, td > .name-variation, td > a[href^=\\/recording\\/]').filter(':first'),
|
||||||
|
$input = $('<input />')
|
||||||
|
.addClass('recording-comment')
|
||||||
|
.insertAfter(node);
|
||||||
|
|
||||||
if (!editing) {
|
if (!editing) {
|
||||||
$input.hide();
|
$input.hide();
|
||||||
|
@ -73,14 +81,17 @@ function setRecordingComments() {
|
||||||
$inputs = $inputs.add($input);
|
$inputs = $inputs.add($input);
|
||||||
});
|
});
|
||||||
|
|
||||||
var release = location.pathname.match(MBID_REGEX)[0];
|
let release = location.pathname.match(MBID_REGEX)[0];
|
||||||
|
|
||||||
$.get("/ws/2/release/" + release + "?inc=recordings&fmt=json", function (data) {
|
$.get(`/ws/2/release/${release}?inc=recordings&fmt=json`, function(data) {
|
||||||
var comments = _.map(_.map(_.flatten(_.map(data.media, "tracks")), "recording"), "disambiguation");
|
let comments = _.map(_.map(_.flatten(_.map(data.media, 'tracks')), 'recording'), 'disambiguation');
|
||||||
|
|
||||||
for (var i = 0, len = comments.length; i < len; i++) {
|
for (let i = 0, len = comments.length; i < len; i++) {
|
||||||
var comment = comments[i];
|
let comment = comments[i];
|
||||||
$inputs.eq(i).val(comment).data("old", comment);
|
$inputs
|
||||||
|
.eq(i)
|
||||||
|
.val(comment)
|
||||||
|
.data('old', comment);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
@ -93,25 +104,28 @@ function setRecordingComments() {
|
||||||
editing = false,
|
editing = false,
|
||||||
activeRequest = null;
|
activeRequest = null;
|
||||||
|
|
||||||
$("body").on("input.rc", ".recording-comment", function () {
|
$('body').on('input.rc', '.recording-comment', function() {
|
||||||
$(this).css("border-color", this.value === $(this).data("old") ? "#999" : "red");
|
$(this).css('border-color', this.value === $(this).data('old') ? '#999' : 'red');
|
||||||
});
|
});
|
||||||
|
|
||||||
var $container = $("<div></div>").insertAfter("h2.tracklist");
|
let $container = $('<div></div>').insertAfter('h2.tracklist');
|
||||||
|
|
||||||
$("<button>Edit recording comments</button>")
|
$('<button>Edit recording comments</button>')
|
||||||
.addClass("styled-button")
|
.addClass('styled-button')
|
||||||
.on("click", function () {
|
.on('click', function() {
|
||||||
editing = !editing;
|
editing = !editing;
|
||||||
$("#set-recording-comments").add($inputs).toggle(editing);
|
$('#set-recording-comments')
|
||||||
$(this).text((editing ? "Hide" : "Edit") + " recording comments");
|
.add($inputs)
|
||||||
|
.toggle(editing);
|
||||||
|
$(this).text(`${editing ? 'Hide' : 'Edit'} recording comments`);
|
||||||
if (editing) {
|
if (editing) {
|
||||||
$("#all-recording-comments").focus();
|
$('#all-recording-comments').focus();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.appendTo($container);
|
.appendTo($container);
|
||||||
|
|
||||||
$container.append('\
|
$container.append(
|
||||||
|
'\
|
||||||
<table id="set-recording-comments">\
|
<table id="set-recording-comments">\
|
||||||
<tr>\
|
<tr>\
|
||||||
<td><label for="all-recording-comments">Set all visible comments to:</label></td>\
|
<td><label for="all-recording-comments">Set all visible comments to:</label></td>\
|
||||||
|
@ -126,71 +140,80 @@ function setRecordingComments() {
|
||||||
<button id="submit-recording-comments" class="styled-button">Submit changes (visible and marked red)</button>\
|
<button id="submit-recording-comments" class="styled-button">Submit changes (visible and marked red)</button>\
|
||||||
</td>\
|
</td>\
|
||||||
</tr>\
|
</tr>\
|
||||||
</table>');
|
</table>'
|
||||||
|
);
|
||||||
|
|
||||||
$("#set-recording-comments").hide();
|
$('#set-recording-comments').hide();
|
||||||
|
|
||||||
$("#all-recording-comments").on("input", function () {
|
$('#all-recording-comments').on('input', function() {
|
||||||
$inputs.filter(":visible").val(this.value).trigger("input.rc");
|
$inputs
|
||||||
|
.filter(':visible')
|
||||||
|
.val(this.value)
|
||||||
|
.trigger('input.rc');
|
||||||
});
|
});
|
||||||
|
|
||||||
var $submitButton = $("#submit-recording-comments").on("click", function () {
|
var $submitButton = $('#submit-recording-comments').on('click', function() {
|
||||||
if (activeRequest) {
|
if (activeRequest) {
|
||||||
activeRequest.abort();
|
activeRequest.abort();
|
||||||
activeRequest = null;
|
activeRequest = null;
|
||||||
$submitButton.text("Submit changes (marked red)");
|
$submitButton.text('Submit changes (marked red)');
|
||||||
$inputs.prop("disabled", false).trigger("input.rc");
|
$inputs.prop('disabled', false).trigger('input.rc');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$submitButton.text("Submitting...click to cancel!");
|
$submitButton.text('Submitting...click to cancel!');
|
||||||
$inputs.prop("disabled", true);
|
$inputs.prop('disabled', true);
|
||||||
|
|
||||||
var editData = [], deferred = $.Deferred();
|
let editData = [],
|
||||||
|
deferred = $.Deferred();
|
||||||
|
|
||||||
$.each($tracks, function (i, track) {
|
$.each($tracks, function(i, track) {
|
||||||
if ($(track).filter(":visible").length > 0) {
|
if ($(track).filter(':visible').length > 0) {
|
||||||
var $input = $inputs.eq(i), comment = $input.val();
|
let $input = $inputs.eq(i),
|
||||||
if (comment === $input.data("old")) {
|
comment = $input.val();
|
||||||
$input.prop("disabled", false);
|
if (comment === $input.data('old')) {
|
||||||
|
$input.prop('disabled', false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
deferred
|
deferred
|
||||||
.done(function () {
|
.done(function() {
|
||||||
$input.data("old", comment).trigger("input.rc").prop("disabled", false);
|
$input
|
||||||
|
.data('old', comment)
|
||||||
|
.trigger('input.rc')
|
||||||
|
.prop('disabled', false);
|
||||||
})
|
})
|
||||||
.fail(function () {
|
.fail(function() {
|
||||||
$input.css("border-color", "red").prop("disabled", false);
|
$input.css('border-color', 'red').prop('disabled', false);
|
||||||
});
|
});
|
||||||
|
|
||||||
var link = track.querySelector("td a[href^='/recording/']"),
|
let link = track.querySelector("td a[href^='/recording/']"),
|
||||||
mbid = link.href.match(MBID_REGEX)[0];
|
mbid = link.href.match(MBID_REGEX)[0];
|
||||||
|
|
||||||
editData.push({edit_type: EDIT_RECORDING_EDIT, to_edit: mbid, comment: comment});
|
editData.push({ edit_type: EDIT_RECORDING_EDIT, to_edit: mbid, comment: comment });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (editData.length === 0) {
|
if (editData.length === 0) {
|
||||||
$inputs.prop("disabled", false);
|
$inputs.prop('disabled', false);
|
||||||
$submitButton.prop("disabled", false).text("Submit changes (marked red)");
|
$submitButton.prop('disabled', false).text('Submit changes (marked red)');
|
||||||
} else {
|
} else {
|
||||||
var editNote = $("#recording-comments-edit-note").val();
|
let editNote = $('#recording-comments-edit-note').val();
|
||||||
|
|
||||||
activeRequest = $.ajax({
|
activeRequest = $.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: '/ws/js/edit/create',
|
url: '/ws/js/edit/create',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: JSON.stringify({edits: editData, editNote: editNote}),
|
data: JSON.stringify({ edits: editData, editNote: editNote }),
|
||||||
contentType: 'application/json; charset=utf-8',
|
contentType: 'application/json; charset=utf-8'
|
||||||
|
})
|
||||||
|
.always(function() {
|
||||||
|
$submitButton.prop('disabled', false).text('Submit changes (marked red)');
|
||||||
})
|
})
|
||||||
.always(function () {
|
.done(function() {
|
||||||
$submitButton.prop("disabled", false).text("Submit changes (marked red)");
|
|
||||||
})
|
|
||||||
.done(function () {
|
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
})
|
})
|
||||||
.fail(function () {
|
.fail(function() {
|
||||||
deferred.reject();
|
deferred.reject();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue