Best way to handle automatic filing of video files, but different names?

I am really into railroads and model railroads, and download a ton of YouTube reference files. The way I am sorting these feels inefficient.

I have a Hazel rule. that looks and sees if it is a .mp4 file, and if the name contains, say, “Amtrak” it files it into the folder I have for Amtrak. I then copy this rule for each road name, so I have a bunch of rules. I then have an “other” rule where if it’s a different video format, it goes into a folder I read for Handbrake conversion.

What I can’t figure out is, can I have a rule that looks in the directory, sees that it is a .mp4, and if the name contains “Amtrak”, move it to the Amtrak folder, and “Union Pacific” and move it to that folder, etc.

Basically, I am just trying to have one rule that looks through the different road names I download.

Do you have a naming convention for the files where the rule could say pick the desired folder name from between two delimiters, or could the keyword(s) exist anywhere in the file name?

If the former, then I believe the answer would be yes. If the latter, I think we’d need to understand more about the limits of the folders, whether they might need creating on the fly, and perhaps how comfortable you are with moving the logic out into a shell script. Otherwise, I think the multiple rules seems a good and easily maintainable approach to me.

1 Like

The folders don’t need to creation. It’s organized like this:

  • Trains
    – Erie Lackawanna
    — EL Videos
    – CSX
    — CSX videos

There are some additional subfolders under each road name that aren’t important for this automation.

An example of one of the rules is:

  • Look at the folder YouTube-DL places the file
  • If name contains CSX, then move to /CSX/CSX Videos

I have a separate Hazel rule for each road name I research, about 7 in all.

What I’d like is if it was possible to combine them:

  • Look at parent folder
  • if it’s a MP4 file then,
  • If it’s a CSX video, move to /CSX/CSX Videos
  • If it’s a Union Pacific, move to /UP/UP videos

What this would let me do is put an additional rule in place at the end that puts all other MP4 files into a folder for later sorting.

I don’t think I can do this in Hazel, though. The way it’s working is fine, just a little extra effort if I end up needing to set it up for a new railroad.

I’m afraid that still doesn’t cover my question about the file names which is key to being able to dynamically pick up the key words for the naming.

Could you explain the file naming the files have when you drop them into your Hazel processing folder?

The file naming is not consistent, and is based off what YouTube-dl grabs from YouTube. For example, this is one of the names: 4K - Amtrak’s Coast Starlight Detouring over the Tehachapi Pass in April 2018-qnhx-4pVodE.mp4

So, the Hazel rule in this case sees that the file is a .mp4 file, and contains the words CSX, so it moves to my CSX video folder,

In that case you would have to have your rule looking for generic matches. While you could have a rule that scans the list of avail le folders and matches against that, you then have potential differences in letter case to account for too.

For the volumes you are talking about, and since the folder structures are always created, I think the overhead on individual Hazel rule maintenance is minimal - i.e. I doubt there’s any time saving in exploring a more complex and dynamic approach.

But, if it happens to be primarily a learning experienc,e or there are other factors that would contribute to the time saving, then I’d look to have a script that is called by Hazel to do the processing. Hazel by the sounds of it would still be a safe match for only triggering this for mp4 files; so keep that match there.

Probably any shell or scripting language would suffice in terms of what would need to be done. Simply pick your favourite or one you would most like to work with.

The process I would take would be as follows.

  • Scan the folders to get a list of viable categories.
  • From the file path passed in from Hazel, Get the file name, lowercase and strip out all symbols, double space to single space, etc.
  • Set a default catch-all destination folder.
  • Loop over the categories and if a match is found, set the destination folder and break the loop.
  • Move the file original file to it new destination.

Hope that helps.

That makes sense. I wasn’t opposed to having the multiple rules, but I wasn’t sure if it was the most efficient way to do the rules.

I may end up writing a bash script to do it, just to learn how.

Thanks for your help.