@@ -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
94163class AudioNoramlize (QtCore .QThread ):
95164 def __init__ (self , app : FastFlixApp , main , audio_type , signal ):
0 commit comments