Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal enabledelayedexpansion
- echo It require a few steps, preparation:
- echo 1. extract .SRT from .MKV files, where episode number is on line in format like: [Episode 27]
- echo 2. rename .SRT files as .MKV videos
- echo 3. run this .BAT file
- :: Iterate through all .srt files in the current directory
- for %%f in (*.srt) do (
- set "episode_number="
- :: Extract the line containing '[episode N]' and parse the episode number
- for /f "tokens=2 delims=[] " %%a in ('findstr /i /c:"[episode" "%%f"') do (
- set "episode_number=%%a"
- )
- :: Check if an episode number was found
- if defined episode_number (
- :: Construct the new base filename for both SRT and MKV files
- set "base_filename=episode_!episode_number!"
- :: Rename the SRT file
- ren "%%f" "!base_filename!.srt"
- echo Renamed SRT file: %%f to !base_filename!.srt
- :: Construct the corresponding MKV filename
- :: set "mkvname=!base_filename!.mkv"
- set "mkvname=%%f"
- set "mkvname=!mkvname:.srt=.mkv!"
- :: Check if the MKV file exists before renaming
- if exist "!mkvname!" (
- :: Rename the MKV file
- ren "!mkvname!" "!base_filename!.mkv"
- echo Renamed MKV file: !mkvname! to !base_filename!.mkv!
- ) else (
- echo WARNING: Corresponding MKV file !mkvname! not found for %%f
- )
- ) else (
- echo WARNING: No episode number found in file %%f
- )
- )
- endlocal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement