added check for dead recorders

got rid of absolute hardcoded paths
renamed some stuff cause of readability
decreased delay between checks
This commit is contained in:
lulzette 2020-03-21 09:33:16 +03:00
parent d34ab6c572
commit d15e9a7132
8 changed files with 36 additions and 24 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
list.sh
conf_python.py
config_python.py
config_list.sh

View File

@ -13,5 +13,6 @@
* Переименовать файл list.sh.template в list.sh, добавить стримеров в параметре list (через пробел), изменить путь для сохранения стримов в path
* Добавить cron.sh в crontab, ну и офк убедиться что cron.service запущен (systemd timer не подойдет ибо он убивает child процессы после завершения работы родителя)
`*/5 * * * * /opt/twitch-downloader/cron.sh`

View File

@ -3,15 +3,23 @@
# 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
full_path=$(dirname "$(realpath $0)")
#check if live
/opt/downloader/lifeChk.py $1 || exit 0
source $full_path/list.sh
#check if not running, kill if running and stream is finished (broken record)
[ -f $storage_path/$1/pid ] && $full_path/lifeChk.py $1 && exit 0 || kill -9 $(cat $storage_path/$1/pid)
#exit if no stream
$full_path/lifeChk.py $1 || exit 0
#set pid and start downloading
touch $path/$1/pid
/home/ubuntu/.local/bin/youtube-dl -v -o $path/$1/"%(upload_date)s_%(title)s__%(timestamp)s_%(id)s.%(ext)s" twitch.tv/$1 >> $path/$1/youtube-dl.log
rm $path/$1/pid
nohup $ytdl_path/youtube-dl -v -o $storage_path/$1/"%(upload_date)s_%(title)s__%(timestamp)s_%(id)s.%(ext)s" twitch.tv/$1 >> $storage_path/$1/youtube-dl.log 2>&1 & echo $! > $storage_path/$1/pid
#remove pid
rm $storage_path/$1/pid

10
config_list.sh.template Normal file
View File

@ -0,0 +1,10 @@
#!/bin/bash
###########
# just config file
###########
list="jesusavgn"
storage_path="/media/nfs/twitch/automatedRecording"
ytdl_path="/home/ubuntu/.local/bin"
ytdl_conf="-o %(uploader)s__%(upload_date)s_%(timestamp)s__%(title)s_%(id)s.%(ext)s"

11
cron.sh
View File

@ -2,17 +2,18 @@
##########
# (actually main) script which cron (systemd.timer) starts by time
##########
source /opt/downloader/list.sh
full_path=$(dirname "$(realpath $0)")
source /opt/downloader/config_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"
[ ! -d $storage_path/$i ] && mkdir -p $storage_path/$i && echo "Created dir $storage_path/$i"
#detached check & start
screen -dmS $i bash /opt/downloader/check.sh $i
sleep 5
screen -dmS $i bash $full_path/check.sh $i
sleep 2
done
@ -20,6 +21,6 @@ done
echo "===="
for i in $list; do
cat $path/$i/pid 2>/dev/null && echo $i "is recording!" || echo $i "is not recording"
[ -f $storage_path/$i/pid] && echo $i "is recording!" || echo $i "is not recording"
done
echo "===="

View File

@ -3,7 +3,7 @@
# return 0 if streamer is live (continue execution while in bash), 1 if not
#################
import sys
import conf_python
import config_python
#if not sys.argv[1]:
# sys.exit(2)

View File

@ -1,9 +0,0 @@
#!/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"