using Hazel with HandbrakeCLI

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

Moderator: Mr_Noodle

Re: using Hazel with HandbrakeCLI Fri Feb 27, 2015 11:09 am • by vinyl_vibe
Thanks. Ok, so the script goes where I thought it would be having added it, I'm not sure it's saving it. Once I add, close the dialouge and click 'ok' I then reopen to check that it's saved the script but it's blank. I then tried adding it again and clicking on the compile option and it tells me that for this section of code:

Code: Select all
register as application "Handbrake Encode Growler" all


‘Expected end of line, etc. but found “””.’

No idea what to do.
vinyl_vibe
 
Posts: 22
Joined: Sat Mar 12, 2011 8:36 am

Re: using Hazel with HandbrakeCLI Fri Feb 27, 2015 11:54 am • by Mr_Noodle
Checking the original script, it seems like you didn't copy that full line so it results in a compile error.
Mr_Noodle
Site Admin
 
Posts: 11235
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: using Hazel with HandbrakeCLI Fri Feb 27, 2015 12:25 pm • by vinyl_vibe
I was working off the code shown here: viewtopic.php?f=4&t=859&start=15#p3573 and from that I can't see that I've missed anything out - especially as I simply copied all. If you can offer any further guidance I'd be grateful
vinyl_vibe
 
Posts: 22
Joined: Sat Mar 12, 2011 8:36 am

Re: using Hazel with HandbrakeCLI Fri Feb 27, 2015 10:42 pm • by vinyl_vibe
Think I've now got this working at last. Problem I had (I think) was that I was telling the rule to look at the folder 'TV Shows' rather than within the 'Season' subfolder of the 'Show Name' subfolder. Didn't realize I had to be that specific. Thought I could just specify the TV Shows folder and it would find ANY .mkv extension and convert.

So questions now are:

1. Does this mean I'm going to have to create a copy of this rule for each individual subfolder?

2. How would I modify the script so that it also converts .avi files?

3. How do I get it to delete all non-converted files (after the conversion has taken place of course)?

Thanks
vinyl_vibe
 
Posts: 22
Joined: Sat Mar 12, 2011 8:36 am

Re: using Hazel with HandbrakeCLI Fri Feb 27, 2015 10:53 pm • by gcoghill
Are you sure Handbrake can convert the files? Some MKV files don't work with Handbrake for whatever reason. Try converting them with the standalone app version to rule out that possibility.
gcoghill
 
Posts: 290
Joined: Tue Sep 18, 2007 8:09 am
Location: Kent, OH

Re: using Hazel with HandbrakeCLI Fri Feb 27, 2015 10:59 pm • by vinyl_vibe
sorry - have updated my last post as I think I've now got it working but did have a couple of further questions so added those to that post as well. If you're able to advise It'd be greatly appreciated. Thanks
vinyl_vibe
 
Posts: 22
Joined: Sat Mar 12, 2011 8:36 am

Re: using Hazel with HandbrakeCLI Sat Feb 28, 2015 12:30 pm • by vinyl_vibe
Guessing the answer to how I get this to convert .avi files is simply in establishing this within the Hazel rules rather than within the script itself. So only thing left really is how to deal with the original .mkv or .avi file since the script is just re-converting over and over again as it sees there's still a .mkv or .avi file in the watched folder.
vinyl_vibe
 
Posts: 22
Joined: Sat Mar 12, 2011 8:36 am

Re: using Hazel with HandbrakeCLI Sat Feb 28, 2015 3:31 pm • by vinyl_vibe
Ok, finally got it all working using the following code:

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=\"Normal\" ;"
      do shell script shellCommand
      
      --Set the label to orange
      set label index of theFile to 3
      
      --Remove the old file
      set shellCommand to "rm -f " & origFilepath
      do shell script shellCommand
      
   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"
end tell



Two new questions if anyone can offer some thoughts on this.

1. While the original file is now deleted, there are still sometimes some .nfo files left behind. Is there a way to modify the script to remove ALL files other than the converted file once complete?

2. This one is really weird. If I look in the iTunes subfolder where the converted files reside, I can see them there and even test them by opening in something like Quicktime - however - if I open up iTunes and browse, the show's subfolder and contents are not shown anywhere. Any ideas?

Thanks
vinyl_vibe
 
Posts: 22
Joined: Sat Mar 12, 2011 8:36 am

Re: using Hazel with HandbrakeCLI Wed Apr 15, 2015 9:17 pm • by MacWorks
Hello

Having a bit of trouble with this script at the end of the conversion. If I run the script below, and add a few files - all the files will convert and then be deleted by the script.

Any help to not have the new converted files deleted would be appreciated.

Thanks!

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=\"Normal\" ;"
do shell script shellCommand

--Set the label to orange
set label index of theFile to 3

--Remove the old file
set shellCommand to "rm -f " & origFilepath
do shell script shellCommand

end try
MacWorks
 
Posts: 6
Joined: Thu Sep 18, 2014 1:52 pm

Re: using Hazel with HandbrakeCLI Sun Sep 09, 2018 8:31 am • by mikejandreau
I can't seem to get the AppleScript to work for me either.

Hazel processes everything, but the resulting .m4v file is only ~50kb

I tried running the CLI right from Terminal on the same file I'm testing with and it works perfectly. No errors, a fully completed file is output.

But when running through the AppleScript in this thread and with Hazel, the CLI seems to never finish. Though, according to Activity Monitor, it runs for quite a while, but the resulting file is only a handful of kb.
mikejandreau
 
Posts: 36
Joined: Sun Sep 09, 2018 8:28 am

Previous

Return to Support

cron