batch-analyze movies for specific properties

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
remo
Posts: 24
Joined: 28 Sep 2019, 19:15

batch-analyze movies for specific properties

Post by remo »

Hello Pros :)

I’d like to build a script to batch-analyze a folder containing all my movie files (eintirely mkv).

My goal is it to finally have a text file listing up all file names where one of the following properties are true:

- bitrate < 3000
- x-resolution < 1920 (better != full-hd)
- at least 1 audio track < 5.1 (6 channels)
- frame rate < 24p

The text file should contain then the appropriate file names with its “true” property or its “true” properties, eg:

“Matrix (1999).mkv 2999kbs 1880x1080 2channels 22fps”

OR

“8 Mile (2002).mkv 1918x860”

...is FileBot capable of doing this?

I have a huge movie collection and want to tidy up a little bit ;)

Thank you so far.

-remo
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: batch-analyze movies for specific properties

Post by rednoah »

The filebot -mediainfo command can do that.

e.g. use --filter to select only files that match your criteria:

Code: Select all

$ filebot -mediainfo -r . --filter "bitrate > 3000 && width >= 1920" --format "{fn} {resolution}"
Avatar 1920x1080
e.g. print the results for your conditions for all files:

Code: Select all

$ filebot -mediainfo -r . --format "{fn} {bitrate > 3000} {width >= 1920}"
Avatar true true

EDIT:

You can then combine that with -exec to batch-delete these files:
viewtopic.php?t=11078
:idea: Please read the FAQ and How to Request Help.
remo
Posts: 24
Joined: 28 Sep 2019, 19:15

Re: batch-analyze movies for specific properties

Post by remo »

Thank you. I‘ll give it a try.
remo
Posts: 24
Joined: 28 Sep 2019, 19:15

Re: batch-analyze movies for specific properties

Post by remo »

Is there also any binding to determine wether the movie‘s source is bluray or hdtv or web?
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: batch-analyze movies for specific properties

Post by rednoah »

remo wrote: 12 Mar 2020, 10:09 Is there also any binding to determine wether the movie‘s source is bluray or hdtv or web?
e.g.

Code: Select all

{source}
https://www.filebot.net/naming.html#bindings
:idea: Please read the FAQ and How to Request Help.
remo
Posts: 24
Joined: 28 Sep 2019, 19:15

Re: batch-analyze movies for specific properties

Post by remo »

Great. Got it so far.
One more thing:
Is there any possibility to check if the current filename matches a specific format?

Kind of:
—filter „fn != {plex.name}“

??
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: batch-analyze movies for specific properties

Post by rednoah »

I suppose this could work:

Code: Select all

f.path.contains(plex.path)
:idea: Note that {plex} only works for files that are already xattr tagged. Please read Metadata and Extended Attributes for details.
:idea: Please read the FAQ and How to Request Help.
remo
Posts: 24
Joined: 28 Sep 2019, 19:15

Re: batch-analyze movies for specific properties

Post by remo »

Ok, no way.

Another idea:
does f or fn have any attribute which contains the "

Code: Select all

Filename
" property (Mediainfo-App, "

Code: Select all

Filename
" Property)

-remo
remo
Posts: 24
Joined: 28 Sep 2019, 19:15

Re: batch-analyze movies for specific properties

Post by remo »

I’ll try to describe it in another way:

When opening a movie file in Mediainfo on my Mac, there is a field labeled „Filename“. This field contains a string written into the movie file‘s metadata by MKVtoolNix - usually I do this manually.

Can FileBot CLI read out that field/property?
The FileBot GUI can!
But I didn‘t find any way via CLI.

-remo
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: batch-analyze movies for specific properties

Post by rednoah »

You can directly access any MediaInfo property:
viewtopic.php?t=4285

:!: {media.FileName} is the same as {fn} though, the current file name without extension.

:idea: {mediaTitle} is the media title that's embedded in the file content.
:idea: Please read the FAQ and How to Request Help.
remo
Posts: 24
Joined: 28 Sep 2019, 19:15

Re: batch-analyze movies for specific properties

Post by remo »

Thank you very much!
This works great!

But, now I ran into another issue:
How can I catch the case when a movie file does not have set {mediaTitle}?

Let's say when it's null or empty.

My --filter statement only works when {mediaTitle} is already embedded in the file content (!= null).

Short: I want to filter files where no {mediaTitle} is set or where {mediaTitle} differs from {fn} ...
(part behind or is already working)

-remo
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: batch-analyze movies for specific properties

Post by rednoah »

:idea: Please read the FAQ and How to Request Help.
remo
Posts: 24
Joined: 28 Sep 2019, 19:15

Re: batch-analyze movies for specific properties

Post by remo »

Got everything working so far.

But I am not able to filter for files which have null or empty mediaTitle tag.
Even after reading viewtopic.php?t=1895 multiple times and trying a lot.

Something like this would be nice:

Code: Select all

