From 885d920fba6320c1b5de5fbb0f07dbed9c288fcd Mon Sep 17 00:00:00 2001 From: Puyodead1 Date: Tue, 15 Mar 2022 19:52:13 -0400 Subject: [PATCH 1/2] attempt to fix ffmpeg hanging + Added nostdin argument to ffmpeg call + Set ffmpeg log level to errors only + Fixed some stuff not getting printed correctly --- main.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index d1cae44..a45e401 100644 --- a/main.py +++ b/main.py @@ -55,6 +55,7 @@ def log_subprocess_output(prefix: str, pipe: IO[bytes]): if pipe: for line in iter(pipe.readline, b''): # b'\n'-separated lines logger.debug('[%s]: %r', prefix, line.decode("utf8").strip()) + pipe.flush() # this is the first function that is called, we parse the arguments, setup the logger, and ensure that required directories exist @@ -1083,14 +1084,14 @@ def mux_process(video_title, video_filepath, audio_filepath, output_path): @author Jayapraveen """ if os.name == "nt": - command = "ffmpeg -y -i \"{}\" -i \"{}\" -acodec copy -vcodec copy -fflags +bitexact -map_metadata -1 -metadata title=\"{}\" \"{}\"".format( + command = "ffmpeg -nostdin -loglevel error -y -i \"{}\" -i \"{}\" -acodec copy -vcodec copy -fflags +bitexact -map_metadata -1 -metadata title=\"{}\" \"{}\"".format( video_filepath, audio_filepath, video_title, output_path) else: - command = "nice -n 7 ffmpeg -y -i \"{}\" -i \"{}\" -acodec copy -vcodec copy -fflags +bitexact -map_metadata -1 -metadata title=\"{}\" \"{}\"".format( + command = "nice -n 7 ffmpeg -nostdin -loglevel error -y -i \"{}\" -i \"{}\" -acodec copy -vcodec copy -fflags +bitexact -map_metadata -1 -metadata title=\"{}\" \"{}\"".format( video_filepath, audio_filepath, video_title, output_path) process = subprocess.Popen( - command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + command, shell=True) log_subprocess_output("FFMPEG-STDOUT", process.stdout) log_subprocess_output("FFMPEG-STDERR", process.stderr) ret_code = process.wait() @@ -1112,7 +1113,7 @@ def decrypt(kid, in_filepath, out_filepath): command = f"nice -n 7 shaka-packager --enable_raw_key_decryption --keys key_id={kid}:key={key} input=\"{in_filepath}\",stream_selector=\"0\",output=\"{out_filepath}\"" process = subprocess.Popen( - command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + command, shell=True) log_subprocess_output("SHAKA-STDOUT", process.stdout) log_subprocess_output("SHAKA-STDERR", process.stderr) ret_code = process.wait() @@ -1147,7 +1148,7 @@ def handle_segments(url, format_id, video_title, args.append("--downloader-args") args.append("aria2c:\"--disable-ipv6\"") process = subprocess.Popen( - args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + args) log_subprocess_output("YTDLP-STDOUT", process.stdout) log_subprocess_output("YTDLP-STDERR", process.stderr) ret_code = process.wait() From 07bfb9163b41aaa610f75656e5baced41e525768 Mon Sep 17 00:00:00 2001 From: Puyodead1 <23562356riley@gmail.com> Date: Tue, 15 Mar 2022 20:38:42 -0400 Subject: [PATCH 2/2] fix: large courses not always working correctly Seems like Udemy changed something and large courses can return a 504 error now --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index a45e401..807ab90 100644 --- a/main.py +++ b/main.py @@ -641,7 +641,7 @@ class Udemy: url = COURSE_URL.format(portal_name=portal_name, course_id=course_id) try: resp = self.session._get(url) - if resp.status_code in [502, 503]: + if resp.status_code in [502, 503, 504]: logger.info( "> The course content is large, using large content extractor..." )