-
Notifications
You must be signed in to change notification settings - Fork 0
/
getMedia.sh
33 lines (28 loc) · 937 Bytes
/
getMedia.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
#!/bin/bash
jsonFile="${1}"
outFolder="${2}"
#echo "Reading from: ${jsonFile}"
pictures=()
videos=()
#while IFS= read -r LINE; do
pictures+=($(jq -r '.media[].fullUrl' "${jsonFile}" | tr -d '[],"'))
videos+=($(jq -r '.media[].variants|sort_by(.bitrate)[-1].url' "${jsonFile}" | tr -d '[],"'))
#done < "$jsonFile"
for url in ${pictures[@]}
do
removeHTTP="${url#*//}"
# echo "Remove HTTP: $removeHTTP"
format="${url#*format=}"
format="${format%&*}"
removeFormat="${removeHTTP%?format=*}"
# echo "Remove format: $removeFormat"
echo "$url - Saving to: ${outFolder}/${removeFormat}.${format}"
curl "${url}" --create-dirs -o "${outFolder}/${removeFormat}.${format}"
done
for url in ${videos[@]}
do
removeHTTP="${url#*//}"
removeTag="${removeHTTP%?tag=*}"
echo "Writing to destination: ${outFolder}/${removeTag}"
curl "${url}" --create-dirs -o "${outFolder}/${removeTag}"
done