Skip to content

Instantly share code, notes, and snippets.

@avwie
Created August 30, 2023 18:52
Show Gist options
  • Save avwie/1fcca9b20e925840293fc61201926563 to your computer and use it in GitHub Desktop.
Save avwie/1fcca9b20e925840293fc61201926563 to your computer and use it in GitHub Desktop.
Download Ultimate Guitar Backing Tracks
// copy and paste this in the browser window console and execute, when you are on the page of the song WITH official backing track
await (async function () {
function download(blob, fileName) {
const url = window.URL.createObjectURL(blob);
const tempLink = document.createElement('a');
tempLink.href = url;
tempLink.setAttribute('download', fileName);
document.body.appendChild(tempLink);
tempLink.click();
document.body.removeChild(tempLink);
window.URL.revokeObjectURL(url);
}
const title = document.querySelector("meta[property='og:title']").content;
if (!title) throw new Error("No title found");
console.log(`Trying to download backing track for ${title}...`);
console.log("Fetching document...")
const rawDocument = await fetch(document.URL)
if (!rawDocument.ok) throw new Error("Failed to fetch document")
console.log("Parsing document...")
const parser = new DOMParser()
const domDocument = parser.parseFromString(await rawDocument.text(), "text/html")
console.log("Finding JS-Store data...")
const jsStores = domDocument.getElementsByClassName("js-store")
if (!jsStores.length) throw new Error("No JS-Store found")
const jsStore = jsStores[0].dataset.content
if (!jsStore) throw new Error("No JS-Store content found")
console.log("Parsing JS-Store data...")
const jsStoreData = JSON.parse(jsStore)
console.log("Finding backing tracks....")
const backingTracks = jsStoreData.store.page.data.tab_view.official_backingtrack.content_urls
if (!backingTracks) throw new Error("No backing tracks found")
console.log(`Found ${backingTracks.length} backing tracks`)
console.log("Downloading backing tracks...")
for (const backingTrack of backingTracks) {
const name = `${title} - ${backingTrack.name}.mp3`
console.log(`\tDownloading ${name}...`)
const url = backingTrack.content_urls.normal
const blob = await (fetch(url).then(r => r.blob()))
download(blob, name)
}
console.log("Done!")
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment