-
Notifications
You must be signed in to change notification settings - Fork 0
/
RenameSubtitles_RE_v1.0.12.bat
2340 lines (2126 loc) · 63 KB
/
RenameSubtitles_RE_v1.0.12.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
@echo off
chcp 65001 1>nul 2>nul
:DEBUG
if not defined debug (
echo [M_DE] 正在启动DEBUG层
set "debug=1"
cmd /c call "%~0"
set "debug="
title %ComSpec%
echo [M_DE] 运行结束
pause
goto :EOF
)
:rsr.GENERAL_SETTINGS
rem -------------------------------------------------------
rem GENERAL SEARCH SETTINGS 全局参数设置
rem -------------------------------------------------------
rem [ext_filters]
rem [subext]:字幕扩展名过滤
rem [vidext]:视频扩展名过滤
rem 控制AUTO模式扩展名过滤器可输入的扩展名
rem 注意:必须在整个变量的尾部也加上一个";",否则无法读取最后一个扩展名
set "subext=ass;ssa;srt;idx;pgs;sup;smi;"
set "vidext=mp4;m4v;mkv;m2ts;avi;mpeg;mpg;wmv;"
rem -------------------------------------------------------
rem [subdir]
rem [vid]: 视频搜索控制
rem [ass]: 字幕搜索控制
rem 控制搜索时是否对子目录也进行搜索
set "ass_subdir=0"
set "vid_subdir=0"
rem 可用值
rem {未定义}:对子目录进行搜索
rem {任意值}:放弃对子目录的搜索
rem 注
rem {未定义}即直接 set "ass_subdir=" 不需要空格
rem -------------------------------------------------------
rem [cache_dir]
rem 缓存文件的临时存放路径
set "cache_dir=%~dp0"
rem 可用值
rem {未定义}: 默认为"%~dp0"
rem {可用路径}: 任何能够正常访问或能够被创建的文件夹
rem 推荐值
rem {%~dp0}: 即BATCH所在位置
rem {%TEMP%/%TMP%}: 系统缓存TEMP文件夹
rem -------------------------------------------------------
rem [check_same]
rem 是否要判断字幕已经与视频匹配
rem 该选项会明显降低匹配速度
set "check_same=1"
rem 可用值
rem {未定义}: 不启用
rem {任意值}: 启用
rem -------------------------------------------------------
rem [check_same_ex]
rem 启用使用命令扩展的check_same
rem 可能出现某些奇怪的错误,但速度非常快
set "check_same_ex=1"
rem 可用值
rem {未定义}: 不启用
rem {任意值}: 启用
rem -------------------------------------------------------
rem [echo_debug]
rem 关闭所有屏幕清空指令并开启命令回显
set "echo_debug="
rem 可用值
rem {未定义}: 不启用
rem {任意值}: 启用
:rsr.AUTOMODE_SETTINGS
rem -------------------------------------------------------
rem AUTO SEARCH MODE SETTINGS 自动模式参数设置
rem -------------------------------------------------------
rem [show_howlong]
rem 显示一次compare到底花费了多长时间,启用该功能可能会慢几毫秒
set "show_howlong=0"
rem 可用值
rem {未定义}:不显示
rem {任意值}:显示
rem -------------------------------------------------------
rem [compare_limit]
rem 控制compare_string误差量的最大值,超过该值则放弃继续搜索
set "compare_limit=6"
rem 可用值
rem {1~n(正整数)}
rem {空缺}(不放弃搜索)
rem 推荐值
rem {误差量+2}(可以防止出错)
rem -------------------------------------------------------
rem [compare_limit_method]
rem 控制达到compare_string误差量的最大值后的长度运算方式
set "compare_limit_method="
rem 可用值
rem {任意值}: 计算字符串的全长,与误差位置相减来得到误差量
rem {空缺}: 直接赋值"-2*%deviation_a%"(速度比较快)
rem -------------------------------------------------------
rem [drop_minus]
rem 控制在 compare_limit_method 设置为空缺时,是否要丢弃误差量为负的结果
set "drop_minus=0"
rem 可用值
rem {任意值}: 丢弃误差量为负的结果
rem {空缺}: 不丢弃
rem -------------------------------------------------------
rem [number_deviation]
rem 控制最终规则决策时允许误差值
rem 集数长度将从该误差范围中选取最小值,集数位置将会选取最大值
rem [deviation_a] 集数长度容差
set "deviation_a=2"
rem [deviation_b] 集数位置容差
set "deviation_b=1"
rem 可用值
rem {a=1~n,b=1~n(正整数)}
rem {留空}(使用默认值,a=2 b=1)
rem 推荐值
rem {a=2,b=1}(对于集数不超过100的)
rem {a=集数长度,b=集数长度-1}
rem -------------------------------------------------------
rem [count_range]
rem 控制compare_list进行比较的项数,可以加快AUTO,但错误率增大
set "count_range=15"
rem 可用值
rem {1~n(正整数)}(从0开始计数,即=15时会比较16项)
rem {留空}(不启用,即全项目检索)
rem 推荐值
rem {10~20}(不建议少于10)
rem {≥100}(对于集数超过100的)
rem -------------------------------------------------------
rem [ls_step]
rem 控制long_string每一循环计数的字符量,值越大对长字符串的计数就越快,但对短字符串就越慢
set "ls_step=5"
rem 可用值
rem {1~n(正整数)}
rem 推荐值
rem {5~10}
rem -------------------------------------------------------
rem [com_step]
rem 控制compare_string每一循环计数的字符量,值越大对长字符串的计数就越快,但对短字符串就越慢
set "com_step=5"
rem 可用值
rem {1~n(正整数)}
rem 推荐值
rem {5~10}
rem -------------------------------------------------------
rem [use_same_long_filename]
rem [same_long_v]:用于视频搜索
rem [same_long_s]:用于字幕搜索
rem
rem 该选项控制是否启用旧的 同长度文件名筛选 算法
rem 在该旧算法下,只有同样长度的文件会进行对比
rem 适用于规范的、格式化的、有一定规律的文件名
set "same_long_v="
set "same_long_s="
rem 可用值
rem {未定义}:不使用该算法
rem {任意值}:使用旧算法
rem 注
rem {未定义}即直接 set "same_long_v=" 不需要空格
rem -------------------------------------------------------
rem [enable_ext_use_most]
rem [ext_use_most_v]:用于视频搜索
rem [ext_use_most_s]:用于字幕搜索
rem 该选项控制是否启用旧的 扩展名筛选 算法
rem 在该算法下,只有文件夹下文件数量最多的扩展名才会被使用
rem 适用于普遍使用同一扩展名的文件
set "ext_use_most_v="
set "ext_use_most_s="
rem 可用值
rem {未定义}:不使用该算法
rem {任意值}:使用旧算法
rem 注
rem {未定义}即直接 set "ext_use_most_v=" 不需要空格
rem -------------------------------------------------------
:rsr.MAIN_LOAD
if defined echo_debug @echo on
if not "%cache_dir:~-1%"=="\" set "cache_dir=%cache_dir%\"
echo a>"%cache_dir%test.txt" 2>nul
if %errorlevel%0 GEQ 10 (
set "cache_dir=%~dp0"
) else (
del /q "%cache_dir%test.txt"
goto :get_cache_dir
)
echo a>"%cache_dir%test.txt"
if %errorlevel%0 GEQ 10 (
if exist "%Temp%" (
if not exist "%Temp%\RENAMESUBTITLES_FSM_CACHE" md "%Temp%\RENAMESUBTITLES_FSM_CACHE"
if exist "%Temp%\RENAMESUBTITLES_FSM_CACHE" (
set "cache_dir=%Temp%\RENAMESUBTITLES_FSM_CACHE"
) else (
echo [ERROR] Can't make "%Temp%\RENAMESUBTITLES_FSM_CACHE" DIR
pause
goto :EOF
)
) else (
echo [ERROR] "%Temp%" DIR not found
pause
goto :EOF
)
) else del /q "%cache_dir%test.txt"
:get_cache_dir
if exist "%cache_dir%" if not "%cache_dir%"=="%~dp0" if not "%cache_dir%"=="%Temp%\" set "remove_cache_dir=0"
set "prefile=%cache_dir%rename_preview.log"
set "logfile=%cache_dir%rename_log.log"
set "vpfile=%cache_dir%vp_cache.log"
set "undofile=%cache_dir%undo_rename.log"
set "vffile=%cache_dir%vf_rename.log"
set "sffile=%cache_dir%sf_rename.log"
set "vsnfile=%cache_dir%vsn_rename.log"
set "sgetfile=%cache_dir%Sget_rename.log"
if exist "%undofile%" del /q "%undofile%"
if exist "%prefile%" del /q "%prefile%"
if exist "%logfile%" del /q "%logfile%"
if exist "%vpfile%" del /q "%vpfile%"
if exist "%vffile%" del /q "%vffile%"
if exist "%sffile%" del /q "%sffile%"
if exist "%vsnfile%" del /q "%vsnfile%"
if exist "%sgetfile%" del /q "%sgetfile%"
echo.
echo [PCHK] 正在检查控制变量
if not defined deviation_a (
set "deviation_a=2"
echo [ASET] deviation_a=2
) else if %deviation_a%0 LSS 10 (
set "deviation_a=2"
echo [ASET] deviation_a=2
) else echo [PCHK] deviation_a=%deviation_a%
if not defined deviation_b (
set "deviation_b=1"
echo [ASET] deviation_b=1
) else if %deviation_b%0 LSS 10 (
set "deviation_b=1"
echo [ASET] deviation_b=1
) else echo [PCHK] deviation_b=%deviation_b%
if not defined com_step (
set "com_step=5"
echo [ASET] com_step=5
) else if 0%com_step% LSS 1 (
set "com_step=5"
echo [ASET] com_step=5
) else echo [PCHK] com_step=%com_step%
if not defined ls_step (
set "ls_step=5"
echo [ASET] ls_step=5
) else if %ls_step%0 LSS 10 (
set "ls_step=5"
echo [ASET] ls_step=5
) else echo [PCHK] ls_step=%ls_step%
if defined count_range (
if %count_range%0 LSS 10 (
set "count_range=15"
echo [ASET] count_range=15
) else echo [PCHK] count_range=%count_range%
)
if defined compare_limit (
if not %compare_limit%0 GTR %deviation_a%0 (
set /a compare_limit=deviation_a+2
echo [ASET] compare_limit=%deviation_a%+2
) else echo [PCHK] compare_limit=%compare_limit%
)
set "test=aba"
if "%test:b=a%"=="aaa" (
set "use_new_echo=0"
) else set "use_new_echo="
set "test="
cls
set "bat_ver=RenameSubtitles RE: Ver1.0.12(q) UTF-8"
title %bat_ver% [(c) yyfll]
echo [INFO] %bat_ver%
echo [INFO] Copyright(c) 2019-2021 yyfll
echo [CDIR] "%cache_dir%"
:MAIN
echo.
set "v_path="
echo [ 视频目录 ]
set /p v_path=[V_IN] V_PATH:
rem goto v_check_end
echo [CHKV] 正在检查视频目录CMD兼容性及可用性
cmd /c if "%v_path:~1,-1%"=="%v_path:~1,-1%" echo. 1>nul 2>NUL
if "%errorlevel%"=="0" if exist "%v_path:~1,-1%" (
set "v_path=%v_path:~1,-1%"
goto vpath_chk_over
)
cmd /c if "%v_path%"=="%v_path%" echo. 1>nul 2>NUL
if "%errorlevel%"=="0" if exist "%v_path%" (
set "v_path=%v_path%"
goto vpath_chk_over
)
cmd /c if "%v_path:~1%"=="%v_path:~1%" echo. 1>nul 2>NUL
if "%errorlevel%"=="0" if exist "%v_path:~1%" (
set "v_path=%v_path:~1%"
goto vpath_chk_over
)
cmd /c if "%v_path:~0,-1%"=="%v_path:~0,-1%" echo. 1>nul 2>NUL
if "%errorlevel%"=="0" if exist "%v_path:0,-1%" (
set "v_path=%v_path:~0,-1%"
goto vpath_chk_over
)
echo [ERRV] 不受支持的非法路径
echo [INFO] 可能是您的路径中含有非法字符
goto MAIN
:vpath_chk_over
for /f "tokens=*" %%a in ("%v_path%") do (
set "v_path_a=%%~aa"
)
if not "%v_path_a:~0,1%"=="d" (
echo [ERRV] 您输入的路径不是目录路径
goto MAIN
)
for /f "tokens=1,2 delims=*" %%a in ("%v_path%") do (
if not "%v_path:~-1%"=="*" (
if "%%~b"=="" goto vpc.vpath_choose_end
)
)
set "list_count=0"
for /d %%a in ("%v_path%") do if exist "%%~a" call :vpc.write_vpath_list "%%~a"
goto vpc.show_vpath_list
:vpc.write_vpath_list
if %list_count% LSS 10 (
set "v_path0%list_count%=%~1"
) else set "v_path%list_count%=%~1"
set /a list_count=list_count+1
goto :EOF
:vpc.show_vpath_list
if %list_count%==1 (
set "v_path=%v_path00%"
echo [FRFC] 自动套用唯一匹配文件夹"%v_path00%"
goto vpc.vpath_choose_end
) else if %list_count%==0 (
echo [ERROR] 没有找到匹配"%v_path%"的目录
goto Main
)
cls
echo [Module] FRF通配路径选择器 视频路径
echo.
set "v_path="
for /f "tokens=1* delims==" %%a in ('set v_path') do (
call :vpc.show_list_2 "%%~a" "%%~b"
)
echo.
:vpc.path_choose
set "v_path_count="
echo 请选择您要输入的目录(填路径前括号内的数字,零开头的可省略零)
set /p v_path_count=:
if "%v_path_count%" GTR "%list_count%" (
echo [ERROR] "%sub_path_count%"^|MAX:"%list_count%-1"
echo [ERROR] 输入不正确!
goto spc.path_choose
)
for /f "tokens=1,2 delims= " %%a in ("%v_path_count%") do (
if not "%%~b"=="" (
echo [ERROR] 输入不能带有空格!
echo [ERROR] 输入不正确!
goto spc.path_choose
)
)
if defined v_path0%v_path_count% (
for /f "tokens=1* delims==" %%a in ('set v_path0%v_path_count%') do (
set "dircache=%%~b"
)
for /f "tokens=1* delims==" %%a in ('set v_path') do set "%%~a="
) else if defined v_path%v_path_count% (
for /f "tokens=1* delims==" %%a in ('set v_path%v_path_count%') do (
set "dircache=%%~b"
)
for /f "tokens=1* delims==" %%a in ('set v_path') do set "%%~a="
) else (
echo [ERROR] 找不到"v_path%v_path_count%"
goto vpc.path_choose
)
set "v_path=%dircache%"
set "dircache="
set "listitem="
set "listitem2="
cls
echo [VPCS] 您选择了目录"%v_path%"!
goto vpc.vpath_choose_end
:vpc.show_list_2
set "listitem=%~1"
set "listitem2=%~2"
echo [%listitem:~6%] "%listitem2%"
goto :EOF
:vpc.vpath_choose_end
if not exist "%v_path%" (
echo [V_EX] 找不到视频路径
goto MAIN
)
echo [CHKV] 视频目录确认成功
if not "%v_path:~-1%"=="\" (
set "v_path=%v_path%\"
) else set "v_path=%v_path%"
:MAIN_S
echo.
set "sub_path="
echo [ 字幕目录(留空默认同视频目录) ]
set /p sub_path=[S_IN] S_PATH:
if not defined sub_path (
echo [VOID] 自动套用视频目录
set "sub_path=%v_path%"
goto s_check_end
)
echo [CHEK] 正在检查字幕目录CMD兼容性及可用性
echo.
cmd /c if "%sub_path:~1,-1%"=="%sub_path:~1,-1%" echo. 1>nul 2>NUL
if "%errorlevel%"=="0" if exist "%sub_path:~1,-1%" (
set "sub_path=%sub_path:~1,-1%"
goto spath_chk_over
)
cmd /c if "%sub_path%"=="%sub_path%" echo. 1>nul 2>NUL
if "%errorlevel%"=="0" if exist "%sub_path%" (
set "sub_path=%sub_path%"
goto spath_chk_over
)
cmd /c if "%sub_path:~1%"=="%sub_path:~1%" echo. 1>nul 2>NUL
if "%errorlevel%"=="0" if exist "%sub_path:~1%" (
set "sub_path=%sub_path:~1%"
goto spath_chk_over
)
cmd /c if "%sub_path:~0,-1%"=="%sub_path:~0,-1%" echo. 1>nul 2>NUL
if "%errorlevel%"=="0" if exist "%sub_path:~0,-1%" (
set "sub_path=%sub_path:~0,-1%"
goto spath_chk_over
)
echo [ERRV] 不受支持的非法路径
echo [INFO] 可能是您的路径中含有非法字符
goto MAIN_S
:spath_chk_over
for /f "tokens=*" %%a in ("%sub_path%") do (
set "sub_path_a=%%~aa"
)
if not "%sub_path_a:~0,1%"=="d" (
echo [ERRS] 您输入的路径不是目录路径
goto MAIN_S
)
for /f "tokens=1,2 delims=*" %%a in ("%sub_path%") do (
if not "%sub_path:~-1%"=="*" (
if "%%~b"=="" goto spc.vpath_choose_end
)
)
set "list_count=0"
for /d %%a in ("%sub_path%") do if exist "%%~a" call :spc.write_vpath_list "%%~a"
goto spc.show_vpath_list
:spc.write_vpath_list
if %list_count% LSS 10 (
set "sub_path0%list_count%=%~1"
) else set "sub_path%list_count%=%~1"
set /a list_count=list_count+1
goto :EOF
:spc.show_vpath_list
if %list_count%==1 (
set "sub_path=%sub_path00%"
echo [FRFC] 自动套用唯一匹配文件夹"%sub_path00%"
goto spc.vpath_choose_end
) else if %list_count%==0 (
echo [ERROR] 没有找到匹配"%sub_path%"的目录
goto Main
)
cls
echo [Module] FRF通配路径选择器 字幕路径
echo.
set "sub_path="
for /f "tokens=1* delims==" %%a in ('set sub_path') do (
call :spc.show_list_2 "%%~a" "%%~b"
)
echo.
:spc.path_choose
set "sub_path_count="
echo 请选择您要输入的目录(填路径前括号内的数字,零开头的可省略零)
set /p sub_path_count=:
if "%sub_path_count%" GTR "%list_count%" (
echo [ERROR] "%sub_path_count%"^|MAX:"%list_count%-1"
echo [ERROR] 输入不正确!
goto spc.path_choose
)
for /f "tokens=1,2 delims= " %%a in ("%sub_path_count%") do (
if not "%%~b"=="" (
echo [ERROR] 输入不能带有空格!
echo [ERROR] 输入不正确!
goto spc.path_choose
)
)
if defined sub_path0%sub_path_count% (
for /f "tokens=1* delims==" %%a in ('set sub_path0%sub_path_count%') do (
set "dircache=%%~b"
)
for /f "tokens=1* delims==" %%a in ('set sub_path') do set "%%~a="
) else if defined sub_path%sub_path_count% (
for /f "tokens=1* delims==" %%a in ('set sub_path%sub_path_count%') do (
set "dircache=%%~b"
)
for /f "tokens=1* delims==" %%a in ('set sub_path') do set "%%~a="
) else (
echo [ERROR] 找不到"sub_path%sub_path_count%"
goto spc.path_choose
)
set "sub_path=%dircache%"
set "dircache="
set "listitem="
set "listitem2="
cls
echo [VINP] 视频目录: "%v_path%"
echo [SPCS] 您选择了目录"%sub_path%"!
goto spc.vpath_choose_end
:spc.show_list_2
set "listitem=%~1"
set "listitem2=%~2"
echo [%listitem:~8%] "%listitem2%"
goto :EOF
:spc.vpath_choose_end
if defined path_inv (
set "path_inv="
goto MAIN_S
)
if not exist "%sub_path%" (
echo [S_EX] 找不到字幕路径
goto MAIN_S
)
echo [CHKS] 字幕目录确认成功
if not "%sub_path:~0,-1%"=="\" set "sub_path=%sub_path%\"
:s_check_end
echo.
echo [ 自动生成匹配规则 即通过分析文件名寻找匹配规则 ]
echo [ 由于批量处理程序比较简单 分析出错率比较大 ]
echo [ 而且自动 非常慢! 非常慢! 非常慢! 非常慢! ]
echo [ 不是很懒的人非常非常非常建议手动输入匹配规则 ]
echo [ 预计时长 约6分钟完成13话分析 于 酷睿2DuoP8400 ]
echo [ 自动匹配 ([y]尝试/[n]不尝试) ]
set /p auto=[AUTO] Auto[y/n]?:
if /i "%auto%"=="y" (
goto AUTO_POINT
) else if /i "%auto%"=="n" (
set "auto="
) else (
set "auto="
)
echo.
echo [ 匹配规则即如何匹配视频 请用半角冒号代替集数 ]
echo [ 例如[CASO][El_Cazador][GB_BIG5][01][DVDRIP] ]
echo [ 替换成[CASO][El_Cazador][GB_BIG5][::][DVDRIP] ]
echo [ 如果视频有非常麻烦的如校验值在文件名结尾 ]
echo [ 请使用通配符 如[CASO][*][GB_BIG5][::][* ]
:v_filter.get
set "filter="
echo [ 视频匹配规则 ]
set /p filter=[V_FI] V_FILTER:
echo.
if not defined filter (
echo [ERRF] 您没有输入匹配规则
goto v_filter.get
)
:s_filter.get
echo [ 字幕匹配规则 ]
set /p s_filter=[S_FI] S_FILTER:
echo.
if not defined s_filter (
echo [ERRF] 您没有输入匹配规则
goto s_filter.get
)
:AUTO_POINT
if defined auto (
cls
echo 在自动搜索之前,我们需要您填写一些必要信息
echo.
)
echo [ 剧集范围即是从多少集到多少集 请以 1,24 表示 ]
echo [ 如我的片有52话 从第01话开始 那么我就写1,52 ]
echo [ 注意必须要用半角逗号 , 否则不被识别 ]
:re_get_ep
echo [ 剧集范围 ]
set /p ep=[EP_R] EP_Range:
for /f "tokens=1,2 delims=," %%a in ("%ep%") do (
if "%%~a"=="" (
echo [ERRE] 剧集输入有误
goto re_get_ep
)
if "%%~b"=="" (
echo [ERRE] 剧集输入有误
goto re_get_ep
)
)
:re_get_annotate
echo.
echo [ 字幕注释信息即文件名后跟的如 .CASO-sc 这样的 ]
echo [ 这种用于表示字幕组与字幕语言的文本 就是注释 ]
echo [ 如[YYDM-11FANS][Rozen Maiden][01].CASO-sc.ass ]
echo [ 多字幕注释:使用":"(半角冒号)隔开每个注释 ]
echo [ 本批处理按照名称排序进行搜索,具体先后顺序 ]
echo [ 与资源管理器中文件夹在最上方的名称排序相同 ]
echo [ 字幕注释(可以留空) ]
set /p s_rem=[SANN] S_Annotate:
rem if not defined echo_debug cls
echo.
setlocal EnableDelayedExpansion
if defined subext[0] if defined vidext[0] goto pre.get_vid_extlist_end
:pre.toList
echo [LIST] 正在转换扩展名表
set "ass_loop=0"
set "ass_count=0"
set "ass_start=0"
:pre.get_sub_extlist
set "a_char=!subext:~%ass_loop%,1!"
if "%a_char%"=="" goto pre.get_sub_extlist_end
if not "%a_char%"==";" (
set /a ass_loop=ass_loop+1
goto pre.get_sub_extlist
)
for /f "tokens=*" %%a in ('set /a ass_loop-ass_start') do (
set "subext[%ass_count%]=.!subext:~%ass_start%,%%~a!"
)
set /a ass_count=ass_count+1
set /a ass_loop=ass_loop+1
set "ass_start=%ass_loop%"
goto pre.get_sub_extlist
:pre.get_sub_extlist_end
set "ass_loop=0"
set "ass_count=0"
set "ass_start=0"
:pre.get_vid_extlist
set "a_char=!vidext:~%ass_loop%,1!"
if "%a_char%"=="" goto pre.get_vid_extlist_end
if not "%a_char%"==";" (
set /a ass_loop=ass_loop+1
goto pre.get_vid_extlist
)
for /f "tokens=*" %%a in ('set /a ass_loop-ass_start') do (
set "vidext[%ass_count%]=.!vidext:~%ass_start%,%%~a!"
)
set /a ass_count=ass_count+1
set /a ass_loop=ass_loop+1
set "ass_start=%ass_loop%"
goto pre.get_vid_extlist
:pre.get_vid_extlist_end
setlocal DisableDelayedExpansion
echo [LIST] Complete making EXT lists.
if not defined s_rem (
if defined auto (
goto START_AUTO
) else goto AUTO_BACK
)
for /f "tokens=1,2 delims=:" %%a in ("%s_rem%") do if "%%~b"=="" (
if not "%s_rem:~0,1%"=="." set "s_rem=.%s_rem%"
if defined auto (
goto START_AUTO
) else goto AUTO_BACK
)
echo [SREM] 正在切分多字幕注释,请稍等...
set "work_s_rem=%s_rem%"
set "count_s_rem=0"
set "s_rem[0]="
set "s_rem="
set "cache_s_rem="
:more_rem_cut
if not defined work_s_rem (
if not "%cache_s_rem:~0,1%"=="." (
set "s_rem[%count_s_rem%]=.%cache_s_rem%"
) else set "s_rem[%count_s_rem%]=%cache_s_rem%"
goto chkann.load
)
if not "%work_s_rem:~0,1%"==":" (
set "cache_s_rem=%cache_s_rem%%work_s_rem:~0,1%"
) else (
if not "%cache_s_rem:~0,1%"=="." (
set "s_rem[%count_s_rem%]=.%cache_s_rem%"
) else set "s_rem[%count_s_rem%]=%cache_s_rem%"
set /a count_s_rem=count_s_rem+1
set "cache_s_rem="
)
set "work_s_rem=%work_s_rem:~1%"
goto more_rem_cut
:chkann.load
cls
echo [Multi-Annotate Check]
echo (注释前的点 "." 是自动添加的)
echo 请确认您的注释是否为以下值:
echo.
if defined s_rem[0] (
for /f "tokens=1* delims==" %%a in ('set s_rem[') do echo %%~b
) else (
echo %s_rem%
)
echo.
choice /M 输入Y继续,输入N重新键入注释
if not "%errorlevel%"=="1" (
for /f "tokens=1* delims==" %%a in ('set s_rem[') do set "%%~a="
goto re_get_annotate
)
if not defined s_rem[0] (
if defined auto (
goto START_AUTO
) else goto AUTO_BACK
)
:chkann.reorder
echo.
if defined s_rem_cache[0] (
for /l %%a in (0,1,%count_s_rem%) do (
for /f "tokens=1* delims==" %%b in ('set s_rem_cache[%%a]') do (
set "s_rem[%%~a]=%%~c"
set "s_rem_cache[%%~a]="
)
)
cls
echo 已为您颠倒注释顺序
)
set "annchk_temp=-1"
echo 请确认您的注释顺序是否与CMD读取文件的顺序相符:
echo.
for /f "tokens=1* delims==" %%a in ('set subext[') do (
if defined ass_subdir (
for /f "tokens=* delims=^|" %%c in ('dir /A:-D /B "%sub_path%*%%~b" 2^>NUL') do (
call :chkann.show "%%~c"
)
) else (
for /f "tokens=* delims=^|" %%c in ('dir /A:-D /B /S "%sub_path%*%%~b" 2^>NUL') do (
call :chkann.show "%%~c"
)
)
)
echo.
choice /M 输入Y继续,输入N重新键入注释,输入R颠倒注释顺序 /C YNR
if "%errorlevel%"=="3" (
for /l %%a in (0,1,%count_s_rem%) do (
for /f "tokens=1* delims==" %%b in ('set s_rem[%%a]') do (
for /f "tokens=*" %%d in ('set /a %count_s_rem%-%%a') do (
set "s_rem_cache[%%~d]=%%~c"
)
)
)
goto chkann.reorder
) else if "%errorlevel%"=="2" goto re_get_annotate
if defined auto (
goto START_AUTO
) else goto AUTO_BACK
:chkann.show
set /a annchk_temp=annchk_temp+1
for /f "tokens=1* delims==" %%a in ('set s_rem[%annchk_temp%]') do echo [%%~b] --^> "%~1"
if %annchk_temp%==%count_s_rem% (
set "annchk_temp=-1"
)
goto :EOF
:START_AUTO
goto auto
:AUTO_BACK
if defined s_rem[0] if not defined s_rem[1] (
set "s_rem=%s_rem[0]%"
set "s_rem[0]="
set "count_s_rem="
) else (
set "s_rem="
)
if not defined echo_debug cls
echo [WORK] 正在匹配规则中寻找剧集位置...
:GET_COUNT
set "get_loop=0"
set "instr[0]="
set "instr[1]="
set "get_count=0"
set "stop_count=0"
echo [V_FI] 视频匹配规则"%filter%"
set "working_filter=0%filter%"
:FIND_COUNT
set "working_filter=%working_filter:~1%"
if not defined working_filter goto END_FIND_COUNT
set "a_char=%working_filter:~0,1%"
if "%a_char%"==":" (
set /a get_count=get_count+1
if not defined instr[0] (
set "instr[0]=%get_loop%"
) else set /a stop_count=stop_count+1
)
if %stop_count% GTR 0 goto END_FIND_COUNT
if not "%a_char%"=="" (
set /a get_loop=get_loop+1
goto FIND_COUNT
) else goto END_FIND_COUNT
goto FIND_COUNT
:END_FIND_COUNT
set "instr[1]=%get_count%"
echo [VINS] 在视频匹配规则中找到位置%instr[0]%,长度%instr[1]%
if not defined s_filter goto END_FIND_SUB_COUNT
set "get_loop=0"
set "s_instr[0]="
set "s_instr[1]="
set "get_count=0"
set "stop_count=0"
echo [S_FI] 字幕匹配规则"%s_filter%"
set "working_filter=0%s_filter%"
:FIND_SUB_COUNT
set "working_filter=%working_filter:~1%"
if not defined working_filter goto END_FIND_SUB_COUNT
set "a_char=%working_filter:~0,1%"
if "%a_char%"==":" (
set /a get_count=get_count+1
if not defined s_instr[0] (
set "s_instr[0]=%get_loop%"
) else set /a stop_count=stop_count+1
)
if %stop_count% GTR 0 goto END_FIND_SUB_COUNT
if not "%a_char%"=="" (
set /a get_loop=get_loop+1
goto FIND_SUB_COUNT
) else goto END_FIND_SUB_COUNT
goto FIND_SUB_COUNT
:END_FIND_SUB_COUNT
set "working_filter="
set "s_instr[1]=%get_count%"
echo [SINS] 在字幕匹配规则中找到位置%s_instr[0]%,长度%s_instr[1]%
echo.
:LOOP_NUM
title %bat_ver% ^| 视频字幕匹配中...
for /f "tokens=1,2 delims=," %%a in ("%ep%") do (
for /l %%c in (%%~a,1,%%~b) do (
echo [LOOP] 尝试匹配剧集%%~c
call :SEARCH_VIDEO "%%~c"
if not defined not_work (
call :SEARCH_ASS "%sub_path%" "%s_filter%" "%%~c"
) else set "not_work="
)
)
if not exist "%prefile%" (
echo [ERR_] 找不到匹配的重命名项
goto end_batch
)
if not exist "%logfile%" (
echo [ERR_] 找不到匹配的重命名项
goto end_batch
)
:preview_check
if not defined echo_debug cls
title %bat_ver% ^| 重命名预览
echo [PREV] 重命名预览
echo.
type "%prefile%"
echo [PREV] 预览显示完毕
choice /M "[CHK_] 要执行这样的重命名吗?"
if %errorlevel%==0 goto preview_check
if %errorlevel%==1 (
echo.
for /f "usebackq tokens=1,2 delims=^|" %%a in ("%logfile%") do (
call :rename_sub "%%~a" "%%~b"
)
if exist "%prefile%" if not "%sub_path:~-1%"=="\" (
move /y "%prefile%" "%sub_path%\rename_log.log"
if exist "%undofile%" move /y "%undofile%" "%sub_path%\undo_rename.log"
) else (
move /y "%prefile%" "%sub_path%rename_log.log"
if exist "%undofile%" move /y "%undofile%" "%sub_path%undo_rename.log"
)
)
:end_batch
if exist "%undofile%" del /q "%undofile%"
if exist "%logfile%" del /q "%logfile%"
if exist "%prefile%" del /q "%prefile%"
if exist "%vpfile%" del /q "%vpfile%"
if exist "%vffile%" del /q "%vffile%"
if exist "%sffile%" del /q "%sffile%"
setlocal DisableDelayedExpansion
goto :EOF
:SEARCH_VIDEO
set "vid_num=%~1"
set "zero_loop=0"
setlocal EnableDelayedExpansion
if "%instr[1]%"=="1" goto :end_add_zero
:add_zero
set "vid_num_r=%vid_num%"
set "vid_num=00000000000000000000000%vid_num%"
set "vid_num=!vid_num:~-%instr[1]%!"
:end_add_zero
set "not_work="
set "video="
set "vid_path[0]=!filter:~0,%instr[0]%!"
for /f "tokens=*" %%a in ('set /a instr[0]+instr[1]') do (
set "vid_path[1]=!filter:~%%~a!"
)
setlocal DisableDelayedExpansion
set "vid_path=%vid_path[0]%%vid_num%%vid_path[1]%"
if exist "%v_path%%vid_path%" (
call :check_video "%v_path%%vid_path%"
if defined video goto got_video
)
if not "%instr[1]%"=="1" set "vid_path_1=%vid_path[0]%%vid_num_r%%vid_path[1]%"