Create soundgasm.py
Browse files- soundgasm.py +85 -0
soundgasm.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#@title <font size="5">⬇️ Soundgasm Downloader</font>
|
| 2 |
+
|
| 3 |
+
# --- Configuration ---
|
| 4 |
+
Url = "" #@param {type:"string"}
|
| 5 |
+
Output_Format = "mp3" #@param ["mp3", "m4a", "wav", "best"]
|
| 6 |
+
|
| 7 |
+
# --- Installation ---
|
| 8 |
+
import os
|
| 9 |
+
import sys
|
| 10 |
+
|
| 11 |
+
# Install yt-dlp (a powerful fork of youtube-dl that supports soundgasm)
|
| 12 |
+
if not os.path.exists('/usr/local/bin/yt-dlp'):
|
| 13 |
+
print("Installing yt-dlp...")
|
| 14 |
+
!pip install -q yt-dlp
|
| 15 |
+
print("yt-dlp installed.")
|
| 16 |
+
|
| 17 |
+
# Install ffmpeg for audio conversion (mp3/wav)
|
| 18 |
+
if not os.path.exists('/usr/bin/ffmpeg'):
|
| 19 |
+
print("Installing ffmpeg...")
|
| 20 |
+
!apt-get -qq install ffmpeg
|
| 21 |
+
print("ffmpeg installed.")
|
| 22 |
+
|
| 23 |
+
import yt_dlp
|
| 24 |
+
|
| 25 |
+
# --- Validation ---
|
| 26 |
+
if not Url:
|
| 27 |
+
print("\033[91mError: Please enter a valid Soundgasm URL in the form field.\033[0m")
|
| 28 |
+
sys.exit()
|
| 29 |
+
|
| 30 |
+
print(f"Processing URL: {Url}")
|
| 31 |
+
|
| 32 |
+
# --- Download Logic ---
|
| 33 |
+
def download_soundgasm(url, format_choice):
|
| 34 |
+
|
| 35 |
+
# Options for yt-dlp
|
| 36 |
+
ydl_opts = {
|
| 37 |
+
'outtmpl': '%(title)s.%(ext)s', # Save filename as the title
|
| 38 |
+
'nocheckcertificate': True,
|
| 39 |
+
'quiet': False,
|
| 40 |
+
'no_warnings': False,
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
# specific format handling
|
| 44 |
+
if format_choice == 'mp3':
|
| 45 |
+
ydl_opts['postprocessors'] = [{
|
| 46 |
+
'key': 'FFmpegExtractAudio',
|
| 47 |
+
'preferredcodec': 'mp3',
|
| 48 |
+
'preferredquality': '192',
|
| 49 |
+
}]
|
| 50 |
+
elif format_choice == 'wav':
|
| 51 |
+
ydl_opts['postprocessors'] = [{
|
| 52 |
+
'key': 'FFmpegExtractAudio',
|
| 53 |
+
'preferredcodec': 'wav',
|
| 54 |
+
}]
|
| 55 |
+
elif format_choice == 'm4a':
|
| 56 |
+
ydl_opts['postprocessors'] = [{
|
| 57 |
+
'key': 'FFmpegExtractAudio',
|
| 58 |
+
'preferredcodec': 'm4a',
|
| 59 |
+
}]
|
| 60 |
+
|
| 61 |
+
try:
|
| 62 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 63 |
+
print("Downloading...")
|
| 64 |
+
info = ydl.extract_info(url, download=True)
|
| 65 |
+
|
| 66 |
+
# Construct the expected filename to show the user
|
| 67 |
+
# If conversion happened, the extension changes
|
| 68 |
+
if 'postprocessors' in ydl_opts:
|
| 69 |
+
final_ext = format_choice
|
| 70 |
+
else:
|
| 71 |
+
final_ext = info.get('ext', 'unknown')
|
| 72 |
+
|
| 73 |
+
filename = ydl.prepare_filename(info)
|
| 74 |
+
# Adjust filename if conversion occurred
|
| 75 |
+
if 'postprocessors' in ydl_opts:
|
| 76 |
+
filename = os.path.splitext(filename)[0] + '.' + final_ext
|
| 77 |
+
|
| 78 |
+
print(f"\n\033[92mSuccess! Downloaded: {filename}\033[0m")
|
| 79 |
+
print(f"You can find the file in the 'Files' tab on the left (folder icon).")
|
| 80 |
+
|
| 81 |
+
except Exception as e:
|
| 82 |
+
print(f"\033[91mAn error occurred: {e}\033[0m")
|
| 83 |
+
|
| 84 |
+
# Run the function
|
| 85 |
+
download_soundgasm(Url, Output_Format)
|