Auto tagging folders created by software based NVR?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Schuller
Posts: 137
Joined: 02 May 2023 21:08

Auto tagging folders created by software based NVR?

Post by Schuller »

Hi,

I have a software based NVR with several 4K PoE cameras that records to a PC where I use XY to view and manage the files instead of the NVR software. At the moment the NVR software is currently set up in a way that it auto creates a folder each day on my system and places all the recorded video from all the cameras into that daily folder and then I've been manually tagging these folders with the day of the week as it makes grouping, branch viewing and overall management much easier. So my question; can I execute a script from a button, custom events, and so on that would tag all these folders with the day of the week based off there created date so I don't have to keep doing this manually?

Thanks
Attachments
2024.10.27 Screenshot.jpg
2024.10.27 Screenshot.jpg (86.11 KiB) Viewed 653 times
Last edited by Schuller on 28 Oct 2024 18:42, edited 1 time in total.

admin
Site Admin
Posts: 62257
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Auto tagging folders created by software based NVR?

Post by admin »

Sure. Here's a first hint:

Code: Select all

echo format("2024-10-28", "dddd"); //Monday

highend
Posts: 13749
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Auto tagging folders created by software based NVR?

Post by highend »

I wouldn't fully automate this (via a cfa), although that could be done as well...

The script itself:
Modify the $root variable and whenever you run it it will add the missing weekday tags

Code: Select all

    $root = "full path to the root of the folders created by nvr";
    if (exists($root) != 2) { end true; }

    $paths = quicksearch("/nd", $root);
    if (!$paths) { end true; }

    foreach($path, $paths, <crlf>, "e") {
        $tag = tagitems("tag", , $path);
        if ($tag) { continue; }

        $date    = filetime($path, "c");
        $weekday = format($date, "dddd"); // Monday, Tuesday, ...
        tagitems("tag", $weekday, $path);
    }
One of my scripts helped you out? Please donate via Paypal

Schuller
Posts: 137
Joined: 02 May 2023 21:08

Re: Auto tagging folders created by software based NVR?

Post by Schuller »

Incredible! With just a click of a button 50 plus folders were tagged properly in the blink of an eye.

Thanks again!

highend
Posts: 13749
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Auto tagging folders created by software based NVR?

Post by highend »

No problem :biggrin:

To automate this you could do the following:

Create a subfolder structure "cea\Changing locations\After painting the file list" in your XY script folder
and create two script files in it:
01. "!Main.xys"
02. "NVR tagging.xys"

Put this content into "!Main.xys":

Code: Select all

    // Tag weekdays in the NVR root folder
    e|load "cea\Changing locations\After painting the file list\NVR tagging.xys";
Put this slightly modified content into "NVR tagging.xys":

Code: Select all

    $root = "full path to the root of the folders created by nvr";

    if (get("path") == $root) {
        $paths = quicksearch("/nd", $root);
        if (!$paths) { end true; }

        foreach($path, $paths, <crlf>, "e") {
            $tag = tagitems("tag", , $path);
            if ($tag) { continue; }

            $date    = filetime($path, "c");
            $weekday = format($date, "dddd"); // Monday, Tuesday, ...
            tagitems("tag", $weekday, $path);
        }
    }
Then in:
Configuration | General | Custom Event Actions | Changing Locations | After painting the file list

You switch the Action to "Run Script" and in the script field you'll use:

Code: Select all

e|load "cea\Changing locations\After painting the file list\!Main.xys";
Afterwards, whenever you visit exactly the NVR root folder, missing tags will automatically be filled...

Why to use this kind of file structure? The (outside) script(s) are easier to edit and to expand if you want to do further customizations...
Additionally, by using a "!Main.xys" script you can easily deactivate scripts to load if necessary instead of commenting out a lot of source code if you'd use only one large file.
One of my scripts helped you out? Please donate via Paypal

Schuller
Posts: 137
Joined: 02 May 2023 21:08

Re: Auto tagging folders created by software based NVR?

Post by Schuller »

Wow!
Totally automated now and very cool. Just tested by removing all the tags from those daily folders then changed locations and went back again and it instantly tagged them accordingly without intervention or action on my part, plus I save on toolbar real estate 8)
Thanks again!

jupe
Posts: 2990
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Auto tagging folders created by software based NVR?

Post by jupe »

Since you have suggested using CEA for this task, seems like it would be more efficient to modify the script to search for untagged items, instead of checking every folder for a tag, every time in that root.

