Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fastflix/ff_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
79 changes: 74 additions & 5 deletions fastflix/widgets/background_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand All @@ -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,
Expand All @@ -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):
Expand Down
1 change: 1 addition & 0 deletions fastflix/widgets/panels/audio_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 17 additions & 5 deletions fastflix/widgets/panels/cover_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
8 changes: 6 additions & 2 deletions fastflix/widgets/panels/subtitle_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

subtitle_types = {
"dvd_subtitle": "picture",
"hdmv_pgs_subtitle": "picture",
"hdmv_pgs_subtitle": "pgs",
"dvdsub": "picture",
"subrip": "text",
"ssa": "text",
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand Down
Loading