commit 53cbd997d0cfb855ac6daf0609cd129a5c38b1a1 Author: l0sted Date: Sat Nov 9 01:29:29 2019 +0300 first diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..64718b4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +list.sh diff --git a/check.sh b/check.sh new file mode 100755 index 0000000..065b266 --- /dev/null +++ b/check.sh @@ -0,0 +1,17 @@ +#!/bin/bash +########## +# check if stream is live and start recording using youtube-dl +########## + +source /opt/downloader/list.sh +#check if not running +[ -f $path/$1/pid ] && exit 0 + +#check if live +/opt/downloader/lifeChk.py $1 || exit 0 + + +#set pid and start downloading +touch $path/$1/pid +/home/ubuntu/.local/bin/youtube-dl -v -o $path/$1/"%(uploader)s__%(upload_date)s_%(timestamp)s__%(title)s_%(id)s.%(ext)s" twitch.tv/$1 > $path/$1/youtube-dl.log +rm $path/$1/pid diff --git a/cron.sh b/cron.sh new file mode 100755 index 0000000..4226eaf --- /dev/null +++ b/cron.sh @@ -0,0 +1,25 @@ +#!/bin/bash +########## +# (actually main) script which cron (systemd.timer) starts by time +########## +source /opt/downloader/list.sh + +for i in $list; do + echo "$i is live?..." + + #check folder + [ ! -d $path/$i ] && mkdir -p $path/$i && echo "Created dir $path/$i" + + #detached check & start + screen -dmS $i bash /opt/downloader/check.sh $i + sleep 5 + +done + +#Show status +echo "====" + +for i in $list; do + cat $path/$i/pid 2>/dev/null && echo $i "is recording!" || echo $i "is not recording" +done +echo "====" diff --git a/lifeChk.py b/lifeChk.py new file mode 100755 index 0000000..58f4c01 --- /dev/null +++ b/lifeChk.py @@ -0,0 +1,19 @@ +#!/usr/bin/python3 +################# +# return 0 if streamer is live (continue exec while in bash), 1 if not +################# +import sys +#if not sys.argv[1]: +# sys.exit(2) + +twitchid = "59hrsplx7dmvc17pqkqcm9l3n1uzc4" +from twitch import TwitchClient +client = TwitchClient(client_id=twitchid) #client init +user_id=client.users.translate_usernames_to_ids(sys.argv[1])[0].id #get id +#get live by id (if var not empty) + +if client.streams.get_stream_by_user(user_id): + sys.exit(0) +else: + sys.exit(1) + diff --git a/list.sh.template b/list.sh.template new file mode 100644 index 0000000..a938f18 --- /dev/null +++ b/list.sh.template @@ -0,0 +1,9 @@ +#!/bin/bash +########### +# just config file +########### + +list="jesusavgn" + +path="/media/twitch/automatedRecording" +ytdliConf="-o %(uploader)s__%(upload_date)s_%(timestamp)s__%(title)s_%(id)s.%(ext)s"