PDA

View Full Version : HELP! - Eye TV 3 to iTunes / Apple TV (Automatic)




heych
Mar 26, 2012, 05:30 AM
Hi All,

I can manually export Eye TV recordings to iTunes, formatted to Apple TV HD.

I was hoping that someone could show me how to write a script to do the following:

- Export all recorded files automatically to iTunes (formatted to Apple TV HD) but not copy the file into iTunes, only create a link (so the file remains in the Eye TV archive on an external drive)

Thanks,

h.



dgalvan123
Mar 26, 2012, 01:03 PM
I'd be interested in this as well. I currently have all my scheduled recordings set to automatically export to iTunes (formatted to Apple TV HD), but exported recordings get physically copied into the iTunes library folder and/or the "Movies" folder in your home directory.

It would be better if one could just send iTunes the "pointer" to the actual file sitting on the external hard drive, since I have less free space on my mac's internal hard drive.

It IS possible to tell iTunes to not copy new files into it's library when they are imported. Meaning if you were to just drag a new video file into the iTunes window pane then iTunes would recognize and catalog the file but not actually copy/duplicate it.
One can do this in two ways:
1.) When dragging the file to the iTunes window, but before letting go of your mouse button, you will probably see a green plus icon where your cursor is. If you press the option key before you let go of the mouse button, the green plus icon will go away, indicating you will not be actually copying the file, just "importing" it into iTunes.
2.) in iTunes go to iTunes-->Preferences-->Advanced and uncheck the box that says "Copy files to iTunes Media folder when importing".

That said, I tried option 2, above, and now when EyeTV exports the files don't actually end up in the iTunes Media Folder BUT now those files are still copied into the Movies folder in your home directory. So it doesn't solve the problem because whether the exported recordings are in your iTunes Media folder or just your Movies folder, they are still on your internal Hard Drive.

So in conclusion I think this is something that would need to be fixed with an update to EyeTV. That or perhaps someone had developed a DIY workaround using applescripts, since EyeTV plays nice with those.

heych
Mar 28, 2012, 01:02 AM
After sniffing around the net, I have been able to put together a solution using applescript.

Firstly, I created a TriggeredScripts directory:
Library/Application Support/EyeTV/Scripts/TriggeredScripts/

I then created a script that automatically exports all recordings to AppleTV format and saves to an external drive (destfolder). It also adds the link to the files to itunes. NOTE: I have my iTunes setting "Copy files to iTunes Media Folder when adding to library" unticked.
*********************RecordingDone.scpt****************
on RecordingDone(recordingID)

set destFolder to "1TB Turbo:Keepers:EyeTV:EyeTV iTunes:"

tell application "EyeTV"

set myid to recordingID as integer
set thisTitle1 to title of recording id myid
set thisTitle1 to my parseout(thisTitle1)
set thisTitle2 to unique ID of recording id myid
set thisTitle to thisTitle1 & " - " & thisTitle2
export from recording id myid to file (destFolder & thisTitle & ".mp4") as AppleTV replacing yes

end tell

end RecordingDone

--Subroutine to remove troublesome characters
to parseout(stringtoparse)
set illegals to (ASCII character of 60) & (ASCII character of 62) & (ASCII character of 58) & (ASCII character of 34) & (ASCII character of 47) & (ASCII character of 92) & (ASCII character of 124)
repeat with i from 1 to count (illegals)
set testletter to (text i thru i of illegals)
set the_offset to 1
repeat
set the_offset to offset of testletter in stringtoparse
if the_offset > 0 then
set stringtoparse to (text 1 thru (the_offset - 1) of stringtoparse) & "" & (text (the_offset + 1) thru -1 of stringtoparse)
else
exit repeat
end if
end repeat
end repeat
return stringtoparse
end parseout
*****************************************************

Since I didn't want to keep the original eyeTV recordings after they were exported to the external drive, I created another script in the same directory to delete the recordings after they are exported.

*******************ExportDone.scpt********************
on ExportDone(recordingID)

