From 9d4b9be7ac757b754c30f1c63f482aefd85cacd8 Mon Sep 17 00:00:00 2001 From: 11trapper Date: Thu, 18 Aug 2022 23:08:31 -0400 Subject: [PATCH] Fixed MP4 and MP3 Video/Audio Sorting --- models.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/models.py b/models.py index 075de45..ec4e67a 100644 --- a/models.py +++ b/models.py @@ -8,15 +8,11 @@ def convert_video(link, media_format): return ''.join(random.choice(chars) for _ in range(size)) rand_filename = f"{randmname(25)}.{media_format.lower()}" - stream_filter = "" - if media_format == "mp4": - stream_filter = "progressive=True, file_extension=mp4" - elif media_format == "mp3": - stream_filter = "only_audio=True" - - yt = YouTube(link) - yt.streams.filter(stream_filter).order_by('resolution').desc().first().download(filename=rand_filename, output_path="files/ytdl") + if media_format == "MP4": + yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download(filename=rand_filename, output_path="files/ytdl") + elif media_format == "MP3": + yt.streams.filter(only_audio=True).first().download(filename=rand_filename, output_path="files/ytdl") cdn_url = { "url": f"https://cdn.oki.cx/files/ytdl/{rand_filename}",