-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathASFMKV_ExtL1.02.bat
1184 lines (1137 loc) · 35.7 KB
/
ASFMKV_ExtL1.02.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@rem UTF-8 without BOM file
@rem 关闭命令回显
@echo off
chcp 65001
rem 变换标题
title [初始化] 请稍等...
rem ------------------------------------------
rem ExtList自定义变量
rem 该变量控制Batch的文件输入过滤器(媒体),请不要随意修改
rem 添加时请以分号隔开每个扩展名
rem 注意!在extlist的末尾也必须有一个分号,否则最后一个扩展名将无法读取
rem 关于详细的格式支持,请详见mkvmerge -l
set "extlist=webm;webmv;vc1;rm;rmvb;rv;ogg;ogv;av1;obu;mov;mkv;mk3d;m1v;m2v;mpv;ts;m2ts;mts;mpg;mpeg;m2v;mpv;evo;evob;vob;mp4;m4v;ivf;flv;avi;265;hevc;h265;x265;264;avc;h264;x264;"
rem ------------------------------------------
rem NotDel自定义变量
rem [空] 无赋值时程序会删除混流前的源文件
rem [任意] 有任意赋值时程序会保留源文件
rem 语法:set "notdel=值"
rem
rem 注意:如果是第三方BAT指定了该值,将会覆盖此处的设置
rem
rem 第三方用法:[0] 值为0不删除源文件
rem [-0] 值不为0删除源文件
set "notdel=0"
rem ------------------------------------------
rem NotSub自定义变量
rem [空] 无赋值时,程序仅会在文件夹下有外挂字幕的时候才会对文件进行封装
rem (若没有外挂字幕即使文件夹下有字体也会跳过该文件)
rem [任意] 有任意赋值时,如果文件夹下有字体,程序会在没有外挂字幕的情况下依然封装字体到文件
rem 语法:set "notsub=值"
rem
rem 注意:如果是第三方BAT指定了该值,将会覆盖此处的设置
rem
rem 第三方用法:[0] 值为0以无赋值处理
rem [-0] 值不为0以任意赋值处理
set "notsub="
rem ------------------------------------------
rem NotFont自定义变量
rem [空] 无赋值时,程序仅会封装外挂字幕而不会封装字体文件
rem [任意] 有任意赋值时,程序不仅会封装外挂字幕而且还会封装字体文件
rem 语法:set "notfont=值"
rem
rem 该选项不允许第三方指定
set "notfont=0"
rem ------------------------------------------
rem OutPath自定义变量
rem [空] 无赋值时,程序会将封装完成的文件输出到源文件夹
rem [有效路径] 有正确赋值时,程序会将封装完成的文件输出到目标文件夹
rem (路径可以为不存在的路径,程序会自动创建)
rem 语法:set "outpath=值(路径不需要前后引号)"
rem
rem 第三方用法:[有效路径] 同上
rem [无效路径] 输出到源文件夹,作无赋值处理
set "outpath="
rem ------------------------------------------
rem SearchFilter自定义变量
rem [空] 无赋值时,程序会使用默认值(*.*)
rem [任意] 任意赋值时,若输入文件夹,程序将只封装符合匹配的文件
rem 过滤器语法:可使用通配符(*),如"*.mp4"将匹配所有后缀名为MP4的文件
rem 也可在文件名中使用通配符,如"*DMG*.*"将匹配所有名称中含有DMG的文件
rem 语法:set "searchfilter=值"
rem
rem 第三方用法:[缺省] 同"空"
rem [任意] 同"任意"
set "searchfilter="
rem ------------------------------------------
rem MKVmerge进程优先级/界面语言
rem 如果您不懂这方面的知识,请不要随意修改
rem 界面语言(默认"zh_CN"(简体中文))
set "ui_language=zh_CN"
rem 优先级(默认"normal"(标准))
set "priority=normal"
rem ------------------------------------------
rem SubDir自定义变量
rem 定义是否搜索指定目录下的子目录
rem [非0] 搜索子目录
rem [0] 不搜索子目录
rem
rem 语法:set "subdir=0"
rem
rem 第三方用法:[0] 同"0"
rem [非0] 同"非0"
set "subdir=0"
rem ------------------------------------------
rem DEBUG_MODE
rem 测试模式下将会关闭所有CLS并开启ECHO
rem 注意!开启此项将强制开启NUL_OUTPUT!
rem [0] 启用
rem [非0] 停用
set "debug_mode=1"
rem ------------------------------------------
rem NUL_OUTPUT
rem 该变量仅用于测试!请不要随意开启!
rem NUL_OUTPUT开启时将会让MKVmerge把结果输出到NUL(不输出)
rem 以加快测试速度并减少磁盘使用
rem [0] 启用
rem [非0] 停用
set "nul_output=1"
rem ------------------------------------------
rem EXEin
rem 该变量决定运行时所用的MKVmerge的路径
rem
set "exein=mkvmerge"
rem ------------------------------------------
rem DEBUG模块,在程序意外终止时会挂起程序
cls
:Module_DEBUG
if not defined debug (
set debug=0
cmd /c call "%~0" "%~1" "%~2%~3%~4%~5%~6%~7%~8%~9"
if "%~1"=="" (
echo [Module_DEBUG] 请按任意键退出...
pause>nul
exit
) else (
if defined title (
title %title%
) else title Command Shell
set "debug="
goto :EOF
)
) else set "debug="
rem 清屏
:get_input
rem EasyUse命令输入分析
if /i "%~1"=="-h" goto Show_Help
if /i "%~1"=="-help" goto Show_Help
if /i "%~1"=="/help" goto Show_Help
if /i "%~1"=="/h" goto Show_Help
if /i "%~1"=="/?" goto Show_Help
if /i "%~1"=="?h" goto Show_Help
if not "%debug_mode%"=="0" cls
if "%debug_mode%"=="0" echo on
if "%~2"=="" goto not_check_input
set "split_count=0"
setlocal enabledelayedexpansion
:split_input
if defined input[%split_count%] (
for /f "tokens=1* delims==" %%a in ('set input[%split_count%]') do (
set "last_split=%%~b"
)
)
set /a split_count=split_count+1
for /f "tokens=%split_count% delims=?" %%a in ("%~2") do (
set "test_input=%%~a"
)
if not "%test_input%"=="" (
if "%last_split%"=="%test_input%" (
set /a split_count=split_count-1
set "last_split="
set "test_input="
set "space_cache="
goto split_out
)
)
:del_space
set "space_cache=%test_input:~-1%"
if "%space_cache%"==" " (
set "test_input=!test_input:~0,-1!"
) else (
set "input[%split_count%]=%test_input%"
goto out_space_del
)
goto del_space
:out_space_del
goto split_input
:split_out
setlocal disabledelayedexpansion
for /l %%a in (1,1,%split_count%) do (
for /f "tokens=1* delims==" %%b in ('set input[%%a]') do (
for /f "tokens=1* delims= " %%d in ("%%c") do (
if /i "%%~d"=="h" (
goto Show_Help
)
if /i "%%~d"=="out" (
if exist "%%~e" (
set "outpath=%%~e"
) else if not "%%~e"=="" (
mkdir "%%~e">nul
if exist "%%~e" (
set "outpath=%%~e"
) else (
echo [EasyUse Error] 输出路径无效
pause
exit
)
)
)
if /i "%%~d"=="exe" (
if exist "%%~e" (
set "exein=%%~e"
) else set "exein=mkvmerge"
)
if /i "%%~d"=="del" (
if /i "%%~e"=="y" (
set "notdel=1"
) else set "notdel=0"
)
if /i "%%~d"=="sub" (
if /i "%%~e"=="y" (
set "notsub=1"
set "notfont=1"
) else (
set "notsub="
)
)
if /i "%%~d"=="dir" (
if /i "%%~e"=="y" (
set "subdir=1"
) else set "subdir=0"
)
if /i "%%~d"=="dbm" (
for /f "tokens=1,2 delims=:" %%f in ("%%~e") do (
if /i "%%~f"=="y" (
set "debug_mode=0"
) else set "debug_mode=1"
if /i "%%~g"=="y" (
set "nul_output=0"
) else set "nul_output=1"
)
)
if /i "%%~d"=="ffl" (
if not "%%~e"=="" (
set "searchfilter=%%~e"
) else set "searchfilter="
)
if /i "%%~d"=="pri" (
if "%%~e"=="0" (
set "priority=lowest"
) else if "%%~e"=="1" (
set "priority=lower"
) else if "%%~e"=="2" (
set "priority=normal"
) else if "%%~e"=="3" (
set "priority=higher"
) else if "%%~e"=="4" (
set "priority=highest"
)
)
if /i "%%~d"=="uil" (
if "%%~e"=="1" (
set "ui_language=en"
) else if "%%~e"=="2" (
set "ui_language=zh_CN"
) else if "%%~e"=="3" (
set "ui_language=zh_TW"
) else if "%%~e"=="4" (
set "ui_language=ja"
) else if not "%%~e"=="" (
set "ui_language=%%~e"
)
)
)
)
)
:check_input
if exist "%~1" (
set "ifolder=%~1"
) else (
echo [ERROR] 输入路径有误
goto Show_Help
)
:not_check_input
if not "%~1"=="" if exist "%~1" (
set "ifolder=%~1"
)
if exist "%rf%fonts_json.log" del /q "%rf%fonts_json.log"
if not defined searchfilter goto not_replace_filter
rem 正则表达式转义
echo [SearchFilter] 检测到文件过滤器输入...请稍等...
echo.
echo [Module_ReplaceBatch] 正在转义为正则表达式...
echo [Module_ReplaceBatch] 进度0/7
call :Module_ReplaceBatch "%searchfilter%" "." "\."
for /f "usebackq tokens=*" %%a in ("%USERPROFILE%\rforbat.log") do set "replace_output=%%~a"
echo [Module_ReplaceBatch] 进度1/7
call :Module_ReplaceBatch "%replace_output%" "(" "\("
for /f "usebackq tokens=*" %%a in ("%USERPROFILE%\rforbat.log") do set "replace_output=%%~a"
echo [Module_ReplaceBatch] 进度2/7
call :Module_ReplaceBatch "%replace_output%" ")" "\)"
for /f "usebackq tokens=*" %%a in ("%USERPROFILE%\rforbat.log") do set "replace_output=%%~a"
echo [Module_ReplaceBatch] 进度3/7
call :Module_ReplaceBatch "%replace_output%" "+" "\+"
for /f "usebackq tokens=*" %%a in ("%USERPROFILE%\rforbat.log") do set "replace_output=%%~a"
echo [Module_ReplaceBatch] 进度4/7
call :Module_ReplaceBatch "%replace_output%" "?" "\?"
for /f "usebackq tokens=*" %%a in ("%USERPROFILE%\rforbat.log") do set "replace_output=%%~a"
echo [Module_ReplaceBatch] 进度5/7
call :Module_ReplaceBatch "%replace_output%" "{" "\{"
for /f "usebackq tokens=*" %%a in ("%USERPROFILE%\rforbat.log") do set "replace_output=%%~a"
echo [Module_ReplaceBatch] 进度6/7
call :Module_ReplaceBatch "%replace_output%" "*" ".*"
for /f "usebackq tokens=*" %%a in ("%USERPROFILE%\rforbat.log") do set "replace_output=%%~a"
echo [Module_ReplaceBatch] 进度7/7
set "filter=%replace_output%"
set "replace_output="
:not_replace_filter
rem 获取基本信息
set "rf=%~dp0"
rem 定位到程序所在目录,防止以管理员模式启动导致尴尬局面
cd /d "%rf%"
rem 变更标题
if not "%debug_mode%"=="0" cls
title [LOAD] 正在测试mkvmerge可用性...
echo [LOAD] 正在测试mkvmerge是否可用...
:check_mkvmerge
rem 测试MKVmerge是否可用
for /f "tokens=*" %%a in ("%exein%") do (
if exist "%%~a" (
for /f "tokens=1 delims=-" %%b in ("%%~aa") do (
if "%%~b"=="d" (
for /r "%exein%" %%c in ("*mkvmerge*.exe") do (
if exist "%%~c" set "exein=%%~c"
)
)
)
)
)
call "%exein%" -V>nul 2>nul
if not %errorlevel%==0 (
echo [ERROR] EXEIN所设置的路径无效
) else goto no_check_again
call "mkvmerge" -V>nul 2>nul
if %errorlevel%==0 (
set "exein=mkvmerge"
echo [CORRECT] EXEIN=mkvmerge
) else (
echo [ERROR] 无法使用MKVmerge
title [ERROR] ASFMKV can't use MKVmerge
exit
)
:no_check_again
echo [LOAD] 正在测试语言"%ui_language%"是否可用...
for /f "skip=1 tokens=1 delims= " %%a in ('call "%exein%" --ui-language list') do (
if "%ui_language%"=="%%~a" goto uil_check_ok
)
echo [ERROR] 语言"%ui_language%"不可用
echo [CORRECT] 已更改为默认语言"en"
set "ui_language=en"
:uil_check_ok
set "extlist_count=1"
set "split_pos=0"
set "search_count=-1"
set "char_count=0"
title [LOAD] 正在转换列表ExtList...请耐心等待...
echo [LOAD] 正在列表ExtList...
set "el_cache=%rf%extlist_cache.log"
if not exist "%el_cache%" (
echo 这是ASFMKV的文件过滤器快速缓存>"%el_cache%"
setlocal enabledelayedexpansion
goto count_extlist
)
set "extca="
:check_extloglist
for /f "usebackq tokens=* skip=1" %%a in ("%el_cache%") do (
call :addend_extloglist "%%~a"
)
:end_check_extloglist
if not "%extca%;"=="%extlist%" (
del /q "%el_cache%"
echo [ExtCache] 缓存ExtLIST与记录不符,正在重建...
goto uil_check_ok
)
:count_extloglist
set "el_count=0"
for /f "usebackq tokens=* skip=1" %%a in ("%el_cache%") do (
call :add_extloglist "%%~a"
)
goto main_UI
:add_extloglist
if "%el_count:~0,1%"=="0" set "el_count=%el_count:~1%"
set /a "el_count=el_count+1"
if not %el_count% GEQ 10 set "el_count=0%el_count%"
set "extlist[%el_count%]=%~1"
echo [LoadExt] %~1
goto :EOF
:addend_extloglist
if not defined extca (
set "extca=%~1"
) else set "extca=%extca%;%~1"
goto :EOF
:count_extlist
set /a search_count=search_count+1
set "extcount=!extlist:~%search_count%,1!"
if "%extcount%"=="" goto end_count
set /a char_count=char_count+1
if "%extcount%"==";" (
call :add_new_ext
)
goto count_extlist
:add_new_ext
if not %extlist_count% GEQ 10 set "extlist_count=0%extlist_count%"
set "extlist[%extlist_count%]=!extlist:~%split_pos%,%char_count%!"
set "extlist[%extlist_count%]=!extlist[%extlist_count%]:~0,-1!"
echo [LoadExt] !extlist[%extlist_count%]!
echo !extlist[%extlist_count%]!>>"%el_cache%"
set /a split_pos=split_pos+char_count
set char_count=0
if "%extlist_count:~0,1%"=="0" set "extlist_count=%extlist_count:~1%"
set /a extlist_count=extlist_count+1
goto :EOF
:end_count
setlocal disabledelayedexpansion
:main_UI
set "ver=1.02-ExtList"
if not "%debug_mode%"=="0" cls
rem 获取MKVmerge的版本信息并更改标题
echo [INF] ASFMKV V%ver% ^| Copyright(c) 2018-2019 yyfll
for /f "tokens=1-2* delims= " %%a in ('call "%exein%" -V') do (
if "%debug_mode%"=="0" (
title AddSubFont-to-MKV [USE:%%a %%b][UTF-8][VER. %ver%^(DEBUG_MODE^)]
) else title AddSubFont-to-MKV [USE:%%a %%b][UTF-8][VER. %ver%]
echo [USE] %%a %%b ^| Copyright^(c^) 2002-2019 Moritz Bunkus
)
echo [EXT] Including %el_count% filetype [ExtList]
rem 如果已有输入就直接执行
echo.
@if "%debug_mode%"=="0" echo off
call :show_custom_settings
@if "%debug_mode%"=="0" echo on
if defined ifolder goto check_path
:need_folder
rem 向用户获取路径
echo.
set "ifolder="
set /p ifolder=文件(或目录)路径(不带引号):
rem 如果用户没有输入,则再次向用户获取;如果存在,则尝试去除引号
if not defined ifolder (
if not "%debug_mode%"=="0" cls
echo [ERR] 您没有输入任何路径!
goto need_folder
)
call :check_path_in
if defined path_inv (
set "path_inv="
goto need_folder
)
rem pause
goto check_path
:check_path_in
cmd /c if "%ifolder%"=="%ifolder%" echo. 2>NUL
if "%errorlevel%"=="0" (
set "ifolder=%ifolder%"
goto :EOF
)
cmd /c if "%ifolder:~1%"=="%ifolder:~1%" echo. 2>NUL
if "%errorlevel%"=="0" (
set "ifolder=%ifolder:~1%"
goto :EOF
)
cmd /c if "%ifolder:~0,-1%"=="%ifolder:~0,-1%" echo. 2>NUL
if "%errorlevel%"=="0" (
set "ifolder=%ifolder:~0,-1%"
goto :EOF
)
cmd /c if "%ifolder:~1,-1%"=="%ifolder:~1,-1%" echo. 2>NUL
if "%errorlevel%"=="0" (
set "ifolder=%ifolder:~1,-1%"
goto :EOF
)
if not "%debug_mode%"=="0" cls
echo [ERR] 不受支持的非法路径
echo [INF] 可能是您的路径中含有非法字符
set "path_inv=1"
goto :EOF
:check_path
rem 如果路径不存在,则再次向用户获取
if not exist "%ifolder%" (
if not "%debug_mode%"=="0" cls
call :show_setting
set "ifolder="
if not defined isSetting (
echo [ERR] 输入路径无效
goto need_folder
)
set "isSetting="
goto main_UI
)
echo.
:start_encode
if not "%debug_mode%"=="0" cls
rem 初始化变量
set working=0
set error=0
set count=0
rem 确认是目录还是文件
set "dirin="
for %%a in ("%ifolder%") do (
set "attribute=%%~aa"
)
if /i %attribute:~0,1%==d set "dirin=1"
if not defined attribute set "dirin=1"
:time_format
for /f "tokens=*" %%a in ('time /T') do (
for /f "delims=: tokens=1,2*" %%b in ("%%a:%time:~6,2%%time:~9,2%") do (
set "work_time=%%b%%c%%d"
)
)
:date_format
for /f "delims=/ tokens=1,2,3" %%a in ('date /T') do (
set "work_date_1=%%~a"
set "work_date_2=%%~b"
set "work_date_3=%%~c"
for /f "tokens=1,2 delims= " %%d in ("%%~a") do if not "%%~d"=="%%~e" (
if "%%~d" GTR "%%~e" (
if not "%%~e"=="" set "work_date_1=%%e"
) else if not "%%~d"=="" set "work_date_1=%%d"
)
for /f "tokens=1,2 delims= " %%d in ("%%~b") do if not "%%~d"=="%%~e" (
if "%%~d" GTR "%%~e" (
if not "%%~e"=="" set "work_date_2=%%e"
) else if not "%%~d"=="" set "work_date_2=%%d"
)
for /f "tokens=1,2 delims= " %%d in ("%%~c") do if not "%%~d"=="%%~e" (
if "%%~d" GTR "%%~e" (
if not "%%~e"=="" set "work_date_3=%%e"
) else if not "%%~d"=="" set "work_date_3=%%d"
)
)
set "test_input=%work_date_1%%work_date_2%%work_date_3%"
:format_del_space
set "space_cache=%test_input:~-1%"
if "%space_cache%"==" " (
set "test_input=%test_input:~0,-1%"
) else (
set "work_date=%test_input%"
goto format_out_space_del
)
goto format_del_space
:format_out_space_del
set "r_out_dir=%rf%[ASFMKV]redirect-output\"
set "date_logdir=%rf%[ASFMKV]redirect-output\%work_date%\"
set "logdir=%rf%[ASFMKV]redirect-output\%work_date%\%work_time%\"
:get_file_list
rem 如果是目录则执行以下流程
rem 删除先前用于记录文件列表的LOG,防止重复写入
if not defined dirin (
for /f "tokens=*" %%a in ("%ifolder%") do (
cd /d "%%~dpa"
set "vpath=%ifolder%"
set "ifolder=%%~dpa"
)
) else cd /d "%ifolder%"
if exist "%APPDATA%\filelist.log" del /q "%APPDATA%\filelist.log"
if exist "%~dp0filereader.log" del /q "%~dp0filereader.log"
title [yyfll的批量混流程序] 正在生成文件列表...请不要关闭本程序...
echo [input.get_file_list] 正在生成运行所需的文件列表...
rem 将符合搜索条件的文件的完整路径全部写入到filelist文件
rem 如果定义了subdir变量等于0,则判断这些路径是否在目标目录而不是其子目录
rem (1812TEST中为进一步减小磁盘读取压力加快速度,使用DIR+FINDSTR代替原有的FOR/R)
if "%subdir%"=="0" (
rem 利用FOR循环从DIR的运行结果中获取目标目录顶层的文件
for /f "tokens=*" %%a in ('dir /B /A:-D "%ifolder%"') do (
if exist "%%~a" (
set /a count=count+1
echo "%%~a">>"%~dp0filereader.log"
) else (
if "%ifolder:~-1%"=="\" (
call :check_path_length "%ifolder%%%~a"
) else call :check_path_length "%ifolder%\%%~a"
)
)
goto INPUT_DIR_SUBDIR
) else (
for /r "%ifolder%" %%a in ("%searchfilter%") do (
set /a count=count+1
echo "%%~a">>"%APPDATA%\filelist.log"
)
)
goto INPUT_DIR_COUNT0
:check_path_length
set "path_length=%~1"
if not "%path_length:~259%"=="" echo [ERROR] 文件路径超长(260字符上限)
goto :EOF
:INPUT_DIR_SUBDIR
rem 如果目标目录顶层没有文件则直接跳到下一步
if %count%==0 goto INPUT_DIR_COUNT0
rem 如果filter没有定义则直接跳到下一步(filter未定义表明不需要进行文件过滤)
if not defined filter goto INPUT_DIR_COUNT0
set "count=0"
rem 利用findstr从已知文件中取出符合搜索过滤的文件
findstr /I "%filter%" "%~dp0filereader.log">>"%APPDATA%\filelist.log"
rem 重新计数符合条件的文件
if defined dirin (
for /f "usebackq tokens=*" %%a in ("%APPDATA%\filelist.log") do set /a count=count+1
) else set count=1
rem 删除临时数据记录LOG
if exist "%~dp0filereader.log" del /q "%~dp0filereader.log"
:INPUT_DIR_COUNT0
rem 如果count记录的文件数为0,则报错
if %count%==0 if %searchfilter%==* (
echo [ERROR] 路径为空目录!
goto need_folder
) else (
echo 在路径下无法匹配到文件
echo 匹配规则无效!
choice /M 是否使用默认匹配规则
if %errorlevel%==1 set "searchfilter=*"
goto need_folder
)
rem 删除记录记录了目标目录及其子目录中的文件路径的log文件
if exist "%~dp0filereader.log" (
rename "%~dp0filereader.log" "filelist.log"
)
rem 获取目标目录中的所有文件,并逐次递交负责输出路径控制、MKV封装的模块
if defined dirin (
for /f "usebackq tokens=*" %%a in ("%APPDATA%\filelist.log") do (
if exist "%%~a" (
set "vpath=%%~a"
call :Module_GetOutputPath
call :Module_EncapsulationMKV
)
)
) else (
rem 如果是文件则仅处理一遍
call :Module_GetOutputPath
call :Module_EncapsulationMKV
)
:check_log_dir
dir /A:-D-I-L /S /B "%logdir%" 1>nul 2>nul
if not %errorlevel%==0 if exist "%logdir%" rmdir /S /Q "%logdir:~0,-1%"
:ld_has_file
dir /A:-D-I-L /S /B "%date_logdir%" 1>nul 2>nul
if not %errorlevel%==0 if exist "%date_logdir%" rmdir /S /Q "%date_logdir:~0,-1%"
:date_ld_has_file
dir /A:-D-I-L /S /B "%r_out_dir%" 1>nul 2>nul
if not %errorlevel%==0 if exist "%r_out_dir%" rmdir /S /Q "%r_out_dir:~0,-1%"
:Process_End
title [yyfll的批量混流程序] 混流完成!
if not "%debug_mode%"=="0" cls
if not "%nul_output%"=="0" if defined outpath echo [OutPath] 混流完成的文件输出到"%outpath%"
if %error% GTR 0 (
goto Has_Error
) else echo [共处理%count%项且全部处理成功]
echo 任务完成!
goto Batch_End
:Has_Error
echo [共处理%count%项,其中有%error%项未能成功处理]
if exist "%logdir%" CHOICE /C YN /M "是否要查看LOG文件?"
if "%errorlevel%"=="1" (
if exist "%logdir%" (
start %logdir%
) else echo 找不到log文件夹...
echo.
:Batch_End
rem 删除运行所需的文件列表
if exist "%rf%fonts_json.log" del /q "%rf%fonts_json.log"
if exist "%APPDATA%\filelist.log" del /q "%APPDATA%\filelist.log"
rem 如果是不是第三方调用则挂起
if "%~1"=="" pause
if not "%~1"=="" exit
set "ifolder="
goto main_UI
:Module_EncapsulationMKV
rem 如果被其他模块要求不执行封装,则立刻退出
if defined notwork set "notwork=" && goto :EOF
set /a working=working+1
title [yyfll的批量混流程序] 正在混流"%filename%"...(第%working%项/共%count%项)
if not "%debug_mode%"=="0" cls
set "setfile=%rf%mkvmerge_settings.json"
echo [Replace] 正在转义JSON...请稍等...
call :Module_ReplaceBackSlash "%opath%"
for /f "tokens=* usebackq" %%a in ("%USERPROFILE%\rforbat.log") do set "r_opath=%%~a"
(echo [
echo "-o",
if not "%nul_output%"=="0" (
echo "%r_opath%",
) else echo "NUL",
echo "--ui-language",
echo "%ui_language%",
echo "-v",
echo "--priority",
echo "%priority%",)>"%setfile%"
:GetSubtitle
rem 如果没有任何字幕文件,则直接跳到字体封装预处理模块
if not defined sub[0] goto Start_Encapsulation
set /a subnum=subnum-1
if %subnum%==0 (
call :GetSub_Num 0
set "sub[0]="
) else (
if defined sub[0] for /l %%a in (0,1,%subnum%) do call :GetSub_Num %%a
)
goto Start_Encapsulation
:GetSub_Num
if not defined sub[%1] goto :EOF
if defined sub[%1] for /f "tokens=2 delims==" %%a in ('set sub[%1]') do set "subname=%%a"
call :Module_ReplaceBackSlash "%subname%"
for /f "tokens=* usebackq" %%a in ("%USERPROFILE%\rforbat.log") do (
(echo "%%~a",)>>"%setfile%"
)
set "sub[%1]="
goto :EOF
:Start_Encapsulation
if not exist "%logdir%" mkdir "%logdir%" 2>nul
for /f "tokens=* usebackq" %%a in ("%rf%fonts_json.log") do (
(echo %%a)>>"%setfile%"
)
call :Module_ReplaceBackSlash "%vpath%"
for /f "tokens=* usebackq" %%b in ("%USERPROFILE%\rforbat.log") do (
(echo "%%~b",
echo "--title",
echo "[ASFMKV-%ver%] %filename%"
echo ]
)>>"%setfile%"
)
if not "%debug%"=="0" cls
call :show_custom_settings
echo.
rem 当nul_output为0时,将会把结果输出到NUL以在测试时不占用磁盘空间
call "%exein%" -i "%vpath%" --ui-language "%ui_language%"
:run_mkvmerge
set "debug_file=%logdir%DEBUG-%working%.log"
if "%nul_output%"=="0" (
set "r_level=2"
) else set "r_level=1"
call "%exein%" @"%setfile%"
if %errorlevel% GEQ %r_level% (
set /a error=error+1
echo [DEBUG.mkvmerge] 正在重新运行并重定向mkvmerge输出...
call "%exein%" -r "%debug_file%" @"%setfile%"
move /-y "%setfile%" "%logdir%DEBUG-%working%.json"
)
goto Encapsulation_OK
:Encapsulation_OK
if not "%nul_output%"=="0" (
if exist "%opath%" (
for %%a in ("%opath%") do set "filelen=%%~za"
) else (
set /a error=error+1
goto :EOF
)
)
if "%filelen%"=="0" set /a error=error+1 & del /q "%opath%" & goto :EOF
if not defined notdel if exist "%vpath%" for %%a in ("%vpath%") do set /a vfilelen=%%~za/1000
:DelRawFile
if defined notdel goto :EOF
set /a filelen=filelen/1000
if %filelen% GEQ %vfilelen% del /q "%vpath%" && for %%a in ("%vpath%") do rename "%opath%" "%%~na.mkv"
goto :EOF
:Module_ReplaceBatch
if "%~1"=="" (
goto RB.error_input
) else if "%~2"=="" (
goto RB.error_input
)
set "input_string=%~1"
if "%input_string:~0,1%"=="" (
echo [ERROR] 您没有输入任何字符!
goto RB.error_input
)
set "for_delims=%~2"
if "%for_delims%"=="" (
echo [ERROR] 您没有输入任何要替换的字符!
goto RB.error_input
)
setlocal enabledelayedexpansion
for /l %%a in (0,1,1) do set "delims[%%a]=!for_delims:~%%a!"
if defined delims[1] (
echo [ERROR] Replace对象必须是单个字符
goto RB.error_input
)
for /f "tokens=1* delims=%for_delims%" %%a in ("%input_string%") do (
if "%%~a%%~b"=="%input_string%" (
echo "%input_string:~1,-1%">"%USERPROFILE%\rforbat.log"
goto RB.end_clear
)
)
set "replace_to=%~3"
set "output_string="
set "loop=-1"
:RB.re_replace
set /a loop=loop+1
set "RB_cache=!input_string:~%loop%,1!"
if "%RB_cache%"=="" goto RB.replace_finish
if "%RB_cache%"=="%for_delims%" (
set "output_string=%output_string%%replace_to%"
) else set "output_string=%output_string%%RB_cache%"
goto RB.re_replace
:RB.replace_finish
echo "%output_string%">"%USERPROFILE%\rforbat.log"
:RB.end_clear
setlocal disabledelayedexpansion
set "RB_cache="
set "input_string="
set "output_string="
set "for_delims="
set "loop="
goto :EOF
:RB.error_input
echo [ERROR] 输入无效
pause
goto RB.end_clear
:Module_ReplaceBackSlash
if "%~1"=="" (
goto RBS.error_input
)
set "input_string=A%~1A"
set "for_delims=\"
setlocal enabledelayedexpansion
for /f "tokens=1* delims=%for_delims%" %%a in ("%input_string%") do (
if "%%~b"=="" (
echo "%input_string:~1,-1%">"%USERPROFILE%\rforbat.log"
set "input_string="
set "for_delims="
goto :EOF
)
)
set "replace_to=\\"
set "output_string="
for /f "tokens=1 delims=%for_delims%" %%a in ("%input_string%") do if not "%%a"=="" (
set "output_string=%%a"
)
set "loop=1"
:RBS.re_replace
set /a loop=loop+1
for /f "tokens=%loop% delims=%for_delims%" %%a in ("%input_string%") do if not "%%a"=="" (
set "output_string=%output_string%%replace_to%%%a"
goto RBS.re_replace
)
echo "%output_string:~1,-1%">"%USERPROFILE%\rforbat.log"
set "input_string="
set "output_string="
set "for_delims="
set "loop="
setlocal disabledelayedexpansion
goto :EOF
:RBS.error_input
echo [ERROR] 输入无效
setlocal disabledelayedexpansion
pause
goto :EOF
:Module_GetOutputPath
goto Get_Output_Path
:SubNum
rem INPUT_VALUE_1:字幕文件路径(不含扩展名)
if "%subdir%"=="0" (
rem 从1902-2开始启用subdir时直接遍历filelist而不是整个目录树,以此降低磁盘使用率
for /f "usebackq tokens=*" %%a in ("%APPDATA%\filelist.log") do (
for /f "tokens=*" %%b in ("%~1") do (
rem 在filelist中寻找是否有目标字幕文件
if "%%~nxa"=="%%~nxb" (
rem echo "%%~a"="%%~b"
set "sub[%subnum%]=%~1"
set /a subnum=subnum+1
goto SubNum_loop
)
)
)
) else (
set "sub[%subnum%]=%~1"
set /a subnum=subnum+1
)
:SubNum_loop
rem pause
goto :EOF
:SubNum_DVDSUB
for %%a in ("%~1") do if not exist "%%~dpna.sub" goto :EOF
call :SubNum "%~1"
goto :EOF
:FontNum
if "%subdir%"=="0" (
rem 从1902-2开始启用subdir时直接遍历filelist而不是整个目录树,以此降低磁盘使用率
for /f "usebackq tokens=*" %%a in ("%APPDATA%\filelist.log") do (
for /f "tokens=*" %%b in ("%~1") do (
rem 在filelist中寻找是否有目标字体文件
if "%%~nxa"=="%%~nxb" (
set /a fontnum=fontnum+1
goto FontNum_loop
)
)
)
) else (
set /a fontnum=fontnum+1
goto FontNum_loop
)
goto :EOF
:FontNum_loop
if /i "%~x1"==".ttc" (
set "ftype=application/x-truetype-font"
) else if /i "%~x1"==".otf" (
set "ftype=application/vnd.ms-opentype"
) else if /i "%~x1"==".ttf" (
set "ftype=application/x-truetype-font"
) else goto :EOF
call :Module_ReplaceBackSlash "%~1"
for /f "tokens=* usebackq" %%a in ("%USERPROFILE%\rforbat.log") do (
(echo "--attachment-mime-type",
echo "%ftype%",
echo "--attach-file",
echo "%%~a",)>>"%rf%fonts_json.log"
)
goto :EOF
:Get_Output_Path
for %%a in ("%vpath%") do set "ext=%%~xa"
for /f "tokens=1* delims==" %%b in ('set extlist[') do (
if "%ext%"==".%%~c" (
goto ext_check_over
)
)
set notwork=0
set /a working=working+1
goto :EOF
:ext_check_over
for %%a in ("%vpath%") do (
set "ostring=%%~dpna"
set "filename=%%~na"
set "odir=%%~dpa"
)
if not defined outpath set "outpath=%odir%REMUX"
if defined outpath (
if not "%outpath%"=="" (
if not exist "%outpath%" mkdir "%outpath%">nul
for %%a in ("%outpath%") do set "test=%%~aa"
)
)
if defined test if "%test:~0,1%"=="d" if "%test:~-1%"=="\" (
set "ostring=%outpath%%filename%"
) else set "ostring=%outpath%\%filename%"
set "test="
set "subnum=0"
set "fontnum=0"
rem 1902-2开始不再遍历两次目录树而是直接利用if分开DVD字幕和一般字幕
for /r "%ifolder%" %%a in ("*%filename%*.ass","*%filename%*.ssa","*%filename%*.srt","*%filename%*.sup","*%filename%*.idx") do if not "%%~xa"==".idx" (
call :SubNum "%%~a"
) else call :SubNum_DVDSUB "%%~a"
if not defined notfont goto notget_font
if not exist "%rf%fonts_json.log" (
for /r "%ifolder%" %%a in ("*.ttf","*.ttc","*.otf") do call :FontNum "%%~a"
)
:notget_font
set "file="
if defined notsub if not defined sub[0] (
if not defined font[0] (
set "notwork=0"
goto :EOF
)
set "notwork="
goto Start_Get_Output_Path
) else if not defined font[0] (
set "notwork=0"
goto :EOF
)
if not defined sub[0] (
set "notwork=0"
goto :EOF
)
:Start_Get_Output_Path
set "ostring=%ostring%[SUB]"
set filenum=1
if not exist "%ostring%.mkv" (
set "opath=%ostring%.mkv"
goto :EOF
)
:ReGet_Output_Path