Almost perfect movie management

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

Almost perfect movie management Sun Mar 23, 2014 5:25 am • by TehFenix242
Hi guys, I'm relatively new to the Mac (after almost 15 years on PC), I'm totally new to AppleScript and only recently discovered Hazel.

I figured it would be a great way to manage my movies from all my different sources so I've developed the following. Please critique and make any suggestions you feel would be helpful and by all means pinch this and play with it to see if you can make it better.

Part 1 - Objective
Have Hazel pick a movie up from a given folder, go look up actors from that movie and apply those actors names as tags to the movie before moving it into a destination folder. Then from Finder > All Tags you can just click your favourite actor and see all of their films that you have on your Mac.

    Image

Part 2 - Pre-requisites
I found that to apply what Hazel calls "Dynamic" tags within an AppleScript required a third party tool called "tag". To install this required the Package Manager "Homebrew" (http://brew.sh) which has simple to follow instructions on installing. Essentially just running

Code: Select all
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"


in Terminal. Once this was installed you install Tag in Terminal by typing

Code: Select all
brew install tag


Also required is JSON Helper (http://www.mousedown.net/mouseware/JSONHelper.html) which is available on the Mac App Store and simply installs.

That's it in terms of pre-requisites.

Part 3 - Hazel Rule
Hazel's powerful simplicity makes this bit a piece of cake, mirror this

    Image

In essence it monitors my Downloads folder (just where I chose to land all of my movies) and if the file is of type "Movie" it runs my AppleScript (next), moves it into my Movies folder and also applies my purple "Movie" tag.

Part 4 - AppleScript
This is where I've struggled; I've done some C based programming before and the syntax and what was possible was a little alien to me but I'll paste the code with comments and see what you think. If you can test a better way to do this then PLEASE let me know, I'd be very grateful!

Code: Select all
#Takes Hazel's input of theFile and creates a filename
#and fileext variable.  fileext isn't used yet but may be
#in future.

set text item delimiters to "/"
POSIX path of (theFile)
set filename to text item -1 of result
set text item delimiters to "."
set fileext to text item 2 of filename
set filename to text item 1 of filename



#Generates a prompt using the filename variable
#as a start from above to determine the movie name
#because the filename doesn't always match the plain
#"English" title of the movie.

tell application "System Events"
   display dialog "What is the movie called?" default answer filename
   set finalTitle to text returned of result
end tell



#Uses JSON Helper to sent the movie title obtained
#above to the OMDB API website.  This returns a JSON
#object and one of the nodes is a collection of Actors.
#This then sets a variable of "actors" to the entire contents
#of that node.

tell application "JSON Helper"
   set movieDetails to fetch JSON from "http://www.omdbapi.com/?t=" & finalTitle name "apiname" password "apipassword"
end tell

if length of movieDetails > 0 then
   
   set actors to |Actors| of movieDetails
   
   
   
   #This sets a file path (aFile) to the POSIX path which is
   #then usable by Terminal.  This caught me out for ages and
   #was just a gap in my knowledge.
   
   set aFile to POSIX path of theFile
   
   
   
   #Open a new instance of Terminal and sends the command to run
   #the Homebrew Tag application the comma separated list of actors
   #and the POSIX path to the Movie before waiting 1 second and
   #quitting Terminal.
   
   tell application "Terminal"
      do script "/usr/local/Cellar/tag/0.7.5/bin/tag -s \"" & actors & "\" " & "\"" & aFile & "\""
      delay 1
      quit
   end tell
end if


Part 5 - Conclusion
If you enter the movie name as it appears on IMDB this works great but any deviation won't return a result and therefore no tags will get set (by the AppleScript but the one in Hazel still does). There's a few bits I'd like to do for v2 but I'm not sure yet how to accomplish them

    1: Use RegEx or similar so that you don't have to manually type in the movie name
    2: Have it to not require an instance of tell application terminal but to just send it as a script. I did play with this but the path to the file kept proving problematic and my *nix / Mac / AppleScript knowledge just wasn't there to accomplish this.

Any advice / suggestions or tips would be greatly appreciated. Thanks.
TehFenix242
 
Posts: 2
Joined: Sun Mar 23, 2014 4:06 am

Re: Almost perfect movie management Tue Apr 29, 2014 1:45 am • by elgallo
Hi I was trying to figure out a similar solution for my Movies AND TV show list. While I enjoy Hazel for multiple reasons. I found something that works nearly perfectly for any situation or setup.

the prerequisites would be Transmission bit torrent client, Hazel of course and Filebot 4.0 found here http://www.filebot.net

read this http://www.filebot.net/forums/viewtopic.php?f=4&t=215

for the Mac specific solution (this requires Transmission as your bit torrent client) this would be for your newly downloaded media http://www.filebot.net/forums/viewtopic.php?f=4&t=520

now where hazel comes in there are some watcher scripts here http://www.filebot.net/forums/viewtopic ... folders#p5

you could set up hazel to watch folder for file type X (movies) or Y (music)
so
IF media kinda is MOVIE
then Run - Embedded Script any of the above.


Considering that there's extensive forum postings on filebot you shouldn't have any trouble sorting it out for your specific purposes.
elgallo
 
Posts: 17
Joined: Sat Apr 19, 2014 7:41 am


Return to Tips & Tricks - DO NOT POST QUESTIONS