@@ -1889,7 +1889,7 @@ def assFontSubset(assfont: dict, fontdir: str, allTTF: bool = False):
1889
1889
showOutChars = ' ' .join ([(c if c .isprintable () else 'U+' + hex (ord (c ))[2 :].rjust (4 , '0' ).upper ()) for c in out_of_range ])
1890
1890
1891
1891
if ignoreLost :
1892
- print ('\033 [1;31m[WARNING] 已忽略不在字体中的字符 {}\033 [0m' .format (showOutChars ))
1892
+ print ('\033 [1;31m[WARNING] 已忽略不在字体中的字符: {}\033 [0m' .format (showOutChars ))
1893
1893
else :
1894
1894
print ('\033 [1;31m[ERROR] 以下字符不在字体\" {1}\" 内\033 [0m\n \" {0}\" \n \033 [1;31m[ERROR] 以上字符不在字体\" {1}\" 内\033 [0m' .format (showOutChars , s [3 ]))
1895
1895
print ('\033 [1;31m[ERROR] 已停止子集化,如果您想要强行子集化,请启用ignoreLost\033 [0m' )
@@ -2181,7 +2181,7 @@ def getSubName(v: str, sub: str) -> tuple[str, str]:
2181
2181
bVideo = basenameNoEXT (v )
2182
2182
return sub , bSub [bSub .find (bVideo ) + len (bVideo ):]
2183
2183
2184
- def ffASFMKV (file : str , outfile : str = '' , asslangs : list = [], asspaths : list = [], fontpaths : list = [], forceSubTrack : str = '?' ) -> int :
2184
+ def ffASFMKV (file : str , outfile : str = '' , asslangs : list = [], asspaths : list = [], fontpaths : list = [], forceSubTrack : str = '?' , makeMKS : bool = False ) -> int :
2185
2185
"""
2186
2186
ffASFMKV,将媒体文件、字幕、字体封装到一个MKV文件,需要ffmpeg、ffprobe命令行支持
2187
2187
@@ -2203,46 +2203,55 @@ def ffASFMKV(file: str, outfile: str = '', asslangs: list = [], asspaths: list =
2203
2203
elif not path .exists (file ) or not path .isfile (file ):
2204
2204
return 4
2205
2205
if outfile is None : outfile = ''
2206
+
2207
+ outExt = '.mkv'
2208
+ if makeMKS :
2209
+ outExt = '.mks'
2210
+
2206
2211
if outfile == '' or not path .exists (path .dirname (outfile )) or path .dirname (outfile ) == path .dirname (file ):
2207
- outfile = '.muxed' .join ([path .splitext (file )[0 ], '.mkv' ])
2208
- outfile = path .splitext (outfile )[0 ] + '.mkv'
2212
+ outfile = '.muxed' .join ([path .splitext (file )[0 ], outExt ])
2213
+ outfile = path .splitext (outfile )[0 ] + outExt
2209
2214
if path .exists (outfile ):
2210
2215
checkloop = 1
2211
2216
while path .exists ('#{0}' .format (checkloop ).join (path .splitext (outfile ))):
2212
2217
checkloop += 1
2213
- outfile = '#{0}' .format (checkloop ).join ([path .splitext (outfile )[0 ], '.mkv' ])
2218
+ outfile = '#{0}' .format (checkloop ).join ([path .splitext (outfile )[0 ], outExt ])
2214
2219
2215
- rawIdx = json .loads (os .popen ('ffprobe -print_format json -show_streams -hide_banner -v 0 -i \" {}\" ' .format (file ), mode = 'r' ).read ())
2216
- firstIdx = len (rawIdx ['streams' ])
2217
2220
ffargs = []
2218
2221
metaList = []
2219
2222
mapList = []
2220
2223
copyList = []
2221
-
2222
- for f in rawIdx ['streams' ]:
2223
- if f ['codec_type' ] == 'video' :
2224
- if '-map 0:v' not in mapList :
2225
- mapList .append ('-map 0:v' )
2226
- copyList .append ('-c:v copy' )
2227
- elif f ['codec_type' ] == 'audio' :
2228
- if '-map 0:a' not in mapList :
2229
- mapList .append ('-map 0:a' )
2230
- copyList .append ('-c:a copy' )
2231
- elif f ['codec_type' ] == 'attachment' :
2232
- if not rmAttach :
2233
- if '-map 0:t' not in mapList :
2234
- mapList .append ('-map 0:t' )
2235
- copyList .append ('-c:t copy' )
2236
- else :
2237
- firstIdx -= 1
2238
- elif f ['codec_type' ] == 'subtitle' :
2239
- if rmAssIn :
2240
- firstIdx -= 1
2241
- elif '-map 0:s' not in mapList :
2242
- mapList .append ('-map 0:s' )
2243
- if not rmAssIn and f ['disposition' ]['default' ] == 1 :
2244
- copyList .append ('-disposition:{} 0' .format (f ['index' ]))
2245
- ffargs .append ('-i \" {}\" ' .format (file ))
2224
+ firstIdx = 0
2225
+
2226
+ if not makeMKS :
2227
+ rawIdx = json .loads (os .popen ('ffprobe -print_format json -show_streams -hide_banner -v 0 -i \" {}\" ' .format (file ), mode = 'r' ).read ())
2228
+
2229
+ firstIdx = len (rawIdx ['streams' ])
2230
+
2231
+ for f in rawIdx ['streams' ]:
2232
+ if f ['codec_type' ] == 'video' :
2233
+ if '-map 0:v' not in mapList :
2234
+ mapList .append ('-map 0:v' )
2235
+ copyList .append ('-c:v copy' )
2236
+ elif f ['codec_type' ] == 'audio' :
2237
+ if '-map 0:a' not in mapList :
2238
+ mapList .append ('-map 0:a' )
2239
+ copyList .append ('-c:a copy' )
2240
+ elif f ['codec_type' ] == 'attachment' :
2241
+ if not rmAttach :
2242
+ if '-map 0:t' not in mapList :
2243
+ mapList .append ('-map 0:t' )
2244
+ copyList .append ('-c:t copy' )
2245
+ else :
2246
+ firstIdx -= 1
2247
+ elif f ['codec_type' ] == 'subtitle' :
2248
+ if rmAssIn and not makeMKS :
2249
+ firstIdx -= 1
2250
+ elif '-map 0:s' not in mapList :
2251
+ mapList .append ('-map 0:s' )
2252
+ if not rmAssIn and f ['disposition' ]['default' ] == 1 :
2253
+ copyList .append ('-disposition:{} 0' .format (f ['index' ]))
2254
+ ffargs .append ('-i \" {}\" ' .format (file ))
2246
2255
2247
2256
fn = path .splitext (path .basename (file ))[0 ]
2248
2257
metaList .append ('-metadata:g title=\" {}\" ' .format (fn ))
@@ -2263,14 +2272,14 @@ def ffASFMKV(file: str, outfile: str = '', asslangs: list = [], asspaths: list =
2263
2272
2264
2273
if len (asslangs ) > 0 and path .splitext (s )[1 ][1 :].lower () not in ['idx' ]:
2265
2274
if assnote .lower () in asslangs :
2266
- metadata .append ('language=\" {}\" ' .format (asslangs [assnote ]))
2275
+ metadata .append ('language=\" {}\" ' .format (asslangs [assnote . lower () ]))
2267
2276
2268
2277
if len (metadata ) > 0 :
2269
2278
for m in metadata :
2270
2279
metaList .append ('-metadata:s:{1} {0}' .format (m , firstIdx ))
2271
2280
2272
2281
ffargs .append ('-i \" {}\" ' .format (s ))
2273
- mapList .append ('-map {}' .format (i + 1 ))
2282
+ mapList .append ('-map {}' .format (i + 1 if not makeMKS else i ))
2274
2283
2275
2284
if not defaultSet and (assnote .lower () == forceSubTrack .lower () or forceSubTrack == '?' ):
2276
2285
copyList .append ('-disposition:{} default' .format (firstIdx ))
@@ -2290,6 +2299,9 @@ def ffASFMKV(file: str, outfile: str = '', asslangs: list = [], asspaths: list =
2290
2299
extMime [path .splitext (s )[1 ][1 :].lower ()], firstIdx ))
2291
2300
ffargs .append ('-attach \" {}\" ' .format (s ))
2292
2301
firstIdx += 1
2302
+
2303
+ if makeMKS : metaList .append ('-f matroska' )
2304
+
2293
2305
ffmr = os .system ('ffmpeg {0} {3} {4} -c:s copy {2} \" {1}\" ' .format (' ' .join (ffargs ), outfile , ' ' .join (metaList ), ' ' .join (mapList ), ' ' .join (copyList )))
2294
2306
2295
2307
if ffmr >= 1 :
@@ -2320,7 +2332,7 @@ def ffASFMKV(file: str, outfile: str = '', asslangs: list = [], asspaths: list =
2320
2332
return ffmr
2321
2333
2322
2334
2323
- def ASFMKV (file : str , outfile : str = '' , asslangs : dict = {}, asspaths : list = [], fontpaths : list = [], forceSubTrack : str = '?' ) -> int :
2335
+ def ASFMKV (file : str , outfile : str = '' , asslangs : dict = {}, asspaths : list = [], fontpaths : list = [], forceSubTrack : str = '?' , makeMKS : bool = False ) -> int :
2324
2336
"""
2325
2337
ASFMKV,将媒体文件、字幕、字体封装到一个MKV文件,需要mkvmerge命令行支持
2326
2338
@@ -2344,18 +2356,27 @@ def ASFMKV(file: str, outfile: str = '', asslangs: dict = {}, asspaths: list = [
2344
2356
elif not path .exists (file ) or not path .isfile (file ):
2345
2357
return 4
2346
2358
if outfile is None : outfile = ''
2359
+
2360
+ outExt = '.mkv'
2361
+ if makeMKS :
2362
+ outExt = '.mks'
2363
+
2347
2364
if outfile == '' or not path .exists (path .dirname (outfile )) or path .dirname (outfile ) == path .dirname (file ):
2348
- outfile = '.muxed' .join ([path .splitext (file )[0 ], '.mkv' ])
2349
- outfile = path .splitext (outfile )[0 ] + '.mkv'
2365
+ outfile = '.muxed' .join ([path .splitext (file )[0 ], outExt ])
2366
+ outfile = path .splitext (outfile )[0 ] + outExt
2350
2367
if path .exists (outfile ):
2351
2368
checkloop = 1
2352
2369
while path .exists ('#{0}' .format (checkloop ).join (path .splitext (outfile ))):
2353
2370
checkloop += 1
2354
- outfile = '#{0}' .format (checkloop ).join ([path .splitext (outfile )[0 ], '.mkv' ])
2371
+ outfile = '#{0}' .format (checkloop ).join ([path .splitext (outfile )[0 ], outExt ])
2372
+
2355
2373
mkvargs = []
2356
- if rmAssIn : mkvargs .append ('-S' )
2357
- if rmAttach : mkvargs .append ('-M' )
2358
- mkvargs .extend (['(' , file , ')' ])
2374
+
2375
+ if not makeMKS :
2376
+ if rmAssIn : mkvargs .append ('-S' )
2377
+ if rmAttach : mkvargs .append ('-M' )
2378
+ mkvargs .extend (['(' , file , ')' ])
2379
+
2359
2380
fn = path .splitext (path .basename (file ))[0 ]
2360
2381
if len (asspaths ) > 0 :
2361
2382
defaultSet = False
@@ -2825,7 +2846,7 @@ def namePosition(files: list):
2825
2846
2826
2847
2827
2848
def main (font_info : list , asspath : list , outdir : list = ['' , '' , '' ], mux : bool = False , vpath : str = '' ,
2828
- asslangs : dict = {}, FFmuxer : int = 0 , fontline : int = - 1 , forceSubTrack : str = '?' ):
2849
+ asslangs : dict = {}, FFmuxer : int = 0 , fontline : int = - 1 , forceSubTrack : str = '?' , makeMKS : bool = False ):
2829
2850
"""
2830
2851
主函数,负责调用各函数走完完整的处理流程
2831
2852
@@ -2934,10 +2955,10 @@ def main(font_info: list, asspath: list, outdir: list = ['', '', ''], mux: bool
2934
2955
outdir [2 ] = path .dirname (outdir [2 ])
2935
2956
if FFmuxer == 1 :
2936
2957
mkvr = ffASFMKV (vpath , path .join (outdir [2 ], path .splitext (path .basename (vpath ))[0 ] + '.mkv' ),
2937
- asslangs = asslangs , asspaths = newasspath , fontpaths = list (set ([f [0 ] for f in newfont_name .values ()])), forceSubTrack = forceSubTrack )
2958
+ asslangs = asslangs , asspaths = newasspath , fontpaths = list (set ([f [0 ] for f in newfont_name .values ()])), forceSubTrack = forceSubTrack , makeMKS = makeMKS )
2938
2959
elif FFmuxer == 0 :
2939
2960
mkvr = ASFMKV (vpath , path .join (outdir [2 ], path .splitext (path .basename (vpath ))[0 ] + '.mkv' ),
2940
- asslangs = asslangs , asspaths = newasspath , fontpaths = list (set ([f [0 ] for f in newfont_name .values ()])), forceSubTrack = forceSubTrack )
2961
+ asslangs = asslangs , asspaths = newasspath , fontpaths = list (set ([f [0 ] for f in newfont_name .values ()])), forceSubTrack = forceSubTrack , makeMKS = makeMKS )
2941
2962
else :
2942
2963
mkvr = 0
2943
2964
if not notfont :
@@ -3449,10 +3470,10 @@ def showFocusSub(i: str):
3449
3470
elif rudeSubN2L :
3450
3471
for k in subName2Lang .keys ():
3451
3472
if k .lstrip ('.' ) in i :
3452
- lang = subName2Lang [i ]
3473
+ lang = subName2Lang [k ]
3453
3474
autoGet = True
3454
3475
break
3455
- else :
3476
+ if not autoGet :
3456
3477
if no_mkvm and len (translationLang ) > 0 :
3457
3478
searchLang = '仅本地语言搜索'
3458
3479
elif no_mkvm :
@@ -3819,13 +3840,21 @@ def cFontSubset(font_info):
3819
3840
sublangs = None
3820
3841
sublangs = {}
3821
3842
forceSubTrack = '?'
3843
+ makeMKSq = False
3822
3844
muxer = 0
3823
3845
cls ()
3824
3846
if domux :
3825
3847
print ('您需要为字幕轨道添加语言信息吗?' )
3826
3848
if os .system ('choice' ) == 1 :
3827
3849
sublangs = getSubsLangsV2 (media_ass )
3850
+
3851
+ cls ()
3828
3852
forceSubTrack = getForceSub (media_ass )
3853
+
3854
+ cls ()
3855
+ print ('您要封装为外置MKS文件吗?' )
3856
+ if os .system ('choice' ) == 1 :
3857
+ makeMKSq = True
3829
3858
# print(media_ass)
3830
3859
if work == 21 or (work == 2 and no_mkvm ):
3831
3860
muxer = 1
@@ -3844,7 +3873,7 @@ def cFontSubset(font_info):
3844
3873
outdir = [assout_cache , fontout_cache , mkvout_cache ],
3845
3874
vpath = k ,
3846
3875
asslangs = sublangs ,
3847
- FFmuxer = muxer , forceSubTrack = forceSubTrack )
3876
+ FFmuxer = muxer , forceSubTrack = forceSubTrack , makeMKS = makeMKSq )
3848
3877
if mkvr != - 2 :
3849
3878
showMessageSubset (newasspaths , newfont_name )
3850
3879
else :
0 commit comments