EyeTV Triggeredscripts: automatisches Ausführen von Funktionen

P

phreichmuth

Aktives Mitglied
Thread Starter
Dabei seit
20.06.2008
Beiträge
101
Reaktionspunkte
8
Hallo zusammen

Einige von euch benutzen sie zum Teil sicher schon

EyeTV bittet die Möglichkeit, Aufgaben und Funktionen bei bestimmten Ereignissen zu automatisieren. Einige von euch nutzen diese Funktion sicher schon, zumindest gibt es hier bereits eine angeregte Diskussion zum triggered Script RecordingDonce.scpt https://www.macuser.de/forum/f28/eyetv3-recordingdone-script-333894/

EyeTV hat aber noch ander auslösende Ereignisse. So kann man unter folgenden Namen noch mehr Skripte ausführen lassen:
- ScheduleCreated.scpt: wenn eine neue Aufnahme programmiert wurde
- RecordingStarted.scpt: wenn eine Aufnahme gestartet wurde
- ExportDone.scpt: wenn eine Aufnahme fertig exportiert wurde
- RecordingDeleted.scpt: wenn eine Aufnahme gelöschen wurde
- RecordingDone.scpt: wenn eine Aufnahme beendet wurde (der Vollständigkeit halber, siehe auch Link oben)

Damit wird ein Mac mit EyeTV zur richtig komfortablen Medienzentrale im Wohnzimmer. Bei mir ersetzt ein Mac mini den Festplatten-Recorder, DVD-Player, Photo-Album und dient auch als Juke-Box.

Für alle für die diese Skripte komplet neu sind, es handelt sich bei den Skripten um Appleskripte und diese üssen im Ordner "/Library/Application Support/EyeTV/Scripts/TriggeredScripts/" unter DEN VORGEGEBENEN NAMEN als Applescrits gespeichert werden (also z.B. /Library/Application Support/EyeTV/Scripts/TriggeredScripts/RecordingDone.scpt).

Da die Beispiele von Elgato selbst nicht wirklich funktionieren (die sollten sich schämen, soetwas zu veröffentlichen!!!), habt ihr nachfolgend mal meine Skripte.

Für die anderen Triggers habe ich schlicht keine Verwendung bzw. finde ich etwas unnütz (z.B. RecordingDeleted)

Nun wünsch ich euch viel Spass beim ausprobieren und selber skripten.
 
  • Gefällt mir
Reaktionen: sharpe11
ScheduleCreated.scpt

ScheduleCreated.scpt
überprüft, ob noch genügend freier Festplattenplatz vorhanden ist gemäss einem vorgegebenen, druchschnittlichen Speicherbedarf. Das Skript frag allenfalls, ob die Aufnahme trotzdem programmiert werden soll.

Code:
-- ScheduleCreated.scpt
-- Free Space Check: This script checks the available disk space on the drive containing the "EyeTV Archive" and compares that to the approximate size of the scheduled recording that you have just made. If you would end up with less than 2 GB of free space afterwards, it will raise a dialog box to warn you.
-- Save script with the name: ScheduleCreated.scpt
-- Save in folder /Library/Application Support/EyeTV/Scripts/TriggeredScripts

on ScheduleCreated(programID)
	tell application "EyeTV"
		set Aufnahme to programID as integer
		set Titel to get the title of program id Aufnahme
		set mydur to (get the duration of program id Aufnahme) / 3600
		--MyQual is the approximate GB/hour of your current recording quality. Adjust this value as necessary. For standard resolution recordings, this will be about 1.8 - 2.7. For 720p recordings, it is about 6. For 1080i, about 8.
		set myqual to 2.6
		set mysize to mydur * myqual
		set mysize to (round (mysize * 100)) / 100
		set AppleScript's text item delimiters to {":"}
		set mydrive to (text items 1 thru 1 of (get the repository url as string)) as alias
		tell application "Finder" to set myspace to (get free space of disk mydrive) / (1000 * 1000 * 1000)
		set myspace to (round (myspace * 100)) / 100
		if mysize > (myspace - 2) then
			display dialog "Die geplante Aufnahme \"" & Titel & "\" benötigt ungefähr " & mysize & " GB Speicherplatz.

