Page 1 of 1
batch-analyze movies for specific properties
Posted: 11 Mar 2020, 18:44
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
Re: batch-analyze movies for specific properties
Posted: 12 Mar 2020, 05:00
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
Re: batch-analyze movies for specific properties
Posted: 12 Mar 2020, 05:35
by remo
Thank you. I‘ll give it a try.
Re: batch-analyze movies for specific properties
Posted: 12 Mar 2020, 10:09
by remo
Is there also any binding to determine wether the movie‘s source is bluray or hdtv or web?
Re: batch-analyze movies for specific properties
Posted: 12 Mar 2020, 11:20
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.
https://www.filebot.net/naming.html#bindings
Re: batch-analyze movies for specific properties
Posted: 12 Mar 2020, 12:58
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}“
??
Re: batch-analyze movies for specific properties
Posted: 12 Mar 2020, 15:07
by rednoah
I suppose this could work:

Note that
{plex} only works for files that are already xattr tagged. Please read
Metadata and Extended Attributes for details.
Re: batch-analyze movies for specific properties
Posted: 12 Mar 2020, 18:34
by remo
Ok, no way.
Another idea:
does f or fn have any attribute which contains the "
" property (Mediainfo-App, "
" Property)
-remo
Re: batch-analyze movies for specific properties
Posted: 12 Mar 2020, 20:40
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
Re: batch-analyze movies for specific properties
Posted: 13 Mar 2020, 07:17
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.
{mediaTitle} is the media title that's embedded in the file content.
Re: batch-analyze movies for specific properties
Posted: 13 Mar 2020, 11:38
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
Re: batch-analyze movies for specific properties
Posted: 13 Mar 2020, 11:45
by rednoah
Re: batch-analyze movies for specific properties
Posted: 18 Mar 2020, 07:15
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
Re: batch-analyze movies for specific properties
Posted: 18 Mar 2020, 08:38
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:
viewtopic.php?f=5&t=1895
Re: batch-analyze movies for specific properties
Posted: 18 Mar 2020, 12:58
by remo
Thank you!
with single
' ... ' instead of double
" ... " did the Job!
-remo
Re: batch-analyze movies for specific properties
Posted: 18 Mar 2020, 13:46
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
Re: batch-analyze movies for specific properties
Posted: 20 Mar 2020, 07:29
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
Re: batch-analyze movies for specific properties
Posted: 20 Mar 2020, 07:31
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
Re: batch-analyze movies for specific properties
Posted: 20 Mar 2020, 09:13
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
Re: batch-analyze movies for specific properties
Posted: 20 Mar 2020, 12:47
by remo
Is there also a way to count the results?
Re: batch-analyze movies for specific properties
Posted: 20 Mar 2020, 19:17
by remo
Got it.
Re: batch-analyze movies for specific properties
Posted: 21 Mar 2020, 04:18
by rednoah
wc -l is your friend:
Code: Select all
<any commands that prints lines> | wc -l
https://stackoverflow.com/a/3137099/1514467