[Plain File Mode] Rename subtitle files to match the name of a nearby video file

All about user-defined episode / movie / file name format expressions
Post Reply
User avatar
rednoah
The Source
Posts: 22836
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

[Plain File Mode] Rename subtitle files to match the name of a nearby video file

Post by rednoah »

Option A: Use the {folder} binding to find nearby files

Use Case: Use a Plain File Mode custom Preset to rename the given files so that the each file is assigned the same file name as the largest file in the same folder.

Format: Select all

{ folder.files.max{ it.length() }.nameWithoutExtension }{ subt }
:!: This code assumes that you have one video file per folder, e.g. movie folders. This code will not work for you if you have multiple video files per folder, e.g. TV series or season folders.

ScreenshotScreenshot




Option B: Use the {mediaFile} binding to find the primary media file

:idea: The {mediaFile} binding can also be used to find the primary video file for a given subtitle file, from the same folder or parent folder, which can then be used to rewrite the subtitle file path:

Format: Select all

{ mediaFile.dir }/{ mediaFile.nameWithoutExtension }{ subt }

:!: {mediaFile.dir} is the parent folder of the primary video file, and so the subtitle file will be moved there. {mediaFile.nameWithoutExtension} will ensure that the subtitle file will be named after the primary video file, so that the names match exactly. If subtitles were originally organized into Subs or Subtitles sub-folders then FileBot will delete these sub-folders automatically if left behind empty.




Option C: Use the name of the n-th video file in the folder to rename the n-th subtitle file in the folder

Use Case: If files are in order, then the n-th video file typically matches the n-th subtitle file, and if that assumption indeed holds true for your files, then matching video / subtitle files is trivial:

Format: Select all

{
	def index = folder.listFiles{ it.hasExtension(ext) }.indexOf(f)
	def videoFile = folder.listFiles{ it.video }.get(index)
	videoFile.nameWithoutExtension
}
ScreenshotScreenshot

Console Output: Select all

$ filebot -rename *.srt --db file --format "{ def index = folder.listFiles{ it.hasExtension(ext) }.indexOf(f); def videoFile = folder.listFiles{ it.video }.get(index); videoFile.nameWithoutExtension }"
Rename files using [Plain File]
[MOVE] from [1.srt] to [Alias.1x01.srt]
[MOVE] from [2.srt] to [Avatar.2009.srt]
:idea: Please read the FAQ and How to Request Help.
Post Reply