-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclipsDump.sh
More file actions
executable file
·150 lines (127 loc) · 5.08 KB
/
clipsDump.sh
File metadata and controls
executable file
·150 lines (127 loc) · 5.08 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
while getopts "ab:c:e:ls:f:h" OPTION
do
case "$OPTION" in
c)
while read STRING
do
clientid=$STRING
done < $OPTARG
;;
s)
startDate=$OPTARG
;;
e)
endDate=$OPTARG
;;
b)
streamer=$OPTARG
;;
a)
startDate="all"
;;
l)
list=true
;;
f)
save=true
location=$OPTARG
;;
h)
echo "-a: Downloads all clips for user"
echo "-b: Provide streamer's username"
echo "-c: Provide Twitch API client ID file"
echo "-e: Set clip dump end date"
echo "-f: Save clip URLs to file"
echo "-h: Help"
echo "-l: List Twitch clip URLs"
echo "-s: Set clip dump start date"
exit 1
esac
done
echo $startDate
echo $endDate
if [ -z "$clientid" ]
then
printf 'Please submit your Twitch API client ID: '
read -r clientid
fi
#while read STRING
#do
# clientid=$STRING
#done < clientID.txt
#fi
#while read STRING2
#do
# broadcasterid=$STRING2
#done < broadcasterid.txt
if [ -z "$streamer" ]
then
printf 'Whose Twitch clips would you like to download? '
read -r streamer
fi
broadcasterid="$(curl -s -H 'Client-ID:'$clientid'' -X GET 'https://api.twitch.tv/helix/users?login='$streamer'' | jq -r '.data[] | .id')" > /dev/null
if [ -z $startDate ]
then
printf 'Please enter the Twitch clip dump starting date in UTC (Format: 2019-01-30T22:19:54Z or "all" for all clips): '
read -r startDate
fi
if [ "$startDate" == "all" ]
then
echo $startDate
if [ "$list" == "true" ]
then
curl -s -H 'Client-ID:'$clientid'' -X GET 'https://api.twitch.tv/helix/clips?broadcaster_id='$broadcasterid'&first=100' | jq -r '.data[] | .url'
elif [ $save == "true" ]
then
curl -s -H 'Client-ID:'$clientid'' -X GET 'https://api.twitch.tv/helix/clips?broadcaster_id='$broadcasterid'&first=100' | jq -r '.data[] | .url' | tee $location > /dev/null
else
url="$(curl -s -H 'Client-ID:'$clientid'' -X GET 'https://api.twitch.tv/helix/clips?broadcaster_id='$broadcasterid'&first=100' | jq -r '.data[] | .url')"
youtube-dl -o "./%(title)s."$clipID".%(ext)s" $url
fi
page="$(curl -s -H 'Client-ID:'$clientid'' -X GET 'https://api.twitch.tv/helix/clips?broadcaster_id='$broadcasterid'&first=100' | jq -r '.pagination.cursor')"
while [ $page != 'null' ]; do
if [ "$list" == "true" ]
then
curl -s -H 'Client-ID:'$clientid'' -X GET 'https://api.twitch.tv/helix/clips?broadcaster_id='$broadcasterid'&first=100&after='$page'' | jq -r '.data[] | .url'
elif [ $save == "true" ]
then
curl -s -H 'Client-ID:'$clientid'' -X GET 'https://api.twitch.tv/helix/clips?broadcaster_id='$broadcasterid'&first=100&after='$page'' | jq -r '.data[] | .url' | tee -a $location > /dev/null
else
url="$(curl -s -H 'Client-ID:'$clientid'' -X GET 'https://api.twitch.tv/helix/clips?broadcaster_id='$broadcasterid'&first=100&after='$page'' | jq -r '.data[] | .url')"
youtube-dl -o "./%(title)s."$clipID".%(ext)s" $url
fi
page="$(curl -s -H 'Client-ID:'$clientid'' -X GET 'https://api.twitch.tv/helix/clips?broadcaster_id='$broadcasterid'&after='$page'' | jq -r '.pagination.cursor')"
done
else
if [ -z $endDate ]
then
printf 'Please enter the Twitch clip dump ending date in UTC (Format: 2019-01-30T22:19:54Z): '
read -r endDate
fi
if [ "$list" == "true" ]
then
curl -s -H 'Client-ID:'$clientid'' -X GET 'https://api.twitch.tv/helix/clips?broadcaster_id='$broadcasterid'&first=100&started_at='$startDate'&ended_at='$endDate'' | jq -r '.data[] | .url'
elif [ "$save" == "true" ]
then
curl -s -H 'Client-ID:'$clientid'' -X GET 'https://api.twitch.tv/helix/clips?broadcaster_id='$broadcasterid'&first=100&started_at='$startDate'&ended_at='$endDate'' | jq -r '.data[] | .url' | tee $location > /dev/null
else
url="$(curl -s -H 'Client-ID:'$clientid'' -X GET 'https://api.twitch.tv/helix/clips?broadcaster_id='$broadcasterid'&first=100&started_at='$startDate'&ended_at='$endDate'' | jq -r '.data[] | .url')" > /dev/null
youtube-dl -o "./%(title)s.%(ext)s" $url
fi
page="$(curl -s -H 'Client-ID:'$clientid'' -X GET 'https://api.twitch.tv/helix/clips?broadcaster_id='$broadcasterid'&first=100&started_at='$startDate'&ended_at='$endDate'' | jq -r '.pagination.cursor')"
while [ $page != 'null' ]
do
if [ "$list" == "true" ]
then
curl -s -H 'Client-ID:'$clientid'' -X GET 'https://api.twitch.tv/helix/clips?broadcaster_id='$broadcasterid'&first=100&started_at='$startDate'&ended_at='$endDate'&after='$page'' | jq -r '.data[] | .url'
elif [ "$save" == "true" ]
then
curl -s -H 'Client-ID:'$clientid'' -X GET 'https://api.twitch.tv/helix/clips?broadcaster_id='$broadcasterid'&first=100&started_at='$startDate'&ended_at='$endDate'&after='$page'' | jq -r '.data[] | .url' | tee -a $location > /dev/null
else
url="$(curl -s -H 'Client-ID:'$clientid'' -X GET 'https://api.twitch.tv/helix/clips?broadcaster_id='$broadcasterid'&first=100&started_at='$startDate'&ended_at='$endDate'&after='$page'' | jq -r '.data[] | .url')" > /dev/null
youtube-dl -o "./%(title)s."$clipID".%(ext)s" $url
fi
page="$(curl -s -H 'Client-ID:'$clientid'' -X GET 'https://api.twitch.tv/helix/clips?broadcaster_id='$broadcasterid'&first=100&started_at='$startDate'&ended_at='$endDate'&after='$page'' | jq -r '.pagination.cursor')"
done
fi