53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
#! /usr/bin/python3
|
|
|
|
import os
|
|
import threading
|
|
import subprocess
|
|
import glob
|
|
import os
|
|
import json
|
|
import io
|
|
import shutil
|
|
import time
|
|
import re
|
|
import logging
|
|
import dvd
|
|
import cd
|
|
|
|
class Encoder(threading.Thread):
|
|
def __init__(self, directory=None, **kwargs):
|
|
self.status = {}
|
|
self.directory = directory
|
|
return super().__init__(**kwargs)
|
|
|
|
def run(self):
|
|
while True:
|
|
wait = True
|
|
self.status = {"type": "encoder", "state": "idle"}
|
|
for fn in glob.glob(os.path.join(self.directory, "*", "sucker.json")):
|
|
fdir = os.path.dirname(fn)
|
|
with open(fn) as f:
|
|
obj = json.load(f)
|
|
self.encode(fdir, obj)
|
|
wait = False
|
|
if wait:
|
|
time.sleep(12)
|
|
|
|
def encode(self, fdir, obj):
|
|
self.status["state"] = "encoding"
|
|
self.status["title"] = obj["title"]
|
|
if obj["type"] == "audio":
|
|
self.encode_audio(fdir, obj)
|
|
else:
|
|
self.encode_video(fdir, obj)
|
|
shutil.rmtree(fdir)
|
|
|
|
def encode_audio(self, fdir, obj):
|
|
cd.encode(obj, fdir)
|
|
|
|
def encode_video(self, fdir, obj):
|
|
enc = dvd.Encoder(fdir, self.status)
|
|
enc.encode(obj)
|
|
|
|
# vi: sw=4 ts=4 et ai
|