diff --git a/.gitignore b/.gitignore index 0728bed..6b55ed5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ list.sh -conf_python.py \ No newline at end of file +config_python.py +config_list.sh \ No newline at end of file diff --git a/README.md b/README.md index 923fa87..ee79f51 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/check.sh b/check.sh index 94f1e46..cd3f433 100755 --- a/check.sh +++ b/check.sh @@ -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 diff --git a/config_list.sh.template b/config_list.sh.template new file mode 100644 index 0000000..7f63e44 --- /dev/null +++ b/config_list.sh.template @@ -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" diff --git a/conf_python.py.template b/config_python.py.template similarity index 100% rename from conf_python.py.template rename to config_python.py.template diff --git a/cron.sh b/cron.sh index 4226eaf..04c3036 100755 --- a/cron.sh +++ b/cron.sh @@ -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 "====" diff --git a/lifeChk.py b/lifeChk.py index e3b576f..cc78314 100755 --- a/lifeChk.py +++ b/lifeChk.py @@ -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) diff --git a/list.sh.template b/list.sh.template deleted file mode 100644 index a938f18..0000000 --- a/list.sh.template +++ /dev/null @@ -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"