Compare commits

..

3 Commits

4 changed files with 3 additions and 79 deletions

View File

@ -1,27 +0,0 @@
#!/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
View File

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

View File

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