From bd185126b663321fca6ad8abd2e10f526e38a861 Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Tue, 13 Feb 2024 17:03:42 +0000 Subject: [PATCH] HLS: Skip merging continuity if all segments were skipped If all segments of a continuity is skipped, i.e. by OnSegmentFilter, then this code fails as the folder wouldn't exist. --- devine/core/manifests/hls.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/devine/core/manifests/hls.py b/devine/core/manifests/hls.py index 7633966..ec0f7cd 100644 --- a/devine/core/manifests/hls.py +++ b/devine/core/manifests/hls.py @@ -325,20 +325,21 @@ class HLS: last_speed_refresh = now download_sizes.clear() - with open(discontinuity_save_path, "wb") as f: - for segment_file in sorted(discontinuity_save_dir.iterdir()): - segment_data = segment_file.read_bytes() - if isinstance(track, Subtitle): - segment_data = try_ensure_utf8(segment_data) - if track.codec not in (Subtitle.Codec.fVTT, Subtitle.Codec.fTTML): - # decode text direction entities or SubtitleEdit's /ReverseRtlStartEnd won't work - segment_data = segment_data.decode("utf8"). \ - replace("‎", html.unescape("‎")). \ - replace("‏", html.unescape("‏")). \ - encode("utf8") - f.write(segment_data) - segment_file.unlink() - shutil.rmtree(discontinuity_save_dir) + if discontinuity_save_dir.exists(): + with open(discontinuity_save_path, "wb") as f: + for segment_file in sorted(discontinuity_save_dir.iterdir()): + segment_data = segment_file.read_bytes() + if isinstance(track, Subtitle): + segment_data = try_ensure_utf8(segment_data) + if track.codec not in (Subtitle.Codec.fVTT, Subtitle.Codec.fTTML): + # decode text direction entities or SubtitleEdit's /ReverseRtlStartEnd won't work + segment_data = segment_data.decode("utf8"). \ + replace("‎", html.unescape("‎")). \ + replace("‏", html.unescape("‏")). \ + encode("utf8") + f.write(segment_data) + segment_file.unlink() + shutil.rmtree(discontinuity_save_dir) if DOWNLOAD_LICENCE_ONLY.is_set(): return