| |
|
|
| |
| Url = "" |
| Output_Format = "mp3" |
|
|
| |
| import os |
| import sys |
|
|
| |
| if not os.path.exists('/usr/local/bin/yt-dlp'): |
| print("Installing yt-dlp...") |
| !pip install -q yt-dlp |
| print("yt-dlp installed.") |
|
|
| |
| if not os.path.exists('/usr/bin/ffmpeg'): |
| print("Installing ffmpeg...") |
| !apt-get -qq install ffmpeg |
| print("ffmpeg installed.") |
|
|
| import yt_dlp |
|
|
| |
| 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}") |
|
|
| |
| def download_soundgasm(url, format_choice): |
| |
| |
| ydl_opts = { |
| 'outtmpl': '%(title)s.%(ext)s', |
| 'nocheckcertificate': True, |
| 'quiet': False, |
| 'no_warnings': False, |
| } |
|
|
| |
| 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) |
| |
| |
| |
| if 'postprocessors' in ydl_opts: |
| final_ext = format_choice |
| else: |
| final_ext = info.get('ext', 'unknown') |
| |
| filename = ydl.prepare_filename(info) |
| |
| 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") |
|
|
| |
| download_soundgasm(Url, Output_Format) |