Skip to content

Instantly share code, notes, and snippets.

@zeroxia
Last active March 12, 2018 13:11
Show Gist options
  • Save zeroxia/15f93c31439b4d277bc529e543b9a04b to your computer and use it in GitHub Desktop.
Save zeroxia/15f93c31439b4d277bc529e543b9a04b to your computer and use it in GitHub Desktop.
Batch scripts on Windows, to rename subtitle files, for the drama Game of Thrones
@echo off
REM echo.ARG1: Video Directory, e.g., \\alarm\media\xiayitiao\download\Game.Of.Thrones.S01\
REM echo.ARG2: Season selection, e.g., S01
REM echo.ARG3: Subtitle directory, e.g., subs-1
REM echo.ARG4: Subtitle naming tag, e.g., zh-1
for %%i in (2 3) do (
call subrename.bat ^
"\\alarm\media\xiayitiao\download\HBO史诗巨著:冰与火之歌.权力的游戏.第六季全.2016.中英字幕£CMCT梦幻" ^
S06 ^
subs-%%i ^
zh-%%i
)
@echo off
setlocal EnableExtensions EnableDelayedExpansion
set VIDEO_EXT=mkv
echo.ARG1: Video Directory, e.g., \\alarm\media\xiayitiao\download\Game.Of.Thrones.S01\
echo.ARG2: Season selection, e.g., S01
echo.ARG3: Subtitle directory, e.g., subs-1
echo.ARG4: Subtitle naming tag, e.g., zh-1
if "%%~4"=="" (
echo.ERROR: I expect 4 args
goto :EOF
)
set video_dir=%~1
set season=%~2
set sub_dir=%~3
set sub_tag=%~4
echo VIDEO_DIR: !video_dir!
for /f %%i in ('dir /A:-D /B %video_dir%\*.%VIDEO_EXT%') do (
REM echo %%i
set v_file=%%~i
set x=%%~i
set x=!x:*%season%=%season%!
set x=!x:~0,6!
REM echo !x!
for /F "usebackq" %%j in (`dir /B /A:-D %sub_dir% ^| findstr "!x!"`) do (
REM set s_file=%%j
MOVE "%sub_dir%\%%~j" ".\%%~ni.%sub_tag%%%~xj"
)
REM dir /B /A:-D %sub_dir% | findstr "!x!"
REM call :get_s_file "!x!"
)
goto :EOF
:get_s_file
for /F %%j in ('dir /B /A:-D %sub_dir% ^| findstr "%~1"') do set s_file=%%j
goto :eof
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment