Skip to content

Instantly share code, notes, and snippets.

@flleeppyy
Last active May 30, 2023 05:12
Show Gist options
  • Save flleeppyy/9e146a434f8ab1a1a780e519bbd7d336 to your computer and use it in GitHub Desktop.
Save flleeppyy/9e146a434f8ab1a1a780e519bbd7d336 to your computer and use it in GitHub Desktop.
DistroKid Copy Paste song info to get ISRC and stuff
<!DOCTYPE html>
<html>
<head>
<title>Song Data</title>
<script>
function parseSongs() {
const inputText = document.getElementById('input').value.trim();
const rd = inputText.includes("Release date: ");
const nlSplit = inputText.split("\n")
const upc = nlSplit[0].split("DK UPC: ")[1];
const releaseDate = rd ? nlSplit[2].split("Release date: ")[1] : "";
const album = nlSplit[rd ? 3 : 2].trim();
const artist = nlSplit[rd ? 4 : 3].trim();
const songRegex = /(^[A-Z]{2}-?\w{3}-?\d{2}-?\d{5}$)\n([0-9]*) · (.*)/m;
const songs = inputText.split("Good\nSongs\n\t\n")[1].split("ISRC \t").slice(1).map(e => {
const reg = songRegex.exec(e);
globalThis.cream = reg;
return {
artist,
album,
releaseDate,
albumUpc: upc,
number: reg[2],
title: reg[3],
isrc: reg[1],
};
});
console.log(songs, releaseDate)
document.getElementById('input').value = ''; // Clear text box
// Save songs array in local storage
let savedAlbums = JSON.parse(localStorage.getItem('albums')) || [];
savedAlbums.push(songs);
localStorage.setItem('albums', JSON.stringify(savedAlbums));
refreshCount();
// Add button to export to JSON
if (!document.getElementById('exportButton')) {
const exportButton = document.createElement('button');
exportButton.id = 'exportButton';
exportButton.innerText = 'Export to JSON';
exportButton.onclick = exportToJSON;
document.body.appendChild(exportButton);
}
}
function exportToJSON() {
const savedAlbums = JSON.parse(localStorage.getItem('albums')).flat();
const jsonData = JSON.stringify(savedAlbums, null, 2);
const downloadLink = document.createElement('a');
downloadLink.href = 'data:text/json;charset=utf-8,' + encodeURIComponent(jsonData);
downloadLink.download = 'song_data.json';
downloadLink.click();
}
function clearAlbums() {
if (confirm("Clear data?")) {
localStorage.setItem("albums", "[]");
refreshCount();
}
}
</script>
</head>
<body>
<h1>Distrokid ISRC and Song Saver</h1>
<p>
So basically what you need to do is select all the text starting at "DK UPC", then going to the very end of the song list.
Inside the textbox is a preview of what the text should look like.
</p>
<p>
After exporting, use a JSON to CSV tool if you'd like, for readability.
</p>
<br>
<textarea id="input" rows="30" cols="50" placeholder="DK UPC: 197547042201
Uploaded: March 30, 2023
Release date: March 31, 2023
I just want to exist
Flleeppyy
Edit Release
This album was successfully processed and delivered to stores.
Artwork
Good
Songs
ISRC QZHN62303746
1 · I just want to exist
Credits Download Vizy Marcel
ISRC QZHN62303747
2 · I just want to dance
Credits Download Vizy Marcel
ISRC QZHN62303748
3 · If I'm lucky
Credits Download Vizy Marcel
ISRC QZHN62303749
4 · If I'm lucky (Mono Mix)
Credits Download Vizy Marcel "></textarea>
<br>
<button onclick="parseSongs()">Parse and Save</button>
<p id="albumCounter"></p>
<br>
<button onclick="clearAlbums()">Clear All</button>
<script>
function refreshCount() {
document.getElementById('albumCounter').innerText = `Albums Processed: ${JSON.parse(localStorage.getItem('albums')).length}`;
}
refreshCount();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment