tarina

git clone https://git.tarina.org/tarina
Log | Files | Refs | README | LICENSE

commit 15e3c51894b8dfe9a467f62c538d57b84e1368ad
parent ecba024d0e27448605762d09a2e516dab164ee61
Author: rob <rob@tarina.org>
Date:   Fri, 17 Mar 2023 15:32:21 +0000

control camera from a browser

Diffstat:
Minstall.sh | 4++--
Msrv/static/style.css | 4++++
Msrv/tarinaserver.py | 112++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Msrv/templates/base.html | 2+-
Msrv/templates/index.html | 25++++++++++++++++++++++++-
Mtarina.py | 99+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
6 files changed, 194 insertions(+), 52 deletions(-)

diff --git a/install.sh b/install.sh @@ -58,9 +58,9 @@ apt-get update apt-get upgrade -y if [ "$version" = "buster" ] then - apt-get -y install git python3-pip python-configparser ffmpeg mediainfo gpac omxplayer sox cpufrequtils apache2 libapache2-mod-wsgi-py3 libdbus-glib-1-dev dbus libdbus-1-dev usbmount python3-numpy python3-pil python3-smbus python3-shortuuid wiringpi make gcc cmake pmount + apt-get -y install git python3-pip python-configparser ffmpeg mediainfo gpac omxplayer sox cpufrequtils apache2 libapache2-mod-wsgi-py3 libdbus-glib-1-dev dbus libdbus-1-dev usbmount python3-numpy python3-pil python3-smbus python3-shortuuid wiringpi make gcc cmake pmount python3-ifaddr else - apt-get -y install git python3-pip python-configparser libav-tools mediainfo gpac omxplayer sox cpufrequtils apache2 libapache2-mod-wsgi-py3 libdbus-glib-1-dev dbus libdbus-1-dev usbmount python3-numpy python3-pil python3-smbus python3-shortuuid wiringpi make gcc cmake + apt-get -y install git python3-pip python-configparser libav-tools mediainfo gpac omxplayer sox cpufrequtils apache2 libapache2-mod-wsgi-py3 libdbus-glib-1-dev dbus libdbus-1-dev usbmount python3-numpy python3-pil python3-smbus python3-shortuuid wiringpi make gcc cmake python3-ifaddr fi echo "installing python-omxplayer-wrapper..." sudo pip3 install omxplayer-wrapper diff --git a/srv/static/style.css b/srv/static/style.css @@ -16,3 +16,7 @@ pre color: #fff; } +a +{ + color: #FCD612; +} diff --git a/srv/tarinaserver.py b/srv/tarinaserver.py @@ -2,6 +2,11 @@ import web import os +import socket +import ifaddr +import sys +import time + # Get path of the current dir, then use it as working directory: rundir = os.path.dirname(__file__) @@ -10,19 +15,76 @@ if rundir != '': filmfolder = '/home/pi/Videos/' +basedir = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(basedir) + # Link video directory to static dir if os.path.isfile('static/Videos') == False: os.system("ln -s -t static/ " + filmfolder) films = [] +#NETWORKS + +networks=[] +adapters = ifaddr.get_adapters() +for adapter in adapters: + print("IPs of network adapter " + adapter.nice_name) + for ip in adapter.ips: + if '::' not in ip.ip[0] and '127.0.0.1' != ip.ip: + print(ip.ip) + networks.append(ip.ip) +network=networks[0] + urls = ( - '/', 'index', + '/?', 'index', '/f/(.*)?', 'films' ) app = web.application(urls, globals()) render = web.template.render('templates/', base="base") +web.config.debug=False +store = web.session.DiskStore(basedir + '/sessions') +session = web.session.Session(app,store,initializer={'login': 0, 'user': '', 'backurl': '', 'bildsida': 0, 'cameras': [], 'reload': 0}) + +port=55555 +ip='0.0.0.0' +cameras=[] + + +##---------------Connection---------------------------------------------- + +def pingtocamera(host, port, data): + print("Sending to "+host+" on port "+str(port)+" DATA:"+data) + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.settimeout(0.01) + try: + while True: + s.connect((host, port)) + s.send(str.encode(data)) + if host not in cameras and host not in networks: + session.cameras.append(host) + print("Found camera! "+host) + print("Sent to server..") + break + except: + ('did not connect') + s.close() + +def sendtocamera(host, port, data): + print("Sending to "+host+" on port "+str(port)+" DATA:"+data) + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.settimeout(0.1) + try: + while True: + s.connect((host, port)) + s.send(str.encode(data)) + print("Sent to server..") + break + except: + ('did not connect') + s.close() + def getfilms(filmfolder): #get a list of films, in order of settings.p file last modified @@ -82,15 +144,53 @@ def counttakes(filmname, filmfolder, scene, shot): class index: def GET(self): + interface=open('/dev/shm/interface','r') + menu=interface.readlines() + selected=int(menu[0]) films = getfilms(filmfolder) renderedfilms = [] unrenderedfilms = [] - for i in films: - if os.path.isfile('static/Videos/' + i[0] + '/' + i[0] + '.mp4') == True: - renderedfilms.append(i[0]) + for f in films: + if os.path.isfile('static/Videos/' + f[0] + '/' + f[0] + '.mp4') == True: + renderedfilms.append(f[0]) else: - unrenderedfilms.append(i[0]) - return render.index(renderedfilms, unrenderedfilms) + unrenderedfilms.append(f[0]) + i=web.input(func=None) + if i.func == 'search': + session.cameras=[] + # ping ip every 10 sec while not recording to connect cameras + pingip=0 + while pingip < 255 : + pingip+=1 + pingtocamera(network[:-3]+str(pingip),port,'PING') + elif i.func == 'rec': + sendtocamera(ip,port,'REC') + elif i.func == 'retake': + sendtocamera(ip,port,'RETAKE') + elif i.func == 'up': + sendtocamera(ip,port,'UP') + elif i.func == 'down': + sendtocamera(ip,port,'DOWN') + elif i.func == 'left': + sendtocamera(ip,port,'LEFT') + elif i.func == 'right': + sendtocamera(ip,port,'RIGHT') + elif i.func == 'view': + sendtocamera(ip,port,'VIEW') + elif i.func == 'middle': + sendtocamera(ip,port,'MIDDLE') + elif i.func == 'delete': + sendtocamera(ip,port,'DELETE') + if i.func != None: + session.reload = 1 + raise web.seeother('/') + if session.reload == 1: + time.sleep(0.35) + interface=open('/dev/shm/interface','r') + menu=interface.readlines() + selected=int(menu[0]) + session.reload = 0 + return render.index(renderedfilms, unrenderedfilms, session.cameras, menu, selected) class films: def GET(self, film): diff --git a/srv/templates/base.html b/srv/templates/base.html @@ -3,7 +3,7 @@ $def with (content) <HEAD> <meta charset="utf-8"> <title>Tarina | video & audio recorder with glue</title> - <link rel="stylesheet" href="/static/style.css" type="text/css" rel="stylesheet"/> + <link rel="stylesheet" href="/static/style.css?v=33" type="text/css" rel="stylesheet"/> </HEAD> <BODY> diff --git a/srv/templates/index.html b/srv/templates/index.html @@ -1,7 +1,30 @@ -$def with (renderedfilms, unrenderedfilms) +$def with (renderedfilms, unrenderedfilms, cameras, menu, selected) $var renderedfilms = renderedfilms $var unrenderedfilms = unrenderedfilms +<script> +function timedRefresh(timeoutPeriod) { + setTimeout("location.reload(true);",timeoutPeriod); +} +</script> +connected +$for i in cameras: + $i +<br> +<br> +<div id="menu" style="margin:0 auto; width:80%"> +$ y=0 +$for m in menu[3:]: + $if selected == y: + <b><a>$m</a></b> + $else: + $m + $ y+=1 +</div> +<br> +<a href="/?func=view">VIEW</a> <a href="/?func=up">__UP__</a> <a href="/?func=record">RECORD</a><br> +<a href="/?func=left">LEFT</a> <a href="/?func=middle">MIDDLE</a> <a href="/?func=right">RIGHT</a><br> +<a href="/?func=delete">DELETE</a> <a href="/?func=down">DOWN</a> <a href="/?func=retake">RETAKE</a><br> <h1>FILMS</h1> $for i in renderedfilms: diff --git a/tarina.py b/tarina.py @@ -75,7 +75,7 @@ while probei2c < 10: #MAIN def main(): - global headphoneslevel, miclevel, tarinafolder, screen, loadfilmsettings, plughw, channels, filmfolder, filmname, scene, showmenu, quality, profilelevel, i2cbuttons, menudone, soundrate, soundformat + global headphoneslevel, miclevel, tarinafolder, screen, loadfilmsettings, plughw, channels, filmfolder, filmname, scene, showmenu, quality, profilelevel, i2cbuttons, menudone, soundrate, soundformat, process, serverstate, que, port # Get path of the current dir, then use it as working directory: rundir = os.path.dirname(__file__) if rundir != '': @@ -193,6 +193,7 @@ def main(): que = Queue() process = Process(target=listenforclients, args=("0.0.0.0", port, que)) process.start() + nextstatus = '' serverstate_old='off' wifistate_old='off' @@ -215,45 +216,6 @@ def main(): elif serverstate == 'off': tarinaserver(False) serverstate_old=serverstate - #Check controller - if process.is_alive() == False: - nextstatus = que.get() - if "*" in nextstatus: - tarinactrl_ip = nextstatus.split('*')[1] - nextstatus = nextstatus.split('*')[0] - print('tarinactrl ip:' + tarinactrl_ip) - process = Process(target=listenforclients, args=("0.0.0.0", port, que)) - process.start() - if nextstatus=="REC": - pressed="record" - elif nextstatus=="STOP": - if recording == True: - pressed="record" - elif nextstatus=="RECSOUND": - if recording==False: - pressed="record" - onlysound=True - elif nextstatus=="PLACEHOLDER": - selected=2 - pressed="insert_shot" - elif "SYNCIP:" in nextstatus: - ip = nextstatus.split(':')[1] - stopinterface(camera) - run_command('rsync -avr --update --progress --exclude="*.wav" pi@'+ip+':'+filmfolder+filmname+'/'+'scene'+str(scene).zfill(3)+' '+filmfolder+filmname+'/') - sendtoserver(tarinactrl_ip,port,'SYNCDONE') - #run_command('scp -r '+filmfolder+filmname+'/'+'scene'+str(scene).zfill(3)+' pi@'+ip+':'+filmfolder+filmname+'/') - startinterface() - camera = startcamera(lens,fps) - loadfilmsettings = True - elif nextstatus=="NEWSCENE": - scenes, shots, takes = browse(filmname,filmfolder,scene,shot,take) - scene=scenes+1 - shot=1 - take=1 - elif nextstatus=="RETAKE": - pressed="retake" - print(nextstatus) - nextstatus='' if recording == False: #SHUTDOWN if pressed == 'middle' and menu[selected] == 'SHUTDOWN': @@ -3338,7 +3300,61 @@ def flushbutton(): break def getbutton(lastbutton, buttonpressed, buttontime, holdbutton): - global i2cbuttons + global i2cbuttons, serverstate, nextstatus, process, que + #Check controller + pressed = '' + if process.is_alive() == False and serverstate == 'on': + nextstatus = que.get() + if "*" in nextstatus: + tarinactrl_ip = nextstatus.split('*')[1] + nextstatus = nextstatus.split('*')[0] + print('tarinactrl ip:' + tarinactrl_ip) + process = Process(target=listenforclients, args=("0.0.0.0", port, que)) + process.start() + if nextstatus=="UP": + pressed="up" + elif nextstatus=="DOWN": + pressed="down" + elif nextstatus=="LEFT": + pressed="left" + elif nextstatus=="RIGHT": + pressed="right" + elif nextstatus=="VIEW": + pressed="view" + elif nextstatus=="MIDDLE": + pressed="middle" + elif nextstatus=="DELETE": + pressed="remove" + elif nextstatus=="REC": + pressed="record" + elif nextstatus=="STOP": + if recording == True: + pressed="record" + elif nextstatus=="RECSOUND": + if recording==False: + pressed="record" + onlysound=True + elif nextstatus=="PLACEHOLDER": + selected=2 + pressed="insert_shot" + elif "SYNCIP:" in nextstatus: + ip = nextstatus.split(':')[1] + stopinterface(camera) + run_command('rsync -avr --update --progress --exclude="*.wav" pi@'+ip+':'+filmfolder+filmname+'/'+'scene'+str(scene).zfill(3)+' '+filmfolder+filmname+'/') + sendtoserver(tarinactrl_ip,port,'SYNCDONE') + #run_command('scp -r '+filmfolder+filmname+'/'+'scene'+str(scene).zfill(3)+' pi@'+ip+':'+filmfolder+filmname+'/') + startinterface() + camera = startcamera(lens,fps) + loadfilmsettings = True + elif nextstatus=="NEWSCENE": + scenes, shots, takes = browse(filmname,filmfolder,scene,shot,take) + scene=scenes+1 + shot=1 + take=1 + elif nextstatus=="RETAKE": + pressed="retake" + print(nextstatus) + nextstatus='' with term.cbreak(): val = term.inkey(timeout=0) if val.is_sequence: @@ -3364,7 +3380,6 @@ def getbutton(lastbutton, buttonpressed, buttontime, holdbutton): else: readbus = 255 readbus2 = 247 - pressed = '' if buttonpressed == False: if event != '': print(term.clear+term.home)