forked from DRMTalks/devine
Move CC extraction to be post-download, use rich status
This commit is contained in:
parent
b535715166
commit
a5c6052292
|
@ -443,7 +443,6 @@ class dl:
|
||||||
self.download_track,
|
self.download_track,
|
||||||
service=service,
|
service=service,
|
||||||
track=track,
|
track=track,
|
||||||
title=title,
|
|
||||||
prepare_drm=partial(
|
prepare_drm=partial(
|
||||||
partial(
|
partial(
|
||||||
self.prepare_drm,
|
self.prepare_drm,
|
||||||
|
@ -485,6 +484,47 @@ class dl:
|
||||||
console.log("Received Keyboard Interrupt, stopping...")
|
console.log("Received Keyboard Interrupt, stopping...")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
video_track_n = 0
|
||||||
|
|
||||||
|
while (
|
||||||
|
not title.tracks.subtitles and
|
||||||
|
len(title.tracks.videos) > video_track_n and
|
||||||
|
any(
|
||||||
|
x.get("codec_name", "").startswith("eia_")
|
||||||
|
for x in ffprobe(title.tracks.videos[video_track_n].path).get("streams", [])
|
||||||
|
)
|
||||||
|
):
|
||||||
|
with console.status(f"Checking Video track {video_track_n + 1} for Closed Captions..."):
|
||||||
|
try:
|
||||||
|
# TODO: Figure out the real language, it might be different
|
||||||
|
# EIA-CC tracks sadly don't carry language information :(
|
||||||
|
# TODO: Figure out if the CC language is original lang or not.
|
||||||
|
# Will need to figure out above first to do so.
|
||||||
|
video_track = title.tracks.videos[video_track_n]
|
||||||
|
track_id = f"ccextractor-{video_track.id}"
|
||||||
|
cc_lang = title.language or video_track.language
|
||||||
|
cc = video_track.ccextractor(
|
||||||
|
track_id=track_id,
|
||||||
|
out_path=config.directories.temp / config.filenames.subtitle.format(
|
||||||
|
id=track_id,
|
||||||
|
language=cc_lang
|
||||||
|
),
|
||||||
|
language=cc_lang,
|
||||||
|
original=False
|
||||||
|
)
|
||||||
|
if cc:
|
||||||
|
# will not appear in track listings as it's added after all times it lists
|
||||||
|
title.tracks.add(cc)
|
||||||
|
console.log(f"Extracted a Closed Caption from Video track {video_track_n + 1}")
|
||||||
|
else:
|
||||||
|
console.log(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..."
|
||||||
|
)
|
||||||
|
sys.exit(1)
|
||||||
|
video_track_n += 1
|
||||||
|
|
||||||
final_path = self.mux_tracks(title, not no_folder, not no_source)
|
final_path = self.mux_tracks(title, not no_folder, not no_source)
|
||||||
|
|
||||||
downloaded_table = Table.grid(expand=True)
|
downloaded_table = Table.grid(expand=True)
|
||||||
|
@ -624,7 +664,6 @@ class dl:
|
||||||
self,
|
self,
|
||||||
service: Service,
|
service: Service,
|
||||||
track: AnyTrack,
|
track: AnyTrack,
|
||||||
title: Title_T,
|
|
||||||
prepare_drm: Callable,
|
prepare_drm: Callable,
|
||||||
progress: partial
|
progress: partial
|
||||||
):
|
):
|
||||||
|
@ -749,39 +788,6 @@ class dl:
|
||||||
if callable(track.OnRepacked):
|
if callable(track.OnRepacked):
|
||||||
track.OnRepacked(track)
|
track.OnRepacked(track)
|
||||||
|
|
||||||
if (
|
|
||||||
isinstance(track, Video) and
|
|
||||||
not title.tracks.subtitles and
|
|
||||||
any(
|
|
||||||
x.get("codec_name", "").startswith("eia_")
|
|
||||||
for x in ffprobe(track.path).get("streams", [])
|
|
||||||
)
|
|
||||||
):
|
|
||||||
console.log("Checking for EIA-CC Captions")
|
|
||||||
try:
|
|
||||||
# TODO: Figure out the real language, it might be different
|
|
||||||
# EIA-CC tracks sadly don't carry language information :(
|
|
||||||
# TODO: Figure out if the CC language is original lang or not.
|
|
||||||
# Will need to figure out above first to do so.
|
|
||||||
track_id = f"ccextractor-{track.id}"
|
|
||||||
cc_lang = track.language
|
|
||||||
cc = track.ccextractor(
|
|
||||||
track_id=track_id,
|
|
||||||
out_path=config.directories.temp / config.filenames.subtitle.format(
|
|
||||||
id=track_id,
|
|
||||||
language=cc_lang
|
|
||||||
),
|
|
||||||
language=cc_lang,
|
|
||||||
original=False
|
|
||||||
)
|
|
||||||
if cc:
|
|
||||||
title.tracks.add(cc)
|
|
||||||
console.log(" + Found & Extracted an EIA-CC Caption")
|
|
||||||
except EnvironmentError:
|
|
||||||
self.log.error(" - Track needs to have CC extracted, but ccextractor wasn't found")
|
|
||||||
sys.exit(1)
|
|
||||||
console.log(" + No EIA-CC Captions...")
|
|
||||||
|
|
||||||
def mux_tracks(self, title: Title_T, season_folder: bool = True, add_source: bool = True) -> Path:
|
def mux_tracks(self, title: Title_T, season_folder: bool = True, add_source: bool = True) -> Path:
|
||||||
"""Mux Tracks, Delete Pre-Mux files, and move to the final location."""
|
"""Mux Tracks, Delete Pre-Mux files, and move to the final location."""
|
||||||
if isinstance(title, (Movie, Episode)):
|
if isinstance(title, (Movie, Episode)):
|
||||||
|
|
|
@ -212,7 +212,7 @@ class Video(Track):
|
||||||
executable,
|
executable,
|
||||||
"-trim", "-noru", "-ru1",
|
"-trim", "-noru", "-ru1",
|
||||||
self.path, "-o", out_path
|
self.path, "-o", out_path
|
||||||
], check=True)
|
], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
out_path.unlink(missing_ok=True)
|
out_path.unlink(missing_ok=True)
|
||||||
if not e.returncode == 10: # No captions found
|
if not e.returncode == 10: # No captions found
|
||||||
|
|
Loading…
Reference in New Issue