filebot -mediainfo -r . --filter "mediaTitle.size() < 1 || !mediaTitle" --format "{fn}"
I need some further assistance please.

-remo
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: batch-analyze movies for specific properties

Post by rednoah »

You'll want to catch mediaTitle errors and return true for those, as uncaught errors default to false as far as --filter expressions are concerned:

Code: Select all

--filter "any{!mediaTitle}{true}"
:idea: viewtopic.php?f=5&t=1895
:idea: Please read the FAQ and How to Request Help.
remo
Posts: 24
Joined: 28 Sep 2019, 19:15

Re: batch-analyze movies for specific properties

Post by remo »

Thank you!

Code: Select all

--filter 'any{!mediaTitle}{true}'
with single ' ... ' instead of double " ... " did the Job!

-remo
remo
Posts: 24
Joined: 28 Sep 2019, 19:15

Re: batch-analyze movies for specific properties

Post by remo »

Here's my entire code.
I want to share my snippets for everyone who is interested in:

Code: Select all

// general file info
filebot -mediainfo -r . --filter "hd != 'HD' || vf != '1080p' || ext != 'mkv' || vc != 'x264' || af != '6ch'" --format "{fn} === {hd} - {vf} - {ext} - {vc} - {af}"

// audio stream name
filebot -mediainfo -r . --filter "audio[0].title != 'Titel 1'" --format "{fn} === {audio[0].title}"
filebot -mediainfo -r . --filter "audio[1].title != 'Titel 2'" --format "{fn} === {audio[1].title}"

// audio stream language
filebot -mediainfo -r . --filter "audioLanguages[0].name != 'German'" --format "{fn} === {audioLanguages[0].name}"
filebot -mediainfo -r . --filter "audioLanguages[1].name != 'English'" --format "{fn} === {audioLanguages[1].name}"

// is first audio stream default
filebot -mediainfo -r . --filter "audio[0].default != 'Yes'" --format "{fn} === {audio[0].default}"

// first subtitle name
filebot -mediainfo -r . --filter "text[0].title != 'erzwungen'" --format "{fn} === {text[0].title}"

// first subtitle language
filebot -mediainfo -r . --filter "text[0].language != 'de'" --format "{fn} === {text[0].language}"

// is first subtitle default and forced
filebot -mediainfo -r . --filter "text[0].default != 'Yes' || text[0].forced != 'Yes'" --format "{fn} === {text[0].default} - {text[0].forced}"

// count embedded video, audio and subtitle streams
filebot -mediainfo -r . --filter "video.size() > 1 || audio.size() > 2 || text.size() > 1" --format "{fn} === {video.size()} - {audio.size()} - {text.size()}"

// find files smaller than 3gb and larger than 15gb
filebot -mediainfo -r . --filter "bytes < 3000000000 || bytes > 15000000000" --format "{fn} === {gigabytes}"

// find files where embedded media title differs from actual file name
filebot -mediainfo -r . --filter "mediaTitle != fn.substring(0,fn.size()-7)" --format "{fn} === {mediaTitle}"
filebot -mediainfo -r . --filter "mediaTitle != fn" --format "{fn} === {mediaTitle}"

// find files where embedded media title is null or empty
filebot -mediainfo -r . --filter 'any{!mediaTitle}{true}' --format "{fn} === {mediaTitle}"
-remo
remo
Posts: 24
Joined: 28 Sep 2019, 19:15

Re: batch-analyze movies for specific properties

Post by remo »

One more thing to make my analyze scripts as useful as possible:

is the also a way for filebot/mediainfo to detect embedded text-based subtitles?

-remo
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: batch-analyze movies for specific properties

Post by rednoah »

remo wrote: 20 Mar 2020, 07:29 is the also a way for filebot/mediainfo to detect embedded text-based subtitles?
I suppose you could check the subtitle format via MediaInfo properties:
viewtopic.php?t=4285
:idea: Please read the FAQ and How to Request Help.
remo
Posts: 24
Joined: 28 Sep 2019, 19:15

Re: batch-analyze movies for specific properties

Post by remo »

Done.

Code: Select all

// is first subtitle stream not a picture-based subtitle
filebot -mediainfo -r . --filter "text[0].format != 'VobSub'" --format "{fn} === {text[0].format}"
Thank you very much for your incredible support!!!

-remo
remo
Posts: 24
Joined: 28 Sep 2019, 19:15

Re: batch-analyze movies for specific properties

Post by remo »

Is there also a way to count the results?
remo
Posts: 24
Joined: 28 Sep 2019, 19:15

Re: batch-analyze movies for specific properties

Post by remo »

Got it.
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: batch-analyze movies for specific properties

Post by rednoah »

wc -l is your friend:

Code: Select all

<any commands that prints lines> | wc -l
:arrow: https://stackoverflow.com/a/3137099/1514467
:idea: Please read the FAQ and How to Request Help.
Post Reply