Create text file based on certain metadata?

Any questions? Need some help?
Post Reply
cagenuts
Posts: 10
Joined: 28 Nov 2021, 17:20

Create text file based on certain metadata?

Post by cagenuts »

This doesn't apply strictly to a TV episode which is why I've posted it here.

Two part question but they are related.

1. Let's say I have a recently aired video but it's not in any of the various databases yet.

Code: Select all

Heaven Made.S01E01.Episode 1.WEBRip.576p.AVC.AAC.2.0.128 kbps.[eng].mp4
I would like to add the airdate to the title. I have this in my preset;

Code: Select all

({dt.format('dd MMM yyyy')})
In this case the video was only downloaded (and subsequently created) on Monday whereas the airdate was Sunday. How could I for example subtract one day from the airdate to reflect the previous day? I don't want to alter the actual file details (metadata). Is this possible? So from (13 Dec 2021) to (12 Dec 2021).

Then...

2. Assuming the above sort of works, is it possible to create a text file that reflects certain metadata from that file?
Something like;

Code: Select all

{ fn.before(/./)} ({airdate.format('dd MMM yyyy')}) [{source} {vf} {cf} {textLanguages}]

Code: Select all

Heaven Made (12 Dec 2021) [WEBRip 576p mp4 subs]
The mp4 mustn't be say mpeg and the subs must say subs but only if subtitles exist in either the filename (muxed) or in the same folder.

I know it's a lot to ask for. I'm busy learning so any input will be appreciated.
User avatar
rednoah
The Source
Posts: 20934
Joined: 16 Nov 2011, 08:59

Re: Create text file based on certain metadata?

Post by rednoah »

1.
If the episode hasn't been added to the database yet, then FileBot will not be able to match the episode at all. Presumably, you mean that the episode itself has been added, but the airdate has not yet filled in, and so {d} doesn't work.

{dt} is based on the MediaInfo.Encoded_Date field and will give you an Instant instance that you can work with like so:

Code: Select all

{ dt.minusSeconds(24*60*60).format('dd MMM yyyy') }


2.
You can use the filebot -mediainfo command to print information line by line and then you can use > mediainfo.txt I/O redirection to write that to a text file:
https://www.filebot.net/cli.html

e.g.

Code: Select all

$ filebot -mediainfo -r . --format "{n} | {d} | {vf} | {cf}"
Alias | 2001-09-30 | 2160p | mpeg-4
...


EDIT:
cagenuts wrote: 14 Dec 2021, 08:43 The mp4 mustn't be say mpeg and the subs must say subs but only if subtitles exist in either the filename (muxed) or in the same folder.
e.g. yield file extension:

Code: Select all

{ ext }
e.g. yield "subs" if there are any embedded text streams:

Code: Select all

{ if (textLanguages) 'subs' }
:idea: Please read the FAQ and How to Request Help.
cagenuts
Posts: 10
Joined: 28 Nov 2021, 17:20

Re: Create text file based on certain metadata?

Post by cagenuts »

rednoah wrote: 14 Dec 2021, 09:06 1.
If the episode hasn't been added to the database yet, then FileBot will not be able to match the episode at all. Presumably, you mean that the episode itself has been added, but the airdate has not yet filled in, and so {d} doesn't work.
Some videos are one-off documentaries and will probably never get to TMDB or TVDB.
{dt} is based on the MediaInfo.Encoded_Date field and will give you an Instant instance that you can work with like so:

Code: Select all

{ dt.minusSeconds(24*60*60).format('dd MMM yyyy') }
This seems to work but only for files that have been processed through Handbrake. If I process a video using ffmpeg (mux in better audio and subtitles), there's no 'Encoded date' in the metadata so {dt} picks up absolutely nothing. I'll have to add "-metadata creation_time=now" to my ffmpeg scripts but no big deal.

Thanks, this is looking good.

Now I'll check out the second part.
User avatar
rednoah
The Source
Posts: 20934
Joined: 16 Nov 2011, 08:59

Re: Create text file based on certain metadata?

Post by rednoah »

You can also derive some value from the Last-Modified file attribute:

Code: Select all

{ f.lastModified().toDate().format('dd MMM yyyy') }

Code: Select all

{ f.lastModified().toDate().minusDays(1).format('dd MMM yyyy') }
:idea: Please read the FAQ and How to Request Help.
cagenuts
Posts: 10
Joined: 28 Nov 2021, 17:20

Re: Create text file based on certain metadata?

Post by cagenuts »

rednoah wrote: 14 Dec 2021, 13:12 You can also derive some value from the Last-Modified file attribute:

Code: Select all

{ f.lastModified().toDate().minusDays(1).format('dd MMM yyyy') }
This actually works much better. I can create different presets for different number of days past the air date.

So for this file;

Code: Select all

Heaven Made.S01E01.Episode 1.WEBRip.576p.AVC.AAC.2.0.128 kbps.[eng].mp4
I run this command;

Code: Select all

filebot -mediainfo -r "." --format "{if (S00E00) n} {S00E00} ({ f.lastModified().toDate().minusDays(6).format('dd MMM yyyy') }) [{vf} {ext} { if (textLanguages) 'subs'}]" > mediainfo.txt
Which outputs this;

Code: Select all

Heaven Made S01E01 (08 Dec 2021) [576p mp4 subs]
100% what I want.

Then for this file;

Code: Select all

The Sky at Night - Telescopes through Time - 704x396 1013K_2.mp4
I run this command;

Code: Select all

filebot -mediainfo -r "." --format "{fn.before(/ - /)} ({ f.lastModified().toDate().minusDays(6).format('dd MMM yyyy') }) [{vf} {ext} { if (textLanguages) 'subs'}]" > mediainfo.txt
Which outputs this;

Code: Select all

The Sky at Night (08 Dec 2021) [480p mp4 ]
One character gap after the 'ext' and my '{fn.before(/ - /)}' code strips everything after the first ' - ' and I'd ideally want it to only strip data from after and including the second ' - ' to end up with some thing like this;

Code: Select all

The Sky at Night - Telescopes through Time (08 Dec 2021) [480p mp4]
So no character gap before the closing square bracket and all title info up to the last ' - '.

If so is there a command that would process them both together?

Not sure how to use 'if NOT S00E00'. So perhaps something like;

Code: Select all

{if (S00E00) n} {S00E00} or if not then {fn}
User avatar
rednoah
The Source
Posts: 20934
Joined: 16 Nov 2011, 08:59

Re: Create text file based on certain metadata?

Post by rednoah »

e.g. match different part of the current file name:

Code: Select all

{ fn.before(/ - /) } - { fn.after(/ - /).before(/ - /) } - 
e.g. add " subs" with space, but no space without "subs":

Code: Select all

{ext}{ if (textLanguages) ' subs'}

:arrow: This can of course all be combined, but the code will get more and more complex, especially if you want to cover xattr-tagged episode files and generic files at the same time.
:idea: Please read the FAQ and How to Request Help.
cagenuts
Posts: 10
Joined: 28 Nov 2021, 17:20

Re: Create text file based on certain metadata?

Post by cagenuts »

Thank you. I'll work on the combination nut need to get up to speed on scripting.

Much appreciated.
User avatar
rednoah
The Source
Posts: 20934
Joined: 16 Nov 2011, 08:59

Re: Create text file based on certain metadata?

Post by rednoah »

I'd have separate commands for separate set of files. And then just concatenate the output of each command.
:idea: Please read the FAQ and How to Request Help.
Post Reply