von andre » 02 Jan 2021, 09:15
Ich habe mir nun einen langgehegten Wunsch erfüllt: Aufnahme-Timer und deren Löschungen werden sowohl mit Neutrino als auch mit iCal gesynct.
Leider kann ich hier nur den Code posten und keinen Tarball, sonst hätte ich die .tcf für das Plugin "Aufnahmesteuerung" bzw. "Recording control" mit hinein gepackt und angehängt. Aus den Kommentaren kann man aber ersehen, wie man das Plugin einrichten muss.
Frohes neues Jahr!
Code: Alles auswählen
#!/bin/bash
# tvb2AB.sh
# Launcher for TV-Browser "Recording control" plugin with optional iCal support
# by andre, 2021-01-02, v3
# USE AT YOUR OWN RISK
# The Neutrino Box's IP address or DNS name (required)
box_ip="h7"
# Seconds to start recordings earlier (required; must match Neutrino's settings)
rec_corr_start="300"
# Seconds to end recordings later (required; must match Neutrino's settings)
rec_corr_end="600"
# Path to your web-browser binary (optional; leave blank if you don't want it to open)
webbrowser="/usr/bin/open"
# iCal calendar to use (optional; leave blank if you don't want iCal. If set, the calendar is created automatically if necessary)
ical_name="TV-Browser"
### No configuration below this line
# The parameters "actors" and "description" cause trouble and are left out
# "Recording control" plugin's "Parameter for recording"
# "<TVB2AB_action>ADD</TVB2AB_action><TVB2AB_channel_name>{channel_name}</TVB2AB_channel_name><TVB2AB_end_unix>{end_unix}</TVB2AB_end_unix><TVB2AB_episode>{episode}</TVB2AB_episode><TVB2AB_episode_number>{episode_number}</TVB2AB_episode_number><TVB2AB_genre>{genre}</TVB2AB_genre><TVB2AB_length_minutes>{length_minutes}</TVB2AB_length_minutes><TVB2AB_origin>{origin}</TVB2AB_origin><TVB2AB_original_episode>{original_episode}</TVB2AB_original_episode><TVB2AB_original_title>{original_title}</TVB2AB_original_title><TVB2AB_production_year>{production_year}</TVB2AB_production_year><TVB2AB_season_number>{season_number}</TVB2AB_season_number><TVB2AB_start_unix>{start_unix}</TVB2AB_start_unix><TVB2AB_title>{title}</TVB2AB_title><TVB2AB_url>{url}</TVB2AB_url>"
# "Recording control" plugin's "Parameter for deletion"
# "<TVB2AB_action>DEL</TVB2AB_action><TVB2AB_channel_name>{channel_name}</TVB2AB_channel_name><TVB2AB_end_unix>{end_unix}</TVB2AB_end_unix><TVB2AB_episode>{episode}</TVB2AB_episode><TVB2AB_episode_number>{episode_number}</TVB2AB_episode_number><TVB2AB_genre>{genre}</TVB2AB_genre><TVB2AB_length_minutes>{length_minutes}</TVB2AB_length_minutes><TVB2AB_origin>{origin}</TVB2AB_origin><TVB2AB_original_episode>{original_episode}</TVB2AB_original_episode><TVB2AB_original_title>{original_title}</TVB2AB_original_title><TVB2AB_production_year>{production_year}</TVB2AB_production_year><TVB2AB_season_number>{season_number}</TVB2AB_season_number><TVB2AB_start_unix>{start_unix}</TVB2AB_start_unix><TVB2AB_title>{title}</TVB2AB_title><TVB2AB_url>{url}</TVB2AB_url>"
func_epochtoas () {
epochtoas=$( date -j -R -r "$1" )
echo "${epochtoas}"
}
func_pingneutrino () {
if ! ping -c1 ${box_ip} ; then
echo "${box_ip} unavailable; exiting"
exit 1
fi
}
func_webbrowser () {
if [ "${webbrowser}" != "" ] ; then
func_pingneutrino
"${webbrowser}" "$1"
fi
}
if [ "$1" = "" ] ; then
echo "Usage: $0 URL"
exit 1
else
tvb=$1
func_pingneutrino
fi
# pass1
eval $(
# The parameters "actors" and "description" cause trouble and are left out
for param in action channel_name episode end_unix episode_number genre length_minutes origin original_episode original_title production_year season_number start_unix title url ; do
value=$( echo "${tvb}" | tr '\n' ' ' | sed -e 's@</TVB2AB_'${param}'>.*@@' -e 's@.*<TVB2AB_'${param}'>@@' )
echo "${param}=\"${value}\""
done
)
# plausability check
if [ "${start_unix}" = "" ] || [ "${end_unix}" = "" ] || [ "${start_unix}" = "${end_unix}" ] ; then
echo "Invalid start_unix or end_unix date; exiting."
exit 1
fi
if [ "${ical_name}" != "" ] ; then
# iCal entry
ical_start=$( func_epochtoas "${start_unix}" )
ical_end=$( func_epochtoas "${end_unix}" )
ical_summary="${title} - ${channel_name}"
ical_description="Genre: ${genre}
Origin: ${origin}
Length (mins.): ${length_minutes}
Original Title: ${original_title}
Production Date: ${production_year}
Season: ${season_number}
Epsisode Number: ${episode_number}
Episode: ${episode}
Original Episode: ${original_episode}"
#Actors: ${actors}"
#Description: ${description}
#Short Info: ${short_info}
ical_url=${url}
#echo "ical_name ${ical_name}"
#echo "ical_start ${ical_start}"
#echo "ical_end ${ical_end}"
#echo "ical_summary ${ical_summary}"
#echo "ical_description ${ical_description}"
#echo "ical_url ${ical_url}"
fi
if [ "${action}" = "ADD" ] ; then
# Neutrino timer
func_pingneutrino
list=$( curl -s "http://${box_ip}/control/channellist" )
# Get the first matching channel id
channel_id=$( echo "${list}" | grep "${channel_name}$" | head -n 1 | sed -e "s@ .*@@" )
# Prepare Neutrino timer
tvb2dbox="http://${box_ip}/control/timer?action=new&alarm=${start_unix}&announce=${start_unix}&channel_id=${channel_id}&rs=1&stop=${end_unix}"
# Create Neutrino timer
func_pingneutrino
curl -s "${tvb2dbox}"
func_webbrowser "http://${box_ip}/Y_Timer_List.yhtm"
if [ "${ical_name}" != "" ] ; then
# Create ical event
osascript -e "
set ical_calendar to \"${ical_name}\"
set ical_start to date (\"${ical_start}\" as string)
set ical_end to date (\"${ical_end}\" as string)
set ical_summary to \"${ical_summary}\"
set ical_description to \"${ical_description}\"
set ical_url to \"${ical_url}\"
tell application \"Calendar\"
try
set theCalendarName to \"${ical_name}\"
set theCalendar to first calendar where its name = theCalendarName
on error
set theNewCalendar to make new calendar with properties {name:theCalendarName, description:\"${ical_name}\"}
end try
tell calendar \"${ical_name}\"
make new event with properties {summary:ical_summary, start date:ical_start, end date:ical_end, description:ical_description, url:ical_url}
end tell
end tell
"
fi
fi
if [ "${action}" = "DEL" ] ; then
# Neutrino timer
#echo "You need to remove The Neutrino timer manually."
#echo "I will try to open your web-browser for you."
del_start=$(( ${start_unix} - ${rec_corr_start} ))
del_end=$(( ${end_unix} + ${rec_corr_end} ))
func_pingneutrino
curl -s "http://${box_ip}/control/timer" | grep "${del_start}" | grep "${del_end}" | grep "${channel_name}" | sed -e "s@ .*@@" | while read timer ; do
func_pingneutrino
curl -s "http://${box_ip}/fb/timer.dbox2?action=remove&id=${timer}"
done
func_webbrowser "http://${box_ip}/Y_Timer_List.yhtm"
if [ "${ical_name}" != "" ] ; then
# Remove ical event
# exec need for TV-Browser timing
( exec osascript -e "
set ical_calendar to \"${ical_name}\"
set ical_start to date (\"${ical_start}\" as string)
set ical_end to date (\"${ical_end}\" as string)
set ical_summary to \"${ical_summary}\"
set ical_description to \"${ical_description}\"
set ical_url to \"${ical_url}\"
tell application \"Calendar\"
try
set theCalendarName to \"${ical_name}\"
set theCalendar to first calendar where its name = theCalendarName
on error
set theNewCalendar to make new calendar with properties {name:theCalendarName, description:\"${ical_name}\"}
end try
tell calendar \"${ical_name}\"
try
set ical_remove to events whose (start date is ical_start and end date is ical_end and summary is ical_summary )
repeat with ical_event in ical_remove
delete ical_event
end repeat
end try
end tell
end tell
"
) & disown
fi
fi
Ich habe mir nun einen langgehegten Wunsch erfüllt: Aufnahme-Timer und deren Löschungen werden sowohl mit Neutrino als auch mit iCal gesynct.
Leider kann ich hier nur den Code posten und keinen Tarball, sonst hätte ich die .tcf für das Plugin "Aufnahmesteuerung" bzw. "Recording control" mit hinein gepackt und angehängt. Aus den Kommentaren kann man aber ersehen, wie man das Plugin einrichten muss.
Frohes neues Jahr!
[code]#!/bin/bash
# tvb2AB.sh
# Launcher for TV-Browser "Recording control" plugin with optional iCal support
# by andre, 2021-01-02, v3
# USE AT YOUR OWN RISK
# The Neutrino Box's IP address or DNS name (required)
box_ip="h7"
# Seconds to start recordings earlier (required; must match Neutrino's settings)
rec_corr_start="300"
# Seconds to end recordings later (required; must match Neutrino's settings)
rec_corr_end="600"
# Path to your web-browser binary (optional; leave blank if you don't want it to open)
webbrowser="/usr/bin/open"
# iCal calendar to use (optional; leave blank if you don't want iCal. If set, the calendar is created automatically if necessary)
ical_name="TV-Browser"
### No configuration below this line
# The parameters "actors" and "description" cause trouble and are left out
# "Recording control" plugin's "Parameter for recording"
# "<TVB2AB_action>ADD</TVB2AB_action><TVB2AB_channel_name>{channel_name}</TVB2AB_channel_name><TVB2AB_end_unix>{end_unix}</TVB2AB_end_unix><TVB2AB_episode>{episode}</TVB2AB_episode><TVB2AB_episode_number>{episode_number}</TVB2AB_episode_number><TVB2AB_genre>{genre}</TVB2AB_genre><TVB2AB_length_minutes>{length_minutes}</TVB2AB_length_minutes><TVB2AB_origin>{origin}</TVB2AB_origin><TVB2AB_original_episode>{original_episode}</TVB2AB_original_episode><TVB2AB_original_title>{original_title}</TVB2AB_original_title><TVB2AB_production_year>{production_year}</TVB2AB_production_year><TVB2AB_season_number>{season_number}</TVB2AB_season_number><TVB2AB_start_unix>{start_unix}</TVB2AB_start_unix><TVB2AB_title>{title}</TVB2AB_title><TVB2AB_url>{url}</TVB2AB_url>"
# "Recording control" plugin's "Parameter for deletion"
# "<TVB2AB_action>DEL</TVB2AB_action><TVB2AB_channel_name>{channel_name}</TVB2AB_channel_name><TVB2AB_end_unix>{end_unix}</TVB2AB_end_unix><TVB2AB_episode>{episode}</TVB2AB_episode><TVB2AB_episode_number>{episode_number}</TVB2AB_episode_number><TVB2AB_genre>{genre}</TVB2AB_genre><TVB2AB_length_minutes>{length_minutes}</TVB2AB_length_minutes><TVB2AB_origin>{origin}</TVB2AB_origin><TVB2AB_original_episode>{original_episode}</TVB2AB_original_episode><TVB2AB_original_title>{original_title}</TVB2AB_original_title><TVB2AB_production_year>{production_year}</TVB2AB_production_year><TVB2AB_season_number>{season_number}</TVB2AB_season_number><TVB2AB_start_unix>{start_unix}</TVB2AB_start_unix><TVB2AB_title>{title}</TVB2AB_title><TVB2AB_url>{url}</TVB2AB_url>"
func_epochtoas () {
epochtoas=$( date -j -R -r "$1" )
echo "${epochtoas}"
}
func_pingneutrino () {
if ! ping -c1 ${box_ip} ; then
echo "${box_ip} unavailable; exiting"
exit 1
fi
}
func_webbrowser () {
if [ "${webbrowser}" != "" ] ; then
func_pingneutrino
"${webbrowser}" "$1"
fi
}
if [ "$1" = "" ] ; then
echo "Usage: $0 URL"
exit 1
else
tvb=$1
func_pingneutrino
fi
# pass1
eval $(
# The parameters "actors" and "description" cause trouble and are left out
for param in action channel_name episode end_unix episode_number genre length_minutes origin original_episode original_title production_year season_number start_unix title url ; do
value=$( echo "${tvb}" | tr '\n' ' ' | sed -e 's@</TVB2AB_'${param}'>.*@@' -e 's@.*<TVB2AB_'${param}'>@@' )
echo "${param}=\"${value}\""
done
)
# plausability check
if [ "${start_unix}" = "" ] || [ "${end_unix}" = "" ] || [ "${start_unix}" = "${end_unix}" ] ; then
echo "Invalid start_unix or end_unix date; exiting."
exit 1
fi
if [ "${ical_name}" != "" ] ; then
# iCal entry
ical_start=$( func_epochtoas "${start_unix}" )
ical_end=$( func_epochtoas "${end_unix}" )
ical_summary="${title} - ${channel_name}"
ical_description="Genre: ${genre}
Origin: ${origin}
Length (mins.): ${length_minutes}
Original Title: ${original_title}
Production Date: ${production_year}
Season: ${season_number}
Epsisode Number: ${episode_number}
Episode: ${episode}
Original Episode: ${original_episode}"
#Actors: ${actors}"
#Description: ${description}
#Short Info: ${short_info}
ical_url=${url}
#echo "ical_name ${ical_name}"
#echo "ical_start ${ical_start}"
#echo "ical_end ${ical_end}"
#echo "ical_summary ${ical_summary}"
#echo "ical_description ${ical_description}"
#echo "ical_url ${ical_url}"
fi
if [ "${action}" = "ADD" ] ; then
# Neutrino timer
func_pingneutrino
list=$( curl -s "http://${box_ip}/control/channellist" )
# Get the first matching channel id
channel_id=$( echo "${list}" | grep "${channel_name}$" | head -n 1 | sed -e "s@ .*@@" )
# Prepare Neutrino timer
tvb2dbox="http://${box_ip}/control/timer?action=new&alarm=${start_unix}&announce=${start_unix}&channel_id=${channel_id}&rs=1&stop=${end_unix}"
# Create Neutrino timer
func_pingneutrino
curl -s "${tvb2dbox}"
func_webbrowser "http://${box_ip}/Y_Timer_List.yhtm"
if [ "${ical_name}" != "" ] ; then
# Create ical event
osascript -e "
set ical_calendar to \"${ical_name}\"
set ical_start to date (\"${ical_start}\" as string)
set ical_end to date (\"${ical_end}\" as string)
set ical_summary to \"${ical_summary}\"
set ical_description to \"${ical_description}\"
set ical_url to \"${ical_url}\"
tell application \"Calendar\"
try
set theCalendarName to \"${ical_name}\"
set theCalendar to first calendar where its name = theCalendarName
on error
set theNewCalendar to make new calendar with properties {name:theCalendarName, description:\"${ical_name}\"}
end try
tell calendar \"${ical_name}\"
make new event with properties {summary:ical_summary, start date:ical_start, end date:ical_end, description:ical_description, url:ical_url}
end tell
end tell
"
fi
fi
if [ "${action}" = "DEL" ] ; then
# Neutrino timer
#echo "You need to remove The Neutrino timer manually."
#echo "I will try to open your web-browser for you."
del_start=$(( ${start_unix} - ${rec_corr_start} ))
del_end=$(( ${end_unix} + ${rec_corr_end} ))
func_pingneutrino
curl -s "http://${box_ip}/control/timer" | grep "${del_start}" | grep "${del_end}" | grep "${channel_name}" | sed -e "s@ .*@@" | while read timer ; do
func_pingneutrino
curl -s "http://${box_ip}/fb/timer.dbox2?action=remove&id=${timer}"
done
func_webbrowser "http://${box_ip}/Y_Timer_List.yhtm"
if [ "${ical_name}" != "" ] ; then
# Remove ical event
# exec need for TV-Browser timing
( exec osascript -e "
set ical_calendar to \"${ical_name}\"
set ical_start to date (\"${ical_start}\" as string)
set ical_end to date (\"${ical_end}\" as string)
set ical_summary to \"${ical_summary}\"
set ical_description to \"${ical_description}\"
set ical_url to \"${ical_url}\"
tell application \"Calendar\"
try
set theCalendarName to \"${ical_name}\"
set theCalendar to first calendar where its name = theCalendarName
on error
set theNewCalendar to make new calendar with properties {name:theCalendarName, description:\"${ical_name}\"}
end try
tell calendar \"${ical_name}\"
try
set ical_remove to events whose (start date is ical_start and end date is ical_end and summary is ical_summary )
repeat with ical_event in ical_remove
delete ical_event
end repeat
end try
end tell
end tell
"
) & disown
fi
fi
[/code]