|
| 1 | +// ==UserScript== |
| 2 | +// @name Import Subvert.fm releases to Musicbrainz |
| 3 | +// @description Add a button on Subvert.fm release pages to open MusicBrainz release editor with pre-filled data for the selected release |
| 4 | +// @version 2026.6.20 |
| 5 | +// @license X11 |
| 6 | +// @downloadURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/subvert_importer.user.js |
| 7 | +// @updateURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/subvert_importer.user.js |
| 8 | +// @namespace https://github.com/murdos/musicbrainz-userscripts |
| 9 | +// @match https://subvert.fm/*/* |
| 10 | +// @match https://www.subvert.fm/*/* |
| 11 | +// @require lib/mbimport.js |
| 12 | +// @require lib/logger.js |
| 13 | +// @require lib/mbimportstyle.js |
| 14 | +// ==/UserScript== |
| 15 | + |
| 16 | +function onLoad() { |
| 17 | + MBImportStyle(); |
| 18 | + const release = retrieveReleaseInfo(); |
| 19 | + insertLink(release, window.location); |
| 20 | +} |
| 21 | + |
| 22 | +function getArtistCredit(data) { |
| 23 | + let artists = []; |
| 24 | + data['release']['artists'].forEach(function (artist) { |
| 25 | + artists.push(artist['name']); |
| 26 | + }); |
| 27 | + return MBImport.makeArtistCredits(artists); |
| 28 | +} |
| 29 | + |
| 30 | +function getFormat() { |
| 31 | + // We only support digital downloads right now. |
| 32 | + return 'Digital Media'; |
| 33 | +} |
| 34 | + |
| 35 | +function getPackaging() { |
| 36 | + // We only support digital downloads right now. |
| 37 | + return 'None'; |
| 38 | +} |
| 39 | + |
| 40 | +function getReleaseType(data) { |
| 41 | + return data['release']['releaseType']; |
| 42 | +} |
| 43 | + |
| 44 | +function getTitle(data) { |
| 45 | + return data['release']['name']; |
| 46 | +} |
| 47 | + |
| 48 | +function getLabels(data) { |
| 49 | + let labels = []; |
| 50 | + data['release']['labelsOnReleases'].forEach(function (label) { |
| 51 | + labels.push({ |
| 52 | + label: label['label']['name'], |
| 53 | + catno: label['catalogNumber'], |
| 54 | + }); |
| 55 | + }); |
| 56 | + return labels; |
| 57 | +} |
| 58 | + |
| 59 | +function getDiscs(data) { |
| 60 | + let tracks = []; |
| 61 | + data['release']['tracks'].forEach(function (track) { |
| 62 | + let artists = []; |
| 63 | + track['track']['artists'].forEach(function (artist) { |
| 64 | + artists.push(artist['name']); |
| 65 | + }); |
| 66 | + tracks.push({ |
| 67 | + artist_credit: MBImport.makeArtistCredits(artists), |
| 68 | + title: track['track']['name'], |
| 69 | + duration: track['track']['duration'] * 1000, |
| 70 | + }); |
| 71 | + }); |
| 72 | + return [ |
| 73 | + { |
| 74 | + tracks: tracks, |
| 75 | + format: getFormat(data), |
| 76 | + }, |
| 77 | + ]; |
| 78 | +} |
| 79 | + |
| 80 | +function getURLs(data) { |
| 81 | + let urls = []; |
| 82 | + if (data['release']['isDownloadAllowed']) { |
| 83 | + urls.push({ |
| 84 | + url: window.location, |
| 85 | + link_type: MBImport.URL_TYPES.purchase_for_download, |
| 86 | + }); |
| 87 | + } |
| 88 | + if (data['release']['isStreamingAllowed']) { |
| 89 | + urls.push({ |
| 90 | + url: window.location, |
| 91 | + link_type: MBImport.URL_TYPES.stream_for_free, |
| 92 | + }); |
| 93 | + } |
| 94 | + if (data['release']['priceCents'] > 0) { |
| 95 | + urls.push({ |
| 96 | + url: window.location, |
| 97 | + link_type: MBImport.URL_TYPES.download_for_free, |
| 98 | + }); |
| 99 | + } |
| 100 | + return urls; |
| 101 | +} |
| 102 | + |
| 103 | +function retrieveReleaseInfo() { |
| 104 | + let json = JSON.parse(document.querySelector('script#__NEXT_DATA__').textContent); |
| 105 | + |
| 106 | + // Skip non-release pages |
| 107 | + if (json['page'] !== '/[artistSlug]/[releaseSlug]') { |
| 108 | + return; |
| 109 | + } |
| 110 | + |
| 111 | + const data = json['props']['pageProps']; |
| 112 | + const releaseDate = new Date(data['release']['releaseDate']); |
| 113 | + const release = { |
| 114 | + artist_credit: getArtistCredit(data), |
| 115 | + title: getTitle(data), |
| 116 | + year: releaseDate.getUTCFullYear(), |
| 117 | + month: releaseDate.getUTCMonth() + 1, |
| 118 | + day: releaseDate.getUTCDate(), |
| 119 | + country: 'XW', |
| 120 | + status: 'official', |
| 121 | + language: 'eng', |
| 122 | + script: 'Latn', |
| 123 | + type: getReleaseType(data), |
| 124 | + urls: getURLs(data), |
| 125 | + labels: getLabels(data), |
| 126 | + discs: getDiscs(data), |
| 127 | + packaging: getPackaging(data), |
| 128 | + format: getFormat(data), |
| 129 | + }; |
| 130 | + LOGGER.info('Parsed release: ', release); |
| 131 | + return release; |
| 132 | +} |
| 133 | + |
| 134 | +// Insert button into page |
| 135 | +function insertLink(release, url) { |
| 136 | + const edit_note = MBImport.makeEditNote(url, 'Subvert'); |
| 137 | + const container = document.querySelector('div.releaseRailMetaWrapper.leftRail.hideMobile'); |
| 138 | + const sourceNode = container.children[container.children.length - 3]; |
| 139 | + const importContainer = sourceNode.cloneNode(true); |
| 140 | + importContainer.children[0].innerHTML = MBImport.buildFormHTML(MBImport.buildFormParameters(release, edit_note)); |
| 141 | + importContainer.children[1].innerHTML = MBImport.buildSearchButton(release); |
| 142 | + sourceNode.after(importContainer); |
| 143 | +} |
| 144 | + |
| 145 | +if (document.readyState !== 'loading') { |
| 146 | + onLoad(); |
| 147 | +} else { |
| 148 | + document.addEventListener('DOMContentLoaded', onLoad); |
| 149 | +} |
0 commit comments