Tuesday, March 24, 2009

AppleScript / Automator: Import AVI video to iTunes as a TV Show or Movie

This is a sweet AppleScript / Automator Workflow that I created which totally automates the task of importing an AVI video into iTunes.
  • Select one or more video files to import. Works on AVI as well as other formats like M4V.
  • Adds metadata to the AVI files to make them iTunes compatible.
  • Prompts if you would like to import into Movies or TV Shows.
  • Sets iTunes metadata to identify the video as Movie or TV Show depending on your choice.
Here is a screenshot of my workflow and here is the workflow file (in a tarball...workflows actually are directories it seems...).

Installing

  1. To install as a Finder plugin (so you can select files in Finder then secondary-click / control-click and choose Automator -> Import to iTunes), open the .workflow file in Automator and choose Save As Plug-in, then in Plug-in for select Finder and Save.
  2. To install as an application so you can drag and drop files onto the application, open the .workflow file in Automator and choose File -> Save As and in File Format choose Application.

The AppleScript code is here if you want to copy and paste it:

on run {input, parameters}
 set videoType to button returned of (display dialog ("What type of video are you importing?") buttons {"Movie", "TV Show"} default button {"TV Show"})
 repeat with i in input
  try
   tell application "Finder" to set file type of file i to "MooV"
  end try
  tell application "iTunes"
   set newAddition to (add (i as alias))
   if videoType = "TV Show" then
    tell newAddition to set video kind to TV show
   end if
  end tell
 end repeat
 return input
end run

12 comments:

robin said...

Karl, this rocks! Exactly what I was looking for. Just one question... I'm I right to say that I can't put any albumart to my collections of avi files?

Karl Varga said...

I'm glad you like it Robin. I hadn't thought of adding albumart to my movies...doesn't look like you can. I've been meaning to improve on the script a bit, automate the labelling of the shows and moving them to my shows folders after download. I can take a look at this then. In the meantime let me know if you figure something out. :)

Anonymous said...

I love your script everything was added nicely to my iTunes movie folder, unfortunately I noticed like you mentioned that you cannot add album art to the files, the reason I was doing this as to be able to add artwork. Do you know any solution?

Anonymous said...

Hi. Love the idea of this, BUT can't get it to work. Run it and receive the error:
The action “Run AppleScript” encountered an error.

Have tried running it from Automator and standalone as a Finder Plugin and app as you suggest on your page.

Any suggestions? I've got a selection of my DVDs saved as AVI, to help stream across home network. But seeing them in itunes would be really useful to keep track of them all

Paul said...

Love it.

This is what I needed, I have just dropped the cash and got a NAS for home (Synology D409 if you are wondering) and I wanted all the Macs on the network to keep there library up to date as "sharing" is so crap in iTunes.

This is wonderful, I have spent all weekend trying to write the AppleScript myself and having no joy.

So thank you so much, this is why I love being a Mac User.

I see some people what to get album art and stuff. The way I'm doing it is with VideoDrive, it costs 13euro, but its a bargain, it will watch a folder for you then it searches IMDB and grabs all the information, then imports to iTunes or a folder

Chris said...

This is great! Is there a way to adjust the applescript to actually have it format as mp4? Wanted to automate a process for watching shows on an apple tv (ie, plop in the avi files, formats as mp4, adds them directly into itunes).

Gercek Karakus said...

It is not working on MacOSx 10.6.4


"The action “Run AppleScript” encountered an error.
Check the action╩╝s properties and try running the workflow again."

Gercek Karakus said...

Get Selected Finder Apps is deprecated.

noeluk said...

Hi there - this is just what I'm looking for but can't seem to get it working in Lion / iTunes 10.

Any ideas?

Anonymous said...

In order to successfully import AVI files to iTunes, we have to convert this AVI video to iTunes compatible video format like MP4. Bigasoft iPad Converter is just the right AVI to iTunes conversion software. It can easily convert AVI video file to iTunes supported MP4 format for transfer AVI to iPad, iPad2, iPhone, iPod, Apple TV and more.

The following is a step by step guide on how to convert and import AVI to iTunes with the help of Bigasoft iPad Video Converter at http://www.bigasoft.com/articles/how-to-import-avi-to-itunes.html

Anonymous said...

I download a Video Converter for AVI to iTunes. Converting like a charm for all of my AVI files. Hope this link helps you: http://www.faasoft.com/articles/avi-to-itunes-sync-avi-to-ipad-iphone-ipod.html

Anonymous said...

Easy Way to Import AVI to iTunes for Play AVI in iTunes or Sync AVI to Apple TV, iPod, iPhone or iPad at http://www.idealshare.net/itunes-quicktime/avi-to-itunes-solution.html