tell application "EyeTV"
set myid to recordingID as integer
delete recording id myid
end tell

end ExportDone
****************************************************

dgalvan123
Mar 28, 2012, 10:16 AM
Nice job! When I get a chance I'll try your script on my own setup.

dgalvan123
Apr 11, 2012, 02:21 PM
So I tried copy-pasting part of your applescript into my existing "Triggered" applescript, since I already have one that uses the ETVcomskip markers to remove commercials. I copied your code from inside your "RecordingDone" block into the existing "RecordingDone block in my ETV comskip script. Unfortunately I couldn't get your part of the code (saving the exported TV show to an external hard drive) to work inside mine. It's probably something I'm doing wrong, since you say this works for you. I'll revisit this on some upcoming night.

(Would you be willing to look over my franken-code if I can't get it to work later? I think you're much more experienced with Applescript than I am. . .)

EvilC5
Apr 11, 2012, 04:11 PM
Did you get comskip to work? I tried several times and got nothing.

newagemac
Apr 11, 2012, 04:33 PM
Maybe I am not understanding the problem but couldn't you just set the iTunes Library on the external drive instead of having to script a workaround?

dgalvan123
Apr 11, 2012, 05:54 PM
Maybe I am not understanding the problem but couldn't you just set the iTunes Library on the external drive instead of having to script a workaround?

Maybe. But there is some benefit to storing your EyeTV movies/TV shows all in one place without sending them into the iTunes library at all. iTunes really just needs the links to the content. I'd prefer to manage my content storage differently for EyeTV than for the rest of my iTunes content. And I'd prefer the exported files sit on my external HD instead of my internal, since as it is I have to micromanage my storage space on my internal drive, which has less free space than my external.

Also, according to this thread: http://www.avsforum.com/avs-vb/archive/index.php/t-1392013.html exports from EyeTV always go into the user/movies folder on your internal drive. The only way to choose where the exports go is to either a.) manually export from EyeTV using the "saveas" dialog box to choose the destination, or b.) use an Applescript like the one above instead of EyeTV's built-in auto-export function.

----------

Here is my current RecordingDone script. Yes the comskip functionality works! The ETV Comskip feature, which marks where the commercials are in the first place, is hit and miss. But if the commercial locations are marked, this script will indeed edit them out so that I don't see them at all when I watch on my apple tv.

You can see how I copy-pasted in your code into my RecordingDone block. See any obvious coding errors?

-- Run the python MarkCommercials script for the given recording
-- this must be run with the RecordingStarted script
-- it will check if there were multiple PIDs for the recording and runs MarkCommercials for each pid
-- requires updated MarkCommercials which allows specifying the pid
-- by Ben Blake, September 2009

global LogMsg

on RecordingDone(recordingID)
set LogMsg to ""
CheckMultiplePIDs(recordingID)

--disable this if you do not want a logfile written
if (count of LogMsg) > 0 then
write_to_file((short date string of (current date) & " " & time string of (current date)) & LogMsg & (ASCII character 13), (path to "logs" as string) & "EyeTV scripts.log", true)
end if


--This is the extra part that will export the recording to iTunes, while keeping the iTunes-transcoded version on the external hard drive. This was thanks to a macrumors post here: http://forums.macrumors.com/showthread.php?t=1348824

set destFolder to "Storage_500GB:EyeTVExports:"

tell application "EyeTV"

set myid to recordingID as integer
set thisTitle1 to title of recording id myid
set thisTitle1 to my parseout(thisTitle1)
set thisTitle2 to unique ID of recording id myid
set thisTitle to thisTitle1 & " - " & thisTitle2
export from recording id myid to file (destFolder & thisTitle & ".m4v") as AppleTVHD replacing yes

end tell

end RecordingDone

