/
start.sh
114 lines (70 loc) · 3.06 KB
/
start.sh
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/dumb-init /bin/bash
# Script to download tv shows from BBC iPlayer
function download() {
shows="${1}"
show_type="${2}"
echo "[info] TV show Name/PID defined as '${shows}'"
# split comma separated string into list from SHOW env variable
IFS=',' read -ra showlist <<< "${shows}"
# process each show in the list
for show in "${showlist[@]}"; do
# strip whitespace from start and end of show
show=$(echo "${show}" | sed -e 's~^[ \t]*~~;s~[ \t]*$~~')
echo "[info] Processing show '${show}'..."
echo "[info] Delete partial downloads from incomplete folder '/data/get_iplayer/incomplete/'..."
find /data/get_iplayer/incomplete/ -type f -name "*partial*" -delete
# '--tv-quality' option defined as 'fhd' is not included in the default list
# '--radio-quality' default does define all bitrates, thus does not require the option to be specified
if [[ "${show_type}" == "name" ]]; then
/usr/bin/get_iplayer --profile-dir /config --get --nopurge --tv-quality="fhd,hd,sd,web,mobile" --file-prefix="${show} - <senum> - <episodeshort>" "${show}" --output "/data/get_iplayer/incomplete/${show}"
else
/usr/bin/get_iplayer --profile-dir /config --get --nopurge --tv-quality="fhd,hd,sd,web,mobile" --file-prefix="${show} - <senum> - <episodeshort>" --pid="${show}" --pid-recursive --output "/data/get_iplayer/incomplete/${show}"
fi
done
}
function move() {
# check incomplete folder DOES contain files with mp4 extension
if [[ -n $(find /data/get_iplayer/incomplete/ -name '*.mp4') ]]; then
echo "[info] Copying show folders in incomplete to completed..."
cp -rf "/data/get_iplayer/incomplete"/* "/data/completed/"
# if copy successful then delete show folder in incomplete folder
if [[ $? -eq 0 ]]; then
echo "[info] Copy successful, deleting incomplete folders..."
rm -rf "/data/get_iplayer/incomplete"/*
else
echo "[error] Copy failed, skipping deletion of show folders in incomplete folder..."
fi
fi
}
function start() {
# make folder for incomplete downloads
mkdir -p "/data/get_iplayer/incomplete"
# make folder for completed downloads
mkdir -p "/data/completed"
# set locations for ffmpeg and atomicparsley
/usr/bin/get_iplayer --prefs-add --ffmpeg='/usr/sbin/ffmpeg' --atomicparsley='/usr/sbin/atomicparsley'
while true; do
if [[ -n "${SHOWS}" ]]; then
download "${SHOWS}" "name"
fi
if [[ -n "${SHOWS_PID}" ]]; then
download "${SHOWS_PID}" "pid"
fi
# run function to move downloaded tv shows
move
# if env variable SCHEDULE not defined then use default
if [[ -z "${SCHEDULE}" ]]; then
echo "[info] Env var SCHEDULE not defined, sleeping for 12 hours..."
sleep 12h
else
echo "[info] Env var SCHEDULE defined, sleeping for ${SCHEDULE}..."
sleep "${SCHEDULE}"
fi
done
}
# if 'SHOWS' env var not defined then exit
if [ -z "${SHOWS}" ] && [ -z "${SHOWS_PID}" ]; then
echo "[crit] TV Show Name and/or PID is not defined, please specify show name to download using the environment variable 'SHOWS' and/or specify the show pid using 'SHOWS_PID'"
fi
# run function to start processing
start