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_idmy export_recording(new_recording)end tellend RecordingDoneon runtell application "EyeTV"set selected_recordings to selection of programs windowrepeat with selected_recording in selected_recordingsmy export_recording(selected_recording)end repeatend tellend runon export_recording(the_recording)tell application "EyeTV"set recording_location to location of the_recording as textset AppleScript's text item delimiters to "."set recording_path to text items 1 through -2 of recording_location as stringset AppleScript's text item delimiters to ""set recording_path to POSIX path of recording_pathset input_file to my escape_path(recording_path & SOURCE_TYPE) as stringset output_file to my escape_path(TARGET_PATH & my get_recording_name(recording_location) & TARGET_TYPE) as stringset cmd to HANDBRAKE_CLI & " -i " & input_file & " -o " & output_file & HANDBRAKE_PARAMETERS & SHELL_SCRIPT_SUFFIXdo shell script "echo \"" & cmd & "\" > /Users/niedral/shellscript.log"do shell script cmdend tellend export_recordingon get_recording_name(recording_location)set oldDelimiters to AppleScript's text item delimitersset 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 stringset AppleScript's text item delimiters to ".eyetv"set recording_name to first item of every text item of recording_folderset AppleScript's text item delimiters to oldDelimitersreturn recording_nameend get_recording_nameon escape_path(the_path)set oldDelimiters to AppleScript's text item delimitersset AppleScript's text item delimiters to "/"set path_components to every text item of the_pathset AppleScript's text item delimiters to oldDelimitersrepeat with counter from 1 to count path_componentsset path_component to item counter of path_componentsset item counter of path_components to my escape_string(path_component)end repeatset AppleScript's text item delimiters to "/"set the_path to path_components as stringset AppleScript's text item delimiters to oldDelimitersreturn the_pathend escape_pathon escape_string(the_string)set chars to every character of the_stringrepeat with i from 1 to length of charsif "!$&\"'*()/{[|;<>?` \\" contains (item i of chars as text) thenset item i of chars to "\\" & (item i of chars as text)end ifend repeatreturn every item of chars as stringend 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