This script was generated by Gemini with the goal of simplifying the process of renaming external language subtitle files (.ass or .srt) to match the naming convention for Jellyfin's External File for subtitles. This script is extremely limited in its current state, and may be changed or modified as needed to suit other use cases.
The script works by checking the episode number (E##) extracted from the video filename and searching the source directory for a subtitle file containing that same number (##) in one of these three common formats:
| Format Check | Example Subtitle Filename | Resulting Match Pattern |
|---|---|---|
| Loose Space | Title 01 Source.ass |
* 01* |
| Square Brackets | [Title] [02][Source].ass |
*[02]* |
| Curly Braces | Title {03} Source.srt |
*{03}* |
Bash shell environment (Linux, macOS, WSL).
The video files (currently .mkv) must follow a consistent episode naming pattern that includes the season and episode number, such as: ...S01E01...
To run the script, execute it from your terminal, providing three mandatory arguments:
-
The Source Directory containing the raw, unnamed subtitle files.
-
The Destination Directory containing the video files whose names the subtitles should match.
-
The Language ISO Code (e.g., jpn, eng, fre).
./subadd.sh [-c|--copy] [-r] <SUBTITLE_SOURCE_DIR> <VIDEO_DESTINATION_DIR> <LANG_ISO_CODE>| Option | Description |
|---|---|
-c, --copy |
Copy subtitles to destination instead of moving |
-r |
Rename original subtitle in source folder to match destination naming |
-cr, -rc |
Combine copy and rename original (both actions) |
-h, --help |
Show help message |
Suppose you have:
Subtitles in: ./Food Court de, Mata Ashita/
Videos in: /mnt/media/Anime/See You Tomorrow at the Food Court (2025)/Season 01/
To match the Japanese subtitles to the videos in the destination directory:
./subadd.sh "Food Court de, Mata Ashita" "/mnt/media/Anime/See You Tomorrow at the Food Court (2025)/Season 01/" "jpn"To copy subtitles to destination and also rename the original files in the source folder:
./subadd.sh -cr "Subin" "DstDir" "ja"Input:
Subin/[Nekomoe kissaten] Apocalypse Hotel - 12 [WebRip][JPN].ass
Output:
Subin/Apocalypse Hotel (2025) - S01E12 - 012 - Title [Bluray-1080p Remux][8bit][h264][FLAC 2.0][JA]-LaCroiX.ja.ass
DstDir/Apocalypse Hotel (2025) - S01E12 - 012 - Title [Bluray-1080p Remux][8bit][h264][FLAC 2.0][JA]-LaCroiX.ja.ass
A successful run will move and rename the subtitle file to match the video, appending the ISO code:
| Original Video Name | Matched Subtitle Name | Final Subtitle Name |
|---|---|---|
...S01E01...mkv |
Food Court... 01.ass |
...S01E01...mkv.jpn.ass |
...S01E02...mkv |
[MingY]...[02].ass |
...S01E02...mkv.jpn.ass |
If a match is not found for an episode, a warning will be displayed.