using Hazel with HandbrakeCLI

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

Moderator: Mr_Noodle

Re: using Hazel with HandbrakeCLI Sun Dec 19, 2010 12:15 pm • by ollie407
Great work on this script but I have two problems I hope someone can help me with.
The first is that the script will convert a file no problem and the result is a .m4v file but sits in the folder for a while with no change to the color label. After a few minutes I get another growl message saying that the conversion is complete and when I check the same m4v file it is now labeled yellow but is only one second long. Weirdly, when I check to see if Handbrake is running during this time (in the activity monitor) it is not, so no idea how the file ends up being only a second long when no conversion programs are running.

Secondly, I threw in a .mkv file into the watched folder and the script will not touch it, any idea how to make it recognize and convert an .mkv?

If anyone could help will be a real lifesaver.

Thanks.
ollie407
 
Posts: 3
Joined: Sun Dec 19, 2010 12:07 pm

Re: using Hazel with HandbrakeCLI Sun Dec 19, 2010 1:22 pm • by dhy8386
A few things. Are you using the latest nightly build of the handBrakeCLI version?

Also, you say it converts to mp4 fine but does not color. Then it colors but is one sec long. To be clear, you have no successful conversion, regardless of color label?

Post your hazel log and if possible your handbrakecli log as it relates to one of the conversions. That might help. Usually one second conversion is a failed conversion.

Also, are you running this embedded in hazel or as a separate script?
dhy8386
 
Posts: 94
Joined: Tue Nov 09, 2010 12:19 pm

Re: using Hazel with HandbrakeCLI Sun Dec 19, 2010 3:23 pm • by ollie407
I was doing this yesterday and downloaded that nightly build.
I do get a successful conversion, I watch handbrakeCLI in the activity monitor and once complete I get the growl notification that it successfully completed although it does not get colored. If I leave this new m4v file for a few minutes this is when I get a second growl notification that it successfully completed the conversion and the same file turns yellow but is only a second long. In activity monitor, handbrake is not running during this time once it completes the initial conversion....very strange.

I will run a few more and post some logs.

I tried running it as a separate script, as an embedded script in Hazel removing the first and last lines and even tried substituting the first and last lines with 'try' per one of the posts and all have the exact same result.

Edit: Here's the Hazel log.
The watched folder is called Temp.
The file being converted is dailyshowtrimmed.
At 14:43:15 the first conversion completes and I get the m4v file.
Four minutes later it looks like then try's to process the new m4v file.
No idea why it's looking for Adobe Unit Types or Flock files....

Code: Select all
 Sunday, December 19, 2010 2:42:37 PM America/New_York
2010-12-19 14:42:45.576 (null)[0] DEBUG: Program is licensed.
2010-12-19 14:42:45.586 hazelfolderwatch[13658] DEBUG: Error reading file /Users/bikerlee/Library/Application Support/Flock/profiles.ini: Error Domain=NSCocoaErrorDomain Code=260 UserInfo=0x10210d0d0 "The file “profiles.ini” couldn’t be opened because there is no such file." Underlying Error=(Error Domain=NSPOSIXErrorDomain Code=2 "The operation couldn’t be completed. No such file or directory")
2010-12-19 14:42:45.594 hazelfolderwatch[13658] DEBUG: Could not resolve alias. Old path: (null) Error: -50
2010-12-19 14:42:45.594 hazelfolderwatch[13658] DEBUG: Could not resolve alias. Old path: (null) Error: -50
2010-12-19 14:42:45.594 hazelfolderwatch[13658] DEBUG: Initialized
2010-12-19 14:42:45.594 hazelfolderwatch[13658] DEBUG: Pausing to wait for things to settle down.
2010-12-19 14:42:47.594 hazelfolderwatch[13658] DEBUG: Processing directories: (
    "/Users/bikerlee/Movies/temp"
)
2010-12-19 14:42:47.594 hazelfolderwatch[13658] DEBUG: About to process directory /Users/bikerlee/Movies/temp
2010-12-19 14:42:47.597 hazelfolderwatch[13658] dailyshowtrimmed.mov: Rule Convert to iphone matched.
2010-12-19 14:42:47.597 hazelfolderwatch[13658] DEBUG: New rule signature. Executing actions.
Old signature: (null)
New Signature:{typeObject isType: "public.movie"}:{(applescript:f49564a19656af1646fe436e7a249932,{
})}
2010-12-19 14:42:47.616 hazelfolderwatch[13658:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types:  dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.  Did find:
   /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: mach-o, but wrong architecture
2010-12-19 14:43:13.763 hazelfolderwatch[13658] DEBUG: AppleScript executed successfully with file /Users/bikerlee/Movies/temp/dailyshowtrimmed.mov. Result: <NSAppleEventDescriptor: 'null'()>
2010-12-19 14:43:13.763 hazelfolderwatch[13658] DEBUG: Action changed file: dailyshowtrimmed.mov
2010-12-19 14:43:13.764 hazelfolderwatch[13658] DEBUG: Writing out DB file: /Users/bikerlee/Movies/temp
2010-12-19 14:43:13.765 hazelfolderwatch[13658] DEBUG: Directory /Users/bikerlee/Movies/temp processed.
2010-12-19 14:43:13.765 hazelfolderwatch[13658] DEBUG: Sleeping
2010-12-19 14:43:15.766 hazelfolderwatch[13658] DEBUG: Done
hazelfolderwatch: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.


2010-12-19 14:47:09.735 (null)[0] DEBUG: Program is licensed.
2010-12-19 14:47:09.745 hazelfolderwatch[13664] DEBUG: Error reading file /Users/bikerlee/Library/Application Support/Flock/profiles.ini: Error Domain=NSCocoaErrorDomain Code=260 UserInfo=0x100738fe0 "The file “profiles.ini” couldn’t be opened because there is no such file." Underlying Error=(Error Domain=NSPOSIXErrorDomain Code=2 "The operation couldn’t be completed. No such file or directory")
2010-12-19 14:47:09.754 hazelfolderwatch[13664] DEBUG: Could not resolve alias. Old path: (null) Error: -50
2010-12-19 14:47:09.754 hazelfolderwatch[13664] DEBUG: Could not resolve alias. Old path: (null) Error: -50
2010-12-19 14:47:09.754 hazelfolderwatch[13664] DEBUG: Initialized
2010-12-19 14:47:09.754 hazelfolderwatch[13664] DEBUG: Pausing to wait for things to settle down.
2010-12-19 14:47:11.754 hazelfolderwatch[13664] DEBUG: Processing directories: (
    "/Users/bikerlee/Movies/temp"
)
2010-12-19 14:47:11.755 hazelfolderwatch[13664] DEBUG: About to process directory /Users/bikerlee/Movies/temp
2010-12-19 14:47:11.760 hazelfolderwatch[13664] dailyshowtrimmed.m4v: Rule Convert to iphone matched.
2010-12-19 14:47:11.760 hazelfolderwatch[13664] DEBUG: New rule signature. Executing actions.
Old signature: (null)
New Signature:{typeObject isType: "public.movie"}:{(applescript:f49564a19656af1646fe436e7a249932,{
})}
2010-12-19 14:47:11.778 hazelfolderwatch[13664:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types:  dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.  Did find:
   /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: mach-o, but wrong architecture
2010-12-19 14:47:13.341 hazelfolderwatch[13664] DEBUG: AppleScript executed successfully with file /Users/bikerlee/Movies/temp/dailyshowtrimmed.m4v. Result: <NSAppleEventDescriptor: 'null'()>
2010-12-19 14:47:13.341 hazelfolderwatch[13664] DEBUG: Action changed file: dailyshowtrimmed.m4v
2010-12-19 14:47:13.344 hazelfolderwatch[13664] DEBUG: dailyshowtrimmed.mov: Rule signature matched for rule Convert to iphone. Not executing actions.
2010-12-19 14:47:13.344 hazelfolderwatch[13664] DEBUG: Writing out DB file: /Users/bikerlee/Movies/temp
2010-12-19 14:47:13.345 hazelfolderwatch[13664] DEBUG: Directory /Users/bikerlee/Movies/temp processed.
2010-12-19 14:47:13.345 hazelfolderwatch[13664] DEBUG: Sleeping
2010-12-19 14:47:15.345 hazelfolderwatch[13664] DEBUG: Done
hazelfolderwatch: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
 


And here's the code I have embedded in Hazel:

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
   end try
end tell
tell application "Finder"
   set movieName to name of item theFile
end tell
tell application "GrowlHelperApp"
   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
ollie407
 
Posts: 3
Joined: Sun Dec 19, 2010 12:07 pm

Re: using Hazel with HandbrakeCLI Mon Dec 20, 2010 2:06 pm • by gcoghill
Not really sure why the script isn't working for you, but I can say that I'm not a huge fan of adding multiple Growl notices in a single AppleScript. They seem to get executed regardless of the previous event (in this case the file conversion) actually having completed successfully.

I prefer to use the method of cascading them into successive folders — that way you can monitor where the process is hanging.

Also, I discovered an issue with a single .mkv movie file that required the Handbrake CLI nightly build due to issues with the audio, but otherwise it's was working fine with the officual build and it looks like you're using it on a .mov file anyways.

I don't know enough about Console messages to help. The only thing I can tell you is that the script seems solid since it works for me and others, so there may be an issue elsewhere on your Mac. Have you tried it with other movie files from a different source?
gcoghill
 
Posts: 290
Joined: Tue Sep 18, 2007 8:09 am
Location: Kent, OH

Re: using Hazel with HandbrakeCLI Mon Dec 20, 2010 2:43 pm • by ollie407
I will remove the growl notifications from the script when I get home tonight, not sure if it will make a difference.
In this case I was using a .mov, when I try with an .mkv or, now it seams, a .wmv file it gets flagged as red but nothing happens, handbrake doesn't even start.
Will try the latest nightly build again tonight to see if that works.
I got around my main problem by creating another hazel rule that looks for .m4v files and moves them out of the watched folder before they get processed again.
If I could just get them flagged to a color by the script then I think that would solve it....

I tried on my girlfriends Macbook Pro and got exactly the same results.
Also, tried over 20 different files, some downloaded and some ripped myself and it behaves the same way on all of them, mkv's and wmv's will not work.

Can you (someone) post the exact script/rules you are using, just want to make sure I am not doing something stupid.
Kinda frustrating as this process is exactly what i've been trying to accomplish for ages, so close to getting it to work that I can taste it....
Thanks.
ollie407
 
Posts: 3
Joined: Sun Dec 19, 2010 12:07 pm

Re: using Hazel with HandbrakeCLI Tue Dec 21, 2010 9:30 am • by dhy8386
Well the script is very very vanilla. The easiest test is to just run a terminal command on your file for the handbrakecli. I would also run it in verbose mode. Try this to see what happens on all your files. Lets assume your file is in /Eser/bikerlee/movies/

From a terminal window, run the following on each of your files and see what happens (assuming you have put the handbrakecli in your applications folder):

/Applications/HandBrakeCLI -i /User/bikerlee/Movies/movie.mkv -o /User/bikerlee/Movies/movie.m4v --preset="Normal" -v

test that on all your files. If it works on everyone, it helps narrow it down to your script and or a mix of that and hazel rules you have. Those error messages in your console script related to Adobe are from a likely upgrade you did to snow leopard when you had CS3 or CS2 or lightroom on your machine. Its a 32bit incompatibility error with Adobe and applescript that will error every time applescript runs. Upgrade the component here http://kb2.adobe.com/cps/516/cpsid_51615.html

Dont think that will solve the problem but who knows....

Let us know on the above handbrake test.
dhy8386
 
Posts: 94
Joined: Tue Nov 09, 2010 12:19 pm

Re: using Hazel with HandbrakeCLI Tue Dec 21, 2010 1:31 pm • by gcoghill
The script I posted is the actual one I use. Despite my preference for external Growl alerts, it was just easier to use the script as-is.

My Hazel rules are nothing special — they just match color labels and file extensions and then run that script. I run the script via an external script, that way I can edit the script and it updates for all Hazel rules that call that script.

I'd try the nightly of HandbrakeCLI, but for me the only reason I needed to use the nightly was due to audio issues in an .mkv file that was giving problems. Worked fine with .avi files and other .mkv files.
gcoghill
 
Posts: 290
Joined: Tue Sep 18, 2007 8:09 am
Location: Kent, OH

Re: using Hazel with HandbrakeCLI Sat Oct 01, 2011 1:57 pm • by gregjsmith
They way I am using Handbrake manually, I may have multiple items to convert so I add them to the queue. How does this work with the CLI? If I use something like the script here will there be multiple handbrakes running?
gregjsmith
 
Posts: 10
Joined: Wed Oct 27, 2010 4:49 pm

Re: using Hazel with HandbrakeCLI Sat Oct 01, 2011 3:45 pm • by gcoghill
Currently the CLI does not do a queue, although I read recently that the nightly builds have added it, so it may be coming soon.

The way it works on my end is it just converts them sequentially (one at a time). The downside to this approach is there is no way to pause the conversion once it's started.
gcoghill
 
Posts: 290
Joined: Tue Sep 18, 2007 8:09 am
Location: Kent, OH

Re: using Hazel with HandbrakeCLI Sat Oct 01, 2011 4:17 pm • by gregjsmith
If you have this fully automated, how do you know if something is in process of being converted?
gregjsmith
 
Posts: 10
Joined: Wed Oct 27, 2010 4:49 pm

Re: using Hazel with HandbrakeCLI Sat Oct 01, 2011 5:23 pm • by gcoghill
I have Growl alerts involved in each stage of the process (started, completed, etc.), as well as a menubar CPU monitor. CPUs filled = current conversion :)
gcoghill
 
Posts: 290
Joined: Tue Sep 18, 2007 8:09 am
Location: Kent, OH

Re: using Hazel with HandbrakeCLI Thu Feb 26, 2015 10:46 pm • by vinyl_vibe
Apologies in advance for what will be a series of n00b questions ...

Firstly having read everything here this looks to be exactly what I'm after. I've modified the script based on the comments to ensure it can be run within Hazel and will also delete the original file:

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 "GrowlHelperApp"
      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
   


Assuming what I've got there is correct I now need to get this working within Hazel and that's where I need some help please. Having specified the folder to be watched, I believe I need to setup as:

If ‘any’ of the following conditions are met
Extension - is - .mkv
Do the following to the matched file or folder:
Run AppleScript -

and here’s where I don’t know how to proceed. Was AppleScript the correct option to select? if so how do I insert the code above into Hazel?

Again, apologies for such basic questions but your help with this would be greatly appreciated. Thanks
vinyl_vibe
 
Posts: 22
Joined: Sat Mar 12, 2011 8:36 am

Re: using Hazel with HandbrakeCLI Fri Feb 27, 2015 12:58 am • by gcoghill
Yes AppleScript is correct. The Hazel manual will explain how to add the code.
gcoghill
 
Posts: 290
Joined: Tue Sep 18, 2007 8:09 am
Location: Kent, OH

Re: using Hazel with HandbrakeCLI Fri Feb 27, 2015 7:18 am • by vinyl_vibe
Thanks. Haven't been able to find a manual for Hazel yet only a few other posts within the forum asking if one exists. Can you tell me if the code I've got looks correct?
vinyl_vibe
 
Posts: 22
Joined: Sat Mar 12, 2011 8:36 am

Re: using Hazel with HandbrakeCLI Fri Feb 27, 2015 10:52 am • by gcoghill
Hazel's Help is available by clicking on the question mark button in the bottom right corner.
gcoghill
 
Posts: 290
Joined: Tue Sep 18, 2007 8:09 am
Location: Kent, OH

PreviousNext

Return to Support