import bcfetch from 'bandcamp-fetch'; const fs = require("fs"); const username = 'noschxl'; async function fetchEntireWishlist() { let allWishlistItems = []; // Set the initial parameters using the username let currentParams = { target: username, imageFormat: 'art_app_large' }; let hasMorePages = true; let pageCount = 1; console.log(`Starting wishlist scrape for user: ${username}...`); // Loop will keep running as long as Bandcamp returns a continuation token while (hasMorePages) { console.log(`Fetching page ${pageCount}...`); try { const result = await bcfetch.fan.getWishlist(currentParams); // Add the items from the current page to our master list // (Assuming the library returns the array inside an 'items' property) if (result && result.items) { allWishlistItems.push(...result.items); } // Check if there are more pages to fetch if (result.continuation) { // Update the target with the continuation object for the next loop iteration currentParams.target = result.continuation; pageCount++; } else { // No continuation token means we've hit the end of the wishlist hasMorePages = false; } } catch (error) { console.error(`Error fetching page ${pageCount}:`, error); break; // Exit the loop if something goes wrong } } console.log(`\nDone! Successfully scraped ${allWishlistItems.length} items from your wishlist.`); // You can now write `allWishlistItems` to a JSON file using Node's 'fs' module // console.log(JSON.stringify(allWishlistItems, null, 2)); fs.writeFile('wishlist.json', JSON.stringify(allWishlistItems, null, 2), (err) => { if (err) { console.error('Error writing to file', err); } else { console.log('Data written to file'); } }) } fetchEntireWishlist();