forked from JustinTimperio/twitch-archive-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitch-archive-bot.sh
executable file
·73 lines (64 loc) · 3.08 KB
/
twitch-archive-bot.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
#!/usr/bin/env bash
CHANNEL="fieldmouse"
DOWNLOAD_DIR="/mnt/videos/fieldmouse"
# DO NOT EDIT BELOW THIS LINE
INSTALL_PATH="/opt/twitch-archive-bot"
CRONCMD="$INSTALL_PATH/twitch-archive-bot.sh -d"
# Loop through arguments and process them
for arg in "$@"
do
case $arg in
-s|--stats)
ID=$(curl -s https://decapi.me/twitch/id/$CHANNEL)
ACCOUNTAGE=$(curl -s https://decapi.me/twitch/accountage/$CHANNEL)
TOTAL_VIEWS=$(curl -s https://decapi.me/twitch/total_views/$CHANNEL)
FOLLOWCOUNT=$(curl -s https://decapi.me/twitch/followcount/$CHANNEL)
# SUBCOUNT=$(curl -s https://decapi.me/twitch/subcount/$CHANNEL)
echo "Channel Name: $CHANNEL"
echo "Channel ID: $ID"
echo "Account Age: $ACCOUNTAGE"
echo "Total Views: $TOTAL_VIEWS"
echo "Follower Count: $FOLLOWCOUNT"
# echo "Sub Count: $SUBCOUNT"
;;
-l|--list)
VOD_JSON=$(curl -H "Accept: application/json" -s https://decapi.me/twitch/videos/$CHANNEL/?limit=100)
echo $VOD_JSON | jq .[] | grep 'https://www.twitch.tv/videos/' | cut -d ":" -f2- | rev | cut -c2- | rev
;;
-cji|--cronjob_install)
cronjob="0 4 * * * $CRONCMD"
( crontab -l | grep -v -F "$CRONCMD" || : ; echo "$cronjob" ) | crontab -
;;
-cjr|--cronjob_remove)
cronjob="0 4 * * * $CRONCMD"
( crontab -l | grep -v -F "$CRONCMD" ) | crontab -
;;
-d|--download)
cd $DOWNLOAD_DIR
for i in $(seq 0 100)
do
VOD_JSON=`curl -H "Accept: application/json" -s https://decapi.me/twitch/videos/$CHANNEL/?offset=$i | jq '. | .videos'`
if [ "$VOD_JSON" = "[]" ]
then
echo "No Video Found at Offset $i"
sleep 1
else
TITLE=$(echo $VOD_JSON | jq '.[0].title' | cut -c2- | rev | cut -c2- | rev | sed -e 's/[]\/$*.^[]/\\&/g')
DATE=$(echo $VOD_JSON | jq '.[0].published_at' | cut -c2- | rev | cut -c12- | rev)
URL=$(echo $VOD_JSON | jq '.[0].url' | cut -c2- | rev | cut -c2- | rev)
echo "youtube-dl $URL -o \"$TITLE: $DATE\"" | bash
fi
done
;;
*)
echo "usage: twitch-archive-bot.sh"
echo ""
echo " -s, --stats Lists stats on the configured channel"
echo " -d, --download Downloads all videos available on a channels 'CHANNEL/videos?filter=archives' to the configured path"
echo " -l, --list Lists all urls available on a channels 'CHANNEL/videos?filter=archives'"
echo " -cji, --cronjob_install INSTALL a cronjob to download all available videos each day"
echo " -cjr, --cronjob_remove REMOVE the cronjob to download all available videos each day"
echo ""
;;
esac
done