Last active
May 5, 2024 10:06
-
-
Save n-ce/b232e9f4457b96a30f16b50bdfc8402d to your computer and use it in GitHub Desktop.
yt-dlp AV1+Opus Downloader Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
from yt_dlp import YoutubeDL | |
def get_video_formats(url): | |
with YoutubeDL({}) as ydl: | |
info_dict = ydl.extract_info(url, download=False) | |
formats = info_dict.get('formats', []) | |
print("{:<10} {:<5} {:>10}".format('Itag', 'Quality', 'Filesize')) | |
print("-" * 30) | |
for format in formats: | |
if format.get('filesize') is None: | |
continue | |
if(len(format['format_id']) != 3): | |
continue | |
# Check for preferred video codecs (av01 or vp09) | |
if format.get('vcodec') and (format.get('vcodec').startswith('av01') or format.get('vcodec').startswith('vp09')): | |
quality_str = format.get('resolution') | |
filesize_mb = round(format.get('filesize') / (1024 * 1024)) | |
print(f"{format['format_id']:<10} {quality_str:<5} {filesize_mb:>10}MB") | |
# Check for preferred audio codecs (opus or mp4a) | |
if format.get('acodec') and (format.get('acodec') == 'opus' or format.get('acodec').startswith('mp4a')): | |
quality_str = f"{int(format.get('abr'))}kbps" | |
filesize_mb = round(format.get('filesize') / (1024 * 1024)) | |
print(f"{format['format_id']:<10} {quality_str:<5} {filesize_mb:>10}MB") | |
if __name__ == '__main__': | |
import sys | |
if len(sys.argv) < 2: | |
print("Usage: python getAV1.py <URL>") | |
sys.exit(0) | |
get_video_formats(sys.argv[1]) | |
itags = input('Enter video itag + audio itag: ') | |
download_command=f"yt-dlp -f {itags} {sys.argv[1]} -P storage/downloads" | |
try: | |
subprocess.run(download_command.split(), check=True) | |
print("Download successful!") | |
sys.exit(0) | |
except subprocess.CalledProcessError as e: | |
print(f"Download failed: {e}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment