using Hazel with HandbrakeCLI

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

Moderator: Mr_Noodle

using Hazel with HandbrakeCLI Sun Oct 10, 2010 6:21 pm • by joshuaconner
I'm trying to set up Hazel to automatically send a file to HandbrakeCLI for conversion. Seems simple and everything looks all right...it's just not working.

My only condition (right now) is "Extension is avi". When I preview my rule matches, the .avi files in said folder are matched; the rule works.

On each matched file I'm having it run the following embedded shell script:
Code: Select all
echo '/Applications/HandbrakeCLI -i ' $1 '-o ' ${1%avi}'mp4 --preset="iPhone & iPod Touch" -v'


I can look up the console messages and see that the following was sent to the console:
10/10/10 3:03:01 PM [0x0-0x12ca2c9].com.noodlesoft.HazelHelper[24274] /Applications/HandbrakeCLI -i /Users/joshuaconner/Movies/filename.avi -o /Users/joshuaconner/Movies/filename.mp4 --preset="iPhone & iPod Touch" -v

which looks right. In fact, if I copy that starting with "/Applications/HandbrakeCLI..." into the terminal, Handbrake starts right up and successfully converts the file.

Anybody have any idea what I'm doing wrong here? Feeling at my wits' end.
Last edited by joshuaconner on Tue Oct 12, 2010 4:24 am, edited 1 time in total.
joshuaconner
 
Posts: 4
Joined: Sun Oct 10, 2010 6:07 pm

Re: using Hazel with HandbrakeCLI Mon Oct 11, 2010 3:13 pm • by Mr_Noodle
The 'echo' command just prints out the text. It doesn't actually run anything.

Also, not relevant in this particular instance, but you should use double quotes around the $1 argument in case the path has spaces.
Mr_Noodle
Site Admin
 
Posts: 8571
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: using Hazel with HandbrakeCLI Tue Oct 12, 2010 4:23 am • by joshuaconner
Thanks to Mr_Noodle, I figured it out! If anyone is trying to do this in the future -- and I recommend it! It's fun and convenient and it makes you feel like you're living in the future! -- here's how I did this it. I created two rules.

The first rule:
For the folder all of the files download to, if extension is avi, do the following:
    -Run the following embedded script:
    Code: Select all
    /Applications/HandbrakeCLI -i  "$1" -o  "${1%avi}"mp4 --preset='iPhone & iPod Touch'
    -Move file to folder: Trash

