CiNoP8

download album's covers from bandcamp

Sep 28th, 2025 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 3.55 KB | Source Code | 0 0
  1. /*
  2. HOW TO USE
  3. 1. Go to an artist's discography page (e.g., https://artist.bandcamp.com/music) or a specific album page.
  4. 2. IMPORTANT: If on the discography page, scroll down to ensure all albums/tracks you want are loaded.
  5. 3. Open the developer console (F12 or Ctrl+Shift+I).
  6. 4. Paste this entire script into the console and press Enter.
  7. 5. A block of commands will be generated. Select and copy (CTRL+C) the entire block.
  8. 6. Open PowerShell, navigate to the folder where you want to save the covers (`cd C:\path\to\your\folder`).
  9. 7. Paste (CTRL+V) the commands and press Enter. The downloads will begin.
  10. */
  11.  
  12.  
  13. // Script to generate PowerShell commands for downloading covers from Bandcamp
  14. (function() {
  15.     'use strict';
  16.  
  17.     // Function to sanitize a filename by removing invalid characters
  18.     function sanitizeFilename(filename) {
  19.         // Remove invalid characters, leaving letters, numbers, spaces, hyphens, and underscores
  20.         const cleaned = filename.replace(/[^a-z0-9\s\-_]/gi, '').trim();
  21.         // Replace multiple spaces with a single one and then with an underscore
  22.         return cleaned.replace(/\s+/g, '_');
  23.     }
  24.  
  25.     // Function to get the URL of the image in maximum quality
  26.     function getFullSizeImageUrl(url) {
  27.         // _10 is usually one of the largest versions. _0 is the original, but may not be available.
  28.         return url.replace(/_\d+\.jpg/, '_0.jpg');
  29.     }
  30.  
  31.     // --- Main function ---
  32.     function generatePowerShellCommands() {
  33.         console.log('🎵 Starting to gather information to generate commands...');
  34.  
  35.         const musicItems = document.querySelectorAll('#music-grid .music-grid-item');
  36.  
  37.         if (musicItems.length === 0) {
  38.             console.error('❌ No music items found on the page.');
  39.             return;
  40.         }
  41.  
  42.         const covers = [];
  43.         musicItems.forEach(item => {
  44.             const imgElement = item.querySelector('.art img');
  45.             const titleElement = item.querySelector('.title');
  46.  
  47.             if (imgElement && titleElement) {
  48.                 const imageUrl = imgElement.src || imgElement.getAttribute('data-original');
  49.                 const title = titleElement.textContent.trim();
  50.                
  51.                 covers.push({
  52.                     fullSizeUrl: getFullSizeImageUrl(imageUrl),
  53.                     filename: `${sanitizeFilename(title)}.jpg`
  54.                 });
  55.             }
  56.         });
  57.  
  58.         if (covers.length === 0) {
  59.             console.error('❌ Failed to extract cover data.');
  60.             return;
  61.         }
  62.        
  63.         console.log(`✅ Found ${covers.length} covers.`);
  64.         console.log('--------------------------------------------------');
  65.         console.log('⬇️ COPY THE ENTIRE COMMAND BLOCK BELOW AND PASTE IT INTO POWERSHELL ⬇️');
  66.         console.log('--------------------------------------------------');
  67.  
  68.         // Generate one large string with all the commands
  69.         const commands = covers.map(cover => {
  70.             // Use the native PowerShell command Invoke-WebRequest
  71.             return `Invoke-WebRequest -Uri "${cover.fullSizeUrl}" -OutFile "${cover.filename}"`;
  72.         }).join('\n');
  73.  
  74.         // Output the entire block to the console for easy copying
  75.         console.log(commands);
  76.  
  77.         console.log('--------------------------------------------------');
  78.         console.log('⬆️ END OF COMMAND BLOCK ⬆️');
  79.         console.log('\n✅ Done! Now open PowerShell in the desired folder and paste the copied commands.');
  80.     }
  81.  
  82.     // Start the generation
  83.     generatePowerShellCommands();
  84. })();
Advertisement
Add Comment
Please, Sign In to add comment