need local logging for dev , adding basic config logic

This commit is contained in:
thelamer 2019-07-21 02:44:23 +00:00
parent 3545c6bf94
commit 71deb01d16
6 changed files with 99 additions and 30 deletions

View File

@ -1,25 +1,23 @@
---
interval: 60
enabled: false
commands:
- name: "test1"
extension: ".mkv"
delete: false
command: |
ffmpeg -i "${INPUTFILE}" \
ffmpeg -i "INPUTFILE" \
-vf scale=-1:720 \
-c:v h264 \
-c:a copy \
-b:v 4000k \
"${OUTPUTFILE}"
"OUTPUTFILE"
- name: "test2"
extension: ".mkv"
delete: true
command: |
ffmpeg -i "${INPUTFILE}" \
ffmpeg -i "INPUTFILE" \
-vf scale=-1:720 \
-c:v h264 \
-c:a copy \
-b:v 4000k \
"${OUTPUTFILE}"
"OUTPUTFILE"

View File

@ -27,15 +27,22 @@ function renderconfig(){
}
socket.on('sendconfig', function(rules){
pagepurge();
var interval = rules.interval;
var enabled = rules.enabled;
if (enabled){
var options = '<option selected value=1>on</option>\
<option value=0>off</option>'
}
else{
var options = '<option selected value=0>off</option>\
<option value=1>on</option>'
}
$('#headerform').append('\
<select class="custom-select form-control mr-sm-2" id="interval">\
<option selected value="' + interval + '">' + interval + '</option>\
<option value"Never">Never</option>\
<option value="30">30 seconds</option>\
<option value="60">60 seconds</option>\
<option value="300">5 minutes</option>\
</select>\
<div class="form-group">\
<label for="email">Processing: </label>\
<select class="custom-select form-control mr-sm-2" id="enabled">\
' + options + '\
</select>\
</div>\
<button style="cursor:pointer;" onclick="saveall()" class="btn btn-primary my-2 my-sm-0" type="submit">Save Config</button>\
');
var editor = [];
@ -126,8 +133,14 @@ function addconfig(){
}
// Save all config data
function saveall(){
var interval = $('#interval').val();
var dataset = {'interval':interval,'commands':[]};
var enabled = $('#enabled').val();
if (enabled == 0){
var enabled = false;
}
else{
var enabled = true;
}
var dataset = {'enabled':enabled,'commands':[]};
var ids = $('.rule').map(function(){
return this.id;
}).get();
@ -141,6 +154,7 @@ function saveall(){
dataset.commands.push(single_command);
}).promise().done(function(){
socket.emit('saveconfig',dataset);
renderconfig();
});
}

View File

@ -1,2 +1,3 @@
flask
flask_socketio
pyyaml

View File

@ -0,0 +1,16 @@
#!/usr/bin/with-contenv bash
# check if config file exists in /config
[[ ! -f /config/config.yml ]] && \
cp /app/ffmpeg-web/config.yml /config/config.yml
# permissions
chown -R abc:abc \
/config
mkdir -p \
/in \
/out
chown abc:abc \
/in \
/out

View File

@ -1,5 +1,9 @@
#!/usr/bin/with-contenv bash
# Make log output for dev
mkdir -p /applogs
chown -R abc:abc /applogs
# Run App in development mode
cd /app/ffmpeg-web
exec \
@ -7,4 +11,5 @@ exec \
watchmedo auto-restart \
-d . \
-p './server.py' \
-- python3 server.py
-- python3 server.py \
>> /applogs/applog.txt 2>&1

View File

@ -1,5 +1,6 @@
from flask import Flask, send_from_directory, request
from flask_socketio import SocketIO
from pathlib import Path
import glob
import os
import pty
@ -9,16 +10,14 @@ import subprocess
import time
import yaml
# Error logging only
import logging
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
#import logging
#log = logging.getLogger('werkzeug')
#log.setLevel(logging.ERROR)
# Websocket server
app = Flask(__name__,static_folder="public")
sio = SocketIO(app)
################################
# Job functions #
################################
@ -31,15 +30,47 @@ def build_list(extension):
all_files = glob.glob('/in/**/*' + extension_regex, recursive=True)
# Check if anything in this array has a processed log or is not a file and pull it out
for file in all_files:
# Remove files from processing list if they have log files and no processing pid
if not os.path.isfile(file) or os.path.isfile(file + '.ffmpeg_log'):
all_files.remove(file)
if not os.path.isfile(file + '.ffmpeg_processing'):
all_files.remove(file)
return all_files
# run individual job
def run_job(file,job_command):
try:
# Create a processing file on disk
os.remove(file + '.ffmpeg_processing')
os.mknod(file + '.ffmpeg_processing')
# Create output structure
filename = os.path.basename(file)
outpath = Path('/out/' + os.path.dirname(os.path.abspath(file)).replace('/in/', '', 1))
outpath.mkdir(parents=True)
# Remove processing file on disk
time.sleep(5)
os.remove(file + '.ffmpeg_processing')
except OSError:
pass
# run jobs based on config
def run_jobs(config):
for command in config['commands']:
file_list = build_list(command['extension'])
for file in file_list:
run_job(file,command['command'])
# Background job thread loop for file processing
def processor():
while True:
files = build_list('.mkv')
sio.emit('testout', files)
with open("/config/config.yml", 'r') as stream:
try:
config = yaml.safe_load(stream)
if config['enabled'] is True:
run_jobs(config)
except yaml.YAMLError as e:
print(e)
# Loop every 5 seconds to check config file and run jobs
stream.close()
time.sleep(5)
sio.start_background_task(processor)
@ -56,7 +87,7 @@ def index():
# Send the current config to the user to render
@sio.on('getconfig')
def config():
with open("./config.yml", 'r') as stream:
with open("/config/config.yml", 'r') as stream:
try:
config = yaml.safe_load(stream)
sio.emit('sendconfig', config, room=request.sid)
@ -75,9 +106,13 @@ def commands():
# Main page for rendering processing history and current
@sio.on('getmain')
def commands():
data = 'test'
sio.emit('sendmain', data, room=request.sid)
def main():
with open("/config/config.yml", 'r') as stream:
try:
config = yaml.safe_load(stream)
sio.emit('sendmain', config, room=request.sid)
except yaml.YAMLError as e:
print(e)
# Save user set config
@sio.on('saveconfig')