forked from ebergama/sonarr-sub-downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sub-downloader.sh
executable file
·65 lines (54 loc) · 1.59 KB
/
sub-downloader.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
#!/bin/bash
set -e
echo `dirname $0`
declare LOG_FILE=`dirname $0`/sub-downloader.log
declare WANTED_FILE=`dirname $0`/wanted/subs.wanted
# Sonarr does not show the stdout as part of the log information displayed by the system,
# So I decided to store the log information by my own.
function doLog {
echo -e $1
echo -e $1 >> $LOG_FILE
}
function printUsage {
msg="Usage: sub-downloader.sh [options]\n\n
-l, --languages <languages-list>:\n
\t Specify a comma-separated list of languages to download.\n
\t example: sub-downloader.sh -l es,en\n\n
-h, --help: print this help"
doLog "$msg"
exit 1
}
if [[ $# -eq 0 ]]; then
printUsage
fi
while [ "$1" != "" ]; do
case $1 in
"-l" | "--languages")
shift
declare LANGUAGES=$(echo "-l $1" | sed "s/,/ -l /g")
;;
*)
printUsage
;;
esac
shift
done
doLog "###### Process started at: $(date) ######"
declare EPISODE_PATH=${sonarr_episodefile_path}
if [[ -z $EPISODE_PATH ]]; then
doLog "sonarr_episodefile_path environment variable not found"
exit 1
fi
doLog "Looking for subtitles for: ${EPISODE_PATH}"
doLog "Executing subliminal"
doLog "subliminal download ${LANGUAGES} ${EPISODE_PATH}"
subliminal download ${LANGUAGES} "${EPISODE_PATH}" >> $LOG_FILE 2>&1
# Look for not found subtitles
declare LANG_ARRAY=($(echo ${LANGUAGES} | sed "s/-l //g"))
for LANG in "${LANG_ARRAY[@]}"; do
SUB_FILE=$(echo $EPISODE_PATH | sed "s/...$/${LANG}\.srt/g")
if [[ ! -f $SUB_FILE ]]; then
doLog "Subtitle ${SUB_FILE} not found, adding it to wanted"
echo $EPISODE_PATH:$SUB_FILE >> ${WANTED_FILE}
fi
done