Page 1 of 1

Batch Rename any type of file

Posted: 13 Oct 2014, 21:47
by rednoah
As a hidden bonus feature, FileBot supports quick and efficient generic batch renaming, and you can rewrite the filenames with awesome Groovy expressions just like in Episode / Movie mode.

1. Drop files into Original Files
2. Click on the empty New Names component
3. Now that New Names has focus hit F2
4. New Names will instantly filled with File objects
5. Double Click any item in New Names to apply a new Format Expression


:idea: Create Presets for repetitive tasks.

:idea: Hit F2 after selecting an item to edit the name.




Batch Rename Photos

When organizing photos, I use the place where I took them and a serial number as the beginning of the filename (for sorting), followed by which camera took it and the photo number from the original filename.

Code: Select all

Taiwan {i.pad(3)} - iPhone {fn.after('IMG_') as int}
i ... item number, fn ... current filename
Image


Pre-Process badly named episode files

FileBot cannot process badly named files like B&B Aug 4 - 14 so you will need to fix it first. Something like The Bold and The Beautiful - 2014.08.04 will immediately be much more sensible.

Code: Select all

{Date.parse('MMM dd - yy', fn.after(/\s/)).format('yyyy.MM.dd')}
Extract, parse and re-format the date.
Image


Batch Rename files based on text content

Generating new filenames based on the text content of the files can be very useful when normalizing a set of text files.

Code: Select all

Report {i.pad(2)} {file.text.match(/\(.+\)/)}
Match first (...) pattern from the text content and add it to the filename.
Image


Batch Rename files based on sibling XML files

In your format you have access to other files or web resources so you can easily build powerful rename logic for your own unique use cases. :ugeek:

Assuming a file structure like so:

Code: Select all

name.cbz
name.xml
The contents of the .xml file looking something like this:

Code: Select all

<ComicInfo>
	<Title>Ask Not</Title>
	<Series>The American Way</Series>
	<Number>1</Number>
</ComicInfo>
And a Groovy format:

Code: Select all

{xml = new XmlSlurper().parse(folder/fn+'.xml'); [xml.Series, xml.Number, xml.Series, xml.Title].join(' - ')}
You'll get output paths like this:

Code: Select all

The American Way - 1 - The American Way - Ask Not



Batch Rename files based on embedded media title tags

If you have suffered from data loss, and your data recovery software was only able to restore file contents, but not file names or folder structures, then you may be able to use metadata embedded in the file content to restore the original filenames.

Code: Select all

{mediaTitle}
Image
e.g.

Code: Select all

$ filebot -rename /path/to/files --db file --file-filter mediaTitle --format {mediaTitle}
Rename files using [Plain File]
[MOVE] from [Babylon.5.S04E22.mkv] to [bab4d6-VTS_01_0-PGC3.mkv]

Re: Batch Rename any type of file

Posted: 06 Oct 2017, 21:22
by dadelayer
Thanks!. I tested it out using the example and it worked fine. However, when I use it with my XML file (I converted the JSON > XML), it says my format is not correct.
I use the same format and code as the example

Re: Batch Rename any type of file

Posted: 07 Oct 2017, 07:42
by rednoah
The example here is very specific. You can learn from it, but you can't copy-and-paste and expect it to work in your case. ;)

If you start by learning how to parse JSON, then you're on the right track:
http://docs.groovy-lang.org/latest/html ... urper.html

:idea: You can hire me though, but you'd need to write down exactly what you need, with examples and example data.

Re: Batch Rename any type of file

Posted: 07 Oct 2017, 08:09
by dadelayer
Well, I wanted to try it in XML since I wanted to use your example, but not coming up with anything.

Code: Select all

def fnn = fn
xml = new XmlSlurper().parse(folder+'/mov.xml')
xml.'**'.find { it.name() == 'scid' && it.text() == fnn}*.parent()*.title*.text()
that should return the title but it's not working as its supposed to. I don't have the money to hire :\ it seems expensive :(

Re: Batch Rename any type of file

Posted: 07 Oct 2017, 10:14
by rednoah
Just debug step by step. Does it parse? Is the first element what you think it should be?

You can prototype and debug these things in the Format Editor in minutes. Just try things and narrow down which exact piece of code isn't working as expected. ;)

Re: Batch Rename any type of file

Posted: 24 Oct 2017, 12:51
by Delmano
This is so useful. Thanks for the tutorial Noah, helps newbies like me a lot.

Re: Batch Rename any type of file

Posted: 06 Feb 2018, 05:18
by yhm28
rednoah wrote:
13 Oct 2014, 21:47
3. Now that New Names has focus hit F2
Is there any way to remap the shortcut to a different key?

Re: Batch Rename any type of file

Posted: 06 Feb 2018, 08:39
by rednoah
No, but for reoccurring tasks I recommend making a Preset. Presets can be called via the number keys or numpad keys.

Re: Batch Rename any type of file

Posted: 29 Mar 2018, 15:18
by ooga123459
This is great! Exactly what I was looking for, thanks much :)

