photofloat/scanner/VideoToolWrapper.py

51 lines
1.3 KiB
Python
Raw Normal View History

2014-01-30 00:11:25 +01:00
from CachePath import message
import os
import subprocess
2014-01-30 00:11:25 +01:00
class VideoToolWrapper(object):
def call(self, *args):
path = args[-1]
for tool in self.wrappers:
try:
if self.check_output:
p = subprocess.check_output((tool,) + args)
else:
p = subprocess.call((tool,) + args)
if p > 0:
return False
else:
return "SUCCESS"
except KeyboardInterrupt:
if self.cleanup:
self.remove(path)
raise
except OSError:
continue
except:
if self.cleanup:
self.remove(path)
continue
return p
return False
def remove(self, path):
try:
os.unlink(path)
except:
pass
2014-01-30 00:11:25 +01:00
class VideoTranscodeWrapper(VideoToolWrapper):
def __init__(self):
self.wrappers = ['avconv', 'ffmpeg']
self.check_output = False
self.cleanup = True
2014-01-30 00:11:25 +01:00
class VideoProbeWrapper(VideoToolWrapper):
def __init__(self):
self.wrappers = ['avprobe', 'ffprobe']
self.check_output = True
self.cleanup = False