Handbrake CLI BASH vs Hazel Rules..... neither working

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

Moderator: Mr_Noodle

I have a workflow that is working well, when MKV files are dropped into the folder, HandbrakeCLI is called and the file is encoded and moved ready for tagging and ultimately to iTunes.

I would like to improve this if I can so I wondered if anyone has any suggestions on the following:

I have two rules in Hazel on the same folder, One says this:

Encode Rule
Code: Select all
If Extension is MKV
Run Shell Script
Move MKV to MKV Archive


The original BASH script I borrowed from this site some months ago it read:
Code: Select all
/Applications/HandbrakeCLI -i "$1" -o "${1%mkv}m4v" --preset="High Profile" -v

and worked a treat but it puts the converted file into the same folder as the MKV

so I put a second rule on the folder:

Move to Tag Rule
Code: Select all
If Extension is M4V and Last Modified is not in the last 3 minutes
Move to folder "to be Tagged"


but the problem I have is that it encodes all the MKV files and then moves all the M4V files, I would like it to move the M4V files as they are finished.

The obvious suggestion seemed to be not to move the files but to use a different destination folder for HandbrakeCLI so I tried this BASH script:

Code: Select all
DestLoc = "/Users/iand/Video Encoding Temp Folders/M4V-From-Handbrake/" & "${1%mkv}m4v"
/Applications/HandbrakeCLI -i "$1" -o "$DestLoc" --preset="High Profile" -v


But the M4V files are still created in the same folder as the source file.

So my questions are:

1) any BASH experts that might happen to be passing that can tell me why the script doesn't work
2) Any Hazel experts that might be able to advise on using the rules to better manage the converted files as they are created rather than once all MKV's have been converted.

Thanks

Ian
sailingbikeruk
 
Posts: 5
Joined: Sat Sep 26, 2015 12:16 pm

I think setting the output directory in the script is the better way to go. Otherwise you'd need to involve an AppleScript to report back to Hazel the new file to move which is a bit more complicated.

I can't help with HandbrakeCLI specifically but I'd try the script in Terminal and make sure you get it working there before returning to Hazel.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I thought that I;'d post my final ruleset and code here in case anybody wants to see what i did, it may help or you may be able to provide a better/cleaner solution.

Ultimately, I have a shell script that reads thus:

Code: Select all
NewDestPath="/Users/iand/Video-Encoding-Folders/M4V-From-Handbrake/"
fname=$(basename "${1%mkv}m4v")
Dest="$NewDestPath"
Dest+="$fname"

/Applications/HandbrakeCLI -i "$1" -o "$Dest" --preset="High Profile" -v


line 1 sets the path of the new destination
line 2 extracts the filename from the current file in hazel
the next two lines concatenate the path with the filename

I had a number of problems, firstly, my original script as posted here was potentially concatenating the new path with the full path and filename of the current file. I needed to use the basename command to extract just the filename, for the longest time I kept getting initialisation errors from handbrake and it turned out to be a missing forward slash at the start of the new destination path - it seems that the Path MUST exist already!

Anyway, mine now works, MakeMKV rips into one folder, Handbrake converts the MKV to an M4V in another folder and I get a Hazel alert to go and Tag the files in subler - once done the colour tag is changed and they are sent to iTunes. The only manual step I have is the tagging, but I am quite particular about this and haven't found an automated method that is acceptable.
sailingbikeruk
 
Posts: 5
Joined: Sat Sep 26, 2015 12:16 pm


Return to Support