--Subroutine to remove troublesome characters
to parseout(stringtoparse)
set illegals to (ASCII character of 60) & (ASCII character of 62) & (ASCII character of 58) & (ASCII character of 34) & (ASCII character of 47) & (ASCII character of 92) & (ASCII character of 124)
repeat with i from 1 to count (illegals)
set testletter to (text i thru i of illegals)
set the_offset to 1
repeat
set the_offset to offset of testletter in stringtoparse
if the_offset > 0 then
set stringtoparse to (text 1 thru (the_offset - 1) of stringtoparse) & "" & (text (the_offset + 1) thru -1 of stringtoparse)
else
exit repeat
end if
end repeat
end repeat
return stringtoparse
end parseout

-- testing code: this will not be called when triggered from EyeTV, but only when the script is run as a stand-alone script
on run
tell application "EyeTV"
set rec to unique ID of item 1 of recordings

my RecordingDone(rec)
end tell
end run

on CheckMultiplePIDs(recordingID)
--check if there are multiple Video PIDs in the file

tell application "EyeTV"
set input_text to my read_from_file((path to "logs" as string) & "ETVComskip" & ":" & recordingID & "_comskip.log")
if (count of (input_text as string)) > 0 then
set logdata to every paragraph of input_text
set logdata_lastrow to (item ((count of logdata) - 1) of logdata) as string

if (items 1 thru 19 of logdata_lastrow) as string = "Video PID not found" then
--multiple Video PIDs, rerun MarkCommercials until successful

set recrdingIDInteger to recordingID as integer
set rec to recording id recrdingIDInteger
set LogMsg to "RecordingDone found multiple PIDs for recording ID: " & recordingID & ", Channel " & (channel number of rec) & " - " & (title of rec)

set PIDs to (items 44 thru ((count of logdata_lastrow) - 2) of logdata_lastrow) as string
set delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to ", "
set PID_List to {}
set PID_List to every word of PIDs
set AppleScript's text item delimiters to delims

repeat with pid in PID_List
my launchComSkip(recordingID, pid)
repeat while (my mcIsRunning())
delay 5
end repeat
end repeat

end if
end if
end tell
end CheckMultiplePIDs

on read_from_file(target_file)
--return the contents of the given file
set fileRef to (open for access (target_file))
set txt to (read fileRef for (get eof fileRef) as «class utf8»)
close access fileRef
return txt
end read_from_file

on write_to_file(this_data, target_file, append_data)
--from http://www.apple.com/applescript/sbrt/sbrt-09.html
try
set the target_file to the target_file as string
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file

on launchComSkip(recID, pid)
if pid = "" then
set cmd to "'/Library/Application Support/ETVComskip/MarkCommercials.app/Contents/MacOS/MarkCommercials' --force --log " & recID & " &> /dev/null &"
else
set cmd to "'/Library/Application Support/ETVComskip/MarkCommercials.app/Contents/MacOS/MarkCommercials' --force --log " & recID & " --pid=" & pid & " &> /dev/null &"
end if

do shell script cmd
end launchComSkip

on mcIsRunning()
set processPaths to do shell script "ps -xww | awk -F/ 'NF >2' | awk -F/ '{print $NF}' | awk -F '-' '{print $1}' "
return (processPaths contains "MarkCommercials")
end mcIsRunning

dgalvan123
Apr 11, 2012, 06:07 PM
Ok so, heych, actually I've discovered that your code inserted into my script DOES work. The exported files are in fact going to my external hard drive. The problem is they are ALSO going onto my internal drive in the Movies folder (as they were before I augmented my RecordingDone script). I wonder if this is because your applescript is exporting the files to the hard drive, but EyeTV is still set to export the files into iTunes as well, so it's doing double-duty. . .

dgalvan123
Apr 12, 2012, 12:57 AM
After sniffing around the net, I have been able to put together a solution using applescript.

Firstly, I created a TriggeredScripts directory:
Library/Application Support/EyeTV/Scripts/TriggeredScripts/

I then created a script that automatically exports all recordings to AppleTV format and saves to an external drive (destfolder). It also adds the link to the files to itunes. NOTE: I have my iTunes setting "Copy files to iTunes Media Folder when adding to library" unticked.


heych: where in your script to you add the file to iTunes? I think that's what my script is missing.