/
R60copy_epgimage
executable file
·95 lines (90 loc) · 3.55 KB
/
R60copy_epgimage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
#
# From VDR's INSTALL file:
# The program will be called with two or three (in case of "editing" and "edited")
# string parameters. The first parameter is one of
#
# before if this is *before* a recording starts
# started if this is after a recording has *started*
# after if this is *after* a recording has finished
# editing if this is before *editing* a recording
# edited if this is after a recording has been *edited*
# deleted if this is after a recording has been *deleted*
#
# and the second parameter contains the full name of the recording's
# directory (which may not yet exists at that moment in the "before" case).
# In the "editing" and "edited" case it will be the name of the edited version
# (second parameter) and the name of the source version (third parameter).
# In the "deleted" case the extension of the directory name is ".del"
# instead of ".rec".
#
# Within this program you can do anything you would like to do before and/or
# after a recording or after an editing process. However, the program must return
# as soon as possible, because otherwise it will block further execution of VDR.
# Be especially careful to make sure the program returns before the watchdog
# timeout you may have set up with the '-w' option! If the operation you want to
# perform will take longer, you will have to run it as a background job.
#
# Example:
# R60copy_epgimage <command> <path to .rec>
#
# R60copy_epgimage after /srv/vdr/video/hitec/Doku/%Die_stille_Revolution_der_Mechatronik/2004-04-23.15\:25.50.99.rec
# $1 <command> after
# $2 <path to .rec> /srv/vdr/video/hitec/Doku/%Die_stille_Revolution_der_Mechatronik/2004-04-23.15\:25.50.99.rec
#
# R60copy_epgimage edited /srv/vdr/video/hitec/Doku/%Die_stille_Revolution_der_Mechatronik/2004-04-23.15\:25.50.99.rec /video0/hitec/Doku/Die_stille_Revolution_der_Mechatronik/2004-04-23.15\:25.50.99.rec
# $1 <command> edited
# $2 <path to new .rec> /srv/vdr/video/hitec/Doku/%Die_stille_Revolution_der_Mechatronik/2004-04-23.15\:25.50.99.rec
# $3 <path to old .rec> /srv/vdr/video/hitec/Doku/Die_stille_Revolution_der_Mechatronik/2004-04-23.15\:25.50.99.rec
#
# epg definitions
EPGIMAGESPATH="/var/cache/vdr/epgimages"
EPGIMAGESFORMAT="jpg"
# eventid for recording
geteventid() {
for file in "${origin}/info"*; do
EVENTID=$(grep -Po "(?<=^E\ )(\d+)(?=\ )" "$file")
[ -n "$EVENTID" ] && return 0
done
return 1
}
copyepgimages() {
# This function takes 3 arguments:
# $1 directory that contains the info file for the recording
# $2 destination for epgimages
# $3 directory with epgimages
origin="$1"
target="$2"
epgimages_dir="$3"
for i in "$origin" "$target" "$epgimages_dir"; do
[ -z "$i" ] && echo "copyepgimages: got an invalid argument" && exit 0
done
geteventid "$origin" || return 0
find "$epgimages_dir" -name "${EVENTID}_*.${EPGIMAGESFORMAT}" -exec cp {} "${target}/" \;
}
case $1 in
before)
# do here whatever you would like to do right BEFORE
# the recording $2 STARTS
;;
started)
# do here whatever you would like to do right AFTER
# the recording $2 STARTED
copyepgimages "$2" "$2" "$EPGIMAGESPATH"
;;
after)
# do here whatever you would like to do right AFTER
# the recording $2 ENDED
#copyepgimages $EPGIMAGESPATH
;;
edited)
# do here whatever you would like to do right AFTER
# the recording $3 has been EDITED (path is $2)
copyepgimages "$3" "$2" "$3"
[ -f "${3}/info.epg2vdr" ] && cp "${3}/info.epg2vdr" "${2}/"
;;
*)
echo "Script needs two parameters. See example inside the script."
exit 0
;;
esac