Skip to content

Instantly share code, notes, and snippets.

@gadelkareem
Forked from FGRibreau/suno-download-all-songs.js
Last active September 16, 2024 21:35
Show Gist options
  • Save gadelkareem/8d807a82845e045070faded8582c1e96 to your computer and use it in GitHub Desktop.
Save gadelkareem/8d807a82845e045070faded8582c1e96 to your computer and use it in GitHub Desktop.
Download all Suno (app.suno.ai) songs displayed on a page
// open your javascript console and paste this
copy([...$('[role="grid"]')[Object.keys($('[role="grid"]')).filter(x => x.startsWith('__reactProps'))[0]].children[0].props.values[0][1].collection]
.filter(x => x.value.audio_url || x.value.video_url)
.map(x => {
const title = x.value.title.trim() || x.value.id ;
const audio = x.value.audio_url ? `${title}.mp3|${x.value.audio_url}` : '';
const video = x.value.video_url ? `${title}.mp4|${x.value.video_url}` : '';
return [audio, video].filter(Boolean).join("\n");
})
.join("\n")
)
// now you have a list of mp3 urls directly in your clipboard that you can pass to wget or a url downloader
# Usage: python suno-downloader.py <path-to-js-output-file>
import requests
import os
import sys
def download_file(url, filename):
response = requests.get(url, stream=True)
response.raise_for_status()
with open(filename, 'wb') as file:
for chunk in response.iter_content(chunk_size=8192):
file.write(chunk)
def main():
js_file = sys.argv[1]
with open(js_file, 'r') as file:
js_output = file.read()
# Split the input string into individual file entries
file_entries = js_output.split("\n")
# Create a directory to store the downloaded files
if not os.path.exists('downloads'):
os.makedirs('downloads')
names = ()
# Process each file entry
for entry in file_entries:
try:
i = 0
print(f"Processing: {entry}")
filename, url = entry.split('|')
print(f"Downloading: {filename}")
org_name = os.path.splitext(filename)[0]
ext = os.path.splitext(filename)[1]
# make sure the file name is unique
while filename in names:
i += 1
name = org_name + "_" + str(i)
filename = name + ext
names = names + (filename,)
download_file(url, os.path.join('downloads', filename))
print(f"Successfully downloaded: {filename}")
except Exception as e:
print(f"Failed to download {entry}. Error: {str(e)}")
print("Download process completed.")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment