From f6e8bda97bddb544d7620f8e6f622881ea6bc652 Mon Sep 17 00:00:00 2001 From: Skullheadx Date: Sun, 13 Oct 2024 17:43:55 -0400 Subject: [PATCH] i dont know --- main.py | 84 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/main.py b/main.py index c20b94f..5f5b3a1 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ from pytubefix import YouTube, Playlist +from pytubefix.exceptions import VideoUnavailable import ffmpeg @@ -7,6 +8,8 @@ ABR = ["160kbps", "128kbps", "70kbps", "50kbps", "48kbps"] target_res = 0 target_abr=0 +failed_download = set() + if __name__ == "__main__": # get list of links from file @@ -28,46 +31,57 @@ if __name__ == "__main__": for link in links: target_res = 0 target_abr = 0 - success = True - yt = YouTube(link) - video_streams = [] - while len(video_streams) == 0: - video_streams = yt.streams.filter(file_extension='mp4', res=RES[target_res]) # find available streams - if target_res + 1 < len(RES): - target_res = target_res + 1 - else: - success = False - break - if not success: - print(f"Unable to find video stream for {yt.title}") - break - vstream = video_streams[0] - - - # audio - audio_streams = [] - while len(audio_streams) == 0: - audio_streams = yt.streams.filter(only_audio=True, abr=ABR[target_abr]) # find available streams + video_success = True + audio_success = True + + try: + yt = YouTube(link) + yt.streams + + except VideoUnavailable: + print(f'Video {link} is unavaialable, skipping.') + failed_download.add(((yt.title, link))) + else: + video_streams = [] + while len(video_streams) == 0: + video_streams = yt.streams.filter(file_extension='mp4', res=RES[target_res]) # find available streams + if target_res + 1 < len(RES): + target_res = target_res + 1 + else: + video_success = False + break + if not video_success: + print(f"Unable to find video stream for {yt.title}") + failed_download.add(((yt.title, link))) - if target_abr + 1 < len(RES): - target_abr = target_abr + 1 - else: - success = False break - if not success: - print(f"Unable to find audio stream for {yt.title}") - break - astream = audio_streams[0] + vstream = video_streams[0] + + # audio + audio_streams = [] + while len(audio_streams) == 0: + audio_streams = yt.streams.filter(only_audio=True, abr=ABR[target_abr]) # find available streams + + if target_abr + 1 < len(RES): + target_abr = target_abr + 1 + else: + audio_success = False + break + if not audio_success: + print(f"Unable to find audio stream for {yt.title}") + failed_download.add(((yt.title, link))) + break + astream = audio_streams[0] - vstream.download(output_path="downloaded/video_only") - astream.download(output_path="downloaded/audio_only") - - input_video = ffmpeg.input(f"downloaded/video_only/{vstream.default_filename}") - input_audio = ffmpeg.input(f"downloaded/audio_only/{astream.default_filename}") - - ffmpeg.concat(input_video, input_audio, v=1, a=1).output(f'downloaded/{yt.title}.mp4').run() + vstream.download(output_path="downloaded/video_only") + astream.download(output_path="downloaded/audio_only") + input_video = ffmpeg.input(f"downloaded/video_only/{vstream.default_filename}") + input_audio = ffmpeg.input(f"downloaded/audio_only/{astream.default_filename}") + ffmpeg.concat(input_video, input_audio, v=1, a=1).output(f'downloaded/{yt.title}.mp4').run() +print("Failed Downloading:") +print(failed_download) -- 2.54.0