2022-02-26 08:05:20 -07:00
|
|
|
#! /usr/bin/python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import io
|
|
|
|
import shutil
|
|
|
|
import time
|
|
|
|
import re
|
2022-08-20 16:42:53 -06:00
|
|
|
import logging
|
2022-08-21 17:22:06 -06:00
|
|
|
import dvd
|
2022-08-23 22:06:44 -06:00
|
|
|
import cd
|
2022-08-25 10:17:25 -06:00
|
|
|
import worker
|
2022-02-26 08:05:20 -07:00
|
|
|
|
2022-08-25 10:17:25 -06:00
|
|
|
class Encoder(worker.Worker):
|
|
|
|
def __init__(self, directory=None):
|
2022-02-26 08:05:20 -07:00
|
|
|
self.status = {}
|
|
|
|
self.directory = directory
|
2022-09-02 17:04:07 -06:00
|
|
|
self.loop_delay = 12
|
2022-08-25 10:17:25 -06:00
|
|
|
return super().__init__(directory)
|
2022-02-26 08:05:20 -07:00
|
|
|
|
2022-09-02 17:04:07 -06:00
|
|
|
def once(self):
|
|
|
|
wait = True
|
|
|
|
self.status["type"] = "encoder"
|
|
|
|
for fn in glob.glob(self.workdir("*", "sucker.json")):
|
|
|
|
directory = os.path.dirname(fn)
|
|
|
|
state = self.read_state(directory)
|
|
|
|
self.encode(directory, state)
|
2022-02-26 08:05:20 -07:00
|
|
|
|
2022-08-25 10:17:25 -06:00
|
|
|
def encode(self, directory, state):
|
2022-08-21 17:22:06 -06:00
|
|
|
self.status["state"] = "encoding"
|
2022-08-25 10:17:25 -06:00
|
|
|
self.status["title"] = state["title"]
|
|
|
|
|
|
|
|
if state["video"]:
|
|
|
|
media = dvd
|
2022-02-26 08:05:20 -07:00
|
|
|
else:
|
2022-08-25 10:17:25 -06:00
|
|
|
media = cd
|
|
|
|
|
|
|
|
logging.info("Encoding %s (%s)" % (directory, state["title"]))
|
|
|
|
for pct in media.encode(state, directory):
|
|
|
|
self.status["complete"] = pct
|
|
|
|
|
|
|
|
media.clean(state, directory)
|
2022-08-25 10:17:25 -06:00
|
|
|
self.clear_state(directory)
|
2022-08-25 10:17:25 -06:00
|
|
|
|
|
|
|
logging.info("Finished encoding")
|
2022-02-26 08:05:20 -07:00
|
|
|
|
|
|
|
# vi: sw=4 ts=4 et ai
|