Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Producer.ai Project Batch Downloader (ZIP)
- // @namespace http://tampermonkey.net/
- // @version 0.2
- // @description Download all song metadata from a project page as a single ZIP
- // @match https://www.producer.ai/project/*
- // @grant none
- // @require https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js
- // ==/UserScript==
- (function() {
- 'use strict';
- // --- Helper: sanitize filename ---
- function sanitizeFilename(name) {
- return name.replace(/[^a-z0-9_\-]+/gi, "_");
- }
- // --- Extract song GUIDs from page ---
- function getSongIdsFromLinks() {
- const links = Array.from(document.querySelectorAll("a[href^='/song/']"));
- const ids = new Set();
- for (const link of links) {
- const match = link.getAttribute("href").match(/\/song\/([a-f0-9-]+)/);
- if (match) ids.add(match[1]);
- }
- return Array.from(ids);
- }
- // --- Create button ---
- const btn = document.createElement("button");
- btn.textContent = "⬇️ Download All Songs (ZIP)";
- btn.style.position = "fixed";
- btn.style.top = "10px";
- btn.style.right = "10px";
- btn.style.zIndex = 9999;
- btn.style.padding = "8px";
- btn.style.background = "#673AB7";
- btn.style.color = "white";
- btn.style.border = "none";
- btn.style.borderRadius = "4px";
- btn.style.cursor = "pointer";
- document.body.appendChild(btn);
- // --- Button click handler ---
- btn.addEventListener("click", async () => {
- const songIds = getSongIdsFromLinks();
- if (songIds.length === 0) {
- alert("No song links found on this page.");
- return;
- }
- try {
- const response = await fetch("https://www.producer.ai/__api/v2/generations", {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ riff_ids: songIds })
- });
- if (!response.ok) throw new Error("Network response was not ok");
- const json = await response.json();
- const generations = json.generations || [];
- if (generations.length === 0) {
- alert("No generation data returned.");
- return;
- }
- const zip = new JSZip();
- for (const gen of generations) {
- const title = gen.title ? sanitizeFilename(gen.title) : gen.id;
- const filename = `${title}.json`;
- zip.file(filename, JSON.stringify(gen, null, 2));
- }
- // Generate ZIP and trigger download
- const blob = await zip.generateAsync({ type: "blob" });
- const url = URL.createObjectURL(blob);
- const a = document.createElement("a");
- a.href = url;
- a.download = "project_songs.zip";
- a.click();
- URL.revokeObjectURL(url);
- alert(`Downloaded ${generations.length} songs into project_songs.zip`);
- } catch (err) {
- console.error("Error fetching batch data:", err);
- alert("Failed to fetch song data. See console for details.");
- }
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment