|
|
|
|
@ -25,11 +25,12 @@ import logging
|
|
|
|
|
import os |
|
|
|
|
import re |
|
|
|
|
import shutil |
|
|
|
|
import subprocess |
|
|
|
|
from os.path import splitext |
|
|
|
|
|
|
|
|
|
from . import image, utils |
|
|
|
|
from .settings import get_thumb, Status |
|
|
|
|
from .utils import call_subprocess, is_valid_html5_video |
|
|
|
|
from .utils import is_valid_html5_video |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SubprocessException(Exception): |
|
|
|
|
@ -43,16 +44,17 @@ def check_subprocess(cmd, source, outname):
|
|
|
|
|
""" |
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
try: |
|
|
|
|
returncode, stdout, stderr = call_subprocess(cmd) |
|
|
|
|
res = subprocess.run(cmd, stdout=subprocess.PIPE, |
|
|
|
|
stderr=subprocess.PIPE, encoding='utf8') |
|
|
|
|
except KeyboardInterrupt: |
|
|
|
|
logger.debug('Process terminated, removing file %s', outname) |
|
|
|
|
if os.path.isfile(outname): |
|
|
|
|
os.remove(outname) |
|
|
|
|
raise |
|
|
|
|
|
|
|
|
|
if returncode: |
|
|
|
|
logger.debug('STDOUT:\n %s', stdout) |
|
|
|
|
logger.debug('STDERR:\n %s', stderr) |
|
|
|
|
if res.returncode: |
|
|
|
|
logger.debug('STDOUT:\n %s', res.stdout) |
|
|
|
|
logger.debug('STDERR:\n %s', res.stderr) |
|
|
|
|
if os.path.isfile(outname): |
|
|
|
|
logger.debug('Removing file %s', outname) |
|
|
|
|
os.remove(outname) |
|
|
|
|
@ -62,11 +64,12 @@ def check_subprocess(cmd, source, outname):
|
|
|
|
|
def video_size(source, converter='ffmpeg'): |
|
|
|
|
"""Returns the dimensions of the video.""" |
|
|
|
|
|
|
|
|
|
ret, stdout, stderr = call_subprocess([converter, '-i', source]) |
|
|
|
|
res = subprocess.run([converter, '-i', source], stderr=subprocess.PIPE, |
|
|
|
|
encoding='utf8') |
|
|
|
|
pattern = re.compile(r'Stream.*Video.* ([0-9]+)x([0-9]+)') |
|
|
|
|
match = pattern.search(stderr) |
|
|
|
|
match = pattern.search(res.stderr) |
|
|
|
|
rot_pattern = re.compile(r'rotate\s*:\s*-?(90|270)') |
|
|
|
|
rot_match = rot_pattern.search(stderr) |
|
|
|
|
rot_match = rot_pattern.search(res.stderr) |
|
|
|
|
|
|
|
|
|
if match: |
|
|
|
|
x, y = int(match.groups()[0]), int(match.groups()[1]) |
|
|
|
|
|