Re: Batch Rename any type of file

Posted: 18 Nov 2019, 16:30
by apeg
With all the problems TVDB has been having this is exactly what i'm looking for but im having a few problems, the behavior of these options are different in 'generic batch renaming mode':

{n} = full file name minus extension
{'Season '+s} = full file name minus extension
{fn} = blank no value

I'm primarily using filebot for sorting in this case, generic batch renaming is exactly what i need so i dont run into issues every time TVDB is having problems. But show name, season and full file name are still needed.

Any ideas? thanks,

Re: Batch Rename any type of file

Posted: 18 Nov 2019, 18:30
by rednoah
In plain file mode:
* n is the filename
* fn is the filename, as usual, same as n in this case
* s is undefined, since files don't have seasons


If you want SxE numbers, or titles, or anything, then you'll have to extract that piece of information by parsing the file name, since the file name is all you've got:

Code: Select all

{f.path.match(/Season (\d+)/)}
:idea: How to parse information from the file name is highly reliant on the file names you have.

Re: Batch Rename any type of file

Posted: 26 Nov 2019, 04:46
by yodaspowart
As the TVDB is down for me on my seedbox (Linux/amc groovy script),
I am now using

Code: Select all

unsortedFormat
Managing to connect and rename to this online FTP folder fine using Mountain Duck and the latest Filebot which is working fine on my Mac.

Code: Select all

--def unsorted=y --def unsortedFormat="Unsorted/{fn =~ /2160p|4K|4k|UHD/ ? 'UHD-2160p/' : fn =~ /1080p/ ? 'HD-1080p' : fn =~ /720p/ ? 'HD-720p' : 'SD'}/{fn}.{ext}"
Image
I have now got TV shows into specific folders for resolution.

Would like to use the file naming setup to match the name of the show in a certain way:
Original file name:

Code: Select all

Legacies.S02E01.HDTV.x264-KILLERS[eztv].mkv
Wanted: Legacies - S02E01 - HDTV x264-KILLERS[eztv]

Not sure how it can be cleaner?

Code: Select all

{fn.before(/S\d{2}E\d{2}/).space(' ')} - {fn.match(/S\d{2}E\d{2}/).space(' ')} - {fn.after(/S\d{2}E\d{2}/).space(' ')}
Using the filebot GUI to test in file mode:
Image

Re: Batch Rename any type of file

Posted: 26 Nov 2019, 05:41
by rednoah
If it works, I'd leave it at that. Once you start parsing file names yourself, things necessarily level up in terms of complexity.

If simplification is the goal, at the cost of getting exactly what you want, then here's my solution:

Code: Select all

{fn.replaceAll(/[ .-]+/, ' - ')}

Code: Select all

Legacies - S02E01 - HDTV - x264 - KILLERS[eztv]

Re: Batch Rename any type of file

Posted: 26 Nov 2019, 19:00
by yodaspowart
Thanks a lot @rednoah also for quick reply.
It's perfect for me.

Re: Batch Rename any type of file

Posted: 26 Nov 2019, 23:22
by yodaspowart
Updated my unsorted folder now:

Currently it's working in case anyone is interested in this:

Code: Select all

--def unsorted=y --def unsortedFormat="Unsorted/{fn =~ /2160p|4K|4k|UHD/ ? 'UHD-2160p/' : fn =~ /1080p/ ? 'HD-1080p' : fn =~ /720p/ ? 'HD-720p' : 'SD'}/{fn.before(/S\d{2}E\d{2}/).upperInitial().space(' ')} - {fn.match(/S\d{2}E\d{2}/).upper()} - {fn.after(/S\d{2}E\d{2}/).stripReleaseInfo().upperInitial().space(' ')} [{allOf{match}{s3d}{hd}{vc}{source}{vf}{('-')}{af}{ac}{channels}{n.findMatch(group) ? null : '- '+group} join ' '}].{ext}" --def exec="curl --insecure https://seedBoxPlexURL:port/library/sections/all/refresh?X-Plex-Token=XXXXXXXXXXXXXXXXXX_X"
Now Plex can pull in the TV shows from my: HD-1080p & UHD-2160p folders.
This is a fallback until TVDB is up and running.
I'm still renaming them properly with the Filebot GUI 4.8.5 through Mountain Duck mounted online FTP drive

Movies rarely go into unsorted.
If they end up here would get named like this:
Original name:

Code: Select all

A.Christmas.Tale.2008.Criterion.576p.BDRip.x264.AC3-Q0S.mp4

becomes:

Code: Select all

A Christmas Tale 2008 Criterion 576p BDRip X264 AC3-Q0S - - A Christmas Tale 2008 Criterion [HD AVC BDRip 1080p - 2ch AAC 2.0]