-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathytca.sh
81 lines (70 loc) · 2.11 KB
/
ytca.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env bash
# yt-dlp YouTube channel archive script by Synertry: https://github.com/Synertry/YT-ChannelArchiver
# help option
while getopts ":h" opt; do
case ${opt} in
h )
echo 'Usage:'
echo ' ytca.sh -h Display this help message.'
echo ' ytca.sh <YT-Channel link> Archive <YT-Channel link>.'
echo ' ytca.sh member <YT-Channel link> Archive with membership-only videos, if you have access.'
echo ''
echo 'Source: https://github.com/Synertry/YT-ChannelArchiver'
exit 0
;;
\? )
echo "Invalid Option: -$OPTARG" 1>&2
echo 'To display help:'
echo ' ytca.sh -h'
exit 1
;;
esac
done
shift $((OPTIND -1))
# membership option
if [[ "$1" == 'member' ]]; then
shift
tabs=('videos' 'membership')
else
tabs=('videos')
fi
# checks user input
if [[ $# -eq 0 ]]; then
echo 'No Link provided'
exit 1
else
# check if link is valid
chan="$(grep -oP '^http[s]:\/\/(?:www\.)?youtube\.com\/c\w*\/[^\/]+'<<< $1)"
if [ $? -ne 0 ]; then
echo "Not a valid YouTube channel URL: $1"
exit 1
fi
# check if input channel link exists
if curl --output /dev/null --silent --head --fail "$chan"; then
true
else
echo "YouTube Channel not found for $1"
exit 1
fi
fi
# get channelName
chanName="$(curl -s "$chan/about" | grep -oP '(?<=<title>).*?(?=\s-\sYouTube</title>)')"
# execution
cd
for tab in "${tabs[@]}"; do
for part in "videos" "live-chat"; do # add more confs
echo "Downloading $part in tab $videos"
logName="yt-dlp_${chanName}_$part"
archive="$HOME/yt-dlp/download/$chanName/Archive_IDs_${chanName}_tab-${tab}_part-${part}.txt"
config="$HOME/yt-dlp/configs/ytca-$part.conf"
yt-dlp --config-locations "$config" --download-archive "$archive" "$chan/$tab" 2>&1 | tee "$logName.log"
mv "$logName.log" "$HOME/yt-dlp/logs/${logName}_$(date +'%Y%m%d').log"
done
done
# result
if [[ -d "$HOME/yt-dlp/download/$chanName" ]]; then
echo "Finshed archiving.
Your download is here -> $HOME/yt-dlp/download/$chanName"
else
echo 'Nothing has been downloaded'
fi