And the second rule:
For the same folder, if extension is mp4 and Date Created is not in the last 1 hour (put this in to give Handbrake time to finish converting; not sure if I actually need it, but better safe than sorry, I suppose), do the following:
    -Import into iTunes to playlist: whatever you want to call your playlist
    -Move file to folder Trash (I have iTunes set up to automagically manage my media files, so whenever I add something to iTunes, it copies the file into it's magic directory structure but leaves the original file. This action deletes the original (converted) file, which I no longer need.)

Actually, I move the file into a monitored folder on another computer, where another copy of Hazel imports the file into THAT computer's iTunes, but, you know, baby steps.

Hope this helps!
joshuaconner
 
Posts: 4
Joined: Sun Oct 10, 2010 6:07 pm

Re: using Hazel with HandbrakeCLI Thu Oct 21, 2010 10:43 pm • by Flynntargart
Hey, I'm trying to get this to work too, but I think I'm not having the success you are.

I installed handbrake and handbrake CLI.
I have Hazel set to find files that are movies, and that are not m4v files (reconverting my library for my new Apple TV).

I entered your code as an embedded shell script with a few changes, perhaps my problem.
Code: Select all
/Applications/HandbrakeCLI -i  "$1" -o  "${1%avi}"m4v --preset='Normal'


I have a preset that I call "Plex" in normal handbrake that I would love to use, but Normal is close enough.

Really I just want hazel to watch my move library folders and convert anything that isn't an m4v to an m4v file (excluding maybe ogg because of multiple language tracks).

Any suggestions, handbrake CLI just doesn't even seem to load, activity monitor doesn't show anything happening.
Flynntargart
 
Posts: 25
Joined: Mon Mar 29, 2010 12:07 pm

Re: using Hazel with HandbrakeCLI Thu Oct 21, 2010 10:58 pm • by joshuaconner
In the Hazel window, you can select a rule and then click the little gear-shaped drop-down button and select "Preview Rule Matches..." which will show you which files -- if any -- are being matched by your rule. Is your rule matching the files you think it should be matching?

Also, under the "Info" tab, you can click View Log to see the Hazel Log and console messages. That was helpful to me in getting this set up.

Let me know if you have any questions; I'll try to help!
joshuaconner
 
Posts: 4
Joined: Sun Oct 10, 2010 6:07 pm

Re: using Hazel with HandbrakeCLI Thu Oct 21, 2010 11:24 pm • by Flynntargart
As a 'test' I told the rule only to see red label files (after having the other conditions first set the reds, so I know that the selection bit of the rule worked) and then following running the Handbrake script, set the file to yellow. It picks files, turns'em red, and then yellow- but no encode love.
(also the preview works ;)

The log says:
2010-10-21 21:20:16.849 (null)[0] 2012 (2009).avi: Rule Mark Unconverted Files matched.
[21:20:16] hb_init: checking cpu count
[21:20:16] hb_init: starting libhb thread
HandBrake 0.9.4 (2009112300) - Darwin i386 - http://handbrake.fr
2 CPUs detected
Opening /Volumes/Little Black Book 1/-Movies3/2012 (2009).avi...
[21:20:16] hb_scan: path=/Volumes/Little Black Book 1/-Movies3/2012 (2009).avi, title_index=1
[21:20:16] scan: trying to open with libdvdread
libdvdnav: Using dvdnav version 4.1.3
libdvdread: Encrypted DVD support unavailable.
libdvdnav:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
libdvdnav:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.BUP failed
libdvdread: Can't open file VIDEO_TS.IFO.
libdvdnav: vm: failed to read VIDEO_TS.IFO
[21:20:17] dvd: not a dvd - trying as a stream/file instead
[21:20:17] hb_stream_open: open /Volumes/Little Black Book 1/-Movies3/2012 (2009).avi failed
[21:20:17] scan: unrecognized file type
[21:20:17] libhb: scan thread found 0 valid title(s)
No title found.
HandBrake has exited.

Which I suppose seems right until it says that it failed to open the file. It's a pretty standard AVI, plays in quicktime, and handbrake GUI will open it as a source no problem...

I'm going to try reinstalling HB CLI and updating my video codecs, but I'm kind of at a loss for a real reason CLI would fail to read the file.

Thoughts?
Flynntargart
 
Posts: 25
Joined: Mon Mar 29, 2010 12:07 pm

Re: using Hazel with HandbrakeCLI Thu Oct 21, 2010 11:27 pm • by joshuaconner
It sounds like Hazel is working okay. Make ask this over at the Handbrake CLI forums?

Sorry. I wish you luck!
joshuaconner
 
Posts: 4
Joined: Sun Oct 10, 2010 6:07 pm

Re: using Hazel with HandbrakeCLI Sat Nov 27, 2010 3:33 pm • by gcoghill
There's an awesome 3-part tutorial on using Hazel with converting & tagging TV shows:

http://forums.mactalk.com.au/56/90801-o ... t-1-a.html

http://www.mactalk.com.au/2010/08/20/or ... azel-pt-2/

http://forums.mactalk.com.au/56/91152-o ... t-3-a.html

Lots of great tips for file renaming, and automating the tagging process. The author uses a QuickTime conversion process via Automator, but this limits the file formats you can convert. I modified his process to include Handbrake CLI as the conversion app, as well as added some Growl alerts for things that happened along the way to keep me updated of progress.
gcoghill
 
Posts: 269
Joined: Tue Sep 18, 2007 8:09 am
Location: Kent, OH

Re: using Hazel with HandbrakeCLI Sat Nov 27, 2010 3:44 pm • by gcoghill
If anyone is interested, here's an external AppleScript that will convert video files to m4v for adding to iTunes, using Handbrake CLI. In this case I just used the "Normal" preset, but you can change those as you please for different presets. Also included is a custom Growl alert, which I included so I could send just this Growl alert to my iPhone using the Howl app, separate from the blanket Growl alerts sent by Hazel.

Note that the AppleScript also includes commands to change the color label of the file as it is processed, so you can keep an eye on how things are going.

Based heavily on the original AppleScript found here: http://cybernetnews.com/batch-convert-v ... plescript/
Code: Select all
on hazelProcessFile(theFile)
   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
   
end hazelProcessFile
gcoghill
 
Posts: 269
Joined: Tue Sep 18, 2007 8:09 am
Location: Kent, OH

Re: using Hazel with HandbrakeCLI Fri Dec 10, 2010 7:53 pm • by Flynntargart
This looks like good stuff, but I can't get Hazel to accept the apple script. Applescript editor compiles it, but Hazel will not...
It highlights the first work "on" and says at least one action has an empty field or an error. (the apple script action is the only action).
Any thoughts?
Flynntargart
 
Posts: 25
Joined: Mon Mar 29, 2010 12:07 pm

Re: using Hazel with HandbrakeCLI Fri Dec 10, 2010 8:52 pm • by dhy8386
Thats because that script is meant to run OUTSIDE of Hazel, hence the on "Hazelprocessfile". That command looks for the process running in OSX called hazelprocessfile. His script is meant to be run as a separate workflow or app. If you want to run it inside hazel, just remove the first line and the last line of the script, i believe.
dhy8386
 
Posts: 94
Joined: Tue Nov 09, 2010 12:19 pm

Re: using Hazel with HandbrakeCLI Mon Dec 13, 2010 12:56 pm • by gcoghill
Flynntargart wrote:This looks like good stuff, but I can't get Hazel to accept the apple script. Applescript editor compiles it, but Hazel will not...
It highlights the first work "on" and says at least one action has an empty field or an error. (the apple script action is the only action).
Any thoughts?


Delete the line
Code: Select all
on hazelProcessFile(theFile)

At the top, and the closing
Code: Select all
end hazelProcessFile


and it should work if pasted directly into Hazel.
gcoghill
 
Posts: 269
Joined: Tue Sep 18, 2007 8:09 am
Location: Kent, OH

Re: using Hazel with HandbrakeCLI Mon Dec 13, 2010 5:44 pm • by Flynntargart
indeed,
I replaced them with try and end try (just to be safe) and it works like a charm!

I've had it running in the background (process throttled) for a few days, it's worked its way through about 120 tv shows so far like a champ! Plex (plexapp.com) is keeping up, updating the library as it goes, soon my entire media collection will be converted, you're a hero!

One question, the script leaves the original file in place, but yellow. Would it be possible to have the script simply delete the source file, then force empty the trash (basically saving me swap space on my HDD)?

Right now I have Hazel going back and deleting yellow files modified in the last 2 days, which seems to be working nicely, but I am chewing up my hdds...
Flynntargart
 
Posts: 25
Joined: Mon Mar 29, 2010 12:07 pm

Re: using Hazel with HandbrakeCLI Mon Dec 13, 2010 6:46 pm • by dhy8386
If you look at the link gcoghill references (the original script he used to make his) there is a line for deleting the original file. I am pretty sure all you have to do is after the line in the code:

Code: Select all
set label index of theFile to 3


Put the following lines:

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


But i would double check with gcog.
dhy8386
 
Posts: 94
Joined: Tue Nov 09, 2010 12:19 pm

Re: using Hazel with HandbrakeCLI Mon Dec 13, 2010 8:03 pm • by gcoghill
Yeah dhy8386 is right — check the link to the original script. I modified it for my use. The original script I believe does delete after converting.

I'm no AppleScript guru, more of a copy/paste/deduce guy :)
gcoghill
 
Posts: 269
Joined: Tue Sep 18, 2007 8:09 am
Location: Kent, OH

Next

Return to Support

cron