Skip to content

Instantly share code, notes, and snippets.

@zachflower
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zachflower/56beb334a3443c0c902f to your computer and use it in GitHub Desktop.
Save zachflower/56beb334a3443c0c902f to your computer and use it in GitHub Desktop.
AppleScript to migrate EyeTV recordings to Plex.
on run {input, parameters}
with timeout of (30 * 60) seconds
tell application "Finder"
repeat with anItem in the input
set parentFolder to container of anItem
set otherFiles to name of files in parentFolder
repeat with otherFile in the otherFiles
if otherFile ends with ".eyetvp" then
set xmlFile to (parentFolder as string) & ":" & otherFile
end if
end repeat
tell application "System Events"
set xmlContents to contents of XML file xmlFile
set xmlData to value of every XML element of XML element "dict" of XML element "dict" of XML element "plist" of xmlContents
set foundEpisodeNum to false
set foundShowTitle to false
set foundEpisodeTitle to false
set foundSeason to false
set episodeNum to 0
set showTitle to "Unknown"
set episodeTitle to "Unknown"
set season to 0
repeat with xmlElement in xmlData
set xmlElement to xmlElement as string
if foundEpisodeNum is true then
set episodeNum to xmlElement
set foundEpisodeNum to false
end if
if foundShowTitle is true then
set showTitle to xmlElement
set foundShowTitle to false
end if
if foundEpisodeTitle is true then
set episodeTitle to xmlElement
set foundEpisodeTitle to false
end if
if foundSeason is true then
set season to xmlElement
set foundSeason to false
end if
if xmlElement is "EPISODENUM" then
set foundEpisodeNum to true
end if
if xmlElement is "TITLE" then
set foundShowTitle to true
end if
if xmlElement is "ABSTRACT" then
set foundEpisodeTitle to true
end if
if xmlElement is "SEASONID" then
set foundSeason to true
end if
end repeat
end tell
set destinationFilename to showTitle & " - s" & season & "e" & episodeNum & " - " & episodeTitle & ".mpg"
set destinationPath to "Volumes:2TB:Recordings:"
try
make new folder at alias destinationPath with properties {name:showTitle}
end try
try
make new folder at alias (destinationPath & showTitle & ":") with properties {name:"Season " & season}
end try
set finalDestinationPath to (destinationPath & showTitle & ":Season " & season) as alias
set theDupe to duplicate anItem to folder finalDestinationPath with replacing
set name of theDupe to destinationFilename
delete (files of parentFolder)
delete parentFolder
end repeat
end tell
end timeout
return input
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment