minFileAge in hours - amc script

All your suggestions, requests and ideas for future development
Post Reply
MonkMad
Posts: 4
Joined: 23 Jun 2022, 14:50

minFileAge in hours - amc script

Post by MonkMad »

Hi,

I searched the forums and documentation, but didn't find anything relevant. Please point me to the correct manual/FAQ/thread in case this feature is already available.

Situation:
  • We can use --file-filter to filter files based on modified DateTime
  • We can use --def minFileAge=n (where n = days) in the amc script
  • However, the amc script minFileAge parameter doesn't seem to accept fractional/decimal days (if we want to process files older than 10 minutes, for instance)
  • We could use --file-filter, but then it would mean passing individual files to amc (via --file-filter), instead of a folder and letting the script handle it
Request:
  • Can minFileAge be updated to accept decimal/fractional days?

    I tried testing with

    Code: Select all

    --def minFileAge=0.04
    and

    Code: Select all

    --def minFileAge={java.lang.Double.valueOf(0.04)}
    but it didn't work.

    or
  • Add "minFileAgeMinutes" or "minFileAgeSeconds" as additional --def parameters to the amc script
Thanks
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: minFileAge in hours - amc script

Post by rednoah »

--def minFileAge does accept fractional numbers because the String value you pass in is interpreted as double-precision Decimal number, so --def minFileAge=0.04 should just work:
https://github.com/filebot/scripts/blob ... groovy#L50


:?: What age do you get for test files where --def minFileAge doesn't work?

Code: Select all

filebot -mediainfo -r . --format "{f.age} | {f}"
:idea: Please read the FAQ and How to Request Help.
MonkMad
Posts: 4
Joined: 23 Jun 2022, 14:50

Re: minFileAge in hours - amc script

Post by MonkMad »

Thanks; it was indeed the

Code: Select all

toDouble()
in the Groovy code that gave me the idea to try fractional minFileAge :)

Your test command above, to print {f.age}, is great. It helped prove that the age is indeed a Double (0.648466 for my test). However, it also proved that the age calculation uses the CreationDateTime for the file, and not the Last Modified DateTime. So, back to the original question: How do I make the amc script filter files based on last modified time? E.g. exclude all files updated in the last 15 minutes.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: minFileAge in hours - amc script

Post by rednoah »

:?: Which OS are you using?


:idea: If you're using Linux, then Creation-Date does not exist, and Last-Modified is used instead. If you're using Windows or Mac then Creation-Date is used. Unfortunately, there's no way to change this behaviour without modifying the amc script yourself.


:arrow: The easiest solution is probably to have a custom script set Creation-Date to Last-Modified for all your files before processing.

:arrow: Alternatively, you can use the f.lastModified() time stamp in a custom --file-filter expression.

:arrow: Alternatively, if you're using Linux or Mac, you can use a find <directory> -type f -nmin -exec filebot... {} + command to select the files and then pass them onto the filebot call.
:idea: Please read the FAQ and How to Request Help.
MonkMad
Posts: 4
Joined: 23 Jun 2022, 14:50

Re: minFileAge in hours - amc script

Post by MonkMad »

It is Windows. Looks like --file-filter is the way to go. If I get time, I'll try my hand at creating a special version of the amc script too. Thanks again for your prompt responses and great suggestions.

On a side note: What I'm trying to do, is to avoid processing files which are still being written to. Other programs I've used earlier had a way to define "minimum age for processing > 5 minutes", which worked well on Windows. If a file has not been written to in 5+ minutes, it is a safe bet that it has finished being downloaded/recorded, and can now be processed.
Am I overcomplicating this? Is there an easier way to do this with FileBot?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: minFileAge in hours - amc script

Post by rednoah »

You'd typically set up your upstream application to only call filebot once the download / recording / etc is complete. The "check for files that haven't been modified recently" approach is the last-resort approach for when your upstream application doesn't support calling 3rd party applications on completed files.


:arrow: I guess you could set it to --def minAgeDays=1 and assume that everything gets completed within a day. The 1 day delay is also useful for currently airing TV Shows if you process them immediately on release, since the information necessary to process the files may not be immediately available.


:arrow: You can probably also write a PowerShell script that collects not-recently-modified files and then passes those onto a filebot call.


:arrow: You can just use --file-filter as-is and cover your use case with a bit of Groovy code:

Code: Select all

--file-filter "((System.currentTimeMillis() - f.lastModified()) / (24 * 60 * 60 * 1000f)) > 0.04"


EDIT:

The amc script has been changed so that --def minAgeDays now works based on the Last-Modified time stamp: https://github.com/filebot/scripts/comm ... 4534f59559
:idea: Please read the FAQ and How to Request Help.
MonkMad
Posts: 4
Joined: 23 Jun 2022, 14:50

Re: minFileAge in hours - amc script

Post by MonkMad »

Holy lightning speed edit and commit, Batman! :o :)
Tested by downloading latest amc.groovy from Github, and it works like a charm; gracias! (How do I force the cli to use the latest version from GitHub? The "fn:amc" parameter seems to be caching the previous version somewhere.)

And yep, you are right, the upstream program doesn't provide an option to call another program (or do anything useful) after the download is finished. The only option it has is "Open file location in Windows Explorer when finished", which is the opposite of useful :roll:
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: minFileAge in hours - amc script

Post by rednoah »

You can use -script dev:amc to run the latest and greatest:
viewtopic.php?t=5
:idea: Please read the FAQ and How to Request Help.
Post Reply