Es sind aber nur " & myspace & " GB verfügbar." buttons {"Nicht aufnehmen", "Trotzdem aufnehmen"} default button "Nicht aufnehmen" with icon note with title "EyeTV-Recorder"
			set Resultat to result
			set Wahl to button returned of Resultat
			if Wahl is "Nicht aufnehmen" then
				tell application "EyeTV" to delete program id Aufnahme
			end if
		end if
	end tell
end ScheduleCreated
 
Zuletzt bearbeitet:
RecordingDone.scpt

RecordingDone.scpt
Das Skript veranlasst die Markierung der Werbung in der beendeten Aufnahme und überprüft, ob der Computer gerade in Verwendung ist, ob iTunes ein etwas abspielt oder nur auf Pause steht, ob Quicktime geöffnet ist und ob in den nächsten 15 bzw. 30 Minuten eine weitere Aufnahme ansteht. Wenn nein geht der Computer in den Ruhezustand bzw. schaltet sich aus.

etv-comskip muss natürlich installiert sein, ansonsten bricht das Skript ab. Leider ohne einen Fehler zu melden.

Code:
- Skript zum automatischen Ausschalten nach einer Aufnahme.
-- Speichern als Skrpt mit Name: RecordingDone.scpt
-- Speichern in /Library/Application Support/EyeTV/Scripts/TriggeredScripts

on RecordingDone(recordingID)
	-- Aufnahmetitel auslesen
	tell application "EyeTV"
		set Aufnahme to recordingID as integer
	end tell
	-- Werbung markieren
	do shell script "/Library/Application\\ Support/ETVComskip/MarkCommercials.app/Contents/MacOS/MarkCommercials " & Aufnahme
	-- IDLE-Time abrufen
	set idletime to do shell script "ioreg -c IOHIDSystem | grep Idle | tail -1 | awk '{printf(\"%d\",  $NF/10^9);}'"
	set idletime to idletime as integer
	-- Wenn IDLE-Time abgelaufen ist, überprüfen ob eine Aufnahme ansteht
	if idletime > 60 then
		tell application "System Events"
			set itunes_running to (name of processes) contains "iTunes"
			set quicktime_running to (name of processes) contains "Quicktime Player"
		end tell
		if itunes_running is true then
			tell application "iTunes"
				if player state is not stopped then
					set itunes_playing to true
				else
					set itunes_playing to false
				end if
			end tell
		else
			set itunes_playing to false
		end if
		if itunes_playing is false and quicktime_running is false then
			tell application "EyeTV"
				if is_recording = false then
					-- überprüfen ob eine Aufnahme ansteht
					set limitsleep to 15 * minutes
					set limitoff to 30 * minutes
					set ruhezustand to true
					set ausmachen to true
					set vorlauf to (prepad time + 2) * minutes
					set jetzt to current date
					repeat with Aufnahme in start time of every program
						set diff to Aufnahme - jetzt
						if diff ≥ vorlauf then set diff to diff - vorlauf
						if diff ≥ 0 and diff ≤ limitsleep then set ruhezustand to false
						if diff ≥ 0 and diff ≤ limitoff then set ausmachen to false
					end repeat
					-- Wenn keine Aufnahme in den nächsten 15 Minuten ansteht, in den Ruhezustand gehen
					if ruhezustand = true and ausmachen = false then
						activate
						set antwort to display dialog "EyeTV hat eine Aufnahme beendet.
Die nächste Aufnahme steht in 15 - 30 Minuten an.

Soll der Computer in den Ruhezustand gehen?" buttons {"Nein", "Ja"} default button "nein" with icon note with title "EyeTV-Recorder" giving up after 30
						if button returned of antwort = "Ja" or button returned of antwort = "" then
							tell application "Finder"
								ignoring application responses
									sleep
								end ignoring
							end tell
						end if
					end if
					-- Wenn keine Aufnahme in den nächsten 30 Minuten ansteht, herunterfahren
					if ausmachen = true then
						activate
						set antwort to display dialog "EyeTV hat eine Aufnahme beendet.
