forked from DRMTalks/devine
fix(DASH/HLS): Don't merge folders, skip final merge if only 1 segment
This commit is contained in:
parent
77e663ebee
commit
4d6c72ba30
|
@ -486,12 +486,17 @@ class DASH:
|
||||||
for control_file in save_dir.glob("*.aria2__temp"):
|
for control_file in save_dir.glob("*.aria2__temp"):
|
||||||
control_file.unlink()
|
control_file.unlink()
|
||||||
|
|
||||||
segments_to_merge = sorted(save_dir.iterdir())
|
segments_to_merge = [
|
||||||
progress(downloaded="Merging", completed=0, total=len(segments_to_merge))
|
x
|
||||||
|
for x in sorted(save_dir.iterdir())
|
||||||
|
if x.is_file()
|
||||||
|
]
|
||||||
with open(save_path, "wb") as f:
|
with open(save_path, "wb") as f:
|
||||||
if init_data:
|
if init_data:
|
||||||
f.write(init_data)
|
f.write(init_data)
|
||||||
|
if len(segments_to_merge) > 1:
|
||||||
|
progress(downloaded="Merging", completed=0, total=len(segments_to_merge))
|
||||||
|
else:
|
||||||
for segment_file in segments_to_merge:
|
for segment_file in segments_to_merge:
|
||||||
segment_data = segment_file.read_bytes()
|
segment_data = segment_file.read_bytes()
|
||||||
# TODO: fix encoding after decryption?
|
# TODO: fix encoding after decryption?
|
||||||
|
|
|
@ -508,18 +508,24 @@ class HLS:
|
||||||
return
|
return
|
||||||
|
|
||||||
# finally merge all the discontinuity save files together to the final path
|
# finally merge all the discontinuity save files together to the final path
|
||||||
|
segments_to_merge = [
|
||||||
|
x
|
||||||
|
for x in sorted(save_dir.iterdir())
|
||||||
|
if x.is_file()
|
||||||
|
]
|
||||||
|
if len(segments_to_merge) == 1:
|
||||||
|
shutil.move(segments_to_merge[0], save_path)
|
||||||
|
else:
|
||||||
progress(downloaded="Merging")
|
progress(downloaded="Merging")
|
||||||
if isinstance(track, (Video, Audio)):
|
if isinstance(track, (Video, Audio)):
|
||||||
HLS.merge_segments(
|
HLS.merge_segments(
|
||||||
segments=sorted(list(save_dir.iterdir())),
|
segments=segments_to_merge,
|
||||||
save_path=save_path
|
save_path=save_path
|
||||||
)
|
)
|
||||||
shutil.rmtree(save_dir)
|
shutil.rmtree(save_dir)
|
||||||
else:
|
else:
|
||||||
with open(save_path, "wb") as f:
|
with open(save_path, "wb") as f:
|
||||||
for discontinuity_file in sorted(save_dir.iterdir()):
|
for discontinuity_file in segments_to_merge:
|
||||||
if discontinuity_file.is_dir():
|
|
||||||
continue
|
|
||||||
discontinuity_data = discontinuity_file.read_bytes()
|
discontinuity_data = discontinuity_file.read_bytes()
|
||||||
f.write(discontinuity_data)
|
f.write(discontinuity_data)
|
||||||
f.flush()
|
f.flush()
|
||||||
|
|
Loading…
Reference in New Issue