Compare commits

..

No commits in common. "115fcefab2da33a8305578ba05bc7f53d2fd30b2" and "06aaed3d0fb470f22f11d26fbb88b4c54e240d41" have entirely different histories.

4 changed files with 79 additions and 3 deletions

27
check.sh Executable file
View File

@ -0,0 +1,27 @@
#!/bin/bash
##########
# check if stream is live and start recording using youtube-dl
##########
full_path=$(dirname "$(realpath $0)")
source $full_path/config_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)
#if pid exists and stream is live, than exit and do not start recording
[ -f $storage_path/$1/pid ] && $full_path/lifeChk.py $1 $twitchid && exit 0
#exit if no stream and remove lock
$full_path/lifeChk.py $1 $twitchid || rm $storage_path/$1/pid ; exit 0
echo $$ > $storage_path/$1/pid
#set pid and start recording
/home/losted/.local/bin/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
# remove pid
rm $storage_path/$1/pid

29
cron.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/bash
##########
# (actually main) script which cron (systemd.timer) starts by time
##########
full_path=$(dirname "$(realpath $0)")
source $full_path/config_list.sh
for i in $list; do
echo "$i is live?..."
#check folder
[ ! -d $storage_path/$i ] && mkdir -p $storage_path/$i && echo "Created dir $storage_path/$i"
#detached check & start
nohup bash $full_path/check.sh $i &>> $storage_path/$1/youtube-dl.log &
sleep 2
done
#Show status
echo
for i in $list; do
[[ -f $storage_path/$i/pid ]] && echo $i "is recording!" || echo $i "is not recording"
done
echo
echo "Removing old files (older than $ctime_remove days):"
find $storage_path/ -ctime +$ctime_remove -name "*mp4*"
find $storage_path/ -ctime +$ctime_remove -name "*mp4*" -exec rm {} \;
echo "Done"

View File

@ -22,7 +22,7 @@ def recorder(i):
# FIXME: пофиксить абсолютный путь # FIXME: пофиксить абсолютный путь
cmdline = ["/home/losted/.local/bin/youtube-dl","twitch.tv/"+i] cmdline = ["/home/losted/.local/bin/youtube-dl","twitch.tv/"+i]
import subprocess import subprocess
s = subprocess.call(cmdline, stdout=subprocess.DEVNULL) s = subprocess.call(cmdline)
print("Запись стрима %s закончена\n" % i) print("Запись стрима %s закончена\n" % i)
def checkAlive(streamers, client_id): def checkAlive(streamers, client_id):
@ -46,8 +46,7 @@ def checkAlive(streamers, client_id):
else: else:
print(i+" Не стримит") print(i+" Не стримит")
def removeOldStreams():
pass
if __name__ == "__main__": if __name__ == "__main__":
checkAlive(config_python.streamers, config_python.twitchid) checkAlive(config_python.streamers, config_python.twitchid)

21
lifeChk.py Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/python3
#################
# return 0 if streamer is live (continue execution while in bash), 1 if not
#################
import sys
if (not sys.argv[1]) or (not sys.argv[2]):
sys.exit(2)
from twitch import TwitchClient
client = TwitchClient(client_id=sys.argv[2]) #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):
print(user_id)
print(client.streams.get_stream_by_user(user_id).stream_type)
if client.streams.get_stream_by_user(user_id).stream_type == 'live':
sys.exit(0)
sys.exit(1)