forked from murdos/musicbrainz-userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
juno_download_importer.user.js
146 lines (130 loc) · 4.4 KB
/
juno_download_importer.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// ==UserScript==
// @name Import Juno Download releases to MusicBrainz
// @namespace https://github.com/murdos/musicbrainz-userscripts/
// @description One-click importing of releases from junodownload.com/products pages into MusicBrainz
// @version 2015.06.21.0
// @downloadURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/juno_download_importer.user.js
// @updateURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/juno_download_importer.user.js
// @include http*://www.junodownload.com/products/*
// @include http*://secure.junodownload.com/products/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
// @require lib/mbimport.js
// @require lib/logger.js
// @require lib/mbimportstyle.js
// @icon https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/assets/images/Musicbrainz_import_logo.png
// ==/UserScript==
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant
this.$ = this.jQuery = jQuery.noConflict(true);
if (!unsafeWindow) unsafeWindow = window;
$(document).ready(function(){
MBImportStyle();
var release_url = window.location.href.replace('/\?.*$/', '').replace(/#.*$/, '');
var release = retrieveReleaseInfo(release_url);
insertLink(release, release_url);
});
function parseReleaseDate(rdate) {
var months = {
"January": 1,
"February": 2,
"March": 3,
"April": 4,
"May": 5,
"June": 6,
"July": 7,
"August": 8,
"September": 9,
"October": 10,
"November": 11,
"December": 12
};
var m = rdate.match(/(\d{1,2}) ([a-z]+), (\d{4})/i);
if (m) {
return {
year: m[3],
month: months[m[2]],
day: m[1]
}
}
return false;
}
function retrieveReleaseInfo(release_url) {
// Release defaults
var release = {
artist_credit: [],
title: $("#product_heading_title").text().trim(),
year: 0,
month: 0,
day: 0,
format: 'Digital Media',
packaging: 'None',
country: 'XW',
status: 'official',
language: 'eng',
script: 'Latn',
type: '',
urls: [],
labels: [],
discs: [],
};
// Release date
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
var tracks = [];
$(".product_tracklist_records[itemprop='tracks']").each(function() {
var artists = [];
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();
var m = trackname.match(/^([^-]+) - (.*)$/);
if (m) {
artists = [m[1]];
trackname = m[2];
}
tracks.push({
'artist_credit': MBImport.makeArtistCredits(artists),
'title': trackname,
'duration': tracklength
});
});
var 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 ]);
}
release.discs.push( {
'tracks': tracks,
'format': release.format
} );
LOGGER.info("Parsed release: ", release);
return release;
}
// Insert button into page under label information
function insertLink(release, release_url) {
var edit_note = MBImport.makeEditNote(release_url, 'Juno Download');
var parameters = MBImport.buildFormParameters(release, edit_note);
var mbUI = $('<div id="mb_buttons">'
+ MBImport.buildFormHTML(parameters)
+ MBImport.buildSearchButton(release)
+ '</div>').hide();
$("div.sociald").before(mbUI);
$('#mb_buttons').css({'background': '#759d44', 'border': '2px solid #ddd', 'text-align': 'center'});
$('form.musicbrainz_import button').css({width: '80%'});
mbUI.slideDown();
}