Supraphonline foobar2000 tagging support

Kopíruje metadata alba ve formátu pro aplikaci tagů ve foobar2000

  1. // ==UserScript==
  2. // @name Supraphonline foobar2000 tagging support
  3. // @name:cs Supraphonline podpora tagování ve foobar2000
  4. // @name:en Supraphonline foobar2000 tagging support
  5. // @namespace https://greasyfork.org/cs/users/321857-anakunda
  6. // @version 1.49
  7. // @description Kopíruje metadata alba ve formátu pro aplikaci tagů ve foobar2000
  8. // @description:cs Kopíruje metadata alba ve formátu pro aplikaci tagů ve foobar2000
  9. // @description:en Copies album metadata to clipboard in machine parseable format
  10. // @author Anakunda
  11. // @copyright 2024, Anakunda (https://openuserjs.org/users/Anakunda)
  12. // @license GPL-3.0-or-later
  13. // @iconURL https://www.supraphonline.cz/favicon.ico
  14. // @match https://*.supraphonline.cz/*
  15. // @match https://supraphonline.cz/*
  16. // @match http://*.supraphonline.cz/*
  17. // @match http://supraphonline.cz/*
  18. // @grant GM_xmlhttpRequest
  19. // @grant GM_setClipboard
  20. // @grant GM_getValue
  21. // @grant GM_getValue
  22. // @grant GM_deleteValue
  23. // @grant GM_info
  24. // @grant window.onurlchange
  25. // @require https://openuserjs.org/src/libs/Anakunda/Requests.min.js
  26. // ==/UserScript==
  27.  
  28. // Výraz pro 'Automatically Fill Values' funkci ve foobaru2000:
  29. // %album artist%%album%%date%%releasedate%%genre%%label%%catalog%%discnumber%%totaldiscs%%discsubtitle%%tracknumber%%totaltracks%%artist%%title%%performer%%composer%%lyricist%%writer%%arranger%%media%%comment%%url%
  30.  
  31. 'use strict';
  32.  
  33. Array.prototype.includesCaseless = function(str) {
  34. if (typeof str != 'string') return false;
  35. str = str.toLowerCase();
  36. return this.some(elem => typeof elem == 'string' && elem.toLowerCase() == str);
  37. };
  38. Array.prototype.pushUnique = function(...items) {
  39. if (Array.isArray(items) && items.length > 0) items.forEach(it => { if (!this.includes(it)) this.push(it) });
  40. return this.length;
  41. };
  42. Array.prototype.pushUniqueCaseless = function(...items) {
  43. if (Array.isArray(items) && items.length > 0) items.forEach(it => { if (!this.includesCaseless(it)) this.push(it) });
  44. return this.length;
  45. };
  46. Array.prototype.equalTo = function(arr) {
  47. return Array.isArray(arr) && arr.length == this.length
  48. && Array.from(arr).sort().toString() == Array.from(this).sort().toString();
  49. };
  50. Array.prototype.equalCaselessTo = function(arr) {
  51. function adjust(elem) { return typeof elem == 'string' ? elem.toLowerCase() : elem }
  52. return Array.isArray(arr) && arr.length == this.length
  53. && arr.map(adjust).sort().toString() == this.map(adjust).sort().toString();
  54. };
  55.  
  56. function joinArtists(arr, decorator = artist => artist) {
  57. if (!Array.isArray(arr)) return null;
  58. if (arr.some(artist => artist.includes('&'))) return arr.map(decorator).join(', ');
  59. if (arr.length < 3) return arr.map(decorator).join(' & ');
  60. return arr.slice(0, -1).map(decorator).join(', ') + ' & ' + decorator(arr.slice(-1).pop());
  61. }
  62.  
  63. function timeStringToTime(str) {
  64. if (!/(-\s*)?\b(\d+(?::\d{2})*(?:\.\d+)?)\b/.test(str)) return null;
  65. var t = 0, a = RegExp.$2.split(':');
  66. while (a.length > 0) t = t * 60 + parseFloat(a.shift());
  67. return RegExp.$1 ? -t : t;
  68. }
  69.  
  70. function normalizeDate(str, countryCode = undefined) {
  71. if (typeof str != 'string') return null;
  72. var match;
  73. function formatOutput(yearIndex, montHindex, dayIndex) {
  74. var year = parseInt(match[yearIndex]), month = parseInt(match[montHindex]), day = parseInt(match[dayIndex]);
  75. if (year < 30) year += 2000; else if (year < 100) year += 1900;
  76. if (year < 1000 || year > 9999 || month < 1 || month > 12 || day < 0 || day > 31) return null;
  77. return year.toString() + '-' + month.toString().padStart(2, '0') + '-' + day.toString().padStart(2, '0');
  78. }
  79. if ((match = /\b(\d{4})-(\d{1,2})-(\d{1,2})\b/.exec(str)) != null) return formatOutput(1, 2, 3); // US
  80. if ((match = /\b(\d{4})\/(\d{1,2})\/(\d{1,2})\b/.exec(str)) != null) return formatOutput(1, 2, 3);
  81. if ((match = /\b(\d{1,2})\/(\d{1,2})\/(\d{2})\b/.exec(str)) != null
  82. && (parseInt(match[1]) > 12 || /\b(?:be|it)/.test(countryCode))) return formatOutput(3, 2, 1); // BE, IT
  83. if ((match = /\b(\d{1,2})\/(\d{1,2})\/(\d{2})\b/.exec(str)) != null) return formatOutput(3, 1, 2); // US
  84. if ((match = /\b(\d{1,2})\/(\d{1,2})\/(\d{4})\b/.exec(str)) != null) return formatOutput(3, 2, 1); // UK, IE, FR, ES
  85. if ((match = /\b(\d{1,2})-(\d{1,2})-((?:\d{2}|\d{4}))\b/.exec(str)) != null) return formatOutput(3, 2, 1); // NL
  86. if ((match = /\b(\d{1,2})\. *(\d{1,2})\. *(\d{4})\b/.exec(str)) != null) return formatOutput(3, 2, 1); // CZ, DE
  87. if ((match = /\b(\d{1,2})\. *(\d{1,2})\. *(\d{2})\b/.exec(str)) != null) return formatOutput(3, 2, 1); // AT, CH, DE, LU
  88. if ((match = /\b(\d{4})\. *(\d{1,2})\. *(\d{1,2})\b/.exec(str)) != null) return formatOutput(1, 2, 3); // JP
  89. return extractYear(str);
  90. }
  91.  
  92. function extractYear(expr) {
  93. if (typeof expr == 'number') return Math.round(expr);
  94. if (typeof expr != 'string') return null;
  95. if (/\b(\d{4})\b/.test(expr)) return parseInt(RegExp.$1);
  96. let d = new Date(expr);
  97. return parseInt(isNaN(d) ? expr : d.getUTCFullYear());
  98. }
  99.  
  100. function durationFromMeta(elem) {
  101. if (!(elem instanceof HTMLElement)) return undefined;
  102. let meta = elem.querySelector('meta[itemprop="duration"][content]');
  103. if (meta == null) return undefined;
  104. let m = /^PT?(?:(?:(\d+)H)?(\d+)M)?(\d+)S$/i.exec(meta.content);
  105. if (m != null) return (parseInt(RegExp.$1) || 0) * 60**2 + (parseInt(RegExp.$2) || 0) * 60 + (parseInt(RegExp.$3) || 0);
  106. return (m = timeStringToTime(meta.content)) != null ? m : undefined;
  107. }
  108.  
  109. let requestTimestamp, requestCounter = 0;
  110. const fetchTrackDetails = url => new Promise((resolve, reject) => (function request() {
  111. if (!requestTimestamp || Date.now() >= requestTimestamp)
  112. [requestTimestamp, requestCounter] = [Date.now() + 10e3, 0];
  113. if (++requestCounter > 30) setTimeout(request, requestTimestamp - Date.now());
  114. else LocalXHR.get(url, { fatalErrors: [503] }).then(({document}) => { resolve(document) },
  115. reason => { /^HTTP error 503\b/.test(reason) ? setTimeout(request, 10e3) : reject(reason) });
  116. })());
  117.  
  118. function fetchAlbum(evt) {
  119. const currentTarget = evt.currentTarget;
  120. if (currentTarget.disabled) return; else currentTarget.disabled = true;
  121. currentTarget.textContent = 'Pracuji...';
  122. let tracks = [ ], discNumber = 0, discSubtitle, ref, media, encoding, format, bitdepth,
  123. trackIdentifiers, releaseDate, samplerate, catalogue, imgUrl, album, totalTracks, albumYear,
  124. label, identifiers = { };
  125. const vaParser = /^(?:Various(?:\s+Artists)?|Varios(?:\s+Artistas)?|V\/?A|\<various\s+artists\>|Různí(?:\s+interpreti)?)$/i;
  126. const pseudoArtistParsers = [
  127. /^(?:#??N[\/\-]?A|[JS]r\.?)$/i,
  128. /^(?:traditional|trad\.|lidová)$/i,
  129. /\b(?:traditional|trad\.|lidová)$/,
  130. /^(?:tradiční|lidová)\s+/,
  131. /^(?:[Aa]nonym)/,
  132. /^(?:[Ll]iturgical\b|[Ll]iturgick[áý])/,
  133. /^(?:auditorium|[Oo]becenstvo|[Pp]ublikum)$/,
  134. /^(?:Various\s+Composers)$/i,
  135. /^(?:Guests|Friends)$/i,
  136. ];
  137. const VA = 'Various Artists';
  138. const artistClassParsers = [
  139. /* 0 */ [/^(?:Main\s?Artist)$/i],
  140. /* 1 */ [/^(?:Featured\s?Artist)$/i],
  141. /* 2 */ [/^(?:Remix)/i],
  142. /* 3 */ [/(?:^(?:Composer|music|music\simprovisation))$/i],
  143. /* 4 */ [/^(?:Conductor|(?:Chorus|Choir)\s?Master|Director|conducts|(?:conducted|directed)[\s\-]by)$/i],
  144. /* 5 */ [/^(?:DJ|Compiler|Compiled[\s\-]By|compiled[\s\-]by)$/],
  145. /* 6 */ [/^(?:Producer|produced[\s\-]by)$/i],
  146. /* 7 */ [/^(?:Artist|Soloist|Vocals|Ensemble|Orchestra|Choir)$/i],
  147. /* 8 */ [
  148. /\b(?:Recorded|Engineer|Producer|Mixer|Programming|Programmer|Arranger|Assistant|Translation)\b/i,
  149. /(?:PersonnelMastering)\b/i,
  150. ],
  151. /* 9 */ [/^(?:Arranger|Arranged[\-\s]By)$/i],
  152. /* 10 */ [/(?:^(?:(?:Composer)?Lyricist|libreto)|\b(?:lyrics))$/i],
  153. /* 11 */ [/(?:^(?:Author|Writer|written[\s\-]by))$/i],
  154. ];
  155. if (/\/album\/(\d+)\b/i.test(document.URL)) identifiers.SUPRAPHONLINE_ID = parseInt(RegExp.$1);
  156. let artist = Array.from(document.querySelectorAll('div.visible-lg-block > h2.album-artist > a'))
  157. .map(a => a.title || a.textContent.trim());
  158. let isVA = (ref = document.querySelector('span[itemprop="byArtist"] > meta[itemprop="name"]')) != null ?
  159. vaParser.test(ref.content) : artist.length <= 0;
  160. if ((ref = document.querySelector('h1[itemprop="name"]')) != null) album = ref.firstChild.data.trim();
  161. if ((ref = document.querySelector('meta[itemprop="numTracks"]')) != null) totalTracks = parseInt(ref.content);
  162. let genres = (ref = document.querySelector('meta[itemprop="genre"]')) != null ? ref.content : undefined;
  163. if ((ref = document.querySelector('li.album-version > div.selected > div')) != null) {
  164. if (/\b(?:MP3)\b/.test(ref.textContent))
  165. [media, encoding, format] = ['Digital Media', 'lossy', 'MP3'];
  166. if (/\b(?:FLAC)\b/.test(ref.textContent))
  167. [media, encoding, format, bitdepth] = ['Digital Media', 'lossless', 'FLAC', 16];
  168. if (/\b(?:Hi[\s\-]*Res)\b/.test(ref.textContent))
  169. [media, encoding, format, bitdepth] = ['Digital Media', 'lossless', 'FLAC', 24];
  170. if (/\b(?:CD)\b/.test(ref.textContent)) media = 'CD';
  171. if (/\b(?:LP)\b/.test(ref.textContent)) media = 'Vinyl';
  172. }
  173. const copyrightParser = /^(?:\([CP]\)|©|℗)$/i;
  174. document.querySelectorAll('ul.summary > li').forEach(function(li) {
  175. if (li.childElementCount <= 0) return;
  176. let key = li.firstElementChild.textContent, value = li.lastChild.textContent.trim();
  177. if (key.includes('Nosič')) media = value;
  178. if (key.includes('Datum vydání')) releaseDate = normalizeDate(value, 'cs');
  179. if (key.includes('První vydání')) albumYear = extractYear(value);
  180. if (key.includes('Žánr')) genres = translateGenre(value);
  181. if (key.includes('Vydavatel')) label = value;
  182. if (key.includes('Katalogové číslo')) catalogue = value;
  183. if (key.includes('Formát')) {
  184. if (/\b(?:FLAC|WAV|AIFF?)\b/.test(value)) { encoding = 'lossless'; format = 'FLAC' }
  185. if (/\b(\d+)[\-\s]?bits?\b/i.test(value)) bitdepth = parseInt(RegExp.$1);
  186. if (/\b([\d\.\,]+)[\-\s]?kHz\b/.test(value)) samplerate = parseFloat(RegExp.$1.replace(',', '.')) * 1000;
  187. }
  188. //if (key.includes('Celková stopáž')) totalTime = timeStringToTime(value);
  189. if (copyrightParser.test(key) && !albumYear) albumYear = extractYear(value);
  190. });
  191. const creators = ['autoři', 'interpreti', 'tělesa', 'digitalizace'];
  192. let artists = [ ], ndx;
  193. for (let i = 0; i < creators.length; ++i) artists[i] = {};
  194. document.querySelectorAll('ul.sidebar-artist > li').forEach(function(it) {
  195. if ((ref = it.querySelector('h3')) != null) {
  196. ndx = undefined;
  197. creators.forEach((it, _ndx) => { if (ref.textContent.includes(it)) ndx = _ndx });
  198. } else {
  199. if (typeof ndx != 'number') return;
  200. if (ndx == 2) var role = 'ensemble';
  201. else if ((ref = it.querySelector('span')) != null) role = translateRole(ref);
  202. if ((ref = it.querySelector('a')) != null) {
  203. if (!Array.isArray(artists[ndx][role])) artists[ndx][role] = [];
  204. artists[ndx][role].pushUnique([ref.textContent.trim(), document.location.origin + ref.pathname]);
  205. }
  206. }
  207. });
  208. let description = Array.from(document.querySelectorAll('div[itemprop="description"] p'))
  209. .map(p => p.textContent.trim()).join('\n\n').replace(/\s+/g, ' ');
  210. let performers = [ ], composer = [ ], conductor = [ ], DJs = [ ], albumGuests = [ ], lyricist = [ ],
  211. writer = [ ], arranger = [ ], volMedia;
  212. for (let i = 1; i < 3; ++i) Object.keys(artists[i]).forEach(function(role) { // performers
  213. var a = artists[i][role].map(a => a[0]);
  214. ([
  215. 'conductor', 'choirmaster', 'director',
  216. ].includes(role) ? conductor : role == 'DJ' ? DJs : [
  217. 'FeaturedArtist',
  218. ].includes(role) ? albumGuests : artist).pushUnique(...a);
  219. });
  220. Object.keys(artists[0]).forEach(function(role) { // composers
  221. composer.pushUnique(...artists[0][role].map(it => it[0])
  222. .filter(it => !pseudoArtistParsers.some(rx => rx.test(it))));
  223. });
  224. if ((ref = document.querySelector('meta[itemprop="image"]')) != null) imgUrl = ref.content.replace(/\?.*$/, '');
  225. const totalDiscs = document.querySelectorAll('table.table-tracklist > tbody > tr.cd-header').length;
  226. document.querySelectorAll('table.table-tracklist > tbody > tr').forEach(function(tr, index) {
  227. if (tr.classList.contains('cd-header') && (ref = tr.querySelector('td > h3')) != null
  228. && /\b(?:(\S*?)\s*)?(\d+)\b/.test(ref.textContent)) {
  229. volMedia = RegExp.$1 ? RegExp.lastMatch : undefined;
  230. ++discNumber; // = parseInt(RegExp.$2) || undefined;
  231. }
  232. if (tr.classList.contains('song-header') && (ref = tr.querySelector('td')) != null)
  233. discSubtitle = ref.title || ref.textContent.trim();
  234. if (tr.classList.contains('track') && tr.id) {
  235. trackIdentifiers = { TRACK_ID: /^(?:track)-(\d+)$/i.exec(tr.id) };
  236. if (trackIdentifiers.TRACK_ID != null) trackIdentifiers.TRACK_ID = parseInt(trackIdentifiers.TRACK_ID[1]);
  237. else delete trackIdentifiers.TRACK_ID;
  238. if (volMedia) trackIdentifiers.VOL_MEDIA = volMedia;
  239. let track = {
  240. artist: isVA ? VA : undefined,
  241. artists: !isVA && artist.length > 0 ? artist : undefined,
  242. //featured_artists: albumGuests.length > 0 ? albumGuests : undefined,
  243. album: album,
  244. album_year: /*trackYear || */albumYear || undefined,
  245. release_date: releaseDate,
  246. label: label,
  247. catalog: catalogue,
  248. encoding: encoding,
  249. codec: format,
  250. bitdepth: bitdepth,
  251. samplerate: samplerate || undefined,
  252. media: media,
  253. genre: genres,
  254. disc_number: discNumber || 1,
  255. total_discs: totalDiscs > 0 ? totalDiscs : 1,
  256. disc_subtitle: discSubtitle,
  257. track_number: /^\s*(\d+)\.?\s*$/.test(tr.children[0].firstChild.textContent) ?
  258. parseInt(RegExp.$1) || RegExp.$1 : undefined,
  259. total_tracks: totalTracks,
  260. title: (ref = tr.querySelector('meta[itemprop="name"][content]')) != null ? ref.content
  261. : (ref = tr.querySelector('td > a.trackdetail')) != null ? ref.textContent.trim() : undefined,
  262. performers: performers.length > 0 ? performers : undefined,
  263. composers: composer.length > 0 ? composer : undefined,
  264. lyricists: lyricist.length > 0 ? lyricist : undefined,
  265. writers: writer.length > 0 ? writer : undefined,
  266. arrangers: arranger.length > 0 ? arranger : undefined,
  267. conductors: conductor.length > 0 ? conductor : undefined,
  268. compilers: DJs.length > 0 ? DJs : undefined,
  269. duration: durationFromMeta(tr),
  270. url: document.location.origin + document.location.pathname,
  271. description: description,
  272. identifiers: mergeIds(),
  273. cover_url: imgUrl,
  274. };
  275. tracks.push((function(track) {
  276. if ((ref = tr.querySelector('td > a.trackdetail')) == null) return Promise.reject('link not found');
  277. return fetchTrackDetails(ref.pathname + ref.search).then(function(document) {
  278. let detail = document.body.querySelector('div[data-swap="trackdetail-' + track.identifiers.TRACK_ID + '"] > div > div.row');
  279. if (detail == null) return Promise.reject('element not found');
  280. detail.querySelectorAll('div[class]:nth-of-type(1) > ul > li').forEach(function(li) {
  281. var key = li.querySelector('span'), value = li.lastChild;
  282. if (key == null || value.nodeType != Node.TEXT_NODE) return;
  283. key = key.textContent.trim(); value = value.wholeText.trim();
  284. if (!key || !value) return;
  285. if (key.startsWith('Žánr')) track.genre = value;
  286. if (key.startsWith('Nahrávka dokončena')) track.rec_year = extractYear(value);
  287. if (key.startsWith('Místo nahrání')) track.venue = value;
  288. if (key.startsWith('Rok prvního vydání')) track.pub_year = extractYear(value);
  289. if (copyrightParser.test(key)) track.copyright = value;
  290. });
  291. let trackArtists = [ ];
  292. for (let i = 0; i < 12; ++i) trackArtists[i] = [ ];
  293. detail.querySelectorAll('div[class]:nth-of-type(2) > ul > li').forEach(function(li) {
  294. var role = li.querySelector('span');
  295. var artists = Array.from(li.getElementsByTagName('a')).map(a => a.textContent.trim())
  296. .filter(artist => !pseudoArtistParsers.some(rx => rx.test(artist)));
  297. if (role != null && artists.length > 0) role = translateRole(role); else return;
  298. if (artistClassParsers[2].some(rx => rx.test(role)))
  299. trackArtists[2].pushUnique(...artists);
  300. else if (artistClassParsers[3].some(rx => rx.test(role)))
  301. trackArtists[3].pushUnique(...artists);
  302. else if (artistClassParsers[9].some(rx => rx.test(role)))
  303. trackArtists[9].pushUnique(...artists);
  304. else if (artistClassParsers[10].some(rx => rx.test(role)))
  305. trackArtists[10].pushUnique(...artists);
  306. else if (artistClassParsers[11].some(rx => rx.test(role)))
  307. trackArtists[11].pushUnique(...artists);
  308. else if (artistClassParsers[5].some(rx => rx.test(role)))
  309. trackArtists[5].pushUnique(...artists);
  310. else if (artistClassParsers[6].some(rx => rx.test(role)))
  311. trackArtists[6].pushUnique(...artists);
  312. else if (role.toLowerCase() == 'performer' || !artistClassParsers[8].some(rx => rx.test(role))) {
  313. if (artistClassParsers[0].some(rx => rx.test(role)))
  314. trackArtists[0].pushUnique(...artists);
  315. else if (artistClassParsers[1].some(rx => rx.test(role)))
  316. trackArtists[1].pushUnique(...artists);
  317. else if (artistClassParsers[4].some(rx => rx.test(role)))
  318. trackArtists[4].pushUnique(...artists);
  319. else artists.forEach(_artist => {
  320. if (artist.includesCaseless(_artist)) trackArtists[0].pushUnique(_artist);
  321. else if (artistClassParsers[7].some(rx => rx.test(role))) trackArtists[1].pushUnique(_artist);
  322. });
  323. trackArtists[7].pushUnique(...artists.map(artist => artist + ' (' + role + ')'));
  324. }
  325. });
  326. if (trackArtists[1].length > 0 && trackArtists[0].length <= 0) {
  327. trackArtists[0] = trackArtists[1]; trackArtists[1] = [];
  328. }
  329. if (trackArtists[0].length > 0 && (isVA || !trackArtists[0].equalCaselessTo(artist)
  330. || trackArtists[1].length > 0/*!trackArtists[1].equalCaselessTo(albumGuests)*/)) {
  331. track.track_artists = trackArtists[0];
  332. if (trackArtists[1].length > 0) track.track_guests = trackArtists[1];
  333. }
  334. [
  335. [2, 'remixer'],
  336. [3, 'composer'],
  337. [4, 'conductor'],
  338. [5, 'compiler'],
  339. //[6, 'producer'],
  340. [7, 'performer'],
  341. [9, 'arranger'],
  342. [10, 'lyricist'],
  343. [11, 'writer'],
  344. ].forEach(def => { if (trackArtists[def[0]].length > 0) track[def[1] + 's'] = trackArtists[def[0]] })
  345. return track;
  346. });
  347. })(track).catch(function(reason) {
  348. console.error('Supraphonline parser failed to get track', index + 1, 'detail:', reason);
  349. return Promise.resolve(track);
  350. }));
  351. } // track
  352. });
  353. Promise.all(tracks).then(tracks => tracks.map(track => {
  354. if (Array.isArray(track.track_artists) && track.track_artists.length > 0) {
  355. var trackArtist = joinArtists(track.track_artists);
  356. if (Array.isArray(track.track_guests) && track.track_guests.length > 0)
  357. trackArtist += ' feat. ' + joinArtists(track.track_guests);
  358. }
  359. return [
  360. isVA ? VA : joinArtists(track.artists) || '',
  361. track.album || '',
  362. track.album_year || track.pub_year || '',
  363. track.release_date || '',
  364. track.genre || '',
  365. track.label || '',
  366. track.catalog || '',
  367. track.disc_number || '',
  368. track.total_discs > 1 ? track.total_discs : '',
  369. track.disc_subtitle || '',
  370. track.track_number || '',
  371. tracks.filter(_track => _track.disc_number == track.disc_number).length || track.total_tracks || '',
  372. trackArtist || (Array.isArray(track.artists) && track.artists.length > 0 ?
  373. joinArtists(track.artists) : track.artist) || '',
  374. track.title || '',
  375. (track.performers || [ ]).join(', '),
  376. (track.composers || [ ]).join(', '),
  377. (track.lyricists || [ ]).join(', '),
  378. (track.writers || [ ]).join(', '),
  379. (track.arrangers || [ ]).join(', '),
  380. track.media,
  381. track.description,
  382. track.url,
  383. ].join('\x1E');
  384. }).join('\n')).then(clipBoard => { GM_setClipboard(clipBoard, 'text') }).catch(e => { alert(e) }).then(function() {
  385. [currentTarget.disabled, currentTarget.textContent] = [false, '✔'];
  386. currentTarget.style.backgroundColor = 'green';
  387. setTimeout(function(button) {
  388. button.style.backgroundColor = null;
  389. button.textContent = button.dataset.originalText;
  390. }, 5000, currentTarget);
  391. });
  392.  
  393. function translateGenre(genre) {
  394. if (!genre || typeof genre != 'string') return undefined;
  395. [
  396. ['Orchestrální hudba', 'Orchestral Music'],
  397. ['Komorní hudba', 'Chamber Music'],
  398. ['Vokální', 'Classical, Vocal'],
  399. ['Klasická hudba', 'Classical'],
  400. ['Melodram', 'Classical, Melodram'],
  401. ['Symfonie', 'Symphony'],
  402. ['Vánoční hudba', 'Christmas Music'],
  403. [/^(?:Alternativ(?:ní|a))$/i, 'Alternative'],
  404. ['Dechová hudba', 'Brass Music'],
  405. ['Elektronika', 'Electronic'],
  406. ['Folklor', 'Folclore, World Music'],
  407. ['Instrumentální hudba', 'Instrumental'],
  408. ['Latinské rytmy', 'Latin'],
  409. ['Meditační hudba', 'Meditative'],
  410. ['Vojenská hudba', 'Military Music'],
  411. ['Pro děti', 'Children'],
  412. ['Pro dospělé', 'Adult'],
  413. ['Mluvené slovo', 'Spoken Word'],
  414. ['Audiokniha', 'audiobook'],
  415. ['Humor', 'humour'],
  416. ['Pohádka', 'Fairy-Tale'],
  417. ].forEach(function(subst) {
  418. if (typeof subst[0] == 'string' && genre.toLowerCase() == subst[0].toLowerCase()
  419. || subst[0] instanceof RegExp && subst[0].test(genre)) genre = subst[1];
  420. });
  421. return genre;
  422. }
  423.  
  424. function translateRole(elem) {
  425. return elem instanceof HTMLElement ? [
  426. [/\b(?:klavír)\b/ig, 'piano'],
  427. [/\b(?:housle)\b/ig, 'violin'],
  428. [/\b(?:violoncello)\b/ig, 'cello'],
  429. [/\b(?:viola)\b/ig, 'alto'],
  430. [/\b(?:varhany)\b/ig, 'organ'],
  431. [/\b(?:cembalo)\b/ig, 'harpsichord'],
  432. [/\b(?:trubka)\b/ig, 'trumpet'],
  433. [/\b(?:soprán)\b/ig, 'soprano'],
  434. [/\b(?:alt)\b/ig, 'alto'],
  435. [/\b(?:baryton)\b/ig, 'baritone'],
  436. [/\b(?:bas)\b/ig, 'basso'],
  437. [/\b(?:akordeon)\b/ig, 'accordion'],
  438. [/\b(?:syntezátor)\b/ig, 'synthesizer'],
  439. [/\b(?:klávesové nástroje)\b/ig, 'keyboards'],
  440. [/\b(?:bicí)\b/ig, 'drums'],
  441. [/\b(?:kontrabas)\b/ig, 'double-bass'],
  442. [/\b(?:zpěv|vokál)\b/ig, 'vocals'],
  443. [/\b(?:baskytara)\b/ig, 'bass guitar'],
  444. [/\b(?:havajská kytara)\b/ig, 'steel guitar'],
  445. [/\b(?:akustická kytara)\b/ig, 'acoustic guitar'],
  446. [/\b(?:kytara)\b/ig, 'guitar'],
  447. [/\b(?:kytary)\b/ig, 'guitars'],
  448. [/(?:čte|četba)\b/ig, 'narration'],
  449. [/\b(?:vypravuje)\b/ig, 'narration'],
  450. [/\b(?:hudební těleso)\b/ig, 'ensemble'],
  451. [/\b(?:Umělec)\b/ig, 'Artist'],
  452. [/\b(?:improvizace)\b/ig, 'improvisation'],
  453. ['český', 'czech'],
  454. ['původní', 'original'],
  455. [/\b(?:text)\b/ig, 'lyrics'],
  456. [/\b(?:hudba)\b/ig, 'music'],
  457. ['hudební', 'music'],
  458. [/\b(?:autor)\b/ig, 'author'],
  459. [/\b(?:překlad)\b/ig, 'translation'],
  460. ['účinkuje', 'participating'],
  461. ['hovoří a zpívá', 'speaks and sings'],
  462. ['hovoří', 'spoken by'],
  463. ['komentář', 'commentary'],
  464. [/\b(?:dirigent)\b/ig, 'conductor'],
  465. ['řídí', 'director'],
  466. [/\b(?:sbormistr)\b/ig, 'choirmaster'],
  467. ['programování', 'programming'],
  468. [/\b(?:produkce)\b/ig, 'produced by'],
  469. ['nahrál', 'recorded by'],
  470. [/\b(?:digitální přepis)\b/ig, 'A/D transfer'],
  471. ].reduce((r, def) => r.replace(...def), elem.textContent.trim().replace(/\s*:.*$/, '')) : undefined;
  472. }
  473.  
  474. function mergeIds() {
  475. const r = Object.assign({}, identifiers, trackIdentifiers);
  476. trackIdentifiers = {};
  477. return r;
  478. }
  479. }
  480.  
  481. function addButton() {
  482. if (!document.location.pathname.startsWith('/album/')) return;
  483. const container = document.body.querySelector('form.table-action'), id = 'copy-info-to-clipboard';
  484. if (container == null || container.querySelector('button#' + id) != null) return;
  485. const button = Object.assign(document.createElement('button'), {
  486. id: id,
  487. type: 'button',
  488. className: 'btn btn-danger topframe_login',
  489. textContent: 'Kopírovat do schránky',
  490. style: 'margin-right: 10px;',
  491. onclick: fetchAlbum,
  492. });
  493. button.dataset.originalText = button.textContent;
  494. container.prepend(button);
  495. };
  496. addButton();
  497. window.onurlchange = addButton;