forked from DRMTalks/devine
Alter behaviour of --skip-dl to allow DRM licensing
Most people used --skip-dl just to license the DRM pre-v1.3.0. Which makes sense, --skip-dl is otherwise a pointless feature. I've fixed it so that --skip-dl worked like before, allowing license calls, while still supporting the new per-segment features post-v1.3.0. Fixes #37
This commit is contained in:
parent
3ec317e9d6
commit
b92708ef45
|
@ -134,6 +134,7 @@ class dl:
|
||||||
return dl(ctx, **kwargs)
|
return dl(ctx, **kwargs)
|
||||||
|
|
||||||
DL_POOL_STOP = Event()
|
DL_POOL_STOP = Event()
|
||||||
|
DL_POOL_SKIP = Event()
|
||||||
DRM_TABLE_LOCK = Lock()
|
DRM_TABLE_LOCK = Lock()
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
@ -458,11 +459,11 @@ class dl:
|
||||||
download_table = Table.grid()
|
download_table = Table.grid()
|
||||||
download_table.add_row(selected_tracks)
|
download_table.add_row(selected_tracks)
|
||||||
|
|
||||||
if skip_dl:
|
|
||||||
self.log.info("Skipping Download...")
|
|
||||||
else:
|
|
||||||
dl_start_time = time.time()
|
dl_start_time = time.time()
|
||||||
|
|
||||||
|
if skip_dl:
|
||||||
|
self.DL_POOL_SKIP.set()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with Live(
|
with Live(
|
||||||
Padding(
|
Padding(
|
||||||
|
@ -527,6 +528,9 @@ 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}[/]",
|
||||||
|
@ -806,6 +810,9 @@ class dl:
|
||||||
prepare_drm: Callable,
|
prepare_drm: Callable,
|
||||||
progress: partial
|
progress: partial
|
||||||
):
|
):
|
||||||
|
if self.DL_POOL_SKIP.is_set():
|
||||||
|
progress(downloaded="[yellow]SKIPPING")
|
||||||
|
|
||||||
if self.DL_POOL_STOP.is_set():
|
if self.DL_POOL_STOP.is_set():
|
||||||
progress(downloaded="[yellow]SKIPPED")
|
progress(downloaded="[yellow]SKIPPED")
|
||||||
return
|
return
|
||||||
|
@ -815,12 +822,6 @@ class dl:
|
||||||
else:
|
else:
|
||||||
proxy = None
|
proxy = None
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
config.directories.temp.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
save_path = config.directories.temp / f"{track.__class__.__name__}_{track.id}.mp4"
|
save_path = config.directories.temp / f"{track.__class__.__name__}_{track.id}.mp4"
|
||||||
if isinstance(track, Subtitle):
|
if isinstance(track, Subtitle):
|
||||||
save_path = save_path.with_suffix(f".{track.codec.extension}")
|
save_path = save_path.with_suffix(f".{track.codec.extension}")
|
||||||
|
@ -841,6 +842,13 @@ 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 self.DL_POOL_SKIP.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)
|
||||||
|
|
||||||
|
config.directories.temp.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
# Delete any pre-existing temp files matching this track.
|
# Delete any pre-existing temp files matching this track.
|
||||||
# We can't re-use or continue downloading these tracks as they do not use a
|
# We can't re-use or continue downloading these tracks as they do not use a
|
||||||
# lock file. Or at least the majority don't. Even if they did I've encountered
|
# lock file. Or at least the majority don't. Even if they did I've encountered
|
||||||
|
@ -854,6 +862,7 @@ class dl:
|
||||||
save_path=save_path,
|
save_path=save_path,
|
||||||
save_dir=save_dir,
|
save_dir=save_dir,
|
||||||
stop_event=self.DL_POOL_STOP,
|
stop_event=self.DL_POOL_STOP,
|
||||||
|
skip_event=self.DL_POOL_SKIP,
|
||||||
progress=progress,
|
progress=progress,
|
||||||
session=service.session,
|
session=service.session,
|
||||||
proxy=proxy,
|
proxy=proxy,
|
||||||
|
@ -865,6 +874,7 @@ class dl:
|
||||||
save_path=save_path,
|
save_path=save_path,
|
||||||
save_dir=save_dir,
|
save_dir=save_dir,
|
||||||
stop_event=self.DL_POOL_STOP,
|
stop_event=self.DL_POOL_STOP,
|
||||||
|
skip_event=self.DL_POOL_SKIP,
|
||||||
progress=progress,
|
progress=progress,
|
||||||
session=service.session,
|
session=service.session,
|
||||||
proxy=proxy,
|
proxy=proxy,
|
||||||
|
@ -893,6 +903,9 @@ class dl:
|
||||||
else:
|
else:
|
||||||
drm = None
|
drm = None
|
||||||
|
|
||||||
|
if self.DL_POOL_SKIP.is_set():
|
||||||
|
progress(downloaded="[yellow]SKIPPED")
|
||||||
|
else:
|
||||||
asyncio.run(aria2c(
|
asyncio.run(aria2c(
|
||||||
uri=track.url,
|
uri=track.url,
|
||||||
out=save_path,
|
out=save_path,
|
||||||
|
@ -917,6 +930,7 @@ class dl:
|
||||||
progress(downloaded="[red]FAILED")
|
progress(downloaded="[red]FAILED")
|
||||||
raise
|
raise
|
||||||
except (Exception, KeyboardInterrupt):
|
except (Exception, KeyboardInterrupt):
|
||||||
|
if not self.DL_POOL_SKIP.is_set():
|
||||||
cleanup()
|
cleanup()
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -924,6 +938,7 @@ class dl:
|
||||||
# we stopped during the download, let's exit
|
# we stopped during the download, let's exit
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not self.DL_POOL_SKIP.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(
|
raise IOError(
|
||||||
"Download failed, the downloaded file is empty. "
|
"Download failed, the downloaded file is empty. "
|
||||||
|
|
|
@ -283,6 +283,7 @@ class DASH:
|
||||||
save_path: Path,
|
save_path: Path,
|
||||||
save_dir: Path,
|
save_dir: Path,
|
||||||
stop_event: Event,
|
stop_event: Event,
|
||||||
|
skip_event: Event,
|
||||||
progress: partial,
|
progress: partial,
|
||||||
session: Optional[Session] = None,
|
session: Optional[Session] = None,
|
||||||
proxy: Optional[str] = None,
|
proxy: Optional[str] = None,
|
||||||
|
@ -458,6 +459,10 @@ class DASH:
|
||||||
else:
|
else:
|
||||||
drm = None
|
drm = None
|
||||||
|
|
||||||
|
if skip_event.is_set():
|
||||||
|
progress(downloaded="[yellow]SKIPPED")
|
||||||
|
return
|
||||||
|
|
||||||
def download_segment(filename: str, segment: tuple[str, Optional[str]]) -> int:
|
def download_segment(filename: str, segment: tuple[str, Optional[str]]) -> int:
|
||||||
if stop_event.is_set():
|
if stop_event.is_set():
|
||||||
# the track already started downloading, but another failed or was stopped
|
# the track already started downloading, but another failed or was stopped
|
||||||
|
|
|
@ -184,6 +184,7 @@ class HLS:
|
||||||
save_path: Path,
|
save_path: Path,
|
||||||
save_dir: Path,
|
save_dir: Path,
|
||||||
stop_event: Event,
|
stop_event: Event,
|
||||||
|
skip_event: Event,
|
||||||
progress: partial,
|
progress: partial,
|
||||||
session: Optional[Session] = None,
|
session: Optional[Session] = None,
|
||||||
proxy: Optional[str] = None,
|
proxy: Optional[str] = None,
|
||||||
|
@ -280,6 +281,10 @@ class HLS:
|
||||||
finally:
|
finally:
|
||||||
segment_key.put(newest_segment_key)
|
segment_key.put(newest_segment_key)
|
||||||
|
|
||||||
|
if skip_event.is_set():
|
||||||
|
progress(downloaded="[yellow]SKIPPING")
|
||||||
|
return 0
|
||||||
|
|
||||||
if not segment.uri.startswith(segment.base_uri):
|
if not segment.uri.startswith(segment.base_uri):
|
||||||
segment.uri = segment.base_uri + segment.uri
|
segment.uri = segment.base_uri + segment.uri
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue