Skip to content

Commit 164d37d

Browse files
authored
Fixing: can not copy cover and improving subtitle extraction (#679)
1 parent 93e3a5a commit 164d37d

5 files changed

Lines changed: 99 additions & 13 deletions

File tree

fastflix/ff_queue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def update_conversion_command(vid, old_path: str, new_path: str):
107107
if not Path(track["file_path"]).exists():
108108
logger.exception("Could not save cover to queue recovery location, removing cover")
109109
continue
110-
new_file = queue_covers / f"{uuid.uuid4().hex}_{track['file_path'].name}"
110+
new_file = queue_covers / f"{uuid.uuid4().hex}_{Path(track['file_path']).name}"
111111
try:
112112
shutil.copy(track["file_path"], new_file)
113113
except OSError:

fastflix/widgets/background_tasks.py

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,38 @@ def __init__(self, app: FastFlixApp, main, index, signal, language):
5555
self.language = language
5656

5757
def run(self):
58+
subtitle_format = self._get_subtitle_format()
59+
if subtitle_format is None:
60+
self.main.thread_logging_signal.emit(
61+
f"WARNING:{t('Could not determine subtitle format for track')} {self.index}, {t('skipping extraction')}"
62+
)
63+
self.signal.emit()
64+
return
65+
66+
if subtitle_format == "srt":
67+
extension = "srt"
68+
output_args = ["-c", "srt", "-f", "srt"]
69+
elif subtitle_format == "ass":
70+
extension = "ass"
71+
output_args = ["-c", "copy"]
72+
elif subtitle_format == "ssa":
73+
extension = "ssa"
74+
output_args = ["-c", "copy"]
75+
elif subtitle_format == "pgs":
76+
extension = "sup"
77+
output_args = ["-c", "copy"]
78+
else:
79+
self.main.thread_logging_signal.emit(
80+
f"WARNING:{t('Subtitle Track')} {self.index} {t('is not in supported format (SRT, ASS, SSA, PGS), skipping extraction')}: {subtitle_format}"
81+
)
82+
self.signal.emit()
83+
return
84+
85+
# filename = str(
86+
# Path(self.main.output_video).parent / f"{self.main.output_video}.{self.index}.{self.language}.srt"
87+
# ).replace("\\", "/")
5888
filename = str(
59-
Path(self.main.output_video).parent / f"{self.main.output_video}.{self.index}.{self.language}.srt"
89+
Path(self.main.output_video).parent / f"{self.main.output_video}.{self.index}.{self.language}.{extension}"
6090
).replace("\\", "/")
6191
self.main.thread_logging_signal.emit(f"INFO:{t('Extracting subtitles to')} {filename}")
6292

@@ -69,10 +99,7 @@ def run(self):
6999
self.main.input_video,
70100
"-map",
71101
f"0:s:{self.index}",
72-
"-c",
73-
"srt",
74-
"-f",
75-
"srt",
102+
*output_args,
76103
filename,
77104
],
78105
stdout=PIPE,
@@ -90,6 +117,48 @@ def run(self):
90117
self.main.thread_logging_signal.emit(f"INFO:{t('Extracted subtitles successfully')}")
91118
self.signal.emit()
92119

