diff --git a/fastflix/ff_queue.py b/fastflix/ff_queue.py index e40130a9..88be2cbf 100644 --- a/fastflix/ff_queue.py +++ b/fastflix/ff_queue.py @@ -107,7 +107,7 @@ def update_conversion_command(vid, old_path: str, new_path: str): if not Path(track["file_path"]).exists(): logger.exception("Could not save cover to queue recovery location, removing cover") continue - new_file = queue_covers / f"{uuid.uuid4().hex}_{track['file_path'].name}" + new_file = queue_covers / f"{uuid.uuid4().hex}_{Path(track['file_path']).name}" try: shutil.copy(track["file_path"], new_file) except OSError: diff --git a/fastflix/widgets/background_tasks.py b/fastflix/widgets/background_tasks.py index 0c9a86ab..c8b60ecb 100644 --- a/fastflix/widgets/background_tasks.py +++ b/fastflix/widgets/background_tasks.py @@ -55,8 +55,38 @@ def __init__(self, app: FastFlixApp, main, index, signal, language): self.language = language def run(self): + subtitle_format = self._get_subtitle_format() + if subtitle_format is None: + self.main.thread_logging_signal.emit( + f"WARNING:{t('Could not determine subtitle format for track')} {self.index}, {t('skipping extraction')}" + ) + self.signal.emit() + return + + if subtitle_format == "srt": + extension = "srt" + output_args = ["-c", "srt", "-f", "srt"] + elif subtitle_format == "ass": + extension = "ass" + output_args = ["-c", "copy"] + elif subtitle_format == "ssa": + extension = "ssa" + output_args = ["-c", "copy"] + elif subtitle_format == "pgs": + extension = "sup" + output_args = ["-c", "copy"] + else: + self.main.thread_logging_signal.emit( + f"WARNING:{t('Subtitle Track')} {self.index} {t('is not in supported format (SRT, ASS, SSA, PGS), skipping extraction')}: {subtitle_format}" + ) + self.signal.emit() + return + + # filename = str( + # Path(self.main.output_video).parent / f"{self.main.output_video}.{self.index}.{self.language}.srt" + # ).replace("\\", "/") filename = str( - Path(self.main.output_video).parent / f"{self.main.output_video}.{self.index}.{self.language}.srt" + Path(self.main.output_video).parent / f"{self.main.output_video}.{self.index}.{self.language}.{extension}" ).replace("\\", "/") self.main.thread_logging_signal.emit(f"INFO:{t('Extracting subtitles to')} {filename}") @@ -69,10 +99,7 @@ def run(self): self.main.input_video, "-map", f"0:s:{self.index}", - "-c", - "srt", - "-f", - "srt", + *output_args, filename, ], stdout=PIPE, @@ -90,6 +117,48 @@ def run(self): self.main.thread_logging_signal.emit(f"INFO:{t('Extracted subtitles successfully')}") self.signal.emit() + def _get_subtitle_format(self): + try: + result = run( + [ + self.app.fastflix.config.ffprobe, + "-v", "error", + "-select_streams", f"s:{self.index}", + "-show_entries", "stream=codec_name", + "-of", "default=noprint_wrappers=1:nokey=1", + self.main.input_video + ], + stdout=PIPE, + stderr=STDOUT, + text=True + ) + + if result.returncode != 0: + self.main.thread_logging_signal.emit( + f"WARNING:{t('Could not probe subtitle track')} {self.index}: {result.stdout}" + ) + return None + + codec_name = result.stdout.strip().lower() + if codec_name in ["subrip", "xsub", "webvtt", "mov_text"]: + return "srt" + elif codec_name == "ass": + return "ass" + elif codec_name == "ssa": + return "ssa" + elif codec_name == "hdmv_pgs_subtitle": + return "pgs" + else: + self.main.thread_logging_signal.emit( + f"WARNING:{t('Subtitle Track')} {self.index} {t('is not in supported format (SRT, ASS, SSA, PGS), skipping extraction')}: {codec_name}" + ) + return None + + except Exception as err: + self.main.thread_logging_signal.emit( + f"WARNING:{t('Error checking subtitle format for track')} {self.index} - {err}" + ) + return None class AudioNoramlize(QtCore.QThread): def __init__(self, app: FastFlixApp, main, audio_type, signal): diff --git a/fastflix/widgets/panels/audio_panel.py b/fastflix/widgets/panels/audio_panel.py index f33a0d0d..c70c7474 100644 --- a/fastflix/widgets/panels/audio_panel.py +++ b/fastflix/widgets/panels/audio_panel.py @@ -253,6 +253,7 @@ def dup_me(self): def del_me(self): self.parent.remove_track(self) del self.app.fastflix.current_video.audio_tracks[self.index] + self.parent.reorder(update=True) def set_outdex(self, outdex): self.app.fastflix.current_video.audio_tracks[self.index].outdex = outdex diff --git a/fastflix/widgets/panels/cover_panel.py b/fastflix/widgets/panels/cover_panel.py index 2d53c67f..3275a474 100644 --- a/fastflix/widgets/panels/cover_panel.py +++ b/fastflix/widgets/panels/cover_panel.py @@ -208,11 +208,23 @@ def get_attachment(self, filename) -> Tuple[Union[Path, None], Union[int, None]] def update_cover_settings(self): if not self.app.fastflix.current_video: return - start_outdex = ( - 1 # Video Track - + len(self.app.fastflix.current_video.audio_tracks) - + len(self.app.fastflix.current_video.subtitle_tracks) - ) + # start_outdex = ( + # 1 # Video Track + # + len(self.app.fastflix.current_video.audio_tracks) + # + len(self.app.fastflix.current_video.subtitle_tracks) + # ) + start_outdex = 1 + + for audio_track in self.app.fastflix.current_video.audio_tracks: + if audio_track.enabled: + audio_track.outdex = start_outdex + start_outdex += 1 + + for subtitle_track in self.app.fastflix.current_video.subtitle_tracks: + if subtitle_track.enabled: + subtitle_track.outdex = start_outdex + start_outdex += 1 + attachments: list[AttachmentTrack] = [] for filename in ("cover", "cover_land", "small_cover", "small_cover_land"): diff --git a/fastflix/widgets/panels/subtitle_panel.py b/fastflix/widgets/panels/subtitle_panel.py index 36b19ca6..0cacea6c 100644 --- a/fastflix/widgets/panels/subtitle_panel.py +++ b/fastflix/widgets/panels/subtitle_panel.py @@ -30,7 +30,7 @@ subtitle_types = { "dvd_subtitle": "picture", - "hdmv_pgs_subtitle": "picture", + "hdmv_pgs_subtitle": "pgs", "dvdsub": "picture", "subrip": "text", "ssa": "text", @@ -130,7 +130,8 @@ def __init__(self, app, parent, index, enabled=True, first=False): self.grid.addWidget(self.widgets.track_number, 0, 1) self.grid.addWidget(self.widgets.title, 0, 2) self.grid.setColumnStretch(2, True) - if sub_track.subtitle_type == "text": + # if sub_track.subtitle_type == "text": + if sub_track.subtitle_type in ["text", "pgs"]: self.grid.addWidget(self.widgets.extract, 0, 3) self.grid.addWidget(self.gif_label, 0, 3) self.gif_label.hide() @@ -376,6 +377,9 @@ def new_source(self): super()._new_source(self.tracks) + # def get_settings(self): + # return # TODO remove + def reload(self, original_tracks): clear_list(self.tracks)