2014-01-30 00:11:25 +01:00
|
|
|
from CachePath import message
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
class VideoToolWrapper(object):
|
|
|
|
def call(self, *args):
|
|
|
|
path = args[-1]
|
|
|
|
for tool in self.wrappers:
|
2018-11-11 04:22:15 +01:00
|
|
|
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"
|
2014-01-30 00:11:25 +01:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
if self.cleanup:
|
|
|
|
self.remove(path)
|
|
|
|
raise
|
|
|
|
except OSError:
|
|
|
|
continue
|
|
|
|
except:
|
|
|
|
if self.cleanup:
|
|
|
|
self.remove(path)
|
2015-05-04 23:57:27 +02:00
|
|
|
continue
|
2014-01-30 00:11:25 +01:00
|
|
|
return p
|
|
|
|
return False
|
|
|
|
|
|
|
|
def remove(self, path):
|
|
|
|
try:
|
|
|
|
os.unlink(path)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
class VideoTranscodeWrapper(VideoToolWrapper):
|
|
|
|
def __init__(self):
|
|
|
|
self.wrappers = ['avconv', 'ffmpeg']
|
2018-11-11 04:22:15 +01:00
|
|
|
self.check_output = False
|
2014-01-30 00:11:25 +01:00
|
|
|
self.cleanup = True
|
|
|
|
|
|
|
|
class VideoProbeWrapper(VideoToolWrapper):
|
|
|
|
def __init__(self):
|
|
|
|
self.wrappers = ['avprobe', 'ffprobe']
|
2018-11-11 04:22:15 +01:00
|
|
|
self.check_output = True
|
2014-01-30 00:11:25 +01:00
|
|
|
self.cleanup = False
|