Es steht keine EyeTV-Aufnahme bevor.

Soll der Computer ausgeschaltet werden?" buttons {"Nein", "Ja", "Ruhezustand"} default button "nein" with icon note with title "EyeTV-Recorder" giving up after 30
						if button returned of antwort = "Ja" or button returned of antwort = "" then
							tell application "Finder"
								ignoring application responses
									shut down
								end ignoring
							end tell
						end if
						if button returned of antwort = "Ruhezustand" then
							tell application "Finder"
								ignoring application responses
									sleep
								end ignoring
							end tell
						end if
					end if
				end if
			end tell
		end if
	end if
end RecordingDone
 
Zuletzt bearbeitet:
ExportDone.scpt

ExportDone.scpt
Das Skript überprüft die Länge des exportierten Films und vergleicht die Länge mit der Originalaufnahme. Falls der Unterschied kleiner als 1% ist, wird nachgefragt, ob das Original in EyeTV gelöscht werden soll (Zeile zum löschen ist auskommentiert).
Anschliessend fragt das Skript, ob die Datei der iTunes Mediathek eingefügt werden soll.
Diese Version des Skripts sucht die Datei nicht nur auf der lokalen Festplatte, sondern auch auf dem Netzwerklaufwerk "Filme" (ist bei mir auf dem NAS). Entsprechend kann das Skript vereinfacht werden wenn es nur lokal suchen soll.

Code:
-- ExportDone.scpt
-- Delete Original After Export With File Duration Check: This script attempts to compare the original EyeTV recording duration to the exported file's duration of the same name. If they are within 1% of each other, then the script deletes the recording. Warning: This script, when enabled, will automatically delete content without a prompt.
-- Save script with the name: RecordingDone.scpt
-- Save in folder /Library/Application Support/EyeTV/Scripts/TriggeredScripts

on ExportDone(recordingID)
	-- Titel und Daer der Aufnahme in EyeTV bestimmen
	tell application "EyeTV"
		set Aufnahme to recordingID as integer
		set origdur to get the actual duration of recording id Aufnahme
		set Titel to get the title of recording id Aufnahme
	end tell
	set Datei to 0
	tell application "Finder"
		-- Suche Anzahl Dateien deren Name den Titel enthalten
		set LokalFilme to count of (files in folder (path to movies folder) whose name contains Titel)
		set NASFilme to count of (files in folder "Filme" whose name contains Titel)
		if (LokalFilme + NASFilme) = 1 then
			if LokalFilme = 1 then
				set Filmname to (get the name of files in folder (path to movies folder) whose name contains Titel)
				set Datei to ((path to movies folder) & Filmname) as text
			else
				set Filmname to (get the name of files in folder ("Filme") whose name contains Titel)
				set Datei to (("Filme:") & Filmname) as text
			end if
		else
			if (LokalFilme + NASFilme) > 1 then
				set myText to "Es wurden mehrere Dateien mit passendem Dateinamen gefunden. " as text
			else
				set myText to "Es wurden aber KEINE Dateien mit passendem Dateinamen gefunden. " as text
			end if
			-- Falls keine oder mehrere zutreffende Datien gefunden wurden, manuell nach der Datei suchen
			tell application "EyeTV"
				activate
				set Auswahl to display dialog "Export von \"" & Titel & "\" abgeschlossen.
