diff --git a/config.yml b/config.yml
index 377c10c..798e3ca 100644
--- a/config.yml
+++ b/config.yml
@@ -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}"
\ No newline at end of file
+ "OUTPUTFILE"
\ No newline at end of file
diff --git a/public/ffmpeg-web.js b/public/ffmpeg-web.js
index d479780..0560945 100644
--- a/public/ffmpeg-web.js
+++ b/public/ffmpeg-web.js
@@ -27,15 +27,22 @@ function renderconfig(){
}
socket.on('sendconfig', function(rules){
pagepurge();
- var interval = rules.interval;
+ var enabled = rules.enabled;
+ if (enabled){
+ var options = '\
+ '
+ }
+ else{
+ var options = '\
+ '
+ }
$('#headerform').append('\
- \
+
\
+ \
+ \
+
\
\
');
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();
});
}
diff --git a/requirements.txt b/requirements.txt
index b61446c..5f14521 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1,3 @@
flask
+flask_socketio
pyyaml
\ No newline at end of file
diff --git a/root/etc/cont-init.d/30-config b/root/etc/cont-init.d/30-config
new file mode 100644
index 0000000..2a1d0d4
--- /dev/null
+++ b/root/etc/cont-init.d/30-config
@@ -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
+
diff --git a/root/etc/services.d/web/run b/root/etc/services.d/web/run
index 5bbe4b0..c2363da 100644
--- a/root/etc/services.d/web/run
+++ b/root/etc/services.d/web/run
@@ -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
diff --git a/server.py b/server.py
index a2667a4..fe9f070 100644
--- a/server.py
+++ b/server.py
@@ -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 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')