120+
def _get_subtitle_format(self):
121+
try:
122+
result = run(
123+
[
124+
self.app.fastflix.config.ffprobe,
125+
"-v", "error",
126+
"-select_streams", f"s:{self.index}",
127+
"-show_entries", "stream=codec_name",
128+
"-of", "default=noprint_wrappers=1:nokey=1",
129+
self.main.input_video
130+
],
131+
stdout=PIPE,
132+
stderr=STDOUT,
133+
text=True
134+
)
135+
136+
if result.returncode != 0:
137+
self.main.thread_logging_signal.emit(
138+
f"WARNING:{t('Could not probe subtitle track')} {self.index}: {result.stdout}"
139+
)
140+
return None
141+
142+
codec_name = result.stdout.strip().lower()
143+
if codec_name in ["subrip", "xsub", "webvtt", "mov_text"]:
144+
return "srt"
145+
elif codec_name == "ass":
146+
return "ass"
147+
elif codec_name == "ssa":
148+
return "ssa"
149+
elif codec_name == "hdmv_pgs_subtitle":
150+
return "pgs"
151+
else:
152+
self.main.thread_logging_signal.emit(
153+
f"WARNING:{t('Subtitle Track')} {self.index} {t('is not in supported format (SRT, ASS, SSA, PGS), skipping extraction')}: {codec_name}"
154+
)
155+
return None
156+
157+
except Exception as err:
158+
self.main.thread_logging_signal.emit(
159+
f"WARNING:{t('Error checking subtitle format for track')} {self.index} - {err}"
160+
)
161+
return None
93162

94163
class AudioNoramlize(QtCore.QThread):
95164
def __init__(self, app: FastFlixApp, main, audio_type, signal):

fastflix/widgets/panels/audio_panel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ def dup_me(self):
253253
def del_me(self):
254254
self.parent.remove_track(self)
255255
del self.app.fastflix.current_video.audio_tracks[self.index]
256+
self.parent.reorder(update=True)
256257

257258
def set_outdex(self, outdex):
258259
self.app.fastflix.current_video.audio_tracks[self.index].outdex = outdex

fastflix/widgets/panels/cover_panel.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,23 @@ def get_attachment(self, filename) -> Tuple[Union[Path, None], Union[int, None]]
208208
def update_cover_settings(self):
209209
if not self.app.fastflix.current_video:
210210
return
211-
start_outdex = (
212-
1 # Video Track
213-
+ len(self.app.fastflix.current_video.audio_tracks)
214-
+ len(self.app.fastflix.current_video.subtitle_tracks)
215-
)
211+
# start_outdex = (
212+
# 1 # Video Track
213+
# + len(self.app.fastflix.current_video.audio_tracks)
214+
# + len(self.app.fastflix.current_video.subtitle_tracks)
215+
# )
216+
start_outdex = 1
217+
218+
for audio_track in self.app.fastflix.current_video.audio_tracks:
219+
if audio_track.enabled:
220+
audio_track.outdex = start_outdex
221+
start_outdex += 1
222+
223+
for subtitle_track in self.app.fastflix.current_video.subtitle_tracks:
224+
if subtitle_track.enabled:
225+
subtitle_track.outdex = start_outdex
226+
start_outdex += 1
227+
216228
attachments: list[AttachmentTrack] = []
217229

218230
for filename in ("cover", "cover_land", "small_cover", "small_cover_land"):

fastflix/widgets/panels/subtitle_panel.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
subtitle_types = {
3232
"dvd_subtitle": "picture",
33-
"hdmv_pgs_subtitle": "picture",
33+
"hdmv_pgs_subtitle": "pgs",
3434
"dvdsub": "picture",
3535
"subrip": "text",
3636
"ssa": "text",
@@ -130,7 +130,8 @@ def __init__(self, app, parent, index, enabled=True, first=False):
130130
self.grid.addWidget(self.widgets.track_number, 0, 1)
131131
self.grid.addWidget(self.widgets.title, 0, 2)
132132
self.grid.setColumnStretch(2, True)
133-
if sub_track.subtitle_type == "text":
133+
# if sub_track.subtitle_type == "text":
134+
if sub_track.subtitle_type in ["text", "pgs"]:
134135
self.grid.addWidget(self.widgets.extract, 0, 3)
135136
self.grid.addWidget(self.gif_label, 0, 3)
136137
self.gif_label.hide()
@@ -376,6 +377,9 @@ def new_source(self):
376377

377378
super()._new_source(self.tracks)
378379

380+
# def get_settings(self):
381+
# return # TODO remove
382+
379383
def reload(self, original_tracks):
380384
clear_list(self.tracks)
381385

0 commit comments

Comments
 (0)