Commit 8d0b85cc authored by Andreas Valder's avatar Andreas Valder

working thumbnail generator

parent 5bbbcd46
Dependencies:
python3
python-psutil
......@@ -6,6 +6,10 @@ import sched
import random
import traceback
import configparser
import psutil
import os
import json
import shlex
config = configparser.ConfigParser()
config.read('config.ini')
......@@ -36,14 +40,27 @@ threading.Thread(target=run_scheduler, daemon=True).start()
@sched_func(5)
def ping_website():
r = requests.post(config['API']['BASE']+'/jobs/api/ping', params={'apikey': config['API']['KEY'], 'host':config['MAIN']['HOST']})
r = requests.post(config['API']['BASE']+'/jobs/api/worker/'+config['MAIN']['HOST']+'/ping', params={'apikey': config['API']['KEY']})
if not r.status_code == 200:
print("Error sending ping: ",r)
@sched_func(10)
def get_jobs():
r = requests.post(config['API']['BASE']+'/jobs/api/schedule', json={'apikey': config['API']['KEY'], 'host':config['MAIN']['HOST'], 'jobtypes': 'thumbnail'})
print(r.text)
if psutil.cpu_percent(interval=3) < 70:
r = requests.post(config['API']['BASE']+'/jobs/api/worker/'+config['MAIN']['HOST']+'/schedule', json={'apikey': config['API']['KEY'], 'jobtypes': 'thumbnail'})
if r.status_code == 200:
threading.Thread(target=executejob, daemon=True, kwargs={'data': r.json()}).start()
def executejob(data):
print(data)
param = json.loads(data['data'])
if (data['type'] == 'thumbnail'):
inputfile = '/mnt/sshfs/video-main/'+param['path']
outputfile = '/tmp/l_'+str(param['lectureid'])+'.png'
r = requests.post(config['API']['BASE']+'/jobs/api/job/'+str(data['id'])+'/ping', params={'apikey': config['API']['KEY'], 'host': config['MAIN']['HOST'], 'state': 'running', 'status': '{}'})
os.system("ffmpeg -loglevel error -i '" + shlex.quote(inputfile) + "' -ss '10:00' -vf 'scale=640:360' -frames:v 1 '" + shlex.quote(outputfile) + "'")
r = requests.post(config['API']['BASE']+'/jobs/api/job/'+str(data['id'])+'/finished', json={'apikey': config['API']['KEY'], 'status': '{}'})
print(r)
while True:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment