#@title ⬇️ Soundgasm Downloader # --- Configuration --- Url = "" #@param {type:"string"} Output_Format = "mp3" #@param ["mp3", "m4a", "wav", "best"] # --- Installation --- import os import sys # Install yt-dlp (a powerful fork of youtube-dl that supports soundgasm) if not os.path.exists('/usr/local/bin/yt-dlp'): print("Installing yt-dlp...") !pip install -q yt-dlp print("yt-dlp installed.") # Install ffmpeg for audio conversion (mp3/wav) if not os.path.exists('/usr/bin/ffmpeg'): print("Installing ffmpeg...") !apt-get -qq install ffmpeg print("ffmpeg installed.") import yt_dlp # --- Validation --- if not Url: print("\033[91mError: Please enter a valid Soundgasm URL in the form field.\033[0m") sys.exit() print(f"Processing URL: {Url}") # --- Download Logic --- def download_soundgasm(url, format_choice): # Options for yt-dlp ydl_opts = { 'outtmpl': '%(title)s.%(ext)s', # Save filename as the title 'nocheckcertificate': True, 'quiet': False, 'no_warnings': False, } # specific format handling if format_choice == 'mp3': ydl_opts['postprocessors'] = [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', 'preferredquality': '192', }] elif format_choice == 'wav': ydl_opts['postprocessors'] = [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'wav', }] elif format_choice == 'm4a': ydl_opts['postprocessors'] = [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'm4a', }] try: with yt_dlp.YoutubeDL(ydl_opts) as ydl: print("Downloading...") info = ydl.extract_info(url, download=True) # Construct the expected filename to show the user # If conversion happened, the extension changes if 'postprocessors' in ydl_opts: final_ext = format_choice else: final_ext = info.get('ext', 'unknown') filename = ydl.prepare_filename(info) # Adjust filename if conversion occurred if 'postprocessors' in ydl_opts: filename = os.path.splitext(filename)[0] + '.' + final_ext print(f"\n\033[92mSuccess! Downloaded: {filename}\033[0m") print(f"You can find the file in the 'Files' tab on the left (folder icon).") except Exception as e: print(f"\033[91mAn error occurred: {e}\033[0m") # Run the function download_soundgasm(Url, Output_Format)