-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathjwget
76 lines (59 loc) · 2.7 KB
/
jwget
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
#!/bin/bash
# Automatically check and download jw.org: wp w g mwb
# Needed programs: bash wget // Optional: gzip pgrep (these are normally preinstalled in most Linux distros)
# v2.3.0 - Updated download link and options of 'g' as large print came out
# v3.0.0 - 2018 version consolidating changes in jw.org and improving code writing
# v3.0.1 - Removed 'ws', simplified version of The Watchtower magazine no longer supported
# Check for multiple instances
[ $(pgrep -c "$(basename $0)") -gt 1 ] && { echo; echo -e "\e[1m\e[93m$(basename $0): \e[0mMutiple script instances found! \e[91mExiting..."; echo; exit 1; }
# Online checker
maj-online () {
ipaddr='8.8.8.8'
[[ -z $(ping -c1 ${ipaddr} |& grep -o 'Network is unreachable') ]] || exit 1
[[ -z $(ping -c3 ${ipaddr} |& grep -o '100% packet loss') ]] && exit 0 || exit 2
}
# User options
DIRBASE="$HOME/Desktop/JWGet"
format='PDF' #EPUB,MOBI,PDF,RTF,BRL Choose one at a time
LANG='E'
# Site options
maguribase='https://apps.jw.org/'
option='GETPUBMEDIALINKS'
# wget options
LOGFILE="/dev/null" # Can be set to "${DIRBASE}/jwget.log"
opts="-bcN -a "${LOGFILE}" --progress=dot:giga --content-disposition"
# Date generate
yearmonth0=$(date -u +%Y%m)
yearmonth1=$(date -u +%Y%m --date='next month')
yearmonth2=$(date -u +%Y%m --date='2 months')
yearmonth3=$(date -u +%Y%m --date='3 months')
yearmonth4=$(date -u +%Y%m --date='4 months')
# Check directories
[ -d "${DIRBASE}" ] || mkdir -p "${DIRBASE}"
[ -d "${DIRBASE}/wp" ] || mkdir -p "${DIRBASE}/wp"
[ -d "${DIRBASE}/w" ] || mkdir -p "${DIRBASE}/w"
[ -d "${DIRBASE}/g" ] || mkdir -p "${DIRBASE}/g"
[ -d "${DIRBASE}/mwb" ] || mkdir -p "${DIRBASE}/mwb"
# Initialize directory and (optionally) logfile
cd "${DIRBASE}"
# [ -f "${LOGFILE}.gz" ] && gzip -dqkf "${LOGFILE}.gz"
### Start of downloader
# Sleep while offline
while ! maj-online; do sleep 15m; done
echo "\n`date`\n" >> "${LOGFILE}"
echo "\n******************************START OF SCRIPT RUN*******************************" >> "${LOGFILE}"
for magtype in 'wp' 'w' 'g' 'mwb'; do
cd "${DIRBASE}/${magtype}"
echo "\n\n" >> "${LOGFILE}"
[ $format = "PDF" ] && ropts="-Hr -nd -A${magtype}_${LANG}_*.pdf" # Other existing filetypes in the directory will be deleted
[ $format = "RTF" ] && ropts="-Hr -nd -A${magtype}_${LANG}_*.zip" # Other existing filetypes in the directory will be deleted
for m in 0 1 2 3 4; do
issue=yearmonth${m}
wget ${opts} ${ropts} "${maguribase}${option}?issue=${!issue}&output=html&pub=${magtype}&fileformat=${format}&alllangs=0&langwritten=${LANG}&txtCMSLang=${LANG}"
sleep 1
done
done
echo "\n ::::: End of script run :::::\n`date`\n" >> "${LOGFILE}"
# Compress logfile
# cd "${DIRBASE}"
# gzip -f "${LOGFILE}"