# # Parental-Rating Recording Action Hook # -------------------------------------- # # Parameter 1 can have the values "before", "after" and "edited", depending # on whether the recording hook is called before the recording starts, # after the recording ends or after the recording has been edited. # # Parameter 2 is the directory of the recording. Be aware, that this directory # doesn't exist before the recording starts. # HOOK="R10.parental-rating" LOG="/usr/bin/logger -t recording-hook" $LOG "$HOOK $@" case $1 in before) # nothing to do - recording directory not yet created ;; after | edited) # extract a literally provided parental rating from the subtitle # and add its "R" tag in the recording info rec="$2" info="$rec/info" orig="$info.orig" temp="$info.temp" # extract the parental rating from the subtitle sline="$( cat "$info" | grep "^S" | tail -1 | cut -c 3- )" rating="$( echo "$sline" | sed 's/^.*\(Altersfreigabe[: ]*ab *[0-9][0-9]*\).*$/\1/' )" age="$( echo "$rating" | sed 's/^.*Altersfreigabe[: ]*ab *\([0-9][0-9]*\).*$/\1/' | sed 's/^.*Altersfreigabe[: ]*[Kk]eine .*[Ff]reigabe.*$/18/' )" if [ "${age//[0-9]/}" = "" -a "$age" != "$rating" ] then $LOG "$HOOK" "age = $age" # save the original recording info or preserve an earlier copy [ -f "$orig" ] || cp -p "$info" "$orig" # enter the extracted rating and the subtitle without rating cat "$info" | grep -v "^[SR]" > "$temp" echo "S $( echo $sline | sed 's/'"$rating"'//' | sed 's/ */ /g' | sed 's/ *$//' )" >> "$temp" echo "R $age" >> "$temp" # replace the previous recording info by the modified one mv -f "$temp" "$info" # trigger a rescan of the recordings path="" OLDIFS="$IFS" IFS=/ dirs=(${rec%\/[^\/]*\/[^\/]*}) IFS="$OLDIFS" for dir in "${dirs[@]}" x y do [ -z $dir ] || path="$path/$dir" if [ -f "$path/.update" ] then $LOG "$HOOK" "triggering rescan of recordings" touch "$path/.update" break fi done fi ;; esac