Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- HOW TO USE
- 1. Go to an artist's discography page (e.g., https://artist.bandcamp.com/music) or a specific album page.
- 2. IMPORTANT: If on the discography page, scroll down to ensure all albums/tracks you want are loaded.
- 3. Open the developer console (F12 or Ctrl+Shift+I).
- 4. Paste this entire script into the console and press Enter.
- 5. A block of commands will be generated. Select and copy (CTRL+C) the entire block.
- 6. Open PowerShell, navigate to the folder where you want to save the covers (`cd C:\path\to\your\folder`).
- 7. Paste (CTRL+V) the commands and press Enter. The downloads will begin.
- */
- // 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();
- })();
Advertisement
Add Comment
Please, Sign In to add comment