From a95a8d15c2a6612a43a662208533ba6bb343a40f Mon Sep 17 00:00:00 2001 From: Raman Sinclair Date: Mon, 21 Apr 2025 07:55:31 +0200 Subject: [PATCH 1/4] bandcamp_importer: enable MB Release links on Discography pages (release lists) --- bandcamp_importer.user.js | 219 +++++++++++++++++++++----------------- 1 file changed, 119 insertions(+), 100 deletions(-) diff --git a/bandcamp_importer.user.js b/bandcamp_importer.user.js index 9c304a3..f0bdf97 100644 --- a/bandcamp_importer.user.js +++ b/bandcamp_importer.user.js @@ -5,8 +5,8 @@ // @namespace http://userscripts.org/users/22504 // @downloadURL https://raw.github.com/murdos/musicbrainz-userscripts/master/bandcamp_importer.user.js // @updateURL https://raw.github.com/murdos/musicbrainz-userscripts/master/bandcamp_importer.user.js -// @include /^https?://[^/]+/(?:album|track)/[^/]+\/?$/ -// @include /^https?://web\.archive\.org/web/\d+/https?://[^/]+/(?:album|track)/[^/]+\/?$/ +// @include /^https:\/\/[^/]+(?:\/(?:album|track)\/[^/]+\/?|\/music\/?|\/?)$/ +// @include /^https?:\/\/web\.archive\.org\/web\/\d+\/https?:\/\/[^/]+(?:\/(?:album|track)\/[^/]+\/?|\/music\/?|\/?)$/ // @require https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js // @require lib/mbimport.js // @require lib/logger.js @@ -299,117 +299,136 @@ $(document).ready(function () { */ if (!unsafeWindow.TralbumData) return; /***/ + let mblinks = new MBLinks('BCI_MBLINKS_CACHE'); - MBImportStyle(); + const isDiscographyPage = !!unsafeWindow.TralbumData.url?.match(/\/music\/?$/); - let mblinks = new MBLinks('BCI_MBLINKS_CACHE'); + if (isDiscographyPage) { + const hostname = unsafeWindow.TralbumData.url.replace("/music", ""); - let release = BandcampImport.retrieveReleaseInfo(); - - // add MB artist link - let root_url = release.url.match(/^(https?:\/\/[^/]+)/)[1].split('?')[0]; - let label_url = ''; - - mblinks.searchAndDisplayMbLink( - root_url, - 'label', - function (link) { - $('p#band-name-location span.title').append(link); - }, - `label:${root_url}` - ); - const labelback = document.querySelector('a.back-to-label-link'); - if (labelback) { - const labelbacklink = labelback.getAttribute('href'); - if (labelbacklink) { - label_url = labelbacklink - .match(/^(https?:\/\/[^/]+)/)[1] - .split('?')[0] - .fix_bandcamp_url(); - mblinks.searchAndDisplayMbLink( - label_url, - 'label', - function (link) { - $('a.back-to-label-link span.back-link-text').append(link); - }, - `label:${label_url}` - ); - } + $('ol#music-grid > li > a').each(function () { + const $link = $(this); + const bandcampReleaseUrl = $link.attr('href'); + + if (bandcampReleaseUrl && bandcampReleaseUrl.match(/^(\/album|\/track)/)) { + const full_url = hostname + bandcampReleaseUrl; + + mblinks.searchAndDisplayMbLink(full_url, 'release', function (link) { + $('p.title', $link).prepend(link); + }, `release:${full_url}`); + } + }); } + else { + MBImportStyle(); + + let release = BandcampImport.retrieveReleaseInfo(); + + // add MB artist link + let root_url = release.url.match(/^(https?:\/\/[^/]+)/)[1].split('?')[0]; + let label_url = ''; + + mblinks.searchAndDisplayMbLink( + root_url, + 'label', + function (link) { + $('p#band-name-location span.title').append(link); + }, + `label:${root_url}` + ); + const labelback = document.querySelector('a.back-to-label-link'); + if (labelback) { + const labelbacklink = labelback.getAttribute('href'); + if (labelbacklink) { + label_url = labelbacklink + .match(/^(https?:\/\/[^/]+)/)[1] + .split('?')[0] + .fix_bandcamp_url(); + mblinks.searchAndDisplayMbLink( + label_url, + 'label', + function (link) { + $('a.back-to-label-link span.back-link-text').append(link); + }, + `label:${label_url}` + ); + } + } - if (release.artist_credit.length == 1) { - // try to get artist's mbid from cache - let artist_mbid = mblinks.resolveMBID(root_url); - if (artist_mbid) { - release.artist_credit[0].mbid = artist_mbid; + if (release.artist_credit.length == 1) { + // try to get artist's mbid from cache + let artist_mbid = mblinks.resolveMBID(root_url); + if (artist_mbid) { + release.artist_credit[0].mbid = artist_mbid; + } } - } - // try to get label mbid from cache - let label_mbid = ''; - let label_name = ''; - if (label_url) { - label_mbid = mblinks.resolveMBID(`label:${label_url}`); - label_name = BandcampImport.getlabelname(); - } else { - label_mbid = mblinks.resolveMBID(`label:${root_url}`); - if (label_mbid) label_name = $('p#band-name-location span.title').text().trim(); - } - if (label_mbid || label_name) { - if (release.labels.length == 0) { - release.labels.push({ - name: '', - mbid: '', - catno: 'none', + // try to get label mbid from cache + let label_mbid = ''; + let label_name = ''; + if (label_url) { + label_mbid = mblinks.resolveMBID(`label:${label_url}`); + label_name = BandcampImport.getlabelname(); + } else { + label_mbid = mblinks.resolveMBID(`label:${root_url}`); + if (label_mbid) label_name = $('p#band-name-location span.title').text().trim(); + } + if (label_mbid || label_name) { + if (release.labels.length == 0) { + release.labels.push({ + name: '', + mbid: '', + catno: 'none', + }); + } + release.labels[0].name = label_name; + release.labels[0].mbid = label_mbid; + } + + BandcampImport.insertLink(release); + LOGGER.info('Parsed release: ', release); + + if (release.type == 'track') { + mblinks.searchAndDisplayMbLink(root_url, 'artist', function (link) { + $('div#name-section h3 span:last').before(link); + }); + // add MB links to parent album + mblinks.searchAndDisplayMbLink(release.parent_album_url, 'release', function (link) { + $('div#name-section h3 span:first').before(link); + }); + } else { + mblinks.searchAndDisplayMbLink(root_url, 'artist', function (link) { + $('div#name-section h3 span:first').before(link); + }); + // add MB release links to album or single + mblinks.searchAndDisplayMbLink(release.url, 'release', function (link) { + $('div#name-section h3 span:first').after(link); }); } - release.labels[0].name = label_name; - release.labels[0].mbid = label_mbid; - } - BandcampImport.insertLink(release); - LOGGER.info('Parsed release: ', release); + // append a comma after each tag to ease cut'n'paste to MB + $('div.tralbum-tags a:not(:last-child).tag').after(', '); - if (release.type == 'track') { - mblinks.searchAndDisplayMbLink(root_url, 'artist', function (link) { - $('div#name-section h3 span:last').before(link); - }); - // add MB links to parent album - mblinks.searchAndDisplayMbLink(release.parent_album_url, 'release', function (link) { - $('div#name-section h3 span:first').before(link); - }); - } else { - mblinks.searchAndDisplayMbLink(root_url, 'artist', function (link) { - $('div#name-section h3 span:first').before(link); - }); - // add MB release links to album or single - mblinks.searchAndDisplayMbLink(release.url, 'release', function (link) { - $('div#name-section h3 span:first').after(link); - }); - } + // append a link to the full size image + const tralbumArt = document.querySelector('div#tralbumArt'); + const fullsizeimageurl = tralbumArt.querySelector('a').getAttribute('href').replace('_10', '_0'); + tralbumArt.insertAdjacentHTML( + 'afterend', + `` + ); - // append a comma after each tag to ease cut'n'paste to MB - $('div.tralbum-tags a:not(:last-child).tag').after(', '); - - // append a link to the full size image - const tralbumArt = document.querySelector('div#tralbumArt'); - const fullsizeimageurl = tralbumArt.querySelector('a').getAttribute('href').replace('_10', '_0'); - tralbumArt.insertAdjacentHTML( - 'afterend', - `` - ); - - const bci_link = document.querySelector('div#bci_link'); - bci_link.style.paddingTop = '0.5em'; - bci_link.style.textAlign = 'right'; - bci_link.querySelector('a').style.fontWeight = 'bold'; - const upc = unsafeWindow.TralbumData.current.upc; - if (typeof upc != 'undefined' && upc !== null) { - document.querySelector('div #trackInfoInner').insertAdjacentHTML( - 'beforeend', - `
UPC: ${upc}
+ const bci_link = document.querySelector('div#bci_link'); + bci_link.style.paddingTop = '0.5em'; + bci_link.style.textAlign = 'right'; + bci_link.querySelector('a').style.fontWeight = 'bold'; + const upc = unsafeWindow.TralbumData.current.upc; + if (typeof upc != 'undefined' && upc !== null) { + document.querySelector('div #trackInfoInner').insertAdjacentHTML( + 'beforeend', + `
UPC: ${upc}
Import: Harmony | a-tisket
` - ); + ); + } } }); From 755cb5e7cdab42534fef40804b36cda1d1ee4a04 Mon Sep 17 00:00:00 2001 From: Raman Sinclair Date: Mon, 21 Apr 2025 09:51:31 +0200 Subject: [PATCH 2/4] chore: fix lint errors --- bandcamp_importer.user.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/bandcamp_importer.user.js b/bandcamp_importer.user.js index f0bdf97..537fbc7 100644 --- a/bandcamp_importer.user.js +++ b/bandcamp_importer.user.js @@ -301,10 +301,10 @@ $(document).ready(function () { /***/ let mblinks = new MBLinks('BCI_MBLINKS_CACHE'); - const isDiscographyPage = !!unsafeWindow.TralbumData.url?.match(/\/music\/?$/); + const isDiscographyPage = unsafeWindow.TralbumData.url && !!unsafeWindow.TralbumData.url.match(/\/music\/?$/); if (isDiscographyPage) { - const hostname = unsafeWindow.TralbumData.url.replace("/music", ""); + const hostname = unsafeWindow.TralbumData.url.replace('/music', ''); $('ol#music-grid > li > a').each(function () { const $link = $(this); @@ -313,13 +313,17 @@ $(document).ready(function () { if (bandcampReleaseUrl && bandcampReleaseUrl.match(/^(\/album|\/track)/)) { const full_url = hostname + bandcampReleaseUrl; - mblinks.searchAndDisplayMbLink(full_url, 'release', function (link) { - $('p.title', $link).prepend(link); - }, `release:${full_url}`); + mblinks.searchAndDisplayMbLink( + full_url, + 'release', + function (link) { + $('p.title', $link).prepend(link); + }, + `release:${full_url}` + ); } }); - } - else { + } else { MBImportStyle(); let release = BandcampImport.retrieveReleaseInfo(); From aff7ad5bc18c16aee5b35938205a270c8c25e659 Mon Sep 17 00:00:00 2001 From: Raman Sinclair Date: Tue, 22 Apr 2025 00:10:33 +0200 Subject: [PATCH 3/4] chore: update version number to 2025.04.22.1 --- bandcamp_importer.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bandcamp_importer.user.js b/bandcamp_importer.user.js index 537fbc7..a2ed897 100644 --- a/bandcamp_importer.user.js +++ b/bandcamp_importer.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Import Bandcamp releases to MusicBrainz // @description Add a button on Bandcamp's album pages to open MusicBrainz release editor with pre-filled data for the selected release -// @version 2024.10.17.1 +// @version 2025.04.22.1 // @namespace http://userscripts.org/users/22504 // @downloadURL https://raw.github.com/murdos/musicbrainz-userscripts/master/bandcamp_importer.user.js // @updateURL https://raw.github.com/murdos/musicbrainz-userscripts/master/bandcamp_importer.user.js From 31c250375522804259f2c5e7c3ede74e48bc5940 Mon Sep 17 00:00:00 2001 From: Raman Sinclair Date: Tue, 22 Apr 2025 03:27:50 +0200 Subject: [PATCH 4/4] chore: re-reran prettier script after dependency upgrades --- bandcamp_importer.user.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bandcamp_importer.user.js b/bandcamp_importer.user.js index a2ed897..cb37f76 100644 --- a/bandcamp_importer.user.js +++ b/bandcamp_importer.user.js @@ -141,7 +141,7 @@ const BandcampImport = { if (numtracks > 0 && numtracks > showntracks) { // display a warning if tracks in download differs from tracks shown $('h2.trackTitle').append( - `

Warning: ${numtracks} vs ${showntracks} tracks

` + `

Warning: ${numtracks} vs ${showntracks} tracks

`, ); // append unknown tracks to the release @@ -319,7 +319,7 @@ $(document).ready(function () { function (link) { $('p.title', $link).prepend(link); }, - `release:${full_url}` + `release:${full_url}`, ); } }); @@ -338,7 +338,7 @@ $(document).ready(function () { function (link) { $('p#band-name-location span.title').append(link); }, - `label:${root_url}` + `label:${root_url}`, ); const labelback = document.querySelector('a.back-to-label-link'); if (labelback) { @@ -354,7 +354,7 @@ $(document).ready(function () { function (link) { $('a.back-to-label-link span.back-link-text').append(link); }, - `label:${label_url}` + `label:${label_url}`, ); } } @@ -418,7 +418,7 @@ $(document).ready(function () { const fullsizeimageurl = tralbumArt.querySelector('a').getAttribute('href').replace('_10', '_0'); tralbumArt.insertAdjacentHTML( 'afterend', - `` + ``, ); const bci_link = document.querySelector('div#bci_link'); @@ -431,7 +431,7 @@ $(document).ready(function () { 'beforeend', `
UPC: ${upc}
Import: Harmony - | a-tisket
` + | a-tisket
`, ); } }