|
5 | 5 | // @namespace http://userscripts.org/users/22504 |
6 | 6 | // @downloadURL https://raw.github.com/murdos/musicbrainz-userscripts/master/bandcamp_importer.user.js |
7 | 7 | // @updateURL https://raw.github.com/murdos/musicbrainz-userscripts/master/bandcamp_importer.user.js |
8 | | -// @include /^https?://[^/]+/(?:album|track)/[^/]+\/?$/ |
9 | | -// @include /^https?://web\.archive\.org/web/\d+/https?://[^/]+/(?:album|track)/[^/]+\/?$/ |
| 8 | +// @include /^https:\/\/[^/]+(?:\/(?:album|track)\/[^/]+\/?|\/music\/?|\/?)$/ |
| 9 | +// @include /^https?:\/\/web\.archive\.org\/web\/\d+\/https?:\/\/[^/]+(?:\/(?:album|track)\/[^/]+\/?|\/music\/?|\/?)$/ |
10 | 10 | // @require https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js |
11 | 11 | // @require lib/mbimport.js |
12 | 12 | // @require lib/logger.js |
@@ -299,117 +299,136 @@ $(document).ready(function () { |
299 | 299 | */ |
300 | 300 | if (!unsafeWindow.TralbumData) return; |
301 | 301 | /***/ |
| 302 | + let mblinks = new MBLinks('BCI_MBLINKS_CACHE'); |
302 | 303 |
|
303 | | - MBImportStyle(); |
| 304 | + const isDiscographyPage = !!unsafeWindow.TralbumData.url?.match(/\/music\/?$/); |
304 | 305 |
|
305 | | - let mblinks = new MBLinks('BCI_MBLINKS_CACHE'); |
| 306 | + if (isDiscographyPage) { |
| 307 | + const hostname = unsafeWindow.TralbumData.url.replace("/music", ""); |
306 | 308 |
|
307 | | - let release = BandcampImport.retrieveReleaseInfo(); |
308 | | - |
309 | | - // add MB artist link |
310 | | - let root_url = release.url.match(/^(https?:\/\/[^/]+)/)[1].split('?')[0]; |
311 | | - let label_url = ''; |
312 | | - |
313 | | - mblinks.searchAndDisplayMbLink( |
314 | | - root_url, |
315 | | - 'label', |
316 | | - function (link) { |
317 | | - $('p#band-name-location span.title').append(link); |
318 | | - }, |
319 | | - `label:${root_url}` |
320 | | - ); |
321 | | - const labelback = document.querySelector('a.back-to-label-link'); |
322 | | - if (labelback) { |
323 | | - const labelbacklink = labelback.getAttribute('href'); |
324 | | - if (labelbacklink) { |
325 | | - label_url = labelbacklink |
326 | | - .match(/^(https?:\/\/[^/]+)/)[1] |
327 | | - .split('?')[0] |
328 | | - .fix_bandcamp_url(); |
329 | | - mblinks.searchAndDisplayMbLink( |
330 | | - label_url, |
331 | | - 'label', |
332 | | - function (link) { |
333 | | - $('a.back-to-label-link span.back-link-text').append(link); |
334 | | - }, |
335 | | - `label:${label_url}` |
336 | | - ); |
337 | | - } |
| 309 | + $('ol#music-grid > li > a').each(function () { |
| 310 | + const $link = $(this); |
| 311 | + const bandcampReleaseUrl = $link.attr('href'); |
| 312 | + |
| 313 | + if (bandcampReleaseUrl && bandcampReleaseUrl.match(/^(\/album|\/track)/)) { |
| 314 | + const full_url = hostname + bandcampReleaseUrl; |
| 315 | + |
| 316 | + mblinks.searchAndDisplayMbLink(full_url, 'release', function (link) { |
| 317 | + $('p.title', $link).prepend(link); |
| 318 | + }, `release:${full_url}`); |
| 319 | + } |
| 320 | + }); |
338 | 321 | } |
| 322 | + else { |
| 323 | + MBImportStyle(); |
| 324 | + |
| 325 | + let release = BandcampImport.retrieveReleaseInfo(); |
| 326 | + |
| 327 | + // add MB artist link |
| 328 | + let root_url = release.url.match(/^(https?:\/\/[^/]+)/)[1].split('?')[0]; |
| 329 | + let label_url = ''; |
| 330 | + |
| 331 | + mblinks.searchAndDisplayMbLink( |
| 332 | + root_url, |
| 333 | + 'label', |
| 334 | + function (link) { |
| 335 | + $('p#band-name-location span.title').append(link); |
| 336 | + }, |
| 337 | + `label:${root_url}` |
| 338 | + ); |
| 339 | + const labelback = document.querySelector('a.back-to-label-link'); |
| 340 | + if (labelback) { |
| 341 | + const labelbacklink = labelback.getAttribute('href'); |
| 342 | + if (labelbacklink) { |
| 343 | + label_url = labelbacklink |
| 344 | + .match(/^(https?:\/\/[^/]+)/)[1] |
| 345 | + .split('?')[0] |
| 346 | + .fix_bandcamp_url(); |
| 347 | + mblinks.searchAndDisplayMbLink( |
| 348 | + label_url, |
| 349 | + 'label', |
| 350 | + function (link) { |
| 351 | + $('a.back-to-label-link span.back-link-text').append(link); |
| 352 | + }, |
| 353 | + `label:${label_url}` |
| 354 | + ); |
| 355 | + } |
| 356 | + } |
339 | 357 |
|
340 | | - if (release.artist_credit.length == 1) { |
341 | | - // try to get artist's mbid from cache |
342 | | - let artist_mbid = mblinks.resolveMBID(root_url); |
343 | | - if (artist_mbid) { |
344 | | - release.artist_credit[0].mbid = artist_mbid; |
| 358 | + if (release.artist_credit.length == 1) { |
| 359 | + // try to get artist's mbid from cache |
| 360 | + let artist_mbid = mblinks.resolveMBID(root_url); |
| 361 | + if (artist_mbid) { |
| 362 | + release.artist_credit[0].mbid = artist_mbid; |
| 363 | + } |
345 | 364 | } |
346 | | - } |
347 | 365 |
|
348 | | - // try to get label mbid from cache |
349 | | - let label_mbid = ''; |
350 | | - let label_name = ''; |
351 | | - if (label_url) { |
352 | | - label_mbid = mblinks.resolveMBID(`label:${label_url}`); |
353 | | - label_name = BandcampImport.getlabelname(); |
354 | | - } else { |
355 | | - label_mbid = mblinks.resolveMBID(`label:${root_url}`); |
356 | | - if (label_mbid) label_name = $('p#band-name-location span.title').text().trim(); |
357 | | - } |
358 | | - if (label_mbid || label_name) { |
359 | | - if (release.labels.length == 0) { |
360 | | - release.labels.push({ |
361 | | - name: '', |
362 | | - mbid: '', |
363 | | - catno: 'none', |
| 366 | + // try to get label mbid from cache |
| 367 | + let label_mbid = ''; |
| 368 | + let label_name = ''; |
| 369 | + if (label_url) { |
| 370 | + label_mbid = mblinks.resolveMBID(`label:${label_url}`); |
| 371 | + label_name = BandcampImport.getlabelname(); |
| 372 | + } else { |
| 373 | + label_mbid = mblinks.resolveMBID(`label:${root_url}`); |
| 374 | + if (label_mbid) label_name = $('p#band-name-location span.title').text().trim(); |
| 375 | + } |
| 376 | + if (label_mbid || label_name) { |
| 377 | + if (release.labels.length == 0) { |
| 378 | + release.labels.push({ |
| 379 | + name: '', |
| 380 | + mbid: '', |
| 381 | + catno: 'none', |
| 382 | + }); |
| 383 | + } |
| 384 | + release.labels[0].name = label_name; |
| 385 | + release.labels[0].mbid = label_mbid; |
| 386 | + } |
| 387 | + |
| 388 | + BandcampImport.insertLink(release); |
| 389 | + LOGGER.info('Parsed release: ', release); |
| 390 | + |
| 391 | + if (release.type == 'track') { |
| 392 | + mblinks.searchAndDisplayMbLink(root_url, 'artist', function (link) { |
| 393 | + $('div#name-section h3 span:last').before(link); |
| 394 | + }); |
| 395 | + // add MB links to parent album |
| 396 | + mblinks.searchAndDisplayMbLink(release.parent_album_url, 'release', function (link) { |
| 397 | + $('div#name-section h3 span:first').before(link); |
| 398 | + }); |
| 399 | + } else { |
| 400 | + mblinks.searchAndDisplayMbLink(root_url, 'artist', function (link) { |
| 401 | + $('div#name-section h3 span:first').before(link); |
| 402 | + }); |
| 403 | + // add MB release links to album or single |
| 404 | + mblinks.searchAndDisplayMbLink(release.url, 'release', function (link) { |
| 405 | + $('div#name-section h3 span:first').after(link); |
364 | 406 | }); |
365 | 407 | } |
366 | | - release.labels[0].name = label_name; |
367 | | - release.labels[0].mbid = label_mbid; |
368 | | - } |
369 | 408 |
|
370 | | - BandcampImport.insertLink(release); |
371 | | - LOGGER.info('Parsed release: ', release); |
| 409 | + // append a comma after each tag to ease cut'n'paste to MB |
| 410 | + $('div.tralbum-tags a:not(:last-child).tag').after(', '); |
372 | 411 |
|
373 | | - if (release.type == 'track') { |
374 | | - mblinks.searchAndDisplayMbLink(root_url, 'artist', function (link) { |
375 | | - $('div#name-section h3 span:last').before(link); |
376 | | - }); |
377 | | - // add MB links to parent album |
378 | | - mblinks.searchAndDisplayMbLink(release.parent_album_url, 'release', function (link) { |
379 | | - $('div#name-section h3 span:first').before(link); |
380 | | - }); |
381 | | - } else { |
382 | | - mblinks.searchAndDisplayMbLink(root_url, 'artist', function (link) { |
383 | | - $('div#name-section h3 span:first').before(link); |
384 | | - }); |
385 | | - // add MB release links to album or single |
386 | | - mblinks.searchAndDisplayMbLink(release.url, 'release', function (link) { |
387 | | - $('div#name-section h3 span:first').after(link); |
388 | | - }); |
389 | | - } |
| 412 | + // append a link to the full size image |
| 413 | + const tralbumArt = document.querySelector('div#tralbumArt'); |
| 414 | + const fullsizeimageurl = tralbumArt.querySelector('a').getAttribute('href').replace('_10', '_0'); |
| 415 | + tralbumArt.insertAdjacentHTML( |
| 416 | + 'afterend', |
| 417 | + `<div id='bci_link'><a class='custom-color' href='${fullsizeimageurl}' title='Open original image in a new tab (Bandcamp importer)' target='_blank'>Original image</a></div>` |
| 418 | + ); |
390 | 419 |
|
391 | | - // append a comma after each tag to ease cut'n'paste to MB |
392 | | - $('div.tralbum-tags a:not(:last-child).tag').after(', '); |
393 | | - |
394 | | - // append a link to the full size image |
395 | | - const tralbumArt = document.querySelector('div#tralbumArt'); |
396 | | - const fullsizeimageurl = tralbumArt.querySelector('a').getAttribute('href').replace('_10', '_0'); |
397 | | - tralbumArt.insertAdjacentHTML( |
398 | | - 'afterend', |
399 | | - `<div id='bci_link'><a class='custom-color' href='${fullsizeimageurl}' title='Open original image in a new tab (Bandcamp importer)' target='_blank'>Original image</a></div>` |
400 | | - ); |
401 | | - |
402 | | - const bci_link = document.querySelector('div#bci_link'); |
403 | | - bci_link.style.paddingTop = '0.5em'; |
404 | | - bci_link.style.textAlign = 'right'; |
405 | | - bci_link.querySelector('a').style.fontWeight = 'bold'; |
406 | | - const upc = unsafeWindow.TralbumData.current.upc; |
407 | | - if (typeof upc != 'undefined' && upc !== null) { |
408 | | - document.querySelector('div #trackInfoInner').insertAdjacentHTML( |
409 | | - 'beforeend', |
410 | | - `<div id="mbimport_upc" style="margin-bottom: 2em; font-size: smaller;">UPC: ${upc}<br/> |
| 420 | + const bci_link = document.querySelector('div#bci_link'); |
| 421 | + bci_link.style.paddingTop = '0.5em'; |
| 422 | + bci_link.style.textAlign = 'right'; |
| 423 | + bci_link.querySelector('a').style.fontWeight = 'bold'; |
| 424 | + const upc = unsafeWindow.TralbumData.current.upc; |
| 425 | + if (typeof upc != 'undefined' && upc !== null) { |
| 426 | + document.querySelector('div #trackInfoInner').insertAdjacentHTML( |
| 427 | + 'beforeend', |
| 428 | + `<div id="mbimport_upc" style="margin-bottom: 2em; font-size: smaller;">UPC: ${upc}<br/> |
411 | 429 | Import: <a href="https://harmony.pulsewidth.org.uk/release?url=${encodeURIComponent(release.url)}&category=default">Harmony</a> |
412 | 430 | | <a href="https://atisket.pulsewidth.org.uk/?upc=${upc}">a-tisket</a></div>` |
413 | | - ); |
| 431 | + ); |
| 432 | + } |
414 | 433 | } |
415 | 434 | }); |
0 commit comments