Greasy Fork 还支持 简体中文。

RED (+ NWCD, Orpheus) Upload Assistant

Script fills in as much accurately the upload and group edit forms based on foobar2000's playlist selection via pasted output of copy command, release consistency check, two tracklist layouts, basic colours customization, featured artists extraction, image URl fetching from store and more...

目前為 2019-09-07 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name RED (+ NWCD, Orpheus) Upload Assistant
  3. // @namespace https://greasyfork.org/cs/users/321857-anakunda
  4. // @version 1.83
  5. // @description Script fills in as much accurately the upload and group edit forms based on foobar2000's playlist selection via pasted output of copy command, release consistency check, two tracklist layouts, basic colours customization, featured artists extraction, image URl fetching from store and more...
  6. // @author Anakunda
  7. // @iconURL https://redacted.ch/favicon.ico
  8. // @match https://redacted.ch/upload.php*
  9. // @match https://redacted.ch/torrents.php?action=editgroup*
  10. // @match https://notwhat.cd/upload.php*
  11. // @match https://notwhat.cd/torrents.php?action=editgroup*
  12. // @match https://orpheus.network/upload.php*
  13. // @match https://orpheus.network/torrents.php?action=editgroup*
  14. // @connect file://*
  15. // @connect *
  16. // @grant GM_xmlhttpRequest
  17. // @grant GM_getValue
  18. // @grant GM_setValue
  19. // @grant GM_deleteValue
  20. // @grant GM_log
  21. // ==/UserScript==
  22.  
  23. // The pattern for built-in copy command or custom Text Tools quick copy command, which is handled by this helper is:
  24. // $fix_eol(%album artist%,)$char(30)$fix_eol(%album%,)$char(30)[$if3(%date%,%ORIGINAL RELEASE DATE%,%year%)]$char(30)[$if3(%releasedate%,%retail date%,%date%,%year%)]$char(30)[$fix_eol($if2(%label%,%publisher%),)]$char(30)[$fix_eol($if3(%catalog%,%CATALOGNUMBER%,%catalog #%,%barcode%,%UPC%,%EAN%),)]$char(30)%__encoding%$char(30)%__codec%$char(30)[%__codec_profile%]$char(30)[%__bitrate%]$char(30)[%__bitspersample%]$char(30)[%__samplerate%]$char(30)[%__channels%]$char(30)[$if3(%media%,%discogs_format%,%source%)]$char(30)[$fix_eol(%genre%,)]['; '$fix_eol(%style%,)]$char(30)[$num(%discnumber%,0)]$char(30)[$num(%totaldiscs%,0)]$char(30)[$fix_eol(%discsubtitle%,)]$char(30)[%track number%]$char(30)[$num(%totaltracks%,0)]$char(30)$fix_eol(%title%,)$char(30)[$fix_eol(%track artist%,)]$char(30)[$if($strcmp($fix_eol(%performer%,),$fix_eol(%artist%,)),,$fix_eol(%performer%,))]$char(30)[$fix_eol(%composer%,)]$char(30)[$fix_eol(%conductor%,)]$char(30)[$fix_eol(%remixer%,)]$char(30)[$fix_eol(%compiler%,)]$char(30)[$fix_eol($if2(%producer%,%producedby%),)]$char(30)%length_seconds_fp%$char(30)[%replaygain_album_gain%]$char(30)[%album dynamic range%]$char(30)[%__tool%][ | %ENCODER%][ | %ENCODER_OPTIONS%]$char(30)[$fix_eol($if2(%url%,'https://www.discogs.com/release/'%discogs_release_id%),)]$char(30)$directory_path(%path%)$char(30)[$replace($replace(%comment%,$char(13),$char(29)),$char(10),$char(28))]
  25.  
  26. 'use strict';
  27.  
  28. var prefs = {
  29. set: function(prop, def) { this[prop] = GM_getValue(prop, def) },
  30. save: function() {
  31. for (var iter in this) { if (typeof this[iter] != 'function') GM_setValue(iter, this[iter]) }
  32. },
  33. };
  34. prefs.set('remap_texttools_newlines', 0); // convert underscores to linebreaks (ambiguous)
  35. prefs.set('clean_on_apply', 0); // clean the input box on successfull fill
  36. prefs.set('keep_meaningles_composers', 0); // keep composers from file tags also for non-composer emphasis works
  37. prefs.set('always_hide_dnu_list', 0); // risky!
  38. prefs.set('single_threshold', 8 * 60); // Max length of single in s
  39. prefs.set('EP_threshold', 28 * 60); // Max time of EP in s
  40. prefs.set('auto_preview_cover', 1);
  41. prefs.set('auto_rehost_cover', 1);
  42. // tracklist specific
  43. prefs.set('tracklist_style', 1); // 1: classical, 2: propertional right aligned
  44. prefs.set('max_tracklist_width', 80); // right margin of the right aligned tracklist. should not exceed the group description width on any device
  45. prefs.set('title_separator', '. '); // divisor of track# and title
  46. prefs.set('tracklist_head_color', '#4682B4');
  47. prefs.set('tracklist_single_color', '#708080');
  48. // classical tracklist only components colouring
  49. prefs.set('tracklist_discsubtitle_color', '#008B8B');
  50. prefs.set('tracklist_classicalblock_color', 'Olive');
  51. prefs.set('tracklist_tracknumber_color', '#8899AA');
  52. prefs.set('tracklist_artist_color', '#889B2F');
  53. prefs.set('tracklist_composer_color', '#556B2F');
  54. prefs.set('tracklist_duration_color', '#4682B4');
  55.  
  56. var iter, ref, tbl, elem, child, tb, warnings, htmlparser = new DOMParser(), dom;
  57. if (/\/upload\.php\b/.test(document.URL)) {
  58. ref = document.querySelector('form#upload_table > div#dynamic_form');
  59. if (ref == null) return;
  60. common1();
  61. let x = [];
  62. x.push(document.createElement('tr'));
  63. x[0].style.verticalAlign = 'middle';
  64. x[0].style.backgroundColor = 'transparent';
  65. child = document.createElement('input');
  66. child.id = 'fill-from-text';
  67. child.value = 'Fill from text (overwrite)';
  68. child.type = 'button';
  69. child.style.width = '13em';
  70. child.onclick = fill_from_text;
  71. x[0].append(child);
  72. elem.append(x[0]);
  73. x.push(document.createElement('tr'));
  74. x[1].style.verticalAlign = 'middle';
  75. x[1].style.backgroundColor = 'transparent';
  76. child = document.createElement('input');
  77. child.id = 'fill-from-text-weak';
  78. child.value = 'Fill from text (keep values)';
  79. child.type = 'button';
  80. child.style.width = '13em';
  81. child.onclick = fill_from_text;
  82. x[1].append(child);
  83. elem.append(x[1]);
  84. common2();
  85. } else if (document.URL.indexOf('/torrents.php?action=editgroup') >= 0) {
  86. ref = document.querySelector('form.edit_form > div > div > input[type="submit"]');
  87. if (ref == null) return;
  88. ref = ref.parentNode;
  89. ref.parentNode.insertBefore(document.createElement('br'), ref);
  90. common1();
  91. child = document.createElement('input');
  92. child.id = 'append-from-text';
  93. child.value = 'Fill from text (append)';
  94. child.type = 'button';
  95. child.onclick = fill_from_text;
  96. elem.append(child);
  97. common2();
  98. tbl.style.marginBottom = '10px';
  99. }
  100. if ((ref = document.getElementById('image')) != null) {
  101. ref.ondblclick = clear0;
  102. ref.onmousedown = clear1;
  103. ref.ondrop = clear0;
  104. }
  105.  
  106. function clear0() { this.value = null }
  107. function clear1(e) { if (e.button == 1) this.value = null }
  108.  
  109. function common1() {
  110. tbl = document.createElement('tr');
  111. tbl.style.backgroundColor = 'darkgoldenrod';
  112. elem = document.createElement('td');
  113. child = document.createElement('textarea');
  114. child.id = 'import_data';
  115. child.name = 'import_data';
  116. child.cols = 50;
  117. child.rows = 3;
  118. child.style.width = '610px';
  119. child.style.height = '3em';
  120. child.style.backgroundColor = 'antiquewhite'; //'darkgoldenrod';
  121. //child.style.color = 'white';
  122. child.style.fontSize = 'small';
  123. child.className = ' wbbarea';
  124. child.spellcheck = false;
  125. child.setAttribute('data-wbb', '');
  126. //child.ondblclick = clear0;
  127. child.onmousedown = clear1;
  128. child.ondrop = clear0;
  129. //child.onpaste = fill_from_text;
  130. elem.append(child);
  131. tbl.append(elem);
  132. elem = document.createElement('td');
  133. elem.align = 'right';
  134. }
  135. function common2() {
  136. tbl.append(elem);
  137. tb = document.createElement('tbody');
  138. tb.append(tbl);
  139. tbl = document.createElement('table');
  140. tbl.id = 'upload assistant';
  141. tbl.cellPadding = 0;
  142. tbl.cellSpacing = 0;
  143. tbl.className = 'layout border';
  144. tbl.border = 0;
  145. tbl.width = '100%';
  146. tbl.append(tb);
  147. ref.parentNode.insertBefore(tbl, ref);
  148. }
  149.  
  150. if (prefs.always_hide_dnu_list && (ref = document.querySelector('div#content > div:first-of-type')) != null) {
  151. ref.style.display = 'none'; // Hide DNU list (warning - risky!)
  152. }
  153.  
  154. class TagManager extends Array {
  155. constructor() {
  156. super();
  157. this.substitutions = [
  158. [/^Alternative(?:\s+and\s+|\s*[&+]\s*)Indie$/i, 'alternative', 'indie'],
  159. [/^Pop(?:\s+and\s+|\s*[&+]\s*)Rock$/i, 'pop', 'rock'],
  160. [/^Pop\s*(?:[\-\−\—\–\/]\s*)?Rock$/i, 'pop.rock'],
  161. [/^Rock(?:\s+and\s+|\s*[&+]\s*)Pop$/i, 'pop', 'rock'],
  162. [/^Rock\s*(?:[\-\−\—\–\/]\s*)?Pop$/i, 'pop.rock'],
  163. [/^Alt\.Rock$/i, 'alternative.rock'],
  164. [/^Synth\s*(?:[\-\−\—\–\/]\s*)?Pop$/i, 'synthpop'],
  165. [/^Soul(?:\s+and\s+|\s*[&+]\s*)Funk$/i, 'soul', 'funk'],
  166. [/^Funk(?:\s+and\s+|\s*[&+]\s*)Soul$/i, 'soul', 'funk'],
  167. [/^World(?:\s+and\s+|\s*[&+]\s*)Country$/i, 'world.music', 'country'],
  168. [/^Jazz Fusion\s*&\s*Jazz Rock$/i, 'jazz.fusion', 'jazz.rock'],
  169. [/^(?:Singer(?:\s+and\s+|\s*[&+]\s*))?Songwriter$/i, 'singer.songwriter'],
  170. [/^(?:R\s*(?:[\'\’\`][Nn](?:\s+|[\'\’\`]\s*)|&\s*)B|RnB)$/i, 'rhytm.and.blues'],
  171. [/\b(?:Soundtracks?)$/i, 'score'],
  172. [/^(?:Electro)$/i, 'electronic'],
  173. [/^(?:Metal)$/i, 'heavy.metal'],
  174. [/^(?:NonFiction)$/i, 'non.fiction'],
  175. [/^(?:Neo[\s\-\−\—\–]+Classical)$/i, 'neoclassical'],
  176. [/^(?:Bluesy[\s\-\−\—\–]+Rock)$/i, 'blues.rock'],
  177. [/^(?:Be[\s\-\−\—\–]+Bop)$/i, 'bebop'],
  178. [/^(?:Rap)$/i, 'hip.hop'],
  179. [/^NeoSoul$/i, 'neo.soul'],
  180. [/^NuJazz$/i, 'nu.jazz'],
  181. ];
  182. this.additions = [
  183. [/^(?:(?:(?:Be|Post|Neo)[\s\-\−\—\–]*)?Bop|Modal|Fusion|Free[\s\-\−\—\–]+Improvisation|Jazz[\s\-\−\—\–]+Fusion|Big[\s\-\−\—\–]*Band)$/i, 'jazz'],
  184. [/^(?:(?:Free|Cool|Avant[\s\-\−\—\–]*Garde|Contemporary|Vocal|Instrumental|Modal|Soul|Smooth|Piano|Latin|Afro[\s\-\−\—\–]*Cuban)[\s\-\−\—\–]+Jazz)$/i, 'jazz'],
  185. [/^(?:Opera)$/i, 'classical'],
  186. [/\b(?:Chamber[\s\-\−\—\–]+Music)\b/i, 'classical'],
  187. ];
  188. this.removals = [
  189. ];
  190. }
  191.  
  192. add(...tags) {
  193. var added = 0;
  194. for (var tag of tags) {
  195. if (typeof tag != 'string') continue;
  196. tag.split(/\s*[\,\/\;\>\|]+\s*/).forEach(function(tag) {
  197. tag = tag.normalize("NFD").
  198. replace(/[\u0300-\u036f]/g, '').
  199. replace(/\(.*?\)|\[.*?\]|\{.*?\}/g, '').
  200. trim();
  201. if (tag.length <= 0 || tag == '?') return null;
  202. for (k of this.removals) {
  203. if (k[0].test(tag)) {
  204. addWarning('Warning: bad tag \'' + tag + '\' found', false, '#C00000');
  205. return;
  206. }
  207. }
  208. for (k of this.additions) {
  209. if (k[0].test(tag)) { added += this.add(...k.slice(1)); }
  210. }
  211. for (var k of this.substitutions) {
  212. if (k[0].test(tag)) { added += this.add(...k.slice(1)); return; }
  213. }
  214. tag = tag.
  215. replace(/\bAlt\.(?=\s+)/i, 'Alternative').
  216. replace(/\s*(?:[\'\’\`][Nn](?:\s+|[\'\’\`]\s*)|[\&\+]\s*)/, ' and ').
  217. replace(/[\s\-\−\—\–\_\.\,\'\`\~]+/g, '.').
  218. replace(/[^\w\.]+/g, '').
  219. toLowerCase();
  220. if (tag.length >= 2 && !this.includes(tag)) {
  221. this.push(tag);
  222. ++added;
  223. }
  224. }.bind(this));
  225. }
  226. return added;
  227. }
  228. toString() {
  229. return this.length > 0 ? this.sort().join(', ') : null;
  230. }
  231. };
  232.  
  233. function fill_from_text(e) {
  234. var overwrite = this.id == 'fill-from-text';
  235. var clipBoard = document.getElementById('import_data');
  236. if (clipBoard == null) return false;
  237. //let promise = clientInformation.clipboard.readText().then(text => clipBoard = text);
  238. //if (typeof clipBoard != 'string') return false;
  239. var category = document.getElementById('categories');
  240. var ref, iter, i, matches, rx;
  241. if ((warnings = document.getElementById('UA warnings')) != null) warnings.parentNode.removeChild(warnings);
  242. if (category == null && document.getElementById('releasetype') != null
  243. || category != null && category.value == 0) return fill_from_text_music();
  244. if (category != null && category.value == 1) return fill_from_text_apps();
  245. if (category != null && (category.value == 2 || category.value == 3)) return fill_from_text_books();
  246. return category == null ? fill_from_text_apps() || fill_from_text_books() : false;
  247.  
  248. function fill_from_text_music() {
  249. const div = ['—', '⸺', '⸻'];
  250. var lines = clipBoard.value.split(/[\r\n]+/);
  251. var track, tracks = [];
  252.  
  253. if (lines.length == 1 && /^https?:\/\//i.test(lines[0])) {
  254. init_from_url_music(lines[0]);
  255. return;
  256. } else for (iter of lines) {
  257. if (!iter.trim()) continue; // skip empty lines
  258. let metaData = iter.split('\x1E');
  259. track = {
  260. artist: metaData.shift().trim() || undefined,
  261. album: metaData.shift().trim() || undefined,
  262. album_year: safeParseYear(metaData.shift()),
  263. release_year: safeParseYear(metaData.shift()),
  264. label: metaData.shift().trim() || undefined,
  265. catalog: metaData.shift().trim() || undefined,
  266. encoding: metaData.shift().trim() || undefined,
  267. codec: metaData.shift().trim() || undefined,
  268. codec_profile: metaData.shift().trim() || undefined,
  269. bitrate: safeParseInt(metaData.shift()),
  270. bd: safeParseInt(metaData.shift()),
  271. sr: safeParseInt(metaData.shift()),
  272. channels: safeParseInt(metaData.shift()),
  273. media: metaData.shift().trim() || undefined,
  274. genre: metaData.shift().trim() || undefined,
  275. discnumber: safeParseInt(metaData.shift()),
  276. totaldiscs: safeParseInt(metaData.shift()),
  277. discsubtitle: metaData.shift().trim() || undefined,
  278. tracknumber: metaData.shift().trim() || undefined,
  279. totaltracks: safeParseInt(metaData.shift()),
  280. title: metaData.shift().trim() || undefined,
  281. track_artist: metaData.shift().trim() || undefined,
  282. performer: metaData.shift().trim() || undefined,
  283. composer: metaData.shift().trim() || undefined,
  284. conductor: metaData.shift().trim() || undefined,
  285. remixer: metaData.shift().trim() || undefined,
  286. compiler: metaData.shift().trim() || undefined,
  287. producer: metaData.shift().trim() || undefined,
  288. duration: safeParseFloat(metaData.shift()),
  289. rg: metaData.shift().trim() || undefined,
  290. dr: metaData.shift().trim() || undefined,
  291. vendor: metaData.shift().trim() || undefined,
  292. url: metaData.shift().trim() || undefined,
  293. dirpath: metaData.shift() || undefined,
  294. comment: metaData.shift().trim() || undefined,
  295. };
  296. if (track.comment == '.') track.comment = undefined;
  297. if (track.comment) {
  298. track.comment = track.comment.replace(/\x1D/g, '\r').replace(/\x1C/g, '\n');
  299. if (prefs.remap_texttools_newlines) track.comment = track.comment.replace(/__/g, '\r\n').replace(/_/g, '\n') // ambiguous
  300. }
  301. if (track.dr != null) track.dr = parseInt(track.dr); // DR0
  302. tracks.push(track);
  303. }
  304. function safeParseInt(x) { return typeof x != 'string' ? null : x.length <= 0 ? undefined : parseInt(x) }
  305. function safeParseFloat(x) { return typeof x != 'string' ? null : x.length <= 0 ? undefined : parseFloat(x) }
  306. function safeParseYear(x) { return typeof x != 'string' ? null : x.length <= 0 ? undefined : extract_year(x) || NaN }
  307. var album_artists = [], albums = [], album_years = [], release_years = [], labels = [], catalogs = [];
  308. var codecs = [], bds = [], medias = [], genres = [], srs = {}, urls = [], comments = [], track_artists = [];
  309. var encodings = [], bitrates = [], codec_profiles = [], drs = [], channels = [], rgs = [], dirpaths = [];
  310. var vendors = [];
  311. let is_va = false, composer_emphasis = false, is_from_dsd = false, is_classical = false;
  312. var total_time = 0, release_type = 1, album_bitrate = 0, totaldiscs = 1, artist_counter = 0;
  313. var edition_title, media, yadg_prefil = '';
  314. const featParser1 = /\(feat(?:\.|uring)\s+([^\(\)]+?)\s*\)$/i;
  315. const featParser2 = /\[feat(?:\.|uring)\s+([^\[\]]+?)\s*\]$/i;
  316. for (iter of tracks) {
  317. push_unique(album_artists, 'artist');
  318. push_unique(track_artists, 'track_artist');
  319. push_unique(albums, 'album');
  320. push_unique(album_years, 'album_year');
  321. push_unique(release_years, 'release_year');
  322. push_unique(labels, 'label');
  323. push_unique(catalogs, 'catalog');
  324. push_unique(encodings, 'encoding');
  325. push_unique(codecs, 'codec');
  326. push_unique(codec_profiles, 'codec_profile');
  327. push_unique(bitrates, 'bitrate');
  328. push_unique(bds, 'bd');
  329. push_unique(channels, 'channels');
  330. push_unique(medias, 'media');
  331. if (iter.sr) {
  332. if (typeof srs[iter.sr] != 'number') {
  333. srs[iter.sr] = iter.duration;
  334. } else {
  335. srs[iter.sr] += iter.duration;
  336. }
  337. }
  338. push_unique(genres, 'genre');
  339. push_unique(urls, 'url');
  340. push_unique(comments, 'comment');
  341. push_unique(rgs, 'rg');
  342. push_unique(drs, 'dr');
  343. push_unique(vendors, 'vendor');
  344. push_unique(dirpaths, 'dirpath');
  345.  
  346. if (iter.discnumber > totaldiscs) totaldiscs = iter.discnumber;
  347. total_time += iter.duration;
  348. album_bitrate += iter.duration * iter.bitrate;
  349. }
  350. function push_unique(array, prop) {
  351. if (iter[prop] !== undefined && iter[prop] !== null && (typeof iter[prop] != 'string' || iter[prop].length > 0)
  352. && !array.includes(iter[prop])) array.push(iter[prop]);
  353. }
  354. // inconsistent releases not allowed - die
  355. const requisites = [
  356. [encodings, 'encoding'],
  357. [codecs, 'codec'],
  358. [codec_profiles, 'codec profile'],
  359. [vendors, 'vendor'],
  360. [medias, 'media'],
  361. [channels, 'channel'],
  362. [album_artists, 'album artists'],
  363. [albums, 'album'],
  364. ];
  365. for (iter of requisites) {
  366. if (iter[0].length > 1) {
  367. addWarning('FATAL: fuzzy releases aren\'t allowed (' + iter[1] + '): ' + iter[0]);
  368. clipBoard.value = null;
  369. return false;
  370. }
  371. }
  372. function validatorFunc(arr, validator, str) {
  373. if (arr.length <= 0 || !arr.some(validator)) return true;
  374. addWarning('FATAL: disallowed ' + str + ' present (' + arr.filter(validator) + ')');
  375. clipBoard.value = null;
  376. return false;
  377. }
  378. if (!validatorFunc(bds, (bd) => ![16, 24].includes(bd), 'bit depths')
  379. || !validatorFunc(Object.keys(srs), (sr) => sr < 44100 || sr > 192000
  380. || sr % 44100 != 0 && sr % 48000 != 0, 'sample rates')) return false;
  381. for (iter of tracks) {
  382. if (iter.duration == undefined) continue;
  383. if (isNaN(iter.duration) || iter.duration <= 0) {
  384. addWarning('FATAL: invalid track ' + iter.tracknumber + ' length: ' + iter.duration);
  385. return false;
  386. }
  387. }
  388. var tags = new TagManager();
  389. album_bitrate /= total_time;
  390. if (total_time > 0 && total_time <= prefs.single_threshold && tracks.length < 8) {
  391. release_type = 9; // single
  392. } else if (total_time > 0 && total_time <= prefs.EP_threshold && tracks.length < 16) {
  393. release_type = 5; // EP
  394. }
  395. if (album_artists.length == 1 && (ref = document.getElementById('artist')) != null) {
  396. const guest_parser = /^(.*?)(?:\s+(?:feat(?:\.|uring)|with)\s+(.*))?$/;
  397. if (matches = album_artists[0].match(guest_parser)) {
  398. let artists = [];
  399. for (iter = 0; iter < 7; ++iter) artists.push([]);
  400. const artist_parser = /\s*(?:[\,\;\/\|]|(?:&)\s+(?!(?:The|His|Friends)\b))+\s*/i;
  401. const weak_artist_parser = /\s*[\,\;\/\|]+\s*/;
  402. const other_artists_parsers = [
  403. [/^(.*?)\s+(?:under|(?:conducted) by)\s+(.*)$/, artists[4]],
  404. [/^()(.*?)\s+\(conductor\)$/i, artists[4]],
  405. //[/^()(.*?)\s+\(.*\)$/i, guests],
  406. ];
  407. const invalid_artist = /^#?N\/?A$/i;
  408. const noakas = /\s+aka\s+(.*)/;
  409. let j;
  410. if (/^(?:Various(?: Artists?)?|VA)$/.test(matches[1])) {
  411. is_va = true;
  412. } else {
  413. j = matches[1].split(artist_parser);
  414. (j.every(twoOrMore) ? j : [ matches[0] ]).forEach(function(i) {
  415. i = guess_other_artists(i);
  416. if (i.length > 0 && !invalid_artist.test(i) && !artists[0].includesCaseless(i)) artists[0].push(i);
  417. });
  418. yadg_prefil = matches[1];
  419. }
  420. if (!is_va && matches[2]) {
  421. artists[1] = matches[2].split(weak_artist_parser);
  422. if (!artists[1].every(twoOrMore)) artists[1] = matches[2];
  423. }
  424. for (iter of tracks) {
  425. add_track_artists('track_artist');
  426. add_track_artists('performer');
  427. add_other_artists(artists[2], 'remixer');
  428. add_other_artists(artists[3], 'composer');
  429. add_other_artists(artists[4], 'conductor');
  430. add_other_artists(artists[5], 'compiler');
  431. add_other_artists(artists[6], 'producer');
  432.  
  433. if (iter.title) {
  434. if ((matches = iter.title.match(/\(remix(?:ed)? by ([^\(\)]+)\)/i)) != null
  435. || (matches = iter.title.match(/\(([^\(\)]+?)(?:[\'\’\`]s)? remix\)/i)) != null
  436. || (matches = iter.title.match(/\[remix(?:ed)? by ([^\[\]]+)\]/i)) != null
  437. || (matches = iter.title.match(/\[([^\[\]]+?)(?:[\'\’\`]s)? remix\]/i)) != null) {
  438. j = matches[1].split(weak_artist_parser);
  439. (j.every(twoOrMore) ? j : [ matches[1] ]).forEach(function(k) {
  440. if (!artists[2].includesCaseless(k)) artists[2].push(k);
  441. });
  442. }
  443. if ((matches = iter.title.match(featParser1)) != null || (matches = iter.title.match(featParser2)) != null) {
  444. j = matches[1].split(weak_artist_parser);
  445. (j.every(twoOrMore) ? j : [ matches[1] ]).forEach(k => { if (!notInGuestSMain(k)) artists[1].push(k) });
  446. addWarning('Warning: featured artist(s) in track name (#' +
  447. iter.tracknumber + ': ' + iter.title + ')', false, '#C00000');
  448. }
  449. }
  450. } // iterate tracks
  451. for (iter = 0; iter < Math.round(tracks.length / 2); ++iter) split_ampersands();
  452.  
  453. function notInGuestSMain(k) { return !artists[0].includesCaseless(k) && !artists[1].includesCaseless(k) }
  454. function twoOrMore(k) { return k.length >= 2 && !invalid_artist.test(k) };
  455. function add_track_artists(prop) {
  456. if (iter[prop] && (matches = iter[prop].match(guest_parser))) {
  457. j = matches[1].split(weak_artist_parser);
  458. for (i of j.every(twoOrMore) ? j : [ matches[1] ]) {
  459. i = guess_other_artists(i);
  460. if (i.length > 0 && !invalid_artist.test(i) && !artists[0].includesCaseless(i)
  461. && (is_va || !artists[1].includesCaseless(i))) (is_va ? artists[0] : artists[1]).push(i);
  462. }
  463. if (matches[2]) {
  464. j = matches[2].split(weak_artist_parser);
  465. for (i of j.every(twoOrMore) ? j : [ matches[2] ]) {
  466. i = i.replace(noakas, '');
  467. if (!invalid_artist.test(i) && notInGuestSMain(i)) artists[1].push(i);
  468. }
  469. }
  470. }
  471. }
  472. function add_other_artists(list, prop) {
  473. if (!iter[prop]) return;
  474. j = iter[prop].split(weak_artist_parser);
  475. for (i of j.every(twoOrMore) ? j : [ iter[prop] ]) {
  476. i = i.replace(noakas, '');
  477. if (!invalid_artist.test(i) && !list.includesCaseless(i)) list.push(i);
  478. }
  479. }
  480. function guess_other_artists(name) {
  481. other_artists_parsers.forEach(function(it) {
  482. if (it[0].exec(name) == null) return;
  483. name = RegExp.$2.replace(noakas, '');
  484. if (name.length > 0 && !invalid_artist.test(name) && !it[1].includesCaseless(name)) it[1].push(RegExp.$2);
  485. name = RegExp.$1;
  486. });
  487. return name.replace(noakas, '');
  488. }
  489. function split_ampersands() {
  490. for (i = artists[0].length; i > 0; --i) {
  491. j = artists[0][i - 1].split(/\s+&\s+/);
  492. if (j.length >= 2 && j.every(twoOrMore) && !j.every(notInGuestSMain)) {
  493. artists[0].splice(i - 1, 1, ...j.filter(k => !artists[0].includesCaseless(k)));
  494. }
  495. }
  496. for (i = artists[1].length; i > 0; --i) {
  497. j = artists[1][i - 1].split(/\s+&\s+/);
  498. if (j.length >= 2 && j.every(twoOrMore) && !j.every(notInGuestSMain)) {
  499. artists[1].splice(i - 1, 1, ...j.filter(notInGuestSMain));
  500. }
  501. }
  502. }
  503.  
  504. if (!ref.disabled) {
  505. let artist_index = 0;
  506. feed_artist_category(artists[0].filter(k => !artists[4].includesCaseless(k)), 1);
  507. feed_artist_category(artists[1].filter(k => !artists[0].includesCaseless(k) && !artists[4].includesCaseless(k)), 2);
  508. for (iter = 2; iter < 7; ++iter) feed_artist_category(artists[iter], iter + 1);
  509. if (overwrite) while (document.getElementById('artist_' + artist_index) != null) {
  510. exec(function() { RemoveArtistField() });
  511. }
  512.  
  513. function feed_artist_category(list, type) {
  514. for (iter of list.sort()) {
  515. let id = 'artist';
  516. if (artist_index > 0) {
  517. id += '_' + artist_index;
  518. if (document.getElementById(id) == null) add_artist();
  519. }
  520. ref = document.getElementById(id);
  521. if (ref != null && (overwrite || !ref.value)) {
  522. ref.value = iter;
  523. ref.nextElementSibling.value = type;
  524. }
  525. ++artist_index;
  526. }
  527. }
  528. }
  529. }
  530. }
  531. if (is_va && release_type == 1) release_type = 7; // compilation
  532. if (albums.length == 1) {
  533. let album = albums[0];
  534. rx = /\s+(?:-\s+Single|\[Single\]|\(Single\))$/i;
  535. if (rx.test(album)) {
  536. album = album.replace(rx, '');
  537. release_type = 9; // single
  538. }
  539. rx = /\s+(?:(?:-\s+)?EP|\[EP\]|\(EP\))$/;
  540. if (rx.test(album)) {
  541. album = album.replace(rx, '')
  542. release_type = 5; // EP
  543. }
  544. rx = /\s+\((?:Live|En\s+directo?|Ao\s+Vivo)\b[^\(\)]*\)$/i;
  545. if (rx.test(album)) {
  546. //album = album.replace(rx, '')
  547. if (release_type == 1 || release_type == 7) release_type = 11; // live album
  548. }
  549. rx = /\s+\[(?:Live|En\s+directo?|Ao\s+Vivo)\b[^\[\]]*\]$/i;
  550. if (rx.test(album)) {
  551. //album = album.replace(rx, '')
  552. if (release_type == 1 || release_type == 7) release_type = 11; // live album
  553. }
  554. if (/(?:^Live\s+[aA]t\b|^Directo?\s+[Ee]n\b|\bUnplugged\b|\bAcoustic\s+Stage\b|\s+Live$)/.test(album)
  555. && (release_type == 1 || release_type == 7)) release_type = 11; // live album
  556. rx = /\b(?:Best [Oo]f|Greatest Hits|Complete\s+(.+?\s+)(?:Albums|Recordings))\b/;
  557. if (rx.test(album) && release_type == 1) release_type = 6; // Anthology
  558. rx = '\\b(?:Soundtrack|Score|Motion\\s+Picture|Series|Television|Original(?:\\s+\\w+)?\\s+Cast|Music\\s+from|(?:Musique|Bande)\\s+originale)\\b';
  559. if (reInParenthesis(rx).test(album) || reInBrackets(rx).test(album)) {
  560. //album = album.replace(rx, '')
  561. release_type = 3; // soundtrack
  562. tags.add('score');
  563. composer_emphasis = true;
  564. }
  565. rx = /\s+(?:\([^\(\)]*\bRemix(?:e[ds])?\b[^\(\)]*\)|Remix(?:e[ds])?)$/i;
  566. if (rx.test(album)) {
  567. //album = album.replace(rx, '')
  568. if (release_type == 1) release_type = 13; // remix
  569. }
  570. rx = /\s+\[[^\[\]]*\bRemix(?:e[ds])?\b[^\[\]]*\]$/i;
  571. if (rx.test(album)) {
  572. //album = album.replace(rx, '')
  573. if (release_type == 1) release_type = 13; // remix
  574. }
  575. rx = /\s+\(([^\(\)]*\b(?:Remaster(?:ed)?\b[^\(\)]*|Reissue|Edition|Version))\)$/i;
  576. if (matches = rx.exec(album)) {
  577. album = album.replace(rx, '');
  578. edition_title = matches[1];
  579. }
  580. rx = /\s+\[([^\[\]]*\b(?:Remaster(?:ed)?\b[^\[\]]*|Reissue|Edition|Version))\]$/i;
  581. if (matches = rx.exec(album)) {
  582. album = album.replace(rx, '');
  583. edition_title = matches[1];
  584. }
  585. rx = /\s+-\s+([^\[\]\(\)\-\−\—\–]*\b(?:(?:Remaster(?:ed)?|Bonus\s+Track)\b[^\[\]\(\)\-\−\—\–]*|Reissue|Edition|Version))$/i;
  586. if (matches = rx.exec(album)) {
  587. album = album.replace(rx, '');
  588. edition_title = matches[1];
  589. }
  590. if (featParser1.test(album)) album = album.replace(featParser1, '');
  591. if (featParser2.test(album)) album = album.replace(featParser1, '');
  592. rx = /\s+(?:\[(?:LP|Vinyl|12"|7")\]|\((?:LP|Vinyl|12"|7")\))$/;
  593. if (rx.test(album)) { album = album.replace(rx, ''); media = 'Vinyl'; }
  594. rx = /\s+(?:\[SA-?CD\]|\(SA-?CD\))$/;
  595. if (rx.test(album)) { album = album.replace(rx, ''); media = 'SACD'; }
  596. rx = /\s+(?:\[(?:Blu[\s\-\−\—\–]?Ray|B[DR])\]|\((?:Blu[\s\-\−\—\–]?Ray|B[DR])\))$/;
  597. if (rx.test(album)) { album = album.replace(rx, ''); media = 'Blu-Ray'; }
  598. rx = /\s+(?:\[DVD(?:-?A)?\]|\(DVD(?:-?A)?\))$/;
  599. if (rx.test(album)) { album = album.replace(rx, ''); media = 'DVD'; }
  600. if (element_writable(ref = document.getElementById('title'))) ref.value = album;
  601. if (yadg_prefil) yadg_prefil += ' ';
  602. yadg_prefil += album;
  603. }
  604. if (yadg_prefil && (ref = document.getElementById('yadg_input')) != null) {
  605. ref.value = yadg_prefil;
  606. ref = document.getElementById('yadg_submit');
  607. if (ref != null && !ref.disabled) ref.click();
  608. }
  609. if (album_years.length == 1) {
  610. if (element_writable(ref = document.getElementById('year'))) ref.value = album_years[0];
  611. } else if (album_years.length > 1) {
  612. addWarning('Warning: inconsistent album year accross album: ' + album_years, false, '#C00000');
  613. }
  614. if (release_years.length == 1) {
  615. if (element_writable(ref = document.getElementById('remaster_year'))) ref.value = release_years[0];
  616. } else if (release_years.length > 1) {
  617. addWarning('Warning: inconsistent release year accross album: ' + release_years, false, '#C00000');
  618. }
  619. if (edition_title) {
  620. if (element_writable(ref = document.getElementById('remaster_title'))) ref.value = edition_title;
  621. }
  622. rx = /\s*[\,\;]\s*/g;
  623. if (labels.length == 1 && element_writable(ref = document.getElementById('remaster_record_label'))) {
  624. ref.value = labels[0].replace(rx, ' / ');
  625. } else if (labels.length > 1) {
  626. addWarning('Warning: inconsistent label accross album: ' + labels, false, '#C00000');
  627. }
  628. if (catalogs.length >= 1 && element_writable(ref = document.getElementById('remaster_catalogue_number'))) {
  629. ref.value = catalogs.map(k => k.replace(rx, ' / ')).join(' / ');
  630. }
  631. var br_isSet = (ref = document.getElementById('bitrate')) != null && ref.value;
  632. if (codecs.length == 1 && element_writable(ref = document.getElementById('format'))) {
  633. ref.value = codecs[0];
  634. exec(function() { Format() });
  635. }
  636. var sel;
  637. if (encodings[0] == 'lossless') {
  638. sel = bds.includes(24) ? '24bit Lossless' : 'Lossless';
  639. } else if (bitrates.length >= 1) {
  640. let lame_version = vendors.length > 0 && (matches = vendors[0].match(/^LAME(\d+)\.(\d+)/i)) ?
  641. parseInt(matches[1]) * 1000 + parseInt(matches[2]) : undefined;
  642. if (codec_profiles.length == 1 && codec_profiles[0] == 'VBR V0') {
  643. sel = lame_version >= 3094 ? 'V0 (VBR)' : 'APX (VBR)'
  644. } else if (codec_profiles.length == 1 && codec_profiles[0] == 'VBR V1') {
  645. sel = 'V1 (VBR)'
  646. } else if (codec_profiles.length == 1 && codec_profiles[0] == 'VBR V2') {
  647. sel = lame_version >= 3094 ? sel = 'V2 (VBR)' : 'APS (VBR)'
  648. } else if (bitrates.length == 1 && [192, 256, 320].includes(Math.round(bitrates[0]))) {
  649. sel = Math.round(bitrates[0]);
  650. } else {
  651. if (element_writable(ref = document.getElementById('bitrate')) && ref.value != 'Other') {
  652. ref.value = 'Other';
  653. exec(function() { Bitrate() });
  654. }
  655. if (element_writable(ref = document.getElementById('other_bitrate'))) {
  656. ref.value = Math.round(bitrates.length == 1 ? bitrates[0] : album_bitrate);
  657. if ((ref = document.getElementById('vbr')) != null && !ref.disabled) ref.checked = bitrates.length > 1;
  658. }
  659. }
  660. }
  661. if (sel && (ref = document.getElementById('bitrate')) != null && !ref.disabled && (overwrite || !br_isSet)) {
  662. ref.value = sel;
  663. }
  664. if (medias.length >= 1) {
  665. sel = undefined;
  666. if (/\b(?:WEB|File|Download)\b/i.test(medias[0])) sel = 'WEB';
  667. if (/\bCD\b/.test(medias[0])) sel = 'CD';
  668. if (/\b(?:SA-?CD|Hybrid)\b/i.test(medias[0])) sel = 'SACD';
  669. if (/\b(?:Blu[\-\−\—\–\s]?Ray|BR|BD)\b/i.test(medias[0])) sel = 'Blu-Ray';
  670. if (/\bDVD(?:-?A)?\b/.test(medias[0])) sel = 'DVD';
  671. if (/\b(?:Vinyl\b|LP\b|12"|7")/i.test(medias[0])) sel = 'Vinyl';
  672. media = sel || media;
  673. if (media && element_writable(ref = document.getElementById('media'))) ref.value = media;
  674. }
  675. if (media == 'WEB') for (iter of tracks) {
  676. if (iter.duration > 29.5 && iter.duration < 30.5)
  677. addWarning('Warning: track ' + iter.tracknumber + ' possible preview', false, '#9f009d');
  678. }
  679. if (genres.length >= 1) {
  680. genres.forEach(function(genre) {
  681. if (/\b(?:Classical|Symphony|Symphonic(?:al)?$|Chamber|Choral|Etude|Opera|Duets|Klassik)\b/i.test(genre)
  682. && !/\b(?:metal|rock|pop)\b/i.test(genre)) {
  683. composer_emphasis = true;
  684. is_classical = true
  685. }
  686. if (/\b(?:Jazz|Vocal)\b/i.test(genre) && !/\b(?:Nu|Future|Acid)[\s\-\−\—\–]*Jazz\b/i.test(genre)
  687. && !/\bElectr(?:o|ic)[\s\-\−\—\–]?Swing\b/i.test(genre)) {
  688. composer_emphasis = true;
  689. }
  690. if (/\b(?:Soundtracks?|Score|Films?|Games?|Video|Series?|Theatre|Musical)\b/i.test(genre)) {
  691. composer_emphasis = true;
  692. if (release_type == 1) release_type = 3;
  693. }
  694. tags.add(genre);
  695. });
  696. if (genres.length > 1) addWarning('Warning: inconsistent genre accross album: ' + genres, false, '#C00000');
  697. }
  698. if (tags.length >= 1 && element_writable(ref = document.getElementById('tags'))) ref.value = tags.toString();
  699. if (element_writable(ref = document.getElementById('releasetype'))) ref.value = release_type;
  700.  
  701. if (!composer_emphasis && !prefs.keep_meaningles_composers) {
  702. ref = document.querySelectorAll('input[name="artists[]"]');
  703. if (ref != null) ref.forEach(i => { if (['4', '5'].includes(i.nextElementSibling.value)) i.value = null });
  704. }
  705. // ============================================= The Playlist =============================================
  706. var description, ripinfo, dur;
  707. const vinyl_test = /^((?:Vinyl|LP) rip by\s+)(.*)$/im;
  708. if (tracks.length > 1) {
  709. gen_full_tracklist();
  710. } else { // single
  711. description = '[align=center]';
  712. description += isRED() ? '[pad=20|20|20|20]' : '';
  713. description += '[size=4][b][color=' + prefs.tracklist_artist_color + ']' + album_artists[0] + '[/color][hr]';
  714. //description += '[color=' + prefs.tracklist_single_color + ']';
  715. description += tracks[0].title;
  716. //description += '[/color]'
  717. description += '[/b]';
  718. if (tracks[0].composer) {
  719. description += '\n[i][color=' + prefs.tracklist_composer_color + '](' + tracks[0].composer + ')[/color][/i]';
  720. }
  721. description += '\n\n[color=' + prefs.tracklist_duration_color +'][' +
  722. make_time_string(tracks[0].duration) + '][/color][/size]';
  723. if (isRED()) description += '[/pad]';
  724. description += '[/align]';
  725. }
  726. if (comments.length == 1 && comments[0]) {
  727. let cmt = comments[0];
  728. if (matches = cmt.match(vinyl_test)) {
  729. ripinfo = cmt.slice(matches.index).trim().split(/[\r\n]+/);
  730. description = description.concat('\n\n', cmt.slice(0, matches.index).trim());
  731. } else {
  732. description = description.concat('\n\n', cmt);
  733. }
  734. }
  735. if (element_writable(ref = document.getElementById('album_desc'))) {
  736. ref.value = description;
  737. preview(0);
  738. }
  739. if ((ref = document.getElementById('body')) != null && !ref.disabled) {
  740. let editioninfo;
  741. if (edition_title) {
  742. editioninfo = '[size=5][b]' + edition_title;
  743. if (release_years.length >= 1) { editioninfo = editioninfo.concat(' (', release_years[0] + ')') }
  744. editioninfo = editioninfo.concat('[/b][/size]\n\n');
  745. } else { editioninfo = '' }
  746. if (ref.textLength > 0) {
  747. ref.value = ref.value.concat('\n\n', editioninfo, description);
  748. } else {
  749. ref.value = editioninfo + description;
  750. }
  751. preview(0);
  752. }
  753. var lineage = '', comment = '', drinfo, srcinfo;
  754. if (Object.keys(srs).length > 0) {
  755. let kHz = Object.keys(srs).sort((a, b) => srs[b] - srs[a]).map(f => f / 1000).join('/').concat('kHz');
  756. if (element_writable(ref = document.getElementById('release_samplerate'))) {
  757. ref.value = Object.keys(srs).length > 1 ? '999' : Math.floor(Object.keys(srs)[0] / 1000);
  758. }
  759. if (bds.some(bd => bd > 16)) {
  760. if (drs.length >= 1) drinfo = '[hide=DR' + (drs.length == 1 ? drs[0] : '') + '][pre][/pre]';
  761. if (media == 'Vinyl') {
  762. let hassr = ref == null || Object.keys(srs).length > 1;
  763. lineage = hassr ? kHz + ' ' : '';
  764. if (ripinfo) {
  765. ripinfo[0] = ripinfo[0].replace(vinyl_test, '$1[color=blue]$2[/color]');
  766. if (hassr) { ripinfo[0] = ripinfo[0].replace(/^Vinyl\b/, 'vinyl') }
  767. lineage += ripinfo[0] + '\n\n[u]Lineage:[/u]' + ripinfo.slice(1).map(k => '\n' + k).join('');
  768. } else {
  769. lineage += (hassr ? 'Vinyl' : ' vinyl') + ' rip by [color=blue][/color]\n\n[u]Lineage:[/u]';
  770. }
  771. if (drs.length >= 1) drinfo += '\n\n[img][/img]\n[img][/img]\n[img][/img][/hide]';
  772. } else if (['Blu-Ray', 'DVD', 'SACD'].includes(media)) {
  773. lineage = ref ? '' : kHz;
  774. if (channels.length == 1) add_channel_info();
  775. if (media == 'SACD' || is_from_dsd) {
  776. lineage += ' from DSD64 using foobar2000\'s SACD decoder (direct-fp64)';
  777. lineage += '\nOutput gain +0dB';
  778. }
  779. drinfo += '[/hide]';
  780. //add_rg_info();
  781. } else { // WEB Hi-Res
  782. if (ref == null || Object.keys(srs).length > 1) lineage = kHz;
  783. if (channels.length == 1 && channels[0] != 2) add_channel_info();
  784. add_dr_info();
  785. //if (lineage.length > 0) add_rg_info();
  786. if (bds.length >= 2) bds.filter(bd => bd != 24).forEach(function(bd) {
  787. let hybrid_tracks = tracks.filter(k => k.bd == bd).map(k => k.tracknumber);
  788. if (hybrid_tracks.length < 1) return;
  789. if (lineage) lineage += '\n';
  790. lineage += 'Note: track';
  791. if (hybrid_tracks.length > 1) lineage += 's';
  792. lineage += ' #' + hybrid_tracks.sort().join(', ') +
  793. (hybrid_tracks.length > 1 ? ' are' : ' is') + ' ' + bd + 'bit lossless';
  794. });
  795. drinfo = Object.keys(srs).includes(88200) ? drinfo.concat('[/hide]') : null;
  796. }
  797. } else { // 16bit or lossy
  798. if (Object.keys(srs).some(f => f != 44100)) lineage = kHz;
  799. if (channels.length == 1 && channels[0] != 2) add_channel_info();
  800. //add_dr_info();
  801. //if (lineage.length > 0) add_rg_info();
  802. if (['AAC', 'Opus', 'Vorbis'].includes(codecs[0]) && vendors[0]) {
  803. let _encoder_settings = vendors[0];
  804. if (codecs[0] == 'AAC' && /^qaac\s+[\d\.]+/i.test(vendors[0])) {
  805. let enc = [];
  806. if (matches = vendors[0].match(/\bqaac\s+([\d\.]+)\b/i)) enc[0] = matches[1];
  807. if (matches = vendors[0].match(/\bCoreAudioToolbox\s+([\d\.]+)\b/i)) enc[1] = matches[1];
  808. if (matches = vendors[0].match(/\b(AAC-\S+)\s+Encoder\b/i)) enc[2] = matches[1];
  809. if (matches = vendors[0].match(/\b([TC]VBR|ABR|CBR)\s+(\S+)\b/)) { enc[3] = matches[1]; enc[4] = matches[2]; }
  810. if (matches = vendors[0].match(/\bQuality\s+(\d+)\b/i)) enc[5] = matches[1];
  811. _encoder_settings = 'Converted by Apple\'s ' + enc[2] + ' encoder (' + enc[3] + '-' + enc[4] + ')';
  812. }
  813. if (lineage) lineage += '\n\n';
  814. lineage += _encoder_settings;
  815. }
  816. }
  817. }
  818. function add_dr_info() {
  819. if (drs.length != 1 || document.getElementById('release_dynamicrange') != null) return false;
  820. if (lineage.length > 0) lineage += ' | ';
  821. if (drs[0] < 4) lineage += '[color=red]';
  822. lineage += 'DR' + drs[0];
  823. if (drs[0] < 4) lineage += '[/color]';
  824. return true;
  825. }
  826. function add_rg_info() {
  827. if (rgs.length != 1) return false;
  828. if (lineage.length > 0) lineage += ' | ';
  829. lineage += 'RG'; //lineage += 'RG ' + rgs[0];
  830. return true;
  831. }
  832. function add_channel_info() {
  833. if (channels.length != 1) return false;
  834. let chi = getChanString(channels[0]);
  835. if (lineage.length > 0 && chi.length > 0) lineage += ', ';
  836. lineage += chi;
  837. return chi.length > 0;
  838. }
  839. if (urls.length == 1 && urls[0]) {
  840. srcinfo = '[url]' + urls[0] + '[/url]';
  841. if (element_writable(document.getElementById('image'))) {
  842. let u = urls[0];
  843. if (/^https?:\/\/(\w+\.)?discogs\.com\/release\/[\w\-]+\/?$/i.test(u)) u += '/images';
  844. GM_xmlhttpRequest({ method: 'GET', url: u, onload: fetch_image_from_store });
  845. }
  846. // } else if (element_writable(document.getElementById('image'))
  847. // && ((ref = document.getElementById('album_desc')) != null || (ref = document.getElementById('body')) != null)
  848. // && ref.textLength > 0 && (matches = ref.value.matchAll(/\b(https?\/\/[\w\-\&\_\?\=]+)/i)) != null) {
  849. }
  850. ref = document.getElementById('release_lineage');
  851. if (ref != null) {
  852. if (element_writable(ref)) {
  853. if (drinfo) comment = drinfo;
  854. if (lineage && srcinfo) lineage += '\n\n';
  855. if (srcinfo) lineage += srcinfo;
  856. ref.value = lineage;
  857. preview(1);
  858. }
  859. } else {
  860. comment = lineage;
  861. if (comment && drinfo) comment += '\n\n';
  862. if (drinfo) comment += drinfo;
  863. if (comment && srcinfo) comment += '\n\n';
  864. if (srcinfo) comment += srcinfo;
  865. }
  866. if (comment.length > 0) {
  867. if (element_writable(ref = document.getElementById('release_desc'))) {
  868. ref.value = comment;
  869. preview(isNWCD() ? 2 : 1);
  870. }
  871. }
  872. if (encodings[0] == 'lossless' && codecs[0] == 'FLAC' && bds.includes(24) && dirpaths.length == 1) {
  873. var uri = new URL(dirpaths[0] + '\\foo_dr.txt');
  874. GM_xmlhttpRequest({
  875. method: 'GET',
  876. url: uri.href,
  877. responseType: 'blob',
  878. onload: function(response) {
  879. if (response.readyState != 4 || !response.responseText) return;
  880. var rlsDesc = document.getElementById('release_lineage') || document.getElementById('release_desc');
  881. if (rlsDesc == null) return;
  882. var value = rlsDesc.value;
  883. matches = value.match(/(^\[hide=DR\d*\]\[pre\])\[\/pre\]/im);
  884. if (matches == null) return;
  885. var index = matches.index + matches[1].length;
  886. rlsDesc.value = value.slice(0, index).concat(response.responseText, value.slice(index));
  887. }
  888. });
  889. }
  890. if (drs.length == 1) {
  891. if (element_writable(ref = document.getElementById('release_dynamicrange'))) ref.value = drs[0];
  892. }
  893. if (prefs.clean_on_apply) clipBoard.value = null;
  894. prefs.save();
  895. return true;
  896.  
  897. function gen_full_tracklist() { // ========================= TACKLIST =========================
  898. description = isRED() ? '[pad=5|0|0|0]' : '';
  899. description += '[size=4][color=' + prefs.tracklist_head_color + '][b]Tracklisting[/b][/color][/size]';
  900. if (isRED()) '[/pad]';
  901. let classical_units = new Set();
  902. if (is_classical) {
  903. for (track of tracks) {
  904. if (matches = track.title.match(/^(.+?)\s*:\s+(.*)$/)) {
  905. classical_units.add(track.classical_unit_title = matches[1]);
  906. track.classical_title = matches[2];
  907. } else {
  908. track.classical_unit_title = null;
  909. }
  910. }
  911. for (let unit of classical_units.keys()) {
  912. let group_performer = array_homogenous(tracks.filter(k => k.classical_unit_title === unit).map(k => k.track_artist));
  913. let group_composer = array_homogenous(tracks.filter(k => k.classical_unit_title === unit).map(k => k.composer));
  914. for (track of tracks) {
  915. if (track.classical_unit_title !== unit) continue;
  916. if (group_composer) track.classical_unit_composer = track.composer;
  917. if (group_performer) track.classical_unit_performer = track.track_artist;
  918. }
  919. }
  920. }
  921. let block = 1, lastdisc, lastsubtitle, lastside, vinyl_trackwidth;
  922. let lastwork = classical_units.size > 0 ? null : undefined;
  923. description += '\n';
  924. let volumes = new Map(tracks.map(k => [k.discnumber, undefined]));
  925. volumes.forEach(function(val, key) {
  926. volumes.set(key, array_homogenous(tracks.filter(k => k.discnumber == key).map(k => k.discsubtitle)));
  927. });
  928. if (media == 'Vinyl') {
  929. let max_side_track = undefined;
  930. rx = /^([A-Z])(\d+)?(\.(\d+))?/i;
  931. for (iter of tracks) {
  932. if (matches = iter.tracknumber.match(rx)) {
  933. max_side_track = Math.max(parseInt(matches[2]) || 1, max_side_track || 0);
  934. }
  935. }
  936. if (typeof max_side_track == 'number') {
  937. max_side_track = max_side_track.toString().length;
  938. vinyl_trackwidth = 1 + max_side_track;
  939. for (iter of tracks) {
  940. if (matches = iter.tracknumber.match(rx)) {
  941. iter.tracknumber = matches[1].toUpperCase();
  942. if (matches[2]) iter.tracknumber += matches[2].padStart(max_side_track, '0');
  943. }
  944. }
  945. }
  946. }
  947. function prologue(prefix, postfix) {
  948. function block1() {
  949. if (block == 3) description += postfix;
  950. description += '\n';
  951. block = 1;
  952. }
  953. function block2() {
  954. if (block == 3) description += postfix;
  955. description += '\n';
  956. block = 2;
  957. }
  958. function block3() {
  959. if (block == 2) { description += '[hr]' } else { description += '\n' }
  960. if (block != 3) description += prefix;
  961. block = 3;
  962. }
  963. if (totaldiscs > 1 && iter.discnumber != lastdisc) {
  964. block1();
  965. description += '[size=3][color=' + prefs.tracklist_discsubtitle_color + '][b]Disc ' + iter.discnumber;
  966. if (iter.discsubtitle && (!volumes.has(iter.discnumber) || volumes.get(iter.discnumber))) {
  967. description += ' - ' + iter.discsubtitle;
  968. lastsubtitle = iter.discsubtitle;
  969. }
  970. description += '[/b][/color][/size]';
  971. lastdisc = iter.discnumber;
  972. }
  973. if (iter.discsubtitle != lastsubtitle) {
  974. block1();
  975. if (iter.discsubtitle) {
  976. description += '[size=2][color=' + prefs.tracklist_discsubtitle_color + '][b]' +
  977. iter.discsubtitle + '[/b][/color][/size]';
  978. }
  979. lastsubtitle = iter.discsubtitle;
  980. }
  981. if (iter.classical_unit_title !== lastwork) {
  982. if (iter.classical_unit_composer || iter.classical_unit_title || iter.classical_unit_performer) {
  983. block2();
  984. description += '[size=2][color=' + prefs.tracklist_classicalblock_color + '][b]';
  985. if (iter.classical_unit_composer) description += iter.classical_unit_composer + ': ';
  986. if (iter.classical_unit_title) description += iter.classical_unit_title;
  987. description += '[/b]';
  988. if (iter.classical_unit_performer) description += ' (' + iter.classical_unit_performer + ')';
  989. description += '[/color][/size]';
  990. } else {
  991. if (block != 2) block1();
  992. }
  993. lastwork = iter.classical_unit_title;
  994. }
  995. block3();
  996. if (media == 'Vinyl') {
  997. let c = iter.tracknumber[0].toUpperCase();
  998. if (lastside != undefined && c != lastside) description += '\n';
  999. lastside = c;
  1000. }
  1001. }
  1002. for (iter of tracks.sort(function(a, b) {
  1003. var d = a.discnumber - b.discnumber;
  1004. var t = a.tracknumber - b.tracknumber;
  1005. return isNaN(d) || d == 0 ? isNaN(t) ? a.tracknumber.localeCompare(b.tracknumber) : t : d;
  1006. })) {
  1007. let title = '';
  1008. let ttwidth = vinyl_trackwidth || Math.max((iter.totaltracks || tracks.length).toString().length, 2);
  1009. if (prefs.tracklist_style == 1) {
  1010. // STYLE 1 ----------------------------------------
  1011. prologue('[size=2]', '[/size]\n');
  1012. track = '[b][color=' + prefs.tracklist_tracknumber_color + ']';
  1013. track += isNaN(parseInt(iter.tracknumber)) ? iter.tracknumber : iter.tracknumber.padStart(ttwidth, '0');
  1014. track += '[/color][/b]' + prefs.title_separator;
  1015. if (iter.track_artist && !iter.classical_unit_performer) {
  1016. title = '[color=' + prefs.tracklist_artist_color + ']' + iter.track_artist + '[/color] - ';
  1017. }
  1018. title += iter.classical_title || iter.title;
  1019. if (iter.composer && composer_emphasis && !iter.classical_unit_composer) {
  1020. title = title.concat(' [color=', prefs.tracklist_composer_color, '](', iter.composer, ')[/color]');
  1021. }
  1022. description += track + title;
  1023. if (iter.duration) description += ' [i][color=' + prefs.tracklist_duration_color +'][' +
  1024. make_time_string(iter.duration) + '][/color][/i]';
  1025. } else if (prefs.tracklist_style == 2) {
  1026. // STYLE 2 ----------------------------------------
  1027. prologue('[size=2][pre]', '[/pre][/size]');
  1028. track = isNaN(parseInt(iter.tracknumber)) ? iter.tracknumber : iter.tracknumber.padStart(ttwidth, '0');
  1029. track += prefs.title_separator;
  1030. if (iter.track_artist && !iter.classical_unit_performer) title = iter.track_artist + ' - ';
  1031. title += iter.classical_title || iter.title;
  1032. if (iter.composer && composer_emphasis && !iter.classical_unit_composer) {
  1033. title = title.concat(' (', iter.composer, ')');
  1034. }
  1035. dur = iter.duration ? '[' + make_time_string(iter.duration) + ']' : null;
  1036. let l = 0;
  1037. let width = prefs.max_tracklist_width - track.length;
  1038. if (dur) width -= dur.length + 1;
  1039. while (title.length > 0) {
  1040. let j = width;
  1041. if (title.length > width) {
  1042. while (j > 0 && title[j] != ' ') { --j }
  1043. if (j <= 0) j = width;
  1044. }
  1045. let left = title.slice(0, j).trim();
  1046. if (++l <= 1) {
  1047. description += track + left.padEnd(width, ' ');
  1048. if (dur) description += ' ' + dur;
  1049. width = prefs.max_tracklist_width - track.length - 2;
  1050. } else {
  1051. description = description.concat('\n', ' '.repeat(track.length), left);
  1052. }
  1053. title = title.slice(j).trim();
  1054. }
  1055. }
  1056. }
  1057. if (prefs.tracklist_style == 1) {
  1058. description += '\n\n' + div[0].repeat(10) + '\n[color=' + prefs.tracklist_duration_color +
  1059. ']Total time: [i]' + make_time_string(total_time) + '[/i][/color][/size]';
  1060. } else if (prefs.tracklist_style == 2) {
  1061. dur = '[' + make_time_string(total_time) + ']';
  1062. description = description.concat('\n\n', div[0].repeat(32).padStart(prefs.max_tracklist_width));
  1063. description = description.concat('\n', 'Total time:'.padEnd(prefs.max_tracklist_width - dur.length), dur);
  1064. description = description.concat('[/pre][/size]');
  1065. }
  1066. }
  1067.  
  1068. function getChanString(n) {
  1069. const chanmap = [
  1070. 'mono',
  1071. 'stereo',
  1072. '2.1',
  1073. '4.0 surround sound',
  1074. '5.0 surround sound',
  1075. '5.1 surround sound',
  1076. '7.0 surround sound',
  1077. '7.1 surround sound',
  1078. ];
  1079. return n >= 1 && n <= 8 ? chanmap[n - 1] : n + 'chn surround sound';
  1080. }
  1081.  
  1082. function init_from_url_music(url) {
  1083. if (typeof url != 'string') return false;
  1084. var remasterYear, channels = 2, label, composer, sr = 44.1, description = '',
  1085. compiler, producer, totaltracks, totaldiscs = null;
  1086. const yearMatch = /\b(\d{4})\b/;
  1087. if (url.toLowerCase().indexOf('qobuz.com') >= 0) {
  1088. GM_xmlhttpRequest({ method: 'GET', url: url, onload: function(response) {
  1089. if (response.readyState != 4 || response.status != 200) return;
  1090. dom = htmlparser.parseFromString(response.responseText, "text/html");
  1091. if (dom == null) return;
  1092.  
  1093. let artist = dom.querySelector('h2.album-meta__artist').textContent.trim();
  1094. let album = dom.querySelector('h1.album-meta__title').textContent.trim();
  1095. let genre;
  1096. ref = dom.querySelectorAll('div.album-meta > ul > li');
  1097. if (ref != null) ref.forEach(function(k) {
  1098. if (/\bGenre\b/.test(k.textContent)) genre = k.children[k.children.length - 1].textContent.trim();
  1099. });
  1100. ref = dom.querySelector('div.album-meta > ul > li:first-of-type');
  1101. if (ref != null && (matches = ref.textContent.match(yearMatch)) != null) remasterYear = parseInt(matches[1]);
  1102. ref = dom.querySelector('p.album-about__copyright');
  1103. let albumYear = ref != null && yearMatch.exec(ref.textContent) != null ? parseInt(RegExp.$1) : remasterYear;
  1104. ref = dom.querySelectorAll('ul.album-about__items > li');
  1105. if (ref != null) ref.forEach(function(k) {
  1106. if (/^(?:Label)\b/.test(k.textContent)) label = k.children[0].textContent.trim()
  1107. else if (/^(?:Composer|Compositeur)\b/.test(k.textContent)) composer = k.children[0].textContent.trim()
  1108. if (/\b(\d+)\s*(?:dis[ck](?:s\b|\(s\))?|disco(?:s\b|\(s\))?|disque(?:s\|\(s\))?)/i.exec(k.textContent) != null) {
  1109. totaldiscs = parseInt(RegExp.$1);
  1110. }
  1111. if (/\b(\d+)\s*(?:track(?:s\b|\(s\))?|pist[ae](?:s\b|\(s\))?|tracce)/i.exec(k.textContent) != null) {
  1112. totaltracks = parseInt(RegExp.$1);
  1113. }
  1114. });
  1115. if (/\bVarious\b/.test(composer)) composer = null;
  1116. let bd = 16;
  1117. if ((ref = dom.querySelectorAll('span.album-quality__info')) != null) ref.forEach(function(k) {
  1118. if (/\b([\d\.\,]+)\s*kHz\b/.exec(k.textContent) != null) sr = parseFloat(RegExp.$1.replace(/,/g, '.'));
  1119. if (/\b(\d+)[\-\s]?Bits?\b/i.exec(k.textContent) != null) bd = parseInt(RegExp.$1);
  1120. if (/\b(?:stereo)b/i.test(k.textContent)) channels = 2;
  1121. if (/\b(?:4.0)b/i.test(k.textContent)) channels = 4;
  1122. if (/\b(?:5.0)b/i.test(k.textContent)) channels = 5;
  1123. if (/\b(?:5.1)b/i.test(k.textContent)) channels = 6;
  1124. if (/\b(?:7.0)b/i.test(k.textContent)) channels = 7;
  1125. if (/\b(?:7.1)b/i.test(k.textContent)) channels = 8;
  1126. });
  1127. ref = dom.querySelectorAll('section#description > p');
  1128. if (ref != null) ref.forEach(k => { description += html2php(k) });
  1129. if (description) description = description.trim().replace(/\n/g, '\x1C').replace(/\r/g, '\x1D');
  1130. if ((ref = dom.querySelectorAll('div.track > div.track__items')) != null) ref.forEach(function(k) {
  1131. let discsubtitle, track_artist;
  1132. let discnumber = k.parentNode.parentNode.parentNode.querySelector('p.player__work');
  1133. discnumber = discnumber != null && /^DIS[CK]\s*(\d+)$/i.exec(discnumber.textContent) != null ?
  1134. parseInt(RegExp.$1) : undefined;
  1135. if (discnumber > totaldiscs) totaldiscs = discnumber;
  1136. let tracknumber = parseInt(k.querySelector('span[itemprop="position"]').textContent.trim());
  1137. let title = k.querySelector('span.track__item--name').textContent.trim();
  1138. let duration = timestrToTime(k.querySelector('span.track__item--duration').textContent);
  1139. track = [
  1140. artist,
  1141. album,
  1142. albumYear,
  1143. remasterYear,
  1144. label,
  1145. undefined,
  1146. 'lossless',
  1147. 'FLAC',
  1148. undefined,
  1149. undefined,
  1150. bd,
  1151. sr * 1000,
  1152. channels,
  1153. 'WEB',
  1154. genre,
  1155. discnumber,
  1156. totaldiscs,
  1157. discsubtitle,
  1158. tracknumber,
  1159. totaltracks,
  1160. title,
  1161. track_artist,
  1162. undefined,
  1163. composer,
  1164. undefined,
  1165. undefined,
  1166. compiler,
  1167. producer,
  1168. duration,
  1169. undefined,
  1170. undefined,
  1171. undefined,
  1172. response.finalUrl,
  1173. undefined,
  1174. description,
  1175. ];
  1176. tracks.push(track.join('\x1E'));
  1177. });
  1178. clipBoard.value = tracks.join('\n');
  1179. fill_from_text_music();
  1180. } });
  1181. } else if (url.toLowerCase().indexOf('highresaudio.com') >= 0) {
  1182. GM_xmlhttpRequest({ method: 'GET', url: url, onload: function(response) {
  1183. if (response.readyState != 4 || response.status != 200) return;
  1184. dom = htmlparser.parseFromString(response.responseText, "text/html");
  1185. if (dom == null) return;
  1186.  
  1187. let artist = dom.querySelector('h1 > span.artist').textContent.trim();
  1188. let album = dom.getElementById('h1-album-title').firstChild.textContent.trim();
  1189. let albumYear, genres = [];
  1190. ref = dom.querySelectorAll('div.album-col-info-data > div > p');
  1191. if (ref != null) ref.forEach(function(k) {
  1192. if (/\b(?:Genre|Subgenre)\b/i.test(k.firstChild.textContent)) genres.push(k.lastChild.textContent.trim());
  1193. if (/\b(?:Label)\b/i.test(k.firstChild.textContent)) label = k.lastChild.textContent.trim();
  1194. if (/\b(?:Album[\s\-]Release)\b/i.test(k.firstChild.textContent) && yearMatch.exec(k.lastChild.textContent) != null) {
  1195. albumYear = parseInt(RegExp.$1);
  1196. }
  1197. if (/\b(?:HRA[\s\-]Release)\b/i.test(k.firstChild.textContent) && yearMatch.exec(k.lastChild.textContent) != null) {
  1198. remasterYear = parseInt(RegExp.$1);
  1199. }
  1200. });
  1201. ref = dom.querySelectorAll('td.col-format');
  1202. if (ref != null) ref.forEach(function(k) {
  1203. if (/^FLAC\s*([\d\.\,]+)\b/.exec(k.textContent) != null) sr = parseFloat(RegExp.$1.replace(/,/g, '.'));
  1204. });
  1205. ref = dom.querySelectorAll('div#albumtab-info > p');
  1206. if (ref != null) ref.forEach(k => { description += html2php(k) });
  1207. if (description) description = description.trim().replace(/\n/g, '\x1C').replace(/\r/g, '\x1D');
  1208. if ((ref = dom.querySelectorAll('ul.playlist > li.pltrack')) != null) {
  1209. totaltracks = ref.length;
  1210. ref.forEach(function(k) {
  1211. let discsubtitle = k, track_artist, discnumber;
  1212. while ((discsubtitle = discsubtitle.previousElementSibling) != null) {
  1213. if (discsubtitle.nodeName == 'LI' && discsubtitle.className == 'plinfo') {
  1214. discsubtitle = discsubtitle.textContent.replace(/\s*:$/, '').trim();
  1215. if (/\b(?:DIS[CK]|Volume|CD)\s*(\d+)\b/i.exec(discsubtitle)) discnumber = parseInt(RegExp.$1);
  1216. break;
  1217. }
  1218. }
  1219. //if (discnumber > totaldiscs) totaldiscs = discnumber;
  1220. let tracknumber = parseInt(k.querySelector('span.track').textContent.trim());
  1221. let title = k.querySelector('span.title').textContent.trim();
  1222. let duration = timestrToTime(k.querySelector('span.time').textContent);
  1223. track = [
  1224. artist,
  1225. album,
  1226. albumYear,
  1227. remasterYear,
  1228. label,
  1229. undefined,
  1230. 'lossless',
  1231. 'FLAC',
  1232. undefined,
  1233. undefined,
  1234. 24,
  1235. sr * 1000,
  1236. channels,
  1237. 'WEB',
  1238. genres.join(', '),
  1239. discnumber,
  1240. totaldiscs,
  1241. undefined, //discsubtitle,
  1242. tracknumber,
  1243. totaltracks,
  1244. title,
  1245. track_artist,
  1246. undefined,
  1247. composer,
  1248. undefined,
  1249. undefined,
  1250. compiler,
  1251. producer,
  1252. duration,
  1253. undefined,
  1254. undefined,
  1255. undefined,
  1256. response.finalUrl,
  1257. undefined,
  1258. description,
  1259. ];
  1260. tracks.push(track.join('\x1E'));
  1261. });
  1262. }
  1263. clipBoard.value = tracks.join('\n');
  1264. fill_from_text_music();
  1265. } });
  1266. }
  1267. }
  1268.  
  1269. function fetch_image_from_store(response) {
  1270. if (response.readyState != 4 || !response.responseText) return;
  1271. ref = document.getElementById('image');
  1272. dom = htmlparser.parseFromString(response.responseText, "text/html");
  1273. if (dom == null) return;
  1274. if (response.finalUrl.toLowerCase().indexOf('qobuz.com') >= 0
  1275. && (ref = dom.querySelector('div.album-cover > img')) != null) set_image(ref.src);
  1276. if (response.finalUrl.toLowerCase().indexOf('highresaudio.com') >= 0
  1277. && (ref = dom.querySelector('div.albumbody > img.cover[data-pin-media]')) != null) {
  1278. set_image(ref.dataset.pinMedia);
  1279. }
  1280. if (response.finalUrl.toLowerCase().indexOf('bandcamp.com') >= 0
  1281. && (ref = dom.querySelector('div#tralbumArt > a.popupImage')) != null) set_image(ref.href);
  1282. if (response.finalUrl.toLowerCase().indexOf('7digital.com') >= 0
  1283. && (ref = dom.querySelector('span.release-packshot-image > img[itemprop="image"]')) != null) {
  1284. set_image(ref.src);
  1285. }
  1286. if (response.finalUrl.toLowerCase().indexOf('hdtracks.com') >= 0
  1287. && (ref = dom.querySelector('p.product-image > img')) != null) set_image(ref.src);
  1288. if (response.finalUrl.toLowerCase().indexOf('discogs.com') >= 0
  1289. && (ref = dom.querySelector('div#view_images > p:first-of-type > span > img')) != null) set_image(ref.src);
  1290. if (response.finalUrl.toLowerCase().indexOf('junodownload.com') >= 0
  1291. && (ref = dom.querySelector('a.productimage')) != null) set_image(ref.href);
  1292. if (response.finalUrl.toLowerCase().indexOf('supraphonline.cz') >= 0
  1293. && (ref = dom.querySelector('div.sexycover > img')) != null) set_image(ref.src.replace(/\?\d+$/, ''));
  1294. }
  1295. }
  1296.  
  1297. function fill_from_text_apps() {
  1298. if (/^https?:\/\//i.test(clipBoard.value)) return false;
  1299. var description, tags = new TagManager();
  1300. if (clipBoard.value.toLowerCase().indexOf('//sanet') >= 0) {
  1301. GM_xmlhttpRequest({ method: 'GET', url: clipBoard.value, onload: function(response) {
  1302. if (response.readyState != 4 || response.status != 200) return;
  1303. dom = htmlparser.parseFromString(response.responseText, "text/html");
  1304.  
  1305. i = dom.querySelector('h1.item_title > span');
  1306. if (i != null && element_writable(ref = document.getElementById('title'))) {
  1307. ref.value = i.textContent.replace(/\(x64\)$/i, '(64-bit)').replace(/\bBuild\s+(\d+)/, 'build $1').
  1308. replace(/\bMultilingual\b/, 'multilingual').replace(/\bMultilanguage\b/, 'multilanguage');
  1309. }
  1310.  
  1311. i = dom.querySelector('section.descr');
  1312. if (i != null) {
  1313. description = '';
  1314. ref = dom.querySelector('section.descr > div.release-info');
  1315. if (ref != null) var releaseInfo = ref.textContent.trim();
  1316. desc_extract(i);
  1317. ref = dom.querySelector('div.txtleft > a');
  1318. if (ref != null) description += '\n\n[b]Product page:[/b]\n[url]' + de_anonymize(ref.href) + '[/url]';
  1319. write_description(description);
  1320.  
  1321. function desc_extract(node) {
  1322. for (var i of node.childNodes) {
  1323. if (i.nodeType == 3) {
  1324. if (i.length < 5) continue;
  1325. description += i.textContent.replace(/[\r\n]+/g, ' ');
  1326. } else if (i.nodeName == 'BR' || i.nodeName == 'HR') {
  1327. description += '\n';
  1328. } else if (i.nodeName == 'LABEL') {
  1329. description += '\n\n[b]' + i.textContent.trim() + '[/b]\n';
  1330. } else if (i.nodeName == 'A') {
  1331. if (i.classList.contains('mfp-image')) {
  1332. //rehost_imgs([de_anonymize(i.href)]).then(new_url => {
  1333. // description += '\n\n[img]' + new_url + '[/img]'
  1334. //}).catch(function() {
  1335. // description += '\n\n[img]' + de_anonymize(i.href) + '[/img]'
  1336. //});
  1337. description += '\n\n[img]' + de_anonymize(i.href) + '[/img]'
  1338. } else {
  1339. description += '[url=' + de_anonymize(i.href) + ']' + i.textContent.trim() + '[/url]';
  1340. }
  1341. } else if (i.nodeName == 'B' || i.nodeName == 'STRONG') {
  1342. description += '[b]' + i.textContent + '[/b]';
  1343. } else if (i.nodeName == 'I') {
  1344. description += '[i]' + i.textContent + '[/i]';
  1345. } else if (i.nodeName == 'DIV') {
  1346. if (i.classList.contains('scrpad') || i.classList.contains('aleft')) {
  1347. desc_extract(i);
  1348. description += '\n';
  1349. }
  1350. }
  1351. }
  1352. }
  1353. }
  1354.  
  1355. if ((i = dom.querySelector('section.descr > div.center > a.mfp-image')) != null) {
  1356. set_image(i.href);
  1357. } else {
  1358. i = dom.querySelector('section.descr > div.center > img[data-src]');
  1359. if (i != null) set_image(i.dataset.src);
  1360. }
  1361.  
  1362. var cat = dom.querySelector('a.cat:last-of-type > span');
  1363. if (cat != null) {
  1364. if (cat.textContent.toLowerCase() == 'windows') {
  1365. tags.add('apps.windows');
  1366. if (releaseInfo && /\bx64\b/i.test(releaseInfo)) tags.add('win64');
  1367. if (releaseInfo && /\bx86\b/i.test(releaseInfo)) tags.add('win32');
  1368. }
  1369. if (cat.textContent.toLowerCase() == 'macos') tags.add('apps.mac');
  1370. if (cat.textContent.toLowerCase() == 'linux' || cat.textContent.toLowerCase() == 'unix') tags.add('apps.linux');
  1371. if (cat.textContent.toLowerCase() == 'android') tags.add('apps.android');
  1372. if (cat.textContent.toLowerCase() == 'ios') tags.add('apps.ios');
  1373. }
  1374. if (tags.length > 0 && element_writable(ref = document.getElementById('tags'))) {
  1375. ref.value = tags.toString();
  1376. }
  1377. }, });
  1378. return true;
  1379. }
  1380. return false;
  1381.  
  1382. function de_anonymize(uri) {
  1383. return uri ? uri.replace('http://anonymz.com/?', '').replace('https://anonymz.com/?', '') : null;
  1384. }
  1385.  
  1386. function html2php(str) {
  1387. return str ? str.replace(/\<b\>/ig, '[b]').replace(/\<\/b\>/ig, '[/b]').
  1388. replace(/\<i\>/ig, '[i]').replace(/\<\/i\>/ig, '[/i]') : null;
  1389. }
  1390. }
  1391.  
  1392. function fill_from_text_books() {
  1393. if (!/^https?:\/\//i.test(clipBoard.value)) return false;
  1394. var description, tags = new TagManager();
  1395. if (clipBoard.value.toLowerCase().indexOf('martinus.cz') >= 0 || clipBoard.value.toLowerCase().indexOf('martinus.sk') >= 0) {
  1396. GM_xmlhttpRequest({ method: 'GET', url: clipBoard.value, onload: function(response) {
  1397. if (response.readyState != 4 || response.status != 200) return;
  1398. dom = htmlparser.parseFromString(response.responseText, "text/html");
  1399.  
  1400. function get_detail(x, y) {
  1401. var ref = dom.querySelector('section#details > div > div > div:first-of-type > div:nth-child(' +
  1402. x + ') > dl:nth-child(' + y + ') > dd');
  1403. return ref != null ? ref.textContent.trim() : null;
  1404. }
  1405.  
  1406. i = dom.querySelectorAll('article > ul > li > a');
  1407. if (i != null && element_writable(ref = document.getElementById('title'))) {
  1408. description = join_authors(i);
  1409. i = dom.querySelector('article > h1');
  1410. if (i != null) description += ' - ' + i.textContent.trim();
  1411. i = dom.querySelector('div.bar.mb-medium > div:nth-child(1) > dl > dd > span');
  1412. if (i != null && (matches = i.textContent.match(/\b(\d{4})\b/)) != null) description += ' (' + matches[1] + ')';
  1413. ref.value = description;
  1414. }
  1415.  
  1416. description = '[quote]' + html2php(dom.querySelector('section#description > div')) + '[/quote]';
  1417. let details = dom.querySelectorAll('section#details > div > div > div:first-of-type > div > dl');
  1418. const translation_map = [
  1419. [/\b(?:originál)/i, 'Original title'],
  1420. [/\b(?:datum|dátum|rok)\b/i, 'Release date'],
  1421. [/\b(?:katalog|katalóg)/i, 'Catalogue #'],
  1422. [/\b(?:stran|strán)\b/i, 'Page count'],
  1423. [/\bjazyk/i, 'Language'],
  1424. [/\b(?:nakladatel|vydavatel)/i, 'Publisher'],
  1425. [/\b(?:doporuč|ODPORÚČ)/i, 'Age rating'],
  1426. ];
  1427. if (details != null) details.forEach(function(detail) {
  1428. var lbl = detail.children[0].textContent.trim();
  1429. var val = detail.children[1].textContent.trim();
  1430. if (/\b(?:rozm)/i.test(lbl) || /\b(?:vazba|vázba)\b/i.test(lbl)) return;
  1431. translation_map.forEach(k => { if (k[0].test(lbl)) lbl = k[1] });
  1432. if (/\b(?:ISBN)\b/i.test(lbl)) {
  1433. val = '[url=https://www.worldcat.org/isbn/' + detail.children[1].textContent.trim() +
  1434. ']' + detail.children[1].textContent.trim() + '[/url]';
  1435. // } else if (/\b(?:ISBN)\b/i.test(lbl)) {
  1436. // val = '[url=https://www.goodreads.com/search/search?q=' + detail.children[1].textContent.trim() +
  1437. // '&search_type=books]' + detail.children[1].textContent.trim() + '[/url]';
  1438. }
  1439. description += '\n[b]' + lbl + ':[/b] ' + val;
  1440. });
  1441. description += '\n[b]More info:[/b] ' + response.finalUrl;
  1442. write_description(description);
  1443.  
  1444. if ((i = dom.querySelector('a.mj-product-preview > img')) != null) {
  1445. set_image(i.src.replace(/\?.*/, ''));
  1446. } else if ((i = dom.querySelector('head > meta[property="og:image"]')) != null) {
  1447. set_image(i.content.replace(/\?.*/, ''));
  1448. }
  1449.  
  1450. var cat = dom.querySelectorAll('dd > ul > li > a');
  1451. if (cat != null) cat.forEach(x => { tags.add(x.textContent) });
  1452. if (tags.length > 0 && element_writable(ref = document.getElementById('tags'))) {
  1453. ref.value = tags.toString();
  1454. }
  1455. }, });
  1456. return true;
  1457. } else if (clipBoard.value.toLowerCase().indexOf('goodreads.com') >= 0) {
  1458. GM_xmlhttpRequest({ method: 'GET', url: clipBoard.value, onload: function(response) {
  1459. if (response.readyState != 4 || response.status != 200) return;
  1460. dom = htmlparser.parseFromString(response.responseText, "text/html");
  1461.  
  1462. i = dom.querySelectorAll('a.authorName > span');
  1463. if (i != null && element_writable(ref = document.getElementById('title'))) {
  1464. description = join_authors(i);
  1465. i = dom.querySelector('h1#bookTitle');
  1466. if (i != null) description += ' - ' + i.textContent.trim();
  1467. i = dom.querySelector('div#details > div#row:nth-child(2)');
  1468. if (i != null && (matches = i.textContent.match(/\b(\d{4})\b/)) != null) description += ' (' + matches[1] + ')';
  1469. ref.value = description;
  1470. }
  1471.  
  1472. description = '[quote]' + html2php(dom.querySelector('div#description > span:last-of-type')) + '[/quote]';
  1473.  
  1474. function strip(str) {
  1475. return typeof str == 'string' ?
  1476. str.replace(/\s{2,}/g, ' ').replace(/[\n\r]+/, '').replace(/\s*\.{3}(?:less|more)\b/g, '').trim() : null;
  1477. }
  1478.  
  1479. i = dom.querySelectorAll('div#details > div.row');
  1480. if (i != null) i.forEach(k => { description += '\n' + strip(k.innerText) });
  1481. description += '\n';
  1482.  
  1483. let details = dom.querySelectorAll('div#bookDataBox > div.clearFloats');
  1484. for (var detail of details) {
  1485. var lbl = detail.children[0].textContent.trim();
  1486. var val = strip(detail.children[1].textContent);
  1487. if (/\b(?:ISBN)\b/i.test(lbl) && ((matches = val.match(/\b(\d{13})\b/)) != null
  1488. || (matches = val.match(/\b(\d{10})\b/)) != null)) {
  1489. val = '[url=https://www.worldcat.org/isbn/' + matches[1] + ']' + strip(detail.children[1].textContent) + '[/url]';
  1490. }
  1491. description += '\n[b]' + lbl + ':[/b] ' + val;
  1492. }
  1493. description += '\n[b]More info:[/b] ' + response.finalUrl;
  1494. write_description(description);
  1495.  
  1496. if ((i = dom.querySelector('div.editionCover > img')) != null) {
  1497. set_image(i.src.replace(/\?.*/, ''));
  1498. }
  1499.  
  1500. var cat = dom.querySelectorAll('div.elementList > div.left');
  1501. if (cat != null) cat.forEach(x => { tags.add(x.textContent.trim()) });
  1502. if (tags.length > 0 && element_writable(ref = document.getElementById('tags'))) {
  1503. ref.value = tags.toString();
  1504. }
  1505. }, });
  1506. return true;
  1507. } else if (clipBoard.value.toLowerCase().indexOf('databazeknih.cz') >= 0) {
  1508. let url = clipBoard.value;
  1509. if (url.toLowerCase().indexOf('show=alldesc') < 0) {
  1510. if (!url.includes('?')) { url += '?show=alldesc' } else { url += '&show=alldesc' }
  1511. }
  1512. GM_xmlhttpRequest({ method: 'GET', url: url, onload: function(response) {
  1513. if (response.readyState != 4 || response.status != 200) return;
  1514. dom = htmlparser.parseFromString(response.responseText, "text/html");
  1515.  
  1516. i = dom.querySelectorAll('span[itemprop="author"] > a');
  1517. if (i != null && element_writable(ref = document.getElementById('title'))) {
  1518. description = join_authors(i);
  1519. i = dom.querySelector('h1[itemprop="name"]');
  1520. if (i != null) description += ' - ' + i.textContent.trim();
  1521. i = dom.querySelector('span[itemprop="datePublished"]');
  1522. if (i != null && (matches = i.textContent.match(/\b(\d{4})\b/)) != null) description += ' (' + matches[1] + ')';
  1523. ref.value = description;
  1524. }
  1525.  
  1526. description = '[quote]' + html2php(dom.querySelector('p[itemprop="description"]')) + '[/quote]';
  1527.  
  1528. let details = dom.querySelectorAll('table.bdetail tr');
  1529. const translation_map = [
  1530. [/\b(?:orig)/i, 'Original title'],
  1531. [/\b(?:série)\b/i, 'Series'],
  1532. [/\b(?:vydáno)\b/i, 'Released'],
  1533. [/\b(?:stran)\b/i, 'Page count'],
  1534. [/\b(?:jazyk)\b/i, 'Language'],
  1535. [/\b(?:překlad)/i, 'Translation'],
  1536. [/\b(?:autor obálky)\b/i, 'Cover author'],
  1537. ];
  1538. if (details != null) details.forEach(function(detail) {
  1539. var lbl = detail.children[0].textContent.trim();
  1540. var val = detail.children[1].textContent.trim();
  1541. if (/(?:žánr|\bvazba)\b/i.test(lbl)) return;
  1542. translation_map.forEach(k => { if (k[0].test(lbl)) lbl = k[1] });
  1543. if (/\b(?:ISBN)\b/i.test(lbl) && /\b(\d+(?:-\d+)*)\b/.exec(val) != null) {
  1544. val = '[url=https://www.worldcat.org/isbn/' + RegExp.$1.replace(/-/g, '') +
  1545. ']' + detail.children[1].textContent.trim() + '[/url]';
  1546. }
  1547. description += '\n[b]' + lbl + '[/b] ' + val;
  1548. });
  1549. description += '\n[b]More info:[/b] ' + response.finalUrl.replace(/\?.*/, '');
  1550. write_description(description);
  1551.  
  1552. if ((i = dom.querySelector('div#icover_mid > a')) != null) set_image(i.href.replace(/\?.*/, ''));
  1553. if ((i = dom.querySelector('div#lbImage')) != null
  1554. && (matches = i.style.backgroundImage.match(/\burl\("(.*)"\)/i)) != null) {
  1555. set_image(matches[1].replace(/\?.*/, ''));
  1556. }
  1557.  
  1558. var cat = dom.querySelectorAll('h5[itemprop="genre"] > a');
  1559. if (cat != null) cat.forEach(x => { tags.add(x.textContent.trim()) });
  1560. cat = dom.querySelectorAll('a.tag');
  1561. if (cat != null) cat.forEach(x => { tags.add(x.textContent.trim()) });
  1562. if (tags.length > 0 && element_writable(ref = document.getElementById('tags'))) {
  1563. ref.value = tags.toString();
  1564. }
  1565. }, });
  1566. return true;
  1567. }
  1568. return false;
  1569.  
  1570. function join_authors(nodeList) {
  1571. if (typeof nodeList != 'object') return null;
  1572. var authors = [];
  1573. nodeList.forEach(k => { authors.push(k.textContent.trim()) });
  1574. return authors.join(' & ');
  1575. }
  1576. }
  1577.  
  1578. function preview(n) {
  1579. if (!prefs.auto_preview) return;
  1580. var btn = document.querySelector('input.button_preview_' + n + '[type="button"][value="Preview"]');
  1581. if (btn != null) btn.click();
  1582. }
  1583.  
  1584. function html2php(node) {
  1585. var text = '';
  1586. if (typeof node == 'object' && node.textContent) node.childNodes.forEach(function(ch) {
  1587. if (ch.nodeType == 3) {
  1588. text += ch.data.replace(/\s+/g, ' ');
  1589. } else if (ch.nodeName == 'P') {
  1590. text += '\n' + html2php(ch);
  1591. } else if (ch.nodeName == 'DIV') {
  1592. text += '\n' + html2php(ch);
  1593. } else if (ch.nodeName == 'SPAN') {
  1594. text += html2php(ch);
  1595. } else if (ch.nodeName == 'BR' || ch.nodeName == 'HR') {
  1596. text += '\n';
  1597. } else if (ch.nodeName == 'B' || ch.nodeName == 'STRONG') {
  1598. text += '[b]' + html2php(ch) + '[/b]';
  1599. } else if (ch.nodeName == 'I' || ch.nodeName == 'EM') {
  1600. text += '[i]' + html2php(ch) + '[/i]';
  1601. } else if (ch.nodeName == 'U') {
  1602. text += '[u]' + html2php(ch) + '[/u]';
  1603. } else if (ch.nodeName == 'CODE') {
  1604. text += '[pre]' + ch.textContent + '[/pre]';
  1605. } else if (ch.nodeName == 'A') {
  1606. text += '[url=' + ch.href + ']' + ch.textContent.replace(/\s+/g, ' ') + '[/url]';
  1607. } else if (ch.nodeName == 'IMG') {
  1608. text += '[img]' + ch.src + '[/img]';
  1609. }
  1610. });
  1611. return text.trim();
  1612. }
  1613.  
  1614. function write_description(desc) {
  1615. if (typeof desc != 'string') return;
  1616. if (element_writable(ref = document.getElementById('desc'))) ref.value = desc;
  1617. if ((ref = document.getElementById('body')) != null && !ref.disabled) {
  1618. if (ref.textLength > 0) ref.value += '\n\n';
  1619. ref.value += desc;
  1620. }
  1621. }
  1622.  
  1623. function set_image(url) {
  1624. var image = document.getElementById('image');
  1625. if (!element_writable(image)) return false;
  1626. image.value = url;
  1627.  
  1628. if (prefs.auto_preview_cover) {
  1629. if ((child = document.getElementById('cover preview')) == null) {
  1630. elem = document.createElement('div');
  1631. elem.style.paddingTop = '10px';
  1632. child = document.createElement('img');
  1633. child.id = 'cover preview';
  1634. child.style.width = '90%';
  1635. elem.append(child);
  1636. image.parentNode.previousElementSibling.append(elem);
  1637. }
  1638. child.src = url;
  1639. }
  1640. // Re-Host to PTPIMG
  1641. if (prefs.auto_rehost_cover) {
  1642. var rehost_btn = document.querySelector('input.rehost_it_cover[type="button"]');
  1643. if (rehost_btn != null) {
  1644. rehost_btn.click();
  1645. } else {
  1646. var pr = rehost_imgs([url]);
  1647. if (pr != null) pr.then(new_urls => { image.value = new_urls[0] });
  1648. }
  1649. }
  1650. }
  1651.  
  1652. // PTPIMG rehoster taken from `PTH PTPImg It`
  1653. function rehost_imgs(urls) {
  1654. if (!Array.isArray(urls)) return null;
  1655. var config = JSON.parse(window.localStorage.ptpimg_it);
  1656. return config.api_key ? new Promise(ptpimg_upload_urls).catch(m => { alert(m) }) : null;
  1657.  
  1658. function ptpimg_upload_urls(resolve, reject) {
  1659. const boundary = 'NN-GGn-PTPIMG';
  1660. var data = '--' + boundary + "\n";
  1661. data += 'Content-Disposition: form-data; name="link-upload"\n\n';
  1662. data += urls.map(function(url) {
  1663. return url.toLowerCase().indexOf('://reho.st/') < 0 && url.toLowerCase().indexOf('discogs.com') >= 0 ?
  1664. 'https://reho.st/' + url : url;
  1665. }).join('\n') + '\n';
  1666. data += '--' + boundary + '\n';
  1667. data += 'Content-Disposition: form-data; name="api_key"\n\n';
  1668. data += config.api_key + '\n';
  1669. data += '--' + boundary + '--';
  1670. GM_xmlhttpRequest({
  1671. method: 'POST',
  1672. url: 'https://ptpimg.me/upload.php',
  1673. responseType: 'json',
  1674. headers: {
  1675. 'Content-type': 'multipart/form-data; boundary=' + boundary,
  1676. },
  1677. data: data,
  1678. onload: response => {
  1679. if (response.status != 200) reject('Response error ' + response.status);
  1680. resolve(response.response.map(item => 'https://ptpimg.me/' + item.code + '.' + item.ext));
  1681. },
  1682. });
  1683. }
  1684. }
  1685.  
  1686. function element_writable(elem) { return elem != null && !elem.disabled && (overwrite || !elem.value) }
  1687. }
  1688.  
  1689. function add_artist() { exec(function() { AddArtistField() }) }
  1690.  
  1691. function array_homogenous(arr) { return arr.every(k => k === arr[0]) }
  1692.  
  1693. function exec(fn) {
  1694. let script = document.createElement('script');
  1695. script.type = 'application/javascript';
  1696. script.textContent = '(' + fn + ')();';
  1697. document.body.appendChild(script); // run the script
  1698. document.body.removeChild(script); // clean up
  1699. }
  1700.  
  1701. function make_time_string(duration) {
  1702. let t = Math.round(duration);
  1703. t = Math.abs(t);
  1704. let x = Math.floor(t / 60 ** 2);
  1705. let res;
  1706. if (x > 0) {
  1707. res = x + ':' + Math.floor(t / 60 % 60).toString().padStart(2, '0');
  1708. } else {
  1709. res = Math.floor(t / 60 % 60).toString();
  1710. }
  1711. return res + ':' + (t % 60).toString().padStart(2, '0');
  1712. }
  1713.  
  1714. function timestrToTime(str) {
  1715. return /\b(?:(?:(\d+):)?(\d+):)?(\d+)\b/.exec(str) != null ?
  1716. parseInt(RegExp.$1 || 0) * 60 ** 2 + parseInt(RegExp.$2 || 0) * 60 + parseInt(RegExp.$3 || 0) : 0;
  1717. }
  1718.  
  1719. function extract_year(expr) {
  1720. if (typeof expr != 'string') return null;
  1721. var year, m = expr.match(/\b(\d{4})\b/);
  1722. return m != null && parseInt(m[1]) || parseInt(expr) || null;
  1723. }
  1724.  
  1725. function isRED() { return document.domain.toLowerCase().endsWith('redacted.ch') }
  1726. function isNWCD() { return document.domain.toLowerCase().endsWith('notwhat.cd') }
  1727. function isOrpheus() { return document.domain.toLowerCase().endsWith('orpheus.network') }
  1728.  
  1729. function reInParenthesis(expr) { return new RegExp('\\s+\\([^\\(\\)]*'.concat(expr, '[^\\(\\)]*\\)$'), 'i') }
  1730. function reInBrackets(expr) { return new RegExp('\\s+\\[[^\\[\\]]*'.concat(expr, '[^\\[\\]]*\\]$'), 'i') }
  1731.  
  1732. function matchCaseless(str) { return str.toLowerCase() == this.toLowerCase() }
  1733.  
  1734. Array.prototype.includesCaseless = function(str) { return this.find(matchCaseless, str) != undefined };
  1735.  
  1736. function addWarning(text, bold = true, color = 'red') {
  1737. warnings = document.getElementById('UA warnings');
  1738. if (warnings == null) {
  1739. var ua = document.getElementById('upload assistant');
  1740. if (ua == null) return null;
  1741. warnings = document.createElement('TR');
  1742. if (warnings == null) return null;
  1743. warnings.id = 'UA warnings';
  1744. ua.children[0].append(warnings);
  1745.  
  1746. elem = document.createElement('TD');
  1747. if (elem == null) return null;
  1748. elem.colSpan = 2;
  1749. elem.style.paddingLeft = '15px';
  1750. elem.style.paddingRight = '15px';
  1751. elem.style.textAlign = 'left';
  1752. warnings.append(elem);
  1753. } else {
  1754. elem = warnings.children[0];
  1755. if (elem == null) return null;
  1756. }
  1757. var div = document.createElement('DIV');
  1758. if (color) div.style.color = color;
  1759. if (bold) {
  1760. div.appendChild(document.createElement('B')).textContent = text;
  1761. } else {
  1762. div.textContent = text;
  1763. }
  1764. return elem.appendChild(div);
  1765. }