forked from DRMTalks/devine
Remove --skip-dl and the DL_POOL_SKIP Event
This commit is contained in:
parent
172ab64017
commit
65bc93b600
|
@ -40,7 +40,7 @@ from rich.tree import Tree
|
|||
|
||||
from devine.core.config import config
|
||||
from devine.core.console import console
|
||||
from devine.core.constants import DOWNLOAD_CANCELLED, DOWNLOAD_LICENCE_ONLY, AnyTrack, context_settings
|
||||
from devine.core.constants import DOWNLOAD_CANCELLED, AnyTrack, context_settings
|
||||
from devine.core.credential import Credential
|
||||
from devine.core.downloaders import downloader
|
||||
from devine.core.drm import DRM_T, Widevine
|
||||
|
@ -119,8 +119,6 @@ class dl:
|
|||
help="Skip downloading and list available tracks and what tracks would have been downloaded.")
|
||||
@click.option("--list-titles", is_flag=True, default=False,
|
||||
help="Skip downloading, only list available titles that would have been downloaded.")
|
||||
@click.option("--skip-dl", is_flag=True, default=False,
|
||||
help="Skip downloading while still retrieving the decryption keys.")
|
||||
@click.option("--export", type=Path,
|
||||
help="Export Decryption Keys as you obtain them to a JSON file.")
|
||||
@click.option("--cdm-only/--vaults-only", is_flag=True, default=None,
|
||||
|
@ -272,7 +270,6 @@ class dl:
|
|||
chapters_only: bool,
|
||||
slow: bool, list_: bool,
|
||||
list_titles: bool,
|
||||
skip_dl: bool,
|
||||
export: Optional[Path],
|
||||
cdm_only: Optional[bool],
|
||||
no_proxy: bool,
|
||||
|
@ -462,9 +459,6 @@ class dl:
|
|||
|
||||
dl_start_time = time.time()
|
||||
|
||||
if skip_dl:
|
||||
DOWNLOAD_LICENCE_ONLY.set()
|
||||
|
||||
try:
|
||||
with Live(
|
||||
Padding(
|
||||
|
@ -529,9 +523,6 @@ class dl:
|
|||
))
|
||||
return
|
||||
|
||||
if skip_dl:
|
||||
console.log("Skipped downloads as --skip-dl was used...")
|
||||
else:
|
||||
dl_time = time_elapsed_since(dl_start_time)
|
||||
console.print(Padding(
|
||||
f"Track downloads finished in [progress.elapsed]{dl_time}[/]",
|
||||
|
@ -598,6 +589,75 @@ class dl:
|
|||
|
||||
muxed_paths = []
|
||||
|
||||
if isinstance(title, (Movie, Episode)):
|
||||
progress = Progress(
|
||||
TextColumn("[progress.description]{task.description}"),
|
||||
SpinnerColumn(finished_text=""),
|
||||
BarColumn(),
|
||||
"•",
|
||||
TimeRemainingColumn(compact=True, elapsed_when_finished=True),
|
||||
console=console
|
||||
)
|
||||
multi_jobs = len(title.tracks.videos) > 1
|
||||
tasks = [
|
||||
progress.add_task(
|
||||
f"Multiplexing{f' {x.height}p' if multi_jobs else ''}...",
|
||||
total=None,
|
||||
start=False
|
||||
)
|
||||
if cc:
|
||||
# will not appear in track listings as it's added after all times it lists
|
||||
title.tracks.add(cc)
|
||||
self.log.info(f"Extracted a Closed Caption from Video track {video_track_n + 1}")
|
||||
else:
|
||||
self.log.info(f"No Closed Captions were found in Video track {video_track_n + 1}")
|
||||
except EnvironmentError:
|
||||
self.log.error(
|
||||
"Cannot extract Closed Captions as the ccextractor executable was not found..."
|
||||
)
|
||||
break
|
||||
video_track_n += 1
|
||||
|
||||
with console.status(f"Converting Subtitles to {sub_format.name}..."):
|
||||
for subtitle in title.tracks.subtitles:
|
||||
if subtitle.codec != sub_format:
|
||||
writer = {
|
||||
Subtitle.Codec.SubRip: pycaption.SRTWriter,
|
||||
Subtitle.Codec.SubStationAlpha: None,
|
||||
Subtitle.Codec.SubStationAlphav4: None,
|
||||
Subtitle.Codec.TimedTextMarkupLang: pycaption.DFXPWriter,
|
||||
Subtitle.Codec.WebVTT: pycaption.WebVTTWriter,
|
||||
# MPEG-DASH box-encapsulated subtitle formats
|
||||
Subtitle.Codec.fTTML: None,
|
||||
Subtitle.Codec.fVTT: None,
|
||||
}[sub_format]
|
||||
if writer is None:
|
||||
self.log.error(f"Cannot yet convert {subtitle.codec} to {sub_format.name}...")
|
||||
sys.exit(1)
|
||||
|
||||
caption_set = subtitle.parse(subtitle.path.read_bytes(), subtitle.codec)
|
||||
subtitle.merge_same_cues(caption_set)
|
||||
|
||||
subtitle_text = writer().write(caption_set)
|
||||
subtitle.path.write_text(subtitle_text, encoding="utf8")
|
||||
|
||||
subtitle.codec = sub_format
|
||||
subtitle.move(subtitle.path.with_suffix(f".{sub_format.value.lower()}"))
|
||||
|
||||
with console.status("Repackaging tracks with FFMPEG..."):
|
||||
has_repacked = False
|
||||
for track in title.tracks:
|
||||
if track.needs_repack:
|
||||
track.repackage()
|
||||
has_repacked = True
|
||||
if callable(track.OnRepacked):
|
||||
track.OnRepacked(track)
|
||||
if has_repacked:
|
||||
# we don't want to fill up the log with "Repacked x track"
|
||||
self.log.info("Repacked one or more tracks with FFMPEG")
|
||||
|
||||
muxed_paths = []
|
||||
|
||||
if isinstance(title, (Movie, Episode)):
|
||||
progress = Progress(
|
||||
TextColumn("[progress.description]{task.description}"),
|
||||
|
@ -803,9 +863,6 @@ class dl:
|
|||
prepare_drm: Callable,
|
||||
progress: partial
|
||||
):
|
||||
if DOWNLOAD_LICENCE_ONLY.is_set():
|
||||
progress(downloaded="[yellow]SKIPPING")
|
||||
|
||||
if DOWNLOAD_CANCELLED.is_set():
|
||||
progress(downloaded="[yellow]CANCELLED")
|
||||
return
|
||||
|
@ -829,7 +886,6 @@ class dl:
|
|||
if save_dir.exists() and save_dir.name.endswith("_segments"):
|
||||
shutil.rmtree(save_dir)
|
||||
|
||||
if not DOWNLOAD_LICENCE_ONLY.is_set():
|
||||
if config.directories.temp.is_file():
|
||||
self.log.error(f"Temp Directory '{config.directories.temp}' must be a Directory, not a file")
|
||||
sys.exit(1)
|
||||
|
@ -888,9 +944,6 @@ class dl:
|
|||
else:
|
||||
drm = None
|
||||
|
||||
if DOWNLOAD_LICENCE_ONLY.is_set():
|
||||
progress(downloaded="[yellow]SKIPPED")
|
||||
else:
|
||||
downloader(
|
||||
uri=track.url,
|
||||
out=save_path,
|
||||
|
@ -926,7 +979,6 @@ class dl:
|
|||
progress(downloaded="[red]FAILED")
|
||||
raise
|
||||
except (Exception, KeyboardInterrupt):
|
||||
if not DOWNLOAD_LICENCE_ONLY.is_set():
|
||||
cleanup()
|
||||
raise
|
||||
|
||||
|
@ -934,7 +986,6 @@ class dl:
|
|||
# we stopped during the download, let's exit
|
||||
return
|
||||
|
||||
if not DOWNLOAD_LICENCE_ONLY.is_set():
|
||||
if track.path.stat().st_size <= 3: # Empty UTF-8 BOM == 3 bytes
|
||||
raise IOError("Download failed, the downloaded file is empty.")
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ from requests import Session
|
|||
from requests.cookies import RequestsCookieJar
|
||||
from rich import filesize
|
||||
|
||||
from devine.core.constants import DOWNLOAD_CANCELLED, DOWNLOAD_LICENCE_ONLY, AnyTrack
|
||||
from devine.core.constants import DOWNLOAD_CANCELLED, AnyTrack
|
||||
from devine.core.downloaders import downloader
|
||||
from devine.core.downloaders import requests as requests_downloader
|
||||
from devine.core.drm import Widevine
|
||||
|
@ -405,10 +405,6 @@ class DASH:
|
|||
else:
|
||||
drm = None
|
||||
|
||||
if DOWNLOAD_LICENCE_ONLY.is_set():
|
||||
progress(downloaded="[yellow]SKIPPED")
|
||||
return
|
||||
|
||||
progress(total=len(segments))
|
||||
|
||||
download_sizes = []
|
||||
|
|
|
@ -24,7 +24,7 @@ from pywidevine.pssh import PSSH
|
|||
from requests import Session
|
||||
from rich import filesize
|
||||
|
||||
from devine.core.constants import DOWNLOAD_CANCELLED, DOWNLOAD_LICENCE_ONLY, AnyTrack
|
||||
from devine.core.constants import DOWNLOAD_CANCELLED, AnyTrack
|
||||
from devine.core.downloaders import downloader
|
||||
from devine.core.downloaders import requests as requests_downloader
|
||||
from devine.core.drm import DRM_T, ClearKey, Widevine
|
||||
|
@ -290,10 +290,6 @@ class HLS:
|
|||
# it successfully downloaded, and it was not cancelled
|
||||
progress(advance=1)
|
||||
|
||||
if download_size == -1: # skipped for --skip-dl
|
||||
progress(downloaded="[yellow]SKIPPING")
|
||||
continue
|
||||
|
||||
now = time.time()
|
||||
time_since = now - last_speed_refresh
|
||||
|
||||
|
@ -307,9 +303,6 @@ class HLS:
|
|||
last_speed_refresh = now
|
||||
download_sizes.clear()
|
||||
|
||||
if DOWNLOAD_LICENCE_ONLY.is_set():
|
||||
return
|
||||
|
||||
with open(save_path, "wb") as f:
|
||||
for segment_file in sorted(save_dir.iterdir()):
|
||||
segment_data = segment_file.read_bytes()
|
||||
|
@ -362,6 +355,8 @@ class HLS:
|
|||
if the Segment's DRM uses Widevine.
|
||||
proxy: Proxy URI to use when downloading the Segment file.
|
||||
session: Python-Requests Session used when requesting init data.
|
||||
stop_event: Prematurely stop the Download from beginning. Useful if ran from
|
||||
a Thread Pool. It will raise a KeyboardInterrupt if set.
|
||||
|
||||
Returns the file size of the downloaded Segment in bytes.
|
||||
"""
|
||||
|
@ -422,9 +417,6 @@ class HLS:
|
|||
finally:
|
||||
segment_key.put(newest_segment_key)
|
||||
|
||||
if DOWNLOAD_LICENCE_ONLY.is_set():
|
||||
return -1
|
||||
|
||||
headers_ = session.headers
|
||||
if segment.byterange:
|
||||
# aria2(c) doesn't support byte ranges, use python-requests
|
||||
|
|
Loading…
Reference in New Issue