Figuring out workflow for movies & tv shows

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

Moderator: Mr_Noodle

Figuring out workflow for movies & tv shows Fri Dec 21, 2012 2:13 am • by tscibilia
hey, i'm having a problem creating rules for an automated workflow to process downloaded movies and shows. Please don't get bored reading this...I was just trying to be thorough :D

Background:
I tried to follow this post (viewtopic.php?f=3&t=874) but its not the greatest walkthrough to setup. so i decided to use most of the programs listed there to download tv shows. I'm using TV Shows v2, Transmission v2.75, Hazel v3.0.16 (obviously), Handbrake CLI v0.9.8, FileBot v3.2, iFlicks v1.4.6

Ideal Workflow
I would like to have TV Shows app send new episodes to Transmission (this works fine). Transmission sends my completed downloads to a folder named "TV Shows." I want Hazel to search that folder for new movie files including file within subfolders and send them to Handbrake to process for my AppleTV format (m4v). Then I'd like Hazel to properly name the file via FileBot and finally pass that file through iFlicks which will ultimately sends it to iTunes. Finally, I'd like Hazel to clean up the old files in the "TV Shows" folder.

My Current Workflow
TV Shows
    Run in Subfolders (Works, but Hazel log constantly running)
    • If <all> conditions met for <the file or folder being matched>
    <Kind> is <Folder> & <Date> is after <Date Last Modified>
    • Do the following
    <Run rules on folder contents>
    Move files to processing (This works as expected)
    • If <any> conditions met for <the file or folder being matched>
    <Kind> is <Movie> & <Extension> is <mkv>
    • Do the following
    <Move> to folder <Processing/1.0 TV Shows - Handbrake>
    Delete empty folders (Rule never triggers)
    • If <all> conditions met for <all of its sub-files and folders>
    <Kind> is <Folder> & <Date Added> is not in the last <10 minutes>
    • Do the following
    <Move> to folder <Trash>

1.0 TV Shows - Handbrake
    Run Handbrake CLI (Works, but not moving files)
    • If <all> conditions met for <the file or folder being matched>
    <Date Added> is after <Date Last Matched> & <Extension> is not <m4v>
    • Do the following
    <Run AppleScript> viewtopic.php?p=3447#p3447
    <Move> to folder <Processing/2.0 TV Shows - Rename>

2.0 TV Shows - Rename
    Rename FileBot (The workflow never gets to this point)
    • If <all> conditions met for <the file or folder being matched>
    <Date Added> is after <Date Last Matched>
    • Do the following
    <Run shell script> <filebot -rename "$1" --format "{n}-{s00e00}-{t}" --db thetvdb -non-strict>
    <Move> to folder <Processing/3.0 TV Shows - iFlicks>

3.0 TV Shows - iFlicks
    iFlicks metadata + transfer (The workflow never gets to this point)
    • If <all> conditions met for <the file or folder being matched>
    <Date Added> is after <Date Last Matched>
    • Do the following
    <Run AppleScript>
    Code: Select all
    tell application "iFlicks" to launch
    delay 7
    tell application "iFlicks"
       import theFile without gui
       delay 300
       tell application "iFlicks" to quit
    end tell

My Problems
    1.) In the "TV Shows" folder, the preview show me that after files are moved the remaning empty folders (which i want to delete is stuck on the "Run in subfolders" rule and never makes it to the "Delete empty folders" rule.
    2.) In the "1.0 TV Shows - Handbrake" folder, the preview show me that my rules are being met as i expected, but the log keeps giving me an error.
    2012-12-21 01:05:34.566 hazelworker[74334] Another hazelworker process is processing folder (null). Exiting.
    3.) In the "2.0 TV Shows - Rename" folder, although the workflow doesn't make it to this point i tried this manually and it seemed to work fine.
    4.) In the "3.0 TV Shows - iFlicks" folder, although the workflow doesn't make it to this point i tried this manually and it seemed to work, except that i tried to add a delay to quit the application which doesn't seem to work.
Please, any help it working this out would be greatly appreciated, I'm new to this!
tscibilia
 
Posts: 11
Joined: Fri Dec 21, 2012 12:55 am

Alright, lets take these one at a time.

tscibilia wrote:My Current Workflow
TV Shows
    Run in Subfolders (Works, but Hazel log constantly running)
    • If <all> conditions met for <the file or folder being matched>
    <Kind> is <Folder> & <Date> is after <Date Last Modified>
    • Do the following
    <Run rules on folder contents>


For subfolder rules especially Hazel has to run nearly constantly to be sure that all subfolders the rule applies to are effectively monitored. I wouldn't worry about the volume of logging.

You might consider limiting the subfolder depth that Hazel searches - for instance setting a maximum depth of 1 will only apply the rule to child folders of the monitored folder (not grandchildren, great-grandchildren etc.)

tscibilia wrote:<Move> to folder <Processing/1.0 TV Shows - Handbrake>[/list]
    Delete empty folders (Rule never triggers)
    • If <all> conditions met for <all of its sub-files and folders>
    <Kind> is <Folder> & <Date Added> is not in the last <10 minutes>
    • Do the following
    <Move> to folder <Trash>


Look at "all of its subfiles and folders"... You're asking Hazel to delete a parent folder that contains folders that have not been added in the last 10 minutes.

Change to this:

Code: Select all
 If (all) conditions met for (the file or folder being matched)
     Kind is Folder
     Size is 0 bytes

Do the following to the matched file or folder:
     Move> to folder Trash


Your subfolder rule will eventually drill down to these folders, where it will monitor them for 0 size and delete.

tscibilia wrote:1.0 TV Shows - Handbrake
    Run Handbrake CLI (Works, but not moving files)
    • If <all> conditions met for <the file or folder being matched>
    <Date Added> is after <Date Last Matched> & <Extension> is not <m4v>
    • Do the following
    <Run AppleScript> viewtopic.php?p=3447#p3447
    <Move> to folder <Processing/2.0 TV Shows - Rename>


I'm a bit confused here - what is the name of the ultimate directory the files are to be placed in? Is it 2.0 TV Shows Rename or do you have a slash in the folder name and the single folder is Processing/2.0 TV Shows - Rename

I imagine it's the former because of the name of the next rule. If the this is the case, then just select the ultimate folder instead of writing out the path. Hazel is likely getting confused by your path. If the latter is the case, I'd suggest renaming the folder because Hazel is likely getting confused by your implied path.

Check the logs for moving errors for further help.

tscibilia wrote:2.0 TV Shows - Rename
    Rename FileBot (The workflow never gets to this point)
    • If <all> conditions met for <the file or folder being matched>
    <Date Added> is after <Date Last Matched>
    • Do the following
    <Run shell script> <filebot -rename "$1" --format "{n}-{s00e00}-{t}" --db thetvdb -non-strict>
    <Move> to folder <Processing/3.0 TV Shows - iFlicks>


Why does the workflow never get here? Because the moving fails from before I'm guessing. Try adding a file manually to see if this works.

tscibilia wrote:3.0 TV Shows - iFlicks
    iFlicks metadata + transfer (The workflow never gets to this point)
    • If <all> conditions met for <the file or folder being matched>
    <Date Added> is after <Date Last Matched>
    • Do the following
    <Run AppleScript>
    Code: Select all
    tell application "iFlicks" to launch
    delay 7
    tell application "iFlicks"
       import theFile without gui
       delay 300
       tell application "iFlicks" to quit
    end tell


Again, have you tried adding a file manually?
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Hey, thanks for taking the time to help me out. I worked out some issues, but i still have a couple of issues.

First, I used your suggestions for the subfolder rule and it worked after reorganizing them to have the "delete" rule first then "search in subfolders" second (see all rules below)

Second, I'm still having problems with my Handbrake workflow but i made an attempt at resolving. The Handbrake CLI works fine; however, even after updating the move to folder (removed the slash as suggested) the converted file still doesn't "move" to the specified folder. I think it has to do with the condition "If extension is not m4v" So i added another rule that can be triggered after the Handbrake CLI is finished processing each file that could move it to the next folder to be renamed? (see added rule below, is there a better way of doing this" since "date last modified" doesn't change as the file is being converted so to be safe i made this a high number since the files could be as large as 2GB!)

Third, when manually triggered, the "rename" workflow does work!

Fourth, I'm still having problems with my iFlicks workflow. The iFlicks application launches and processes the file, i just can't figure out how to safely quit the application after its finished. If one or two files are be processed it goes fast and my 5minute delay to quit works fine, but if i'm processing a few more files, i get a popup message saying "files are still being processed, are you sure you want to quit?" Any suggestions on how to do this?

HERE ARE MY CURRENT WORKFLOWS:
TV Shows
    Delete empty folders (This works)
    • If <all> conditions met for <the file or folder being matched>
    <Kind> is <Folder>
    <Size> is <0 bytes>
    • Do the following
    <Move> to folder <Trash>
    Run in Subfolders (This works)
    • If <all> conditions met for <the file or folder being matched>
    <Kind> is <Folder>
    <Subfolder Depth> is less than <1>
    • Do the following
    <Run rules on folder contents>
    Move files to processing (This works)
    • If <any> conditions met for <the file or folder being matched>
    <Kind> is <Movie>
    <Extension> is <mkv>
    • Do the following
    <Move> to folder <1.0 TV Shows - Handbrake>

1.0 TV Shows - Handbrake
    Run Handbrake CLI (This works)
    • If <all> conditions met for <the file or folder being matched>
    <Date Added> is after <Date Last Matched>
    <Extension> is not <m4v>
    • Do the following
    <Run AppleScript>
    Code: Select all
    tell application "Finder"
       try
          --Set to red label to indicate processing
          set label index of theFile to 2
          --Assemble original and new file paths
          set origFilepath to quoted form of POSIX path of (theFile as alias)
          set newFilepath to (characters 1 thru -5 of origFilepath as string) & "m4v'"
          --Start the conversion
          set shellCommand to "nice /Applications/HandBrakeCLI -i " & origFilepath & " -o " & newFilepath & " --preset=\"AppleTV 3\" ;"
          do shell script shellCommand
          --Set the label to orange
          set label index of theFile to 3
       end try
    end tell
    tell application "Finder"
       set movieName to name of item theFile
    end tell
    tell application "Growl"
       set the allNotificationsList to {"Handbrake convert complete"}
       set the enabledNotificationsList to {"Handbrake convert complete"}
       register as application "Handbrake Encode Growler" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "HandBrake"
       notify with name "Handbrake convert complete" title "Handbrake conversion complete" description "The video \"" & movieName & "\" has been converted." application name "Handbrake Encode Growler"
       --Remove the old file
       set shellCommand to "rm -f " & origFilepath
       do shell script shellCommand
    end tell
    Move to be Renamed (This works, but I'm not sure how low I can make the trigger such as 3 mins?)
    • If <all> conditions met for <the file or folder being matched>
    <Extension> is <m4v>
    <Date Last Modified> is not in the last <30 minutes>
    • Do the following
    <Move> to folder <2.0 TV Shows - Rename>

2.0 TV Shows - Rename
    Rename FileBot (This works)
    • If <all> conditions met for <the file or folder being matched>
    <Date Added> is after <Date Last Matched>
    • Do the following
    <Run shell script> <filebot -rename "$1" --format "{n}-{s00e00}-{t}" --db thetvdb -non-strict>
    <Move> to folder <3.0 TV Shows - iFlicks>

3.0 TV Shows - iFlicks
    iFlicks metadata + transfer (This works, but i need suggestions on how to quit the application, any suggestions?)
    • If <all> conditions met for <the file or folder being matched>
    <Date Added> is after <Date Last Matched>
    • Do the following
    <Run AppleScript>
    Code: Select all
    tell application "iFlicks" to launch
    delay 7
    tell application "iFlicks"
       import theFile without gui
       delay 300
       tell application "iFlicks" to quit
    end tell
tscibilia
 
Posts: 11
Joined: Fri Dec 21, 2012 12:55 am

tscibilia wrote:Move to be Renamed (This works, but I'm not sure how low I can make the trigger such as 3 mins?)


Why not move at the bottom of your conversion script, instead of a separate rule? Hazel will wait for the script to finish before moving on to the next action.


tscibilia wrote:iFlicks metadata + transfer (This works, but i need suggestions on how to quit the application, any suggestions?)


If tell application "iFlicks" to quit doesn't work, then run a shell script:

Code: Select all
killall -9 iFlicks
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Thanks so much for helping me work this out. I'll try those suggestions.

Much appreciated,
Thomas
tscibilia
 
Posts: 11
Joined: Fri Dec 21, 2012 12:55 am

tscibilia wrote:TV Shows
[list]Run in Subfolders (Works, but Hazel log constantly running)


A solution:

If your are willing to specify the path to the folder you can set a "Passes shells script" rule to determine if a folder is empty – this will trigger "Run in Subfolders" only if the specified subfolder has some kind of content:

Code: Select all
[ "$(ls -A ~/Movies/rest-of-the-path)" ] && exit 0 || exit 1


Another approach (needs some tweaking to work):

If you know how to write a variable with this command, then you can omit specifying the path by writing the variable at the top of your embedded shell script:

Code: Select all
path=`dirname "$1"/sub_dir`


This should target the subfolder directly, it has worked for me in another rule (maybe even adding another sub_dir level would work too). But when trying to write the next lines…

Code: Select all
[ "$(ls -A "$path")" ] && exit 0 || exit 1

OR
Code: Select all
[ "$(ls -A ${path})" ] && exit 0 || exit 1


it doesn't work. I don't know how to add the variable properly, so the snippet would be more versatile.
pattulus
 
Posts: 13
Joined: Sun Nov 06, 2011 1:05 pm

This is nearly the perfect scenario which I'm trying to create. The only difference is that I am trying to get the TV shows and movies to Plex. My setup is different though.

I am using TV Shows 2.1 (r631), Hazel 3.2.7 (build 1099), Transmission 2.82 (14160), Handbrake CLI, Filebot 4.0, iFlicks 2.0.2 and Alfred App 2.2 (243)

I use the Macintosh HD is for Apps and documents and downloading DMG/app updates/prefpanes etc. My
movies are on /Volumes/Media/M0vies [to distinguish between cinematic theatrical releases and ~/movies/personal.mp4] My
TV Shows are on /Volumes/TV/Showname/season #/show (year/US) SxxExx - epi title

I have a third volume that I can use to do the processing-renaming of files. Once the processing is completeI would like to return them to the respective folders .../M0vies or .../Showname/season #

Currently TV shows auto adds shows to Transmission which is automatically setup to "save each show into its own folder" and "Create season subfolders"

Also I know to pick the folder within Hazel, the paths are listed simply for reference.
My Ideal Workflow
/Volumes/TV/
    Run in Subfolders
    • If <all> conditions met for <the file or folder being matched>
    <Kind> is <Folder> & <Date> is after <Date Last Modified>
    • Do the following
    <Run rules on folder contents>

    Move for processing
    • If <all> conditions met for <the file or folder being matched>
    <Kind> is <Movie> & <Extension> is <mkv>
    • Do the following
    <Color Label> green
    <Move> to folder </Volumes/Backup/Shows/Process/>OPTION <throw away if duplicate>

    REPEAT for AVI

/Volumes/Backup/Shows/Process/
    Run Handbrake CLI
    • If <all> conditions met for <file matched>
    <color label> is green
    • Do the following
    <Run AppleScript> as the aforementioned but set the color label to yellow

    Delete MKV
    • If <all> conditions met for <file>
    <color label> is yellow
    • Do the following
    <move>to folder <trash>

    Move to rename
    • If <all> conditions met for <file>
    <extension> is m4v
    AND
    <Date Created> is NOT int he last 90 minutes (time for Handbrake CLI to encode)
    • Do the following
    <color label> is purple
    <move> to folder </Volumes/Backup/Shows/rename/>

/Volumes/Backup/Shows/rename/

    rename with filebot
    •if <all> conditions met for <file>
    <color label> is purple
    • Do the following
    <run Applescript>
    Code: Select all
    set ProgramPath to "/Applications/FileBot.app/Contents/MacOS/filebot"
    set FilePath to "/Volumes/Media/process/2 Rename/"
    set FileTestPath to "Volumes:Media:process:2 Rename:" as alias
    set FormatFile to "{n} -{sxe} -{t}"

    tell application "Finder"
       set TVShowFileNames to name of every file in FileTestPath
    end tell

    repeat with TVShow in TVShowFileNames
       try
          set RenameFile to FilePath & TVShow
          do shell script (quoted form of ProgramPath) & " -rename " & (quoted form of RenameFile) & " --db TheTVDB --conflict skip -non-strict --format " & (quoted form of FormatFile)
       on error
          --do nothing
       end try
    end repeat

    <color label> red

    Move to metadata folder
    •if <all> conditions met for <file>
    <color label> is red
    • Do the following
    <move> to /Volumes/Backup/Shows/metadata/


/Volumes/Backup/Shows/metadata/
    add metadata
    •if <all> conditions met for <file>
    <color label> is red
    • Do the following
    <run applescript> embedded script
    Code: Select all
    tell application "iFlicks 2" to launch
    delay 7
    tell application "iFlicks 2"
       «event iFlsImpt» theFile without «class ugui»
    end tell

    <color label> orange

inserting properly named and color labeled M4V into /Volumes/Backup/Shows/metadata/ and running hazel rules for this folder I get this error

"2014-04-21 06:57:10.280 hazelworker[692] orphan black 2x01.m4v: Rule Add Metadata w/ iFlicks matched.
2014-04-21 06:59:17.707 hazelworker[692] [Error] AppleScript failed: Error executing AppleScript on file /Volumes/Backup/Shows/3 metadata/orphan black 2x01.m4v.
2014-04-21 06:59:17.707 hazelworker[692] AppleScript error: {
NSLocalizedDescription = "iFlicks 2 got an error: AppleEvent timed out.";
NSLocalizedFailureReason = "AppleEvent timed out.";
OSAScriptErrorAppAddressKey = "<NSAppleEventDescriptor: [0x0,9009 \"iFlicks 2\"]>";
OSAScriptErrorAppNameKey = "iFlicks 2";
OSAScriptErrorBriefMessageKey = "AppleEvent timed out.";
OSAScriptErrorMessageKey = "iFlicks 2 got an error: AppleEvent timed out.";
OSAScriptErrorNumberKey = "-1712";
OSAScriptErrorRangeKey = "NSRange: {0, 0}";
}
2014-04-21 06:59:17.713 hazelworker[692] Done processing folder 3 metadata"

    Move to original location/Volumes/Media/TV/showName/season#[/b]
    •if <all> conditions met for <file>
    <color label> is orange
    • Do the following
    <run ???> to move <file> to /Volumes/Media/TV/ into showname/season# folder based on 'filename-season#'

this last part is what i have the most trouble with as I have ZERO experience with scripts.
elgallo
 
Posts: 17
Joined: Sat Apr 19, 2014 7:41 am


Return to Support