Regex for lowercase, crop and replace

All about user-defined episode / movie / file name format expressions
Post Reply
martzell
Posts: 4
Joined: 14 Nov 2013, 23:38

Regex for lowercase, crop and replace

Post by martzell »

Hello, which regex-magic is necessary to change the filenames like these?

name s00e00 title.year-source.ac-af.mbps-vc.fps-vf.extension
Breaking Bad s03e05 Offene Worte.2010-bluray.dts-6ch.4.9-avc.29-720p.mkv
Children of Men.2011-dvd.ac3-2ch.0.8-xvid.25-394p.m4v

The challenge:
- all lowercase of type information
- shortened framerate, e.g. 29 instead 29.976 and 30 instead 30.000.
- rounded (or shortened if not possible) bitrate in mbps with 1 decimal-place, e.g. "4.9" instead "4 890 Kbps" and "0.8" instead "830 Kbps".
- the file name extension .mp4 to .m4v and lowercase.
- source "DVDrip" to "dvd" and "BluRay" to „bluray"
- if no information like source or year exists the output has to be adjusted
User avatar
rednoah
The Source
Posts: 23935
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Regex for lowercase, crop and replace

Post by rednoah »

Have you looked at the format expressions? Like the examples here in the forums? You can play with it in the GUI editor.

By default filebot won't allow u to change the extension, but if you change to "Extension: Override" in Rename Options you can enable that. Just make sure you include the extension in your format.
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 23935
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Regex for lowercase, crop and replace

Post by rednoah »

It's all pretty straight-forward. Here's some hints:

Code: Select all

{vc.lower()} {ac.lower()}

Code: Select all

{video.FrameRate.toFloat().round()} 

Code: Select all

{(video.bitrate.toFloat() / 1024).round(1)}

Code: Select all

{ext.equalsIgnoreCase('m4v') ? 'mp4' : ext.lower()}

Code: Select all

{source.lower().replaceAll(/dvdrip/, 'dvd')}
:idea: Please read the FAQ and How to Request Help.
martzell
Posts: 4
Joined: 14 Nov 2013, 23:38

Re: Regex for lowercase, crop and replace

Post by martzell »

Thanks. Where is a complete documentation / reference? .round isn't mentioned here:

http://www.filebot.net/naming.html
http://www.filebot.net/forums/viewtopic.php?f=5&t=2#p51

I need a function to short the framerate 29.976 without rounding to 29. How to obtain with regex?

How to adjust the output when no source is given? At the moment it looks like this:

Avatar.2009-.dts-6ch.5503-x264.23.98-720p.mkv

{n}.{y}-{source.lower()}.{ac.lower()}-{af.lower()}.{(video.bitrate.toFloat()/1000).round()}-{vc.lower()}.{video.framerate.toFloat().round(2)}-{vf}
User avatar
rednoah
The Source
Posts: 23935
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Regex for lowercase, crop and replace

Post by rednoah »

1.
Complete documentation on the Groovy programming language:
http://groovy.codehaus.org/Documentation

2.
So you don't want to round, just typecast to int:

Code: Select all

(int) video.FrameRate.toFloat()
3.
Every {...} block works as a whole or fails as a whole.

Look at the examples more closely => http://www.filebot.net/forums/viewtopic ... 5&t=2#p783
:idea: Please read the FAQ and How to Request Help.
martzell
Posts: 4
Joined: 14 Nov 2013, 23:38

Re: Regex for lowercase, crop and replace

Post by martzell »

Thanks. Now I've got it.

Movie Format: Children of Men.2009.bluray.6ch.dts.23fps.5503kbps.x264.720p.mkv

Code: Select all

{n}.{y}.{source.lower()}.{af.lower()}.{ac.lower()}.{(int)video.framerate.toFloat()}fps.{(video.bitrate.toFloat()/1000).round()}kbps.{vc.lower()}.{vf}

Episode Format: Breaking Bad S03E11 Offene Worte.2002.ithd.2ch.ac3.25fps.4361kbps.avc.720p.mkv

Code: Select all

{n} {s00e00} {t}.{y}.{source.lower()}.{af.lower()}.{ac.lower()}.{(int)video.framerate.toFloat()}fps.{(video.bitrate.toFloat()/1000).round()}kbps.{vc.lower()}.{vf}
martzell
Posts: 4
Joined: 14 Nov 2013, 23:38

More than one language

Post by martzell »

Is it possible to add all the audio languages to the filename? "audio.language" only inserts „de“ for german, but there is the original audio stream in english also in the .mkv-file. I’ve looked at the groovy documentation even before you posted the link, but where can I find in this programming language documentation a list of all keywords used by FileBot for fields? http://groovy.codehaus.org/Getting+Started+Guide

I’ve tried audio.stream1.language and audio[1].language and similar things to access the second audio stream. But no luck. MediaInfo shows a field „Audio_Language_Strings“ but how can it be accessed?
User avatar
rednoah
The Source
Posts: 23935
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Regex for lowercase, crop and replace

Post by rednoah »

Use {media} or {audios} bindings:

Code: Select all

{media.Audio_Language_Strings}

Code: Select all

{audios.language}
:idea: Please read the FAQ and How to Request Help.
Post Reply