Unsure of your needs OP, but if all you need the info for is basically column display/sorting/filtering, and you expect the folder timestamps not to ever be changed (although the folder name is a date anyway), you could just use a custom column to display the same info, instead of tagging every folder, but you probably have your reasons why you prefer adding to the tags db.

Schuller
Posts: 137
Joined: 02 May 2023 21:08

Re: Auto tagging folders created by software based NVR?

Post by Schuller »

Thought of custom columns at first but I don't believe, or could not find any options in the info panels search options that would allow to search for information in a custom column plus I like live filtering a tagged item vs the column sort header where the live filter eliminates everything out of site I'm not typing for as I type and quickly only shows me what I am looking for. Also, where I'm going with this in future, I think tagging may be better. And now you just made me realize something, I may need to modify that script to also automatically tag all the files in those folders too with the day of the week. My hope in the near future is that I could do things such as create search templates or scripts that would for example; "show me all the motion activated recordings named mechanical room* that was created every second Friday, between 3pm and 6pm from the directory motion activated clips".
By the way, within in those folders are only motion activated recorded files that are named by their location(each camera) along with some sequential numbering that should make searching motion events on a particular camera and on a particular day possible. The NVR software is also simultaneously recording 24/7 to a different directory which is treated differently and I have plans in future to use their "connect AI server' option for additional video analytics where I believe it would record additional categories such as package detection, facial recognition and so on, each to its own directory, if I set it up that way. I'm hoping then XY's search capabilities will compliment all this in my overall file management.

Anyway, please let me know what to change in that script.

Thanks

highend
Posts: 13749
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Auto tagging folders created by software based NVR?

Post by highend »

To only tag untagged files & folders:

Code: Select all

    $root = "full path to the root of the folders created by nvr";

    if (get("path") == $root) {
        $untagged = quicksearch('!tags:?* /E', $root);
        if (!$untagged) { end true; }

        foreach($item, $untagged, <crlf>, "e") {
            $date    = filetime($item, "c");
            $weekday = format($date, "dddd"); // Monday, Tuesday, ...
            tagitems("tag", $weekday, $item);
        }
    }
Regarding your future search wishes:
Will you need only a set of predefined searches or do you need to modify they from case to case every time?
One of my scripts helped you out? Please donate via Paypal

Schuller
Posts: 137
Joined: 02 May 2023 21:08

Re: Auto tagging folders created by software based NVR?

Post by Schuller »

Probably a set of predefined searches with some that will likely coincide with predetermined events that are routine. If anything is going to be a case by case search, I can always search those manually. At the moment I'm using a few search templates that are setup to show me things like "last 2 hours" and "last 24 hours" in particular locations and with particular names, but I would have liked if there was an option under Find Files, Date range, where you could put a time range too that would be recursive each day which allow to pin point finding files better between times. For example, "search all video files created from July 1, 2024 to October 10, 2024, tagged Friday, but only those that were created between 3pm and 6pm each day between those dates. Maybe it is possible and I missed something, or is that where scripting kicks in?

Anyway, thanks for the updated script. I have noticed though with this script that auto tagging the almost 26,000 thousand files took quite some time with a few XY freezes towards the end. Eventually all the files got tagged but I had to end XY task in task manager a few times. Now that all the files are tagged, a new problem arose and that is, every time I go to the directory where all the daily folders and files are, XY freezes up. Its seems the script before may have been better but I can't be sure because it was only 117 folders before and this time it was over 20,000 files. I checked the Tag.dat and it 15MB now and I read somewhere that it has a limit of 100MB, so I don't know. For now I turned the script off or switched "After painting the file list" back to none and I can access that directory fine again.

admin
Site Admin
Posts: 62257
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Auto tagging folders created by software based NVR?

Post by admin »

Schuller wrote: 31 Oct 2024 07:11 I checked the Tag.dat and it 15MB now and I read somewhere that it has a limit of 100MB...
No, there is no such limit.

By the way, in general: If tagging can be automated, then tagging is not the answer. See also jupe above.

highend
Posts: 13749
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Auto tagging folders created by software based NVR?

Post by highend »

1. Doable via the gui but requires some parts written into the "Name" field. Scripting would be better suited for this

2. Go into the root of your NVR folder, execute this script:

Code: Select all

$start = now("msecs");
    $untagged = quicksearch('!tags:?* /E');
    e "Time: " . now("msecs") - $start . " msecs";
How long does it took?
One of my scripts helped you out? Please donate via Paypal

highend
Posts: 13749
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Auto tagging folders created by software based NVR?

Post by highend »

Here is a script that would be way faster to tag that many files (it does it in batches for each day instead of each item individually).
Additionally it checks if you've entered only the root or a subfolder of it so it doesn't try to find all files and folders that are untagged but only untagged folders in root and only untagged files in the current subfolder...

It assumes that there is one hierarchy of folders inside of root and each of these subfolders only has files in it...

Code: Select all

    $root = "full path to the root of the folders created by nvr";

    $curPath = get("path");
    $escRoot = regexreplace($root, "([\\^$.+()\[{])", "\$1");

    // Just tag folder(s) in root
    if ($curPath == $root) {
        tag(quicksearch('!tags:?* /E /d', $root));

    // Tag file(s) in subfolder of root
    } elseif (regexmatches($curPath, $escRoot . "\\\d{2}\d{2}\d{4}")) {
        tag(quicksearch('!tags:?* /E /f', $curPath));
    }


function tag($untagged) {
    if (!$untagged) { end true; }

    status "Preparing tags...", , "progress";
    $wMo = ""; $wTu = ""; $wWe = ""; $wTh = ""; $wFr = ""; $wSa = ""; $wSu = "";
    foreach($item, $untagged, <crlf>, "e") {
        $date    = filetime($item, "c");
        $weekday = format($date, "dddd"); // Monday, Tuesday, ...
        switch ($weekday) {
            case "Monday":
                $wMo .= $item . <crlf>; break;
            case "Tuesday":
                $wTu .= $item . <crlf>; break;
            case "Wednesday":
                $wWe .= $item . <crlf>; break;
            case "Thursday":
                $wTh .= $item . <crlf>; break;
            case "Friday":
                $wFr .= $item . <crlf>; break;
            case "Saturday":
                $wSa .= $item . <crlf>; break;
            case "Sunday":
                $wSu .= $item . <crlf>; break;
        }
    }
    if ($wMo) { tagitems("tag", "Monday",    $wMo); }
    if ($wTu) { tagitems("tag", "Tuesday",   $wTu); }
    if ($wWe) { tagitems("tag", "Wednesday", $wWe); }
    if ($wTh) { tagitems("tag", "Thursday",  $wTh); }
    if ($wFr) { tagitems("tag", "Friday",    $wFr); }
    if ($wSa) { tagitems("tag", "Saturday",  $wSa); }
    if ($wSu) { tagitems("tag", "Sunday",    $wSu); }
    status "Done!", , "ready";
}

One of my scripts helped you out? Please donate via Paypal

Schuller
Posts: 137
Joined: 02 May 2023 21:08

Re: Auto tagging folders created by software based NVR?

Post by Schuller »

Just tried this script, but first removed all the tags again(25,000 plus), saved, verified tagged items in list management and indeed, they were removed, then changed locations and went back again and they were all tagged again at mind boggling speed but this time with nothing freezing up. Just incredible! Also, It would always be one hierarchy of folders inside of root and each of the sub folders will only ever have files so that should be fine.
Curious, with that "After painting the file list", is it possible to auto delete files in a certain folder(s) after a certain age? One of the things I'd like to do on another folder where the NVR is also taking a series of still shots from the same cameras, which they call "grabs", is auto delete files after a certain age, permanently(no recycling). Much of these NVR recordings just end up getting deleted at some point anyway and new files are constantly being written everyday and the files of interest that I want to keep, I end up manually moving them to a different location.

Also,
By the way, in general: If tagging can be automated, then tagging is not the answer.
Food for thought

Schuller
Posts: 137
Joined: 02 May 2023 21:08

Re: Auto tagging folders created by software based NVR?

Post by Schuller »

I'm a bit confused here. I could be wrong but it appears that this script is meant to do what the other script did with tagging but with the option to delete files where the motion recorded clips are and not where I want to auto delete the files? The root directories where I want to auto delete the other NVR generated files are at totally different locations on different storage drives that don't share the same root as the files being tagged. Can "After painting the files list" run multiple scripts in different locations? How is this script implemented?

Here is a partial look of the NVR recording locations. Its recording different types of files(photos and videos) to different locations so there is no single NVR root but rather multiple roots.

G:\Axis\Motions Recordings\ (this is where the folders and files that are currently getting tagged)
H:\Axis\Parking\grabs (this is where I want to auto delete the photo files by age)
I:\Axis\Shop\grabs (this where is also where I want to auto delete the photo files by age)

Post Reply