-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathyoutube-download.sh
More file actions
executable file
·49 lines (44 loc) · 1.06 KB
/
youtube-download.sh
File metadata and controls
executable file
·49 lines (44 loc) · 1.06 KB
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
#!/usr/bin/env bash
# Dirty script to download a bunch of youtube videos
# Supports format selection and redownloading when the connection breaks
# Usage:
# $ ./youtube-download.sh url1 url2 ...
faveFormats=(fmt46_1080p fmt37_1080p fmt45_720p fmt22_720p)
outputDirectory="$HOME/yt"
set -e
download() {
if ! clive -F "$1" &> /dev/null; then
echo ">>> Cannot list formats for video: '$1'"
return 1
fi
formats="$(clive -F "$1" | grep fmt | head -1 | cut -d ' ' -f 1 | sed -r 's/\|/\n/g')"
chosenFormat=''
for f in "${faveFormats[@]}"; do
if echo "$formats" | grep -q "$f"; then
chosenFormat="-f '$f'"
break
fi
done
echo ">>> Downloading: '$1'"
cd "$outputDirectory"
while true; do
if clive $chosenFormat "$1"; then
break
fi
sleep 3
done
echo ">>> Done downloading: '$1'"
}
failedVideos=()
for arg; do
echo "> Processing: '$arg'"
if ! download "$arg"; then
failedVideos+=("$arg")
fi
done
if [ "${#failedVideos[@]}" -ne 0 ]; then
echo "> Failed videos:"
for failedVideo in "${failedVideos[@]}"; do
echo ">>> Failed: '$failedVideo'"
done
fi