" & myText & "Wollen Sie zur Kontrolle des Exports selber nach der Datei suchen?" buttons {"Ja", "Nein"} default button {"Ja"} with title "EyeTV - Export" with icon note
				if button returned of Auswahl is "Ja" then
					set Datei to (choose file with prompt ("Wählen Sie die Datei des Films \"" & Titel & "\" aus:") default location (path to movies folder)) as text
				end if
			end tell
		end if
	end tell
	if Datei is not 0 then
		tell application "System Events"
			set quicktime_running to (name of processes) contains "Quicktime Player"
		end tell
		try
			tell application "QuickTime Player"
				open file Datei
				set exportdur to get the duration of document 1
				repeat while exportdur = 0
					delay 1
					set exportdur to get the duration of document 1
				end repeat
				if quicktime_running is false then
					quit
				else
					close document 1
				end if
			end tell
		end try
		-- Dauer des Originals und des Exports vergleichen
		if origdur > exportdur then
			set thediff to (origdur - exportdur)
		else
			set thediff to (exportdur - origdur)
		end if
		--Small discrepancies between the original file duration and the exported file duration can occur during exports. To compensate for this, the script assumes that if the difference in file duration is less than 1% of the total duration, then the export was successful.
		tell application "EyeTV"
			activate
			if thediff < origdur * (0.01) then
				--uncomment the line below to enable file deleting.
				set WahlDelete to display dialog "Export von \"" & Titel & "\" war erfolgreich.
Exportierte Datei hat dieselbe Dauer wie die Originalaufnahme.
Soll die Aufnahme in EyeTV gelöscht werden?" buttons {"Löschen", "Nicht Löschen"} default button {"Löschen"} with title "EyeTV - Export" with icon note
				if button returned of WahlDelete is "Löschen" then
					try
						-- nächste Zeile Kommentarzeichen (--) entfernen damit Dateien gelöscht werden. VORSICHT! Nur wenn du weisst, was du tust!
						-- delete recording id Aufnahme 
					on error
						display dialog "Die Aufnahme \"" & Titel & "\" konnte nicht gelöscht werden." buttons {"Ok"} with title "EyeTV - Export" with icon caution
					end try
				end if
				set WahliTunes to display dialog "Soll \"" & Titel & "\" in die iTunes-Mediathek importiert werden?" buttons {"Nein", "Ja"} default button {"Ja"} with title "EyeTV - Export" with icon note
				if button returned of WahliTunes is "Ja" then
					tell application "iTunes"
						set newAddition to (add (Datei as alias))
						tell newAddition to set video kind to movie
					end tell
				end if
			else
				display dialog "Export von \"" & Titel & "\" war NICHT erfolgreich.
Die exportierte Datei und die Originalaufnahme haben nicht dieselbe Dauer.
Wiederholen Sie den Export." buttons {"OK"} with title "EyeTV - Export" with icon caution
			end if
		end tell
	end if
end ExportDone
 
Zuletzt bearbeitet:
Skripte testen

Die Skripte zu testen ist nicht ganz einfach, da man keine Fehlermeldungen bekommt. Das Skript läuft bis zum fehlerhaften Befehl und bricht dann ab.

Um die Skripte zu testen, benutze ich jeweils folgende Änderungen:

- Das Skript in einen separates Skript-Editor-Fenster kopieren
- "on ScheduleCreated(programID)" am Anfang und "end ScheduleCreated" am Ende löschen
- die ersten paar Zeilen des Skripts ändern, damit eine Aufnahme aufgerufen wird (EyeTV übergibt ja in diesem Fall keine RecordingID):
Code:
	tell application "EyeTV"
		set Aufnahme to the unique ID of record <Zahl>
		set Titel to get the title of program id Aufnahme
		display dialog Titel
...

Damit bekomme ich einen Dialog mit dem Titel der Aufnahme und kann entscheiden, ob ich den Test mit dieser Aufnahme machen will oder nicht.
 
  • Gefällt mir
Reaktionen: DerPicknicker
Komisch, dass sich noch keiner für deine Mühe bedankt hat. Die Skripte sehen interessant aus ... will sagen, die Funktionen hören sich gut an. Ich möchte eigentlich nur, dass nach der Aufnahme die Datei in ein Format konvertiert und in einen anderen Ordner kopiert und das Original gelöscht wird.
 
Zurück
Oben Unten