-- "Broadcatching"-style importer into iTunes for TV show episodes -- -- Requires Smile: http://www.satimage.fr/software/en/smile/index.html -- Do change the path to movie_file for your machine if you plan to use this. -- -- To use, paste this into the Script Editor, save the result as an Application. -- Then drop .avi files on top of it - names should be regular torrent-style -- release file names, nothing special like "4x04.Episode Title", unfortunately. (* Copyright (c) 2007 Andreas Fuchs Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *) on open theFileList repeat with theFile in theFileList tell application "Finder" set relativeName to do shell script "basename " & quoted form of POSIX path of theFile & " .avi" set movie_file to "Macintosh HD:Users:asf:p2p:converted:" & relativeName & ".mov" set theFileUrl to (URL of theFile) set decodedName to do shell script "echo " & quoted form of relativeName & " | nc laa.ilaaha.illa.a.la 57007 | head -1" end tell if decodedName is not "ERROR" and decodedName is not "" then set AppleScript's text item delimiters to "@@@" set decodedName to item 2 of decodedName's text items set AppleScript's text item delimiters to {""} tell application "Smile" to set seasonSpec to ufind text "(.*) - ([0-9]+)x([0-9]+) - (.*)" in decodedName regexpflag {"IGNORECASE"} using {"\\1", "\\2", "\\3", "\\4"} with regexp and string result else set seasonSpec to {-1, -1, -1, ""} end if set showName to item 1 of seasonSpec set seasonNumber to item 2 of seasonSpec set episodeNumber to item 3 of seasonSpec set trackName to item 4 of seasonSpec tell application "QuickTime Player" set theDocument to open location theFileUrl save self contained (item 1 of theDocument) in movie_file end tell tell application "iTunes" launch set theTrack to add movie_file set video kind of theTrack to TV show if seasonNumber is not -1 then set season number of theTrack to (seasonNumber as integer) set episode number of theTrack to (episodeNumber as integer) set episode ID of theTrack to ((seasonNumber as integer) as string) & "x" & episodeNumber set show of theTrack to showName set name of theTrack to trackName end if end tell tell application "Finder" move movie_file to trash move theFile to trash end tell end repeat tell application "Smile" to quit end open