Compare commits

...

1 Commits

Author SHA1 Message Date
rlaphoenix 65bc93b600 Remove --skip-dl and the DL_POOL_SKIP Event 2024-01-21 19:01:46 +00:00
3 changed files with 231 additions and 192 deletions

View File

@ -40,7 +40,7 @@ from rich.tree import Tree
from devine.core.config import config from devine.core.config import config
from devine.core.console import console 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.credential import Credential
from devine.core.downloaders import downloader from devine.core.downloaders import downloader
from devine.core.drm import DRM_T, Widevine 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.") help="Skip downloading and list available tracks and what tracks would have been downloaded.")
@click.option("--list-titles", is_flag=True, default=False, @click.option("--list-titles", is_flag=True, default=False,
help="Skip downloading, only list available titles that would have been downloaded.") 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, @click.option("--export", type=Path,
help="Export Decryption Keys as you obtain them to a JSON file.") help="Export Decryption Keys as you obtain them to a JSON file.")
@click.option("--cdm-only/--vaults-only", is_flag=True, default=None, @click.option("--cdm-only/--vaults-only", is_flag=True, default=None,
@ -272,7 +270,6 @@ class dl:
chapters_only: bool, chapters_only: bool,
slow: bool, list_: bool, slow: bool, list_: bool,
list_titles: bool, list_titles: bool,
skip_dl: bool,
export: Optional[Path], export: Optional[Path],
cdm_only: Optional[bool], cdm_only: Optional[bool],
no_proxy: bool, no_proxy: bool,
@ -462,9 +459,6 @@ class dl:
dl_start_time = time.time() dl_start_time = time.time()
if skip_dl:
DOWNLOAD_LICENCE_ONLY.set()
try: try:
with Live( with Live(
Padding( Padding(
@ -529,9 +523,6 @@ class dl:
)) ))
return return
if skip_dl:
console.log("Skipped downloads as --skip-dl was used...")
else:
dl_time = time_elapsed_since(dl_start_time) dl_time = time_elapsed_since(dl_start_time)
console.print(Padding( console.print(Padding(
f"Track downloads finished in [progress.elapsed]{dl_time}[/]", f"Track downloads finished in [progress.elapsed]{dl_time}[/]",
@ -598,6 +589,75 @@ class dl:
muxed_paths = [] 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)): if isinstance(title, (Movie, Episode)):
progress = Progress( progress = Progress(
TextColumn("[progress.description]{task.description}"), TextColumn("[progress.description]{task.description}"),
@ -803,9 +863,6 @@ class dl:
prepare_drm: Callable, prepare_drm: Callable,
progress: partial progress: partial
): ):
if DOWNLOAD_LICENCE_ONLY.is_set():
progress(downloaded="[yellow]SKIPPING")
if DOWNLOAD_CANCELLED.is_set(): if DOWNLOAD_CANCELLED.is_set():
progress(downloaded="[yellow]CANCELLED") progress(downloaded="[yellow]CANCELLED")
return return
@ -829,7 +886,6 @@ class dl:
if save_dir.exists() and save_dir.name.endswith("_segments"): if save_dir.exists() and save_dir.name.endswith("_segments"):
shutil.rmtree(save_dir) shutil.rmtree(save_dir)
if not DOWNLOAD_LICENCE_ONLY.is_set():
if config.directories.temp.is_file(): if config.directories.temp.is_file():
self.log.error(f"Temp Directory '{config.directories.temp}' must be a Directory, not a file") self.log.error(f"Temp Directory '{config.directories.temp}' must be a Directory, not a file")
sys.exit(1) sys.exit(1)
@ -888,9 +944,6 @@ class dl:
else: else:
drm = None drm = None
if DOWNLOAD_LICENCE_ONLY.is_set():
progress(downloaded="[yellow]SKIPPED")
else:
downloader( downloader(
uri=track.url, uri=track.url,
out=save_path, out=save_path,
@ -926,7 +979,6 @@ class dl:
progress(downloaded="[red]FAILED") progress(downloaded="[red]FAILED")
raise raise
except (Exception, KeyboardInterrupt): except (Exception, KeyboardInterrupt):
if not DOWNLOAD_LICENCE_ONLY.is_set():
cleanup() cleanup()
raise raise
@ -934,7 +986,6 @@ class dl:
# we stopped during the download, let's exit # we stopped during the download, let's exit
return return
if not DOWNLOAD_LICENCE_ONLY.is_set():
if track.path.stat().st_size <= 3: # Empty UTF-8 BOM == 3 bytes if track.path.stat().st_size <= 3: # Empty UTF-8 BOM == 3 bytes
raise IOError("Download failed, the downloaded file is empty.") raise IOError("Download failed, the downloaded file is empty.")

View File

@ -26,7 +26,7 @@ from requests import Session
from requests.cookies import RequestsCookieJar from requests.cookies import RequestsCookieJar
from rich import filesize 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 downloader
from devine.core.downloaders import requests as requests_downloader from devine.core.downloaders import requests as requests_downloader
from devine.core.drm import Widevine from devine.core.drm import Widevine
@ -405,10 +405,6 @@ class DASH:
else: else:
drm = None drm = None
if DOWNLOAD_LICENCE_ONLY.is_set():
progress(downloaded="[yellow]SKIPPED")
return
progress(total=len(segments)) progress(total=len(segments))
download_sizes = [] download_sizes = []

View File

@ -24,7 +24,7 @@ from pywidevine.pssh import PSSH
from requests import Session from requests import Session
from rich import filesize 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 downloader
from devine.core.downloaders import requests as requests_downloader from devine.core.downloaders import requests as requests_downloader
from devine.core.drm import DRM_T, ClearKey, Widevine from devine.core.drm import DRM_T, ClearKey, Widevine
@ -290,10 +290,6 @@ class HLS:
# it successfully downloaded, and it was not cancelled # it successfully downloaded, and it was not cancelled
progress(advance=1) progress(advance=1)
if download_size == -1: # skipped for --skip-dl
progress(downloaded="[yellow]SKIPPING")
continue
now = time.time() now = time.time()
time_since = now - last_speed_refresh time_since = now - last_speed_refresh
@ -307,9 +303,6 @@ class HLS:
last_speed_refresh = now last_speed_refresh = now
download_sizes.clear() download_sizes.clear()
if DOWNLOAD_LICENCE_ONLY.is_set():
return
with open(save_path, "wb") as f: with open(save_path, "wb") as f:
for segment_file in sorted(save_dir.iterdir()): for segment_file in sorted(save_dir.iterdir()):
segment_data = segment_file.read_bytes() segment_data = segment_file.read_bytes()
@ -362,6 +355,8 @@ class HLS:
if the Segment's DRM uses Widevine. if the Segment's DRM uses Widevine.
proxy: Proxy URI to use when downloading the Segment file. proxy: Proxy URI to use when downloading the Segment file.
session: Python-Requests Session used when requesting init data. 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. Returns the file size of the downloaded Segment in bytes.
""" """
@ -422,9 +417,6 @@ class HLS:
finally: finally:
segment_key.put(newest_segment_key) segment_key.put(newest_segment_key)
if DOWNLOAD_LICENCE_ONLY.is_set():
return -1
headers_ = session.headers headers_ = session.headers
if segment.byterange: if segment.byterange:
# aria2(c) doesn't support byte ranges, use python-requests # aria2(c) doesn't support byte ranges, use python-requests