-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
jwdl
98 lines (77 loc) · 2.78 KB
/
jwdl
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
#!/bin/bash
# https://www.majlovesreg.one/tag/code/
source $HOME/bin/maj-source
pubs=(\
"osg" \
"sjjm" \
"sjjc" \
"sjji" \
"pksjj" \
)
pubs_desc=(\
"Original Songs" \
"Sing Out Joyfully—Meetings" \
"Sing Out Joyfully—Vocals" \
"Sing Out Joyfully—Instrumentals" \
"Sing Out Joyfully—Children" \
)
dir_save=(\
"/home/maj/Music/Watchtower Music/Original Songs" \
"/home/maj/Music/Watchtower Music/“Sing out Joyfully”—Meetings" \
"/home/maj/Music/Watchtower Music/“Sing out Joyfully”—Vocals" \
"/home/maj/Music/Watchtower Music/“Sing out Joyfully”—Instrumentals" \
"/home/maj/Music/Watchtower Music/“Sing out Joyfully”—Children" \
)
[ -z "${1}" ] && errx "usage: $(basename ${0}) <dl type> [language code]\n\n\
Types:\n\n\
$(for a in ${!pubs[@]}; do echo ${pubs[${a}]} - ${pubs_desc[${a}]}; done)\n\
all - download all music files\n" 1
[ "${1}" = "all" ] && pub="all" || pub=""
for b in ${!pubs[@]}; do
[ "${1}" = "${pubs[${b}]}" ] && {
pub="${pubs[${b}]}"
dir="${dir_save[${b}]}"
}
done
[ -z "${pub}" ] && errx "usage: $(basename ${0}) <dl type> [language code]\n\n\
Types:\n\n\
$(for a in ${!pubs[@]}; do echo ${pubs[${a}]} - ${pubs_desc[${a}]}; done)\n\
all - download all music files\n" 2
for d in ${!dir_save[@]}; do
[ -d "${dir_save[${d}]}" ] || {
mkdir -p "${dir_save[${d}]}"
echo
echo "Created directory: ${dir_save[${d}]}"
echo
}
done
[ -z "${2}" ] && lang='E' || lang="${2}"
################################################################################
function dl {
dl_json="https://b.jw-cdn.org/apis/pub-media/GETPUBMEDIALINKS?output=json&pub=${1}&fileformat=MP3%2CAAC&alllangs=0&langwritten=${lang}"
tmp_json="/tmp/${1}_$(date '+%F_%T').json"
curl -so "${tmp_json}" "${dl_json}" || errx "Download from ${dl_json} failed." 10
readarray -t url < <(cat "${tmp_json}" | jq -r ".files.${lang}.MP3[].file.url")
readarray -t title < <(cat "${tmp_json}" | jq -r ".files.${lang}.MP3[].title")
[ "${#url[@]}" -ne "${#title[@]}" ] && errx "Titles and URL count do not match." 11
cd "${2}"
echo "Processing pub: ${1}, lang: ${lang}, file: ${tmp_json} ..."
echo
for n in ${!url[@]}; do
filename="${2}/$(basename ${url[${n}]} | grep -o '^[^\.]\+') ($(echo ${title[${n}]} | sed 's/'\''/’/g' | sed 's/^"/“/g' | sed 's/\. "/. “/g' | sed 's/"$/”/g')).mp3"
[ ! -f "${filename}" ] && echo "${url[${n}]}" | grep -q '\.mp3$' && {
printf "Downloading and saving to \"${filename}\" ... "
curl -so "${filename}" "${url[${n}]}"
echo-g "done"
}
done
echo
}
################################################################################
[ "${pub}" = "all" ] && {
for c in ${!pubs[@]}; do
dl "${pubs[${c}]}" "${dir_save[${c}]}"
done
} || {
dl "${pub}" "${dir}"
}