AppleScript for exporting EyeTV recordings using HandBrake

AppleScript for exporting EyeTV recordings using HandBrake

Diese Seite gibt es auch auf deutsch!

EyeTV offers quite comfortable ways to export your recordings in common formats, but there are almost no way to change the settings of this export. Also the resulting filesize and quality does not satifsfy me. The OpenSource project HandBrake on the other hand pleased me especialy in this areas. As of version 0.9.3 of HandBrake you can use it to export usual video files as well and so I use it to archive my EyeTV recordings. After a while a take a look at the scripting interface of EyeTV to automate this process, adn this is the resulting AppleScript.

property HANDBRAKE_CLI : "~/bin/HandBrakeCLI"
property HANDBRAKE_PARAMETERS : " -O -I -f mp4 -e x264 -x level=30:bframes=0:cabac=0:ref=1:vbv-maxrate=1500:vbv-bufsize=2000:analyse=all:me=umh:subq=6:no-fast-pskip=1 -b 1000 -2 -T -E faac -B 128 -R 48 -A Deutsch -w 640"
property TARGET_PATH : "~/"
property TARGET_TYPE : ".mp4"
property SOURCE_TYPE : ".mpg"
property SHELL_SCRIPT_SUFFIX : " > /dev/null 2>&1 & "

on RecordingDone(recordingID)
       tell application "EyeTV"
               set new_recording_id to (recordingID as integer)
               set new_recording to recording id new_recording_id
               my export_recording(new_recording)
       end tell
end RecordingDone
 
on run
       tell application "EyeTV"
               set selected_recordings to selection of programs window
               repeat with selected_recording in selected_recordings
                       my export_recording(selected_recording)
               end repeat
       end tell
end run
 
on export_recording(the_recording)
       tell application "EyeTV"
               set recording_location to location of the_recording as text
               set AppleScript's text item delimiters to "."
               set recording_path to text items 1 through -2 of recording_location as string
               set AppleScript's text item delimiters to ""
               set recording_path to POSIX path of recording_path
               set input_file to my escape_path(recording_path & SOURCE_TYPE) as string
               set output_file to my escape_path(TARGET_PATH & my get_recording_name(recording_location) & TARGET_TYPE) as string
               set cmd to HANDBRAKE_CLI & " -i " & input_file & " -o  " & output_file & HANDBRAKE_PARAMETERS & SHELL_SCRIPT_SUFFIX
               do shell script "echo \"" & cmd & "\" > /Users/niedral/shellscript.log"
               do shell script cmd
       end tell
end export_recording
 
on get_recording_name(recording_location)
       set oldDelimiters to AppleScript's text item delimiters
       set AppleScript's text item delimiters to "/"
       set path_components to every text item of POSIX path of (recording_location as string)
       set recording_folder to item -2 of path_components as string
       set AppleScript's text item delimiters to ".eyetv"
       set recording_name to first item of every text item of recording_folder
       set AppleScript's text item delimiters to oldDelimiters
       return recording_name
end get_recording_name
 
on escape_path(the_path)
       set oldDelimiters to AppleScript's text item delimiters
       set AppleScript's text item delimiters to "/"
       set path_components to every text item of the_path
       set AppleScript's text item delimiters to oldDelimiters
       repeat with counter from 1 to count path_components
               set path_component to item counter of path_components
               set item counter of path_components to my escape_string(path_component)
       end repeat
       set AppleScript's text item delimiters to "/"
       set the_path to path_components as string
       set AppleScript's text item delimiters to oldDelimiters
       return the_path
end escape_path
 
on escape_string(the_string)
       set chars to every character of the_string
       repeat with i from 1 to length of chars
               if "!$&\"'*()/{[|;<>?` \\" contains (item i of chars as text) then
                       set item i of chars to "\\" & (item i of chars as text)
               end if
       end repeat
       return every item of chars as string
end escape_string

Installation and Usage

To use this script you need the command line version of HandBrake that's available for download on the HandBrake homepage.

If you copy this script to /Library/Application Support/EyeTV/Scripts, you are able to export a selected recording using the entry in the script menu of EyeTV. You can select more than one recording, but the export jobs are not qued but startet concurrent in the background.

Or you can copy the script into /Library/Application Support/EyeTV/Scripts/TriggeredScripts and name it RecordingDone.scpt. Then every new recording is automatically exported once the recording has finished.

You can customize the script using the first sich lines of code.

  • HANDBRAKE_CLI is the path to the HandBrakeCLI binary.
  • HANDBRAKE_PARAMETERS defines the export parameters. Here you can define the settings of your export.
  • TARGET_PATH determins the target path where the exported files are located (Must end with an /).
  • TARGET_TYPE defines the filetype of the target file.
  • SOURCE_TYPE defines the filetype of the source file.
  • SHELL_SCRIPT_SUFFIX determins the last parameters of the shell script call. You can use this to write the output to a log file. Don't forget the & at the end to start it in the background.

Download

HandBrake Export Script


Werbung