Page 1 of 1

Rename media file to match subtitle filenames

Posted: 26 Oct 2025, 23:00
by appyface
I am wondering if there is an easy way to do this, either in GUI or command line?

I have a folder containing multiple media files. One media file per TV episode, TV.Show.Name.S01E01.some_text.<ext>

There are also one or more .srt files in the folder, for each episode. They are named TV.Show.Name.S01E01.some_other_text.<lang><optional HI SDH etc.>.srt

All of the .srt filenames for the episodes start with the same TV show name and season/episode, after that the text is different, and there is optionally a 2-char lang code, maybe an HI, SDH, etc. designation.

What I want to do, is have Filebot rename the *media* file to match one of the .srt files for that same season/episode? It doesn't matter which .srt for that episode, and using the entire .srt filename is fine (I can strip off the language code, etc. after the rename).

Code: Select all

TVshow.S01E01.thisepisodeblahblahblah.mkv
TVshow.S01E01.somekindoftextishere.HI.srt		<--- rename the media filename from this filename,
TVshow.S01E01.someothername.es.srt			<--- or this one, 
TVshow.S01E01.stillanothername.it.SDH.srt		<--- or this one,
TVshow.S01E01.somemoretextstuff.srt			<--- or this one 
Is this possible? Thank you for any help or ideas. Kind regards.

Re: Rename media file to match subtitle filenames

Posted: 27 Oct 2025, 04:43
by rednoah
You can use [Plain File Mode] Batch Rename any type of file for this kind of use case. You'll have to write custom code to connect the files though.

e.g.

Format: Select all

{
	def prefix = f.name.match(/^.*S\d+E\d+/)
	def subtitleFile = folder.listFiles().find{ it.name.startsWith(prefix) && it.subtitle }
	return subtitleFile.nameWithoutExtension.before(/[.][a-z]{2}$|[.][a-z]{2}[.][A-Z]{2,3}$/)
}
/^.*S\d+E\d+/ matches the leading TVshow.S01E01 pattern
/[.][a-z]{2}$|[.][a-z]{2}[.][A-Z]{2,3}$/ matches the trailing .es or .it.SDH pattern

Re: Rename media file to match subtitle filenames

Posted: 27 Oct 2025, 07:04
by appyface
Thank you! I had tried to follow the Plain File Mode instructions before I posted this, but didn't work. I must not have set it up correctly. I will give it another go. Thanks again.

Re: Rename media file to match subtitle filenames

Posted: 27 Oct 2025, 09:15
by rednoah
:idea: Here's what it looks like:

Screenshot


:!: If the sample file paths you have provided are not actually representative of the files you have, then the code will go awry. You may have to modify the code - likely the regex patterns - fit your needs.


:idea: If you want to only process video files, then How do I process only specific kinds of files? will get you sorted in that regard.

Re: Rename media file to match subtitle filenames

Posted: 27 Oct 2025, 15:31
by appyface
Thank you for more info. I only wish to rename each media file to match any one of its .srt files. Does this also rename .srt files?

Re: Rename media file to match subtitle filenames

Posted: 27 Oct 2025, 15:37
by rednoah
:idea: If you want to only process video files, then How do I process only specific kinds of files? will get you sorted in that regard.


:arrow: Plain File Mode works the same for any file. If you drop subtitle files and video files then it'll work with that. If you only want to process video files then you need to only drop video files into the Original Files area. The Filter tool makes it easy to do just that.

Screenshot

Re: Rename media file to match subtitle filenames

Posted: 27 Oct 2025, 17:50
by appyface
Thank you again for all the detailed help. I will give it a go.

Re: Rename media file to match subtitle filenames

Posted: 28 Oct 2025, 16:50
by appyface
From my OP:
>>>What I want to do, is have Filebot rename the *media* file to match one of the .srt files for that same season/episode? It doesn't matter which .srt for that episode

I'm not having any luck, I guess I'm still not setting it up correctly. Thanks anyway.

Re: Rename media file to match subtitle filenames

Posted: 28 Oct 2025, 16:54
by rednoah
appyface wrote: 28 Oct 2025, 16:50 What I want to do, is have Filebot rename the *media* file to match one of the .srt files for that same season/episode?
:idea: This screenshot shows the media file in row 5 about to be renamed to the name of the subtitle file in row 4. The same logic is applied to all files in fact. I just so happen to have dropped in all of them during testing. You can just drop in the media files if you only want to rename the media files.

Screenshot



appyface wrote: 28 Oct 2025, 16:50 I'm not having any luck, I guess I'm still not setting it up correctly. Thanks anyway.
:?: What do you see? Take a screenshot so I can see what you can see.

Re: Rename media file to match subtitle filenames

Posted: 28 Oct 2025, 22:54
by appyface
Whatever files I load on the left, when I press F2 on the blank right side, it just populates the same files that are on the left. If the left is only media files, that's all that comes on the right. If the left is only .srt files that's all I get on the right. If the left is all files from the folder, I get them all on the right.

Re: Rename media file to match subtitle filenames

Posted: 29 Oct 2025, 02:30
by rednoah
appyface wrote: 28 Oct 2025, 22:54 Whatever files I load on the left, when I press F2 on the blank right side, it just populates the same files that are on the left.
That sounds a bit like you're still using {fn} as format and not the custom format that I wrote for you.


:arrow: Please show me a screenshot that shows (A) Original Files, (B) New Names and (C) Format Editor so that I can see the file names and the format being used. Please look at the screenshot that I posted above. Exactly like that would be very helpful.


:idea: You can open the Format Editor by double-clicking on an New Names item and then clicking on Edit Format.

Re: Rename media file to match subtitle filenames

Posted: 31 Oct 2025, 06:33
by appyface
Source directory:
Screenshot

I loaded just the four AVI files on the left pane. Then clicked on right pane and pressed F2. Same files loaded.

Then added custom format and clicked "use format".

Nothing changed. I reopened the format area again for reference then took this screenshot:
Screenshot

After taking screenshot, I clicked "use format" again and it applied. I am not sure why it didn't apply the first time, because it was definitely saved there.

Is there any place in Filebot that saves custom formats so they can be recalled later?

Thank you again for bearing with me and all the help.

Re: Rename media file to match subtitle filenames

Posted: 31 Oct 2025, 06:54
by rednoah
:idea: I see the problem. You are editing the Episode Format which is used when formatting Episode type items. However, your Episode Format is not used when formatting non-Episode type items. You are using Plain File Mode and are thus formatting File type items and thus your File Format is used.


:idea: If you use Double-Click <New Names> item ➔ Edit Format then FileBot will open the File Format (or whichever is applicable for the type of item at hand) automatically.


:?: Which version of FileBot are you using? Recent versions of FileBot will switch to the File Format automatically even if you open the Format Editor without selection but happen to have only Episode items / Movie items / File items / etc loaded into New Names at the moment.


:idea: You can use the Clipboard button in the Format Editor to quickly switch to a previously used custom format. Alternatively, you can create a custom Preset for frequent use cases.

Re: Rename media file to match subtitle filenames

Posted: 31 Oct 2025, 14:18
by appyface
This is where I put the custom format - options, edit format. It's the only place I've used for pasting my own, I didn't know there is more than one place.

Screenshot

I pressed F5 twice (is that still right way?) and it says "FileBot 5.1.7 (r10514)".

Is the "format editor", the place where I pasted the custom format? I don't see a button called "clipboard". I do have a button called 'recent formats", when I click it, the only "pop up" is a single line with this custom format. Clicking that did cause some right and left arrows to appear in the bottom left, when I scroll with those I see what you're talking about now - the title changes to "episode" "movie" "file" etc. I never noticed any of that before, I've always just opened this up and put my format in. But I only ever have episodes (until now), and it always worked, so I never looked around for anything else.

Re: Rename media file to match subtitle filenames

Posted: 31 Oct 2025, 15:25
by rednoah
I see. Yep, this menu allows you to open the Format Editor (where you edit your custom format) before loading any files into FileBot. In the past it just opened in Episode Mode by default. I guess we only recently made that more aware of the current context with the latest release last month. The double-click menu is better in some ways since it can be aware of the item you clicked on, but also isn't available until after you have already loaded / matched files.

Re: Rename media file to match subtitle filenames

Posted: 31 Oct 2025, 15:32
by appyface
Is there somewhere else I should see my prior formats then? If not is OK, I always kept them in notepad file because I never knew whether Filebot saved them.

Re: Rename media file to match subtitle filenames

Posted: 31 Oct 2025, 15:51
by rednoah
The Icon Recent Formats button (the icon is supposed to be a clipboard) will remember recently used formats (for the currently selected mode; previous Episode formats will not show up in File mode) so you can quick switch. It'll only remember the most recent handful of formats though. I'd create a Preset for each of your custom Plain File Mode use cases. It's easier to manage that way.

Re: Rename media file to match subtitle filenames

Posted: 31 Oct 2025, 15:53
by appyface
Thanks for all the help and info.