/*
HOW TO USE
1. go to the artist's page on bandcamp (e.g., https://artistname.bandcamp.com/album/...)
2. use this script via console (F12 to open)
3. CTRL+C generated commands
4. open powershell and go to the folder wich you want to storage covers
5. CTRL+V generated commands and press enter
*/
// Script to generate PowerShell commands for downloading covers from Bandcamp
(function() {
'use strict';
// Function to sanitize a filename by removing invalid characters
function sanitizeFilename(filename) {
// Remove invalid characters, leaving letters, numbers, spaces, hyphens, and underscores
const cleaned = filename.replace(/[^a-z0-9\s\-_]/gi, '').trim();
// Replace multiple spaces with a single one and then with an underscore
return cleaned.replace(/\s+/g, '_');
}
// Function to get the URL of the image in maximum quality
function getFullSizeImageUrl(url) {
// _10 is usually one of the largest versions. _0 is the original, but may not be available.
return url.replace(/_\d+\.jpg/, '_0.jpg');
}
// --- Main function ---
function generatePowerShellCommands() {
console.log('🎵 Starting to gather information to generate commands...');
const musicItems = document.querySelectorAll('#music-grid .music-grid-item');
if (musicItems.length === 0) {
console.error('❌ No music items found on the page.');
return;
}
const covers = [];
musicItems.forEach(item => {
const imgElement = item.querySelector('.art img');
const titleElement = item.querySelector('.title');
if (imgElement && titleElement) {
const imageUrl = imgElement.src || imgElement.getAttribute('data-original');
const title = titleElement.textContent.trim();
covers.push({
fullSizeUrl: getFullSizeImageUrl(imageUrl),
filename: `${sanitizeFilename(title)}.jpg`
});
}
});
if (covers.length === 0) {
console.error('❌ Failed to extract cover data.');
return;
}
console.log(`✅ Found ${covers.length} covers.`);
console.log('--------------------------------------------------');
console.log('⬇️ COPY THE ENTIRE COMMAND BLOCK BELOW AND PASTE IT INTO POWERSHELL ⬇️');
console.log('--------------------------------------------------');
// Generate one large string with all the commands
const commands = covers.map(cover => {
// Use the native PowerShell command Invoke-WebRequest
return `Invoke-WebRequest -Uri "${cover.fullSizeUrl}" -OutFile "${cover.filename}"`;
}).join('\n');
// Output the entire block to the console for easy copying
console.log(commands);
console.log('--------------------------------------------------');
console.log('⬆️ END OF COMMAND BLOCK ⬆️');
console.log('\n✅ Done! Now open PowerShell in the desired folder and paste the copied commands.');
}
// Start the generation
generatePowerShellCommands();
})();