Auto sort TV shows If folder exists or if not create folder

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

I just want to start with I am a huge fan of Hazel and have been using it for years but lately I have been thinking and scouring the forums but haven't had much luck and for those promising forum posts they are missing their images and hard to follow. I am still only using a portion of what Hazel can do but here goes my dilemma.

Current Setup
Here are four prior rules before my "Krypton" rule.
Image
To open up any torrent file downloaded to the desktop.

Image
Auto-delete extra unnecessary files that often come with the tv show or movies.

Image
Rule to look into the subfolders.

Image
TV Show downloads into the Downloads folder. Example: Krypton.S01E01.720p.mkv in a subfolder. Hazel looks and then moves Krypton.S01E01.720p.mkv into already existing Krypton folder in users/TV Shows/Krypton folder then shell script below is ran to rename the file to "Krypton S01E01.mkv".
Code: Select all
/usr/local/bin/tvnamer --batch "$1"


The Dilemma
This setup works. But the only problem is for each TV Show I have to create a separate rule and folder before it starts downloading. Like the one above. I keep thinking there has to be a better way.

The Goal
Is there a way to condense and/or make it so I don't have to create a rule and folder prior for each TV show?
Example the following episodes download simultaneously into my local Downloads folder.
Krypton.S01E01.720p.mkv
The.Flash.S02E04.mkv
Hazel checks and see's there is no "Krypton" folder so it creates one and then the shell script of TVNamer runs. All other files if any that downloaded in the Krypton.S01E01.720p folder are then moved to the Trash.
The.Flash.S02E04.mkv already has a folder so it is moved there, then TVNamer kicks in.

I am thinking this has to do with name matches and custom tokens but I don't know where to start with that. Any and all help is greatly appreciated!

Thank you!
horatioo
 
Posts: 6
Joined: Fri Feb 20, 2015 9:25 pm

Yes, a match pattern would probably work here. First, read up on it in the manual.

You can probably create a pattern which mathces anything that contains the "S" and "E" parts at the end. You can use a custom attribute to match the part of the file up to that point. Once you have that name, you can use it in the Sort into subfolder action. You might want to use the "Replace text" option there to replace the periods with spaces.

Give it a try and post back here if you run into problems.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I think I understand or hopefully I am on the right track. Here is what I have so far.
Image
TV show file is downloaded into my "Downloads" Folder. If it matches with the patterns above then the shell script to rename the file goes through. Krypton.S01E01.720p.mkv is renamed Krypton S01E01.mkv. It is then moved to the "TV Shows" folder. Then the Sort into subfolder comes next with the custom attribute to create the folder or move it to the folder named "Krypton" but here is where I am lost. I can create a pattern to capture just the first word but can you please provide an example or explanation how to make it so it omits everything once the S(1)(1)E(1)(1) pattern starts? Shows the have multiple words in the title wouldn't work with that logic.

Sidenote I just want to mention that with the current rule it does not work to identify the original Krypton.S01E01.720p.mkv file.
horatioo
 
Posts: 6
Joined: Fri Feb 20, 2015 9:25 pm

Note that the pattern in this case has to account for all characters in the name. You want to create a custom attribute to match the part before the S/E part so you can re-use it in the actions. You should also have the pattern match the parts after the S/E part, even if you end up discarding it later.

The manual should have an example that goes into more details about how to use patterns and custom attributes so I suggest checking that out.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I got the matching pattern down! Thank you! Now what I noticed is if I set the Sort into Subfolder rule to (name) it creates the folder Krypton S01E01. Is there a way to use the Sort into Subfolder rule to rename the folder to everything before S01E01? I looked into applescripts to rename based on character count but that wouldn't work for the variety of show names. Any suggestions?
horatioo
 
Posts: 6
Joined: Fri Feb 20, 2015 9:25 pm

What I would try, and what should point in the right direction, is the "custom text" token in the match pattern. I would set it up like this:
Image
Where the custom text token is set to (...) anything. This one you can use again in the subfolder rule to name the subfolder:
Image
Make sure to set the trigger to "Full Name" and not just Name because Hazel will stop checking the Name at dot "." if you have only "name" set (I think). Hope that helps!
You can find more on the topic here: https://www.noodlesoft.com/manual/hazel ... ttributes/
"Behind all the inhuman aspects of automation (...) its real possibilities appear: the genesis of a technological world in which man can finally withdraw from (...) the apparatus of his labor – in order to experiment freely with it." /Marcuse
Robert
 
Posts: 52
Joined: Sun Dec 16, 2018 8:05 am

THAT WAS IT!!!!

Robert and Mr_Noodle thank you!!! With a few tweaks it now works for any show name like a charm!
horatioo
 
Posts: 6
Joined: Fri Feb 20, 2015 9:25 pm

Hey Horatioo, was wondering if you could post the full set of rules that ended up working for you? I am also looking to do the same thing but having difficulties. Currently, I have a rule for each show as well and would like to consolidate it so it would work for any show and sorted into separate season folders. Would greatly appreciate it, thanks in advance!
blackjack32
 
Posts: 1
Joined: Fri Dec 27, 2019 12:29 pm


Return to Support