PEP8: Fix formatting

* Remove redundant backslash between brackets
* Fix multiple statements on one line
* Fix missing/excess whitespace
* Fix comments not starting with a single # and a space
* Convert tabs to spaces
* Use triple-quoted docstring
This commit is contained in:
Labrys 2016-06-04 22:07:03 -04:00
parent 81ffe0456d
commit 8cd0e76ef8
35 changed files with 1342 additions and 947 deletions

View file

@ -12,6 +12,7 @@ import re
from core import logger
from core.nzbToMediaUtil import makeDir
def isVideoGood(videofile, status):
fileNameExt = os.path.basename(videofile)
fileName, fileExt = os.path.splitext(fileNameExt)
@ -20,7 +21,7 @@ def isVideoGood(videofile, status):
disable = True
else:
test_details, res = getVideoDetails(core.TEST_FILE)
if res !=0 or test_details.get("error"):
if res != 0 or test_details.get("error"):
disable = True
logger.info("DISABLED: ffprobe failed to analyse test file. Stopping corruption check.", 'TRANSCODER')
if test_details.get("streams"):
@ -28,7 +29,8 @@ def isVideoGood(videofile, status):
audStreams = [item for item in test_details["streams"] if item["codec_type"] == "audio"]
if not (len(vidStreams) > 0 and len(audStreams) > 0):
disable = True
logger.info("DISABLED: ffprobe failed to analyse streams from test file. Stopping corruption check.", 'TRANSCODER')
logger.info("DISABLED: ffprobe failed to analyse streams from test file. Stopping corruption check.",
'TRANSCODER')
if disable:
if status: # if the download was "failed", assume bad. If it was successful, assume good.
return False
@ -51,9 +53,11 @@ def isVideoGood(videofile, status):
logger.info("SUCCESS: [%s] has no corruption." % (fileNameExt), 'TRANSCODER')
return True
else:
logger.info("FAILED: [%s] has %s video streams and %s audio streams. Assume corruption." % (fileNameExt, str(len(videoStreams)), str(len(audioStreams))), 'TRANSCODER')
logger.info("FAILED: [%s] has %s video streams and %s audio streams. Assume corruption." % (
fileNameExt, str(len(videoStreams)), str(len(audioStreams))), 'TRANSCODER')
return False
def zip_out(file, img, bitbucket):
procin = None
cmd = [core.SEVENZIP, '-so', 'e', img, file]
@ -63,6 +67,7 @@ def zip_out(file, img, bitbucket):
logger.error("Extracting [%s] has failed" % (file), 'TRANSCODER')
return procin
def getVideoDetails(videofile, img=None, bitbucket=None):
video_details = {}
result = 1
@ -76,7 +81,8 @@ def getVideoDetails(videofile, img=None, bitbucket=None):
try:
if img:
videofile = '-'
command = [core.FFPROBE, '-v', 'quiet', print_format, 'json', '-show_format', '-show_streams', '-show_error', videofile]
command = [core.FFPROBE, '-v', 'quiet', print_format, 'json', '-show_format', '-show_streams', '-show_error',
videofile]
print_cmd(command)
if img:
procin = zip_out(file, img, bitbucket)
@ -87,7 +93,8 @@ def getVideoDetails(videofile, img=None, bitbucket=None):
out, err = proc.communicate()
result = proc.returncode
video_details = json.loads(out)
except: pass
except:
pass
if not video_details:
try:
command = [core.FFPROBE, '-v', 'quiet', print_format, 'json', '-show_format', '-show_streams', videofile]
@ -104,6 +111,7 @@ def getVideoDetails(videofile, img=None, bitbucket=None):
logger.error("Checking [%s] has failed" % (file), 'TRANSCODER')
return video_details, result
def buildCommands(file, newDir, movieName, bitbucket):
if isinstance(file, str):
inputFile = file
@ -119,8 +127,8 @@ def buildCommands(file, newDir, movieName, bitbucket):
name = ('%s.cd%s' % (movieName, check.groups()[0]))
elif core.CONCAT and re.match("(.+)[cC][dD][0-9]", name):
name = re.sub("([\ \.\-\_\=\:]+[cC][dD][0-9])", "", name)
if ext == core.VEXTENSION and newDir == dir: # we need to change the name to prevent overwriting itself.
core.VEXTENSION = '-transcoded' + core.VEXTENSION # adds '-transcoded.ext'
if ext == core.VEXTENSION and newDir == dir: # we need to change the name to prevent overwriting itself.
core.VEXTENSION = '-transcoded' + core.VEXTENSION # adds '-transcoded.ext'
else:
img, data = file.iteritems().next()
name = data['name']
@ -139,7 +147,8 @@ def buildCommands(file, newDir, movieName, bitbucket):
meta_cmd = []
other_cmd = []
if not video_details or not video_details.get("streams"): # we couldn't read streams with ffprobe. Set defaults to try transcoding.
if not video_details or not video_details.get(
"streams"): # we couldn't read streams with ffprobe. Set defaults to try transcoding.
videoStreams = []
audioStreams = []
subStreams = []
@ -166,12 +175,13 @@ def buildCommands(file, newDir, movieName, bitbucket):
if core.ACODEC:
audio_cmd.extend(['-c:a', core.ACODEC])
if core.ACODEC in ['aac', 'dts']: # Allow users to use the experimental AAC codec that's built into recent versions of ffmpeg
if core.ACODEC in ['aac',
'dts']: # Allow users to use the experimental AAC codec that's built into recent versions of ffmpeg
audio_cmd.extend(['-strict', '-2'])
else:
audio_cmd.extend(['-c:a', 'copy'])
if core.ACHANNELS:
audio_cmd.extend(['-ac', str(core.ACHANNELS)])
audio_cmd.extend(['-ac', str(core.ACHANNELS)])
if core.ABITRATE:
audio_cmd.extend(['-b:a', str(core.ABITRATE)])
if core.OUTPUTQUALITYPERCENT:
@ -183,7 +193,7 @@ def buildCommands(file, newDir, movieName, bitbucket):
sub_cmd.extend(['-c:s', 'copy'])
else: # http://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/subtitle_options
sub_cmd.extend(['-sn']) # Don't copy the subtitles over
if core.OUTPUTFASTSTART:
other_cmd.extend(['-movflags', '+faststart'])
@ -192,23 +202,29 @@ def buildCommands(file, newDir, movieName, bitbucket):
audioStreams = [item for item in video_details["streams"] if item["codec_type"] == "audio"]
subStreams = [item for item in video_details["streams"] if item["codec_type"] == "subtitle"]
if core.VEXTENSION not in ['.mkv', '.mpegts']:
subStreams = [item for item in video_details["streams"] if item["codec_type"] == "subtitle" and item["codec_name"] != "hdmv_pgs_subtitle" and item["codec_name"] != "pgssub"]
subStreams = [item for item in video_details["streams"] if
item["codec_type"] == "subtitle" and item["codec_name"] != "hdmv_pgs_subtitle" and item[
"codec_name"] != "pgssub"]
for video in videoStreams:
codec = video["codec_name"]
try:
fr = video["avg_frame_rate"]
except: fr = 0
except:
fr = 0
try:
width = video["width"]
except: width = 0
except:
width = 0
try:
height = video["height"]
except: height = 0
except:
height = 0
scale = core.VRESOLUTION
try:
framerate = float(fr.split('/')[0])/float(fr.split('/')[1])
except: framerate = 0
framerate = float(fr.split('/')[0]) / float(fr.split('/')[1])
except:
framerate = 0
if codec in core.VCODEC_ALLOW or not core.VCODEC:
video_cmd.extend(['-c:v', 'copy'])
else:
@ -216,16 +232,16 @@ def buildCommands(file, newDir, movieName, bitbucket):
if core.VFRAMERATE and not (core.VFRAMERATE * 0.999 <= fr <= core.VFRAMERATE * 1.001):
video_cmd.extend(['-r', str(core.VFRAMERATE)])
if scale:
w_scale = width/float(scale.split(':')[0])
h_scale = height/float(scale.split(':')[1])
if w_scale > h_scale: # widescreen, Scale by width only.
scale = scale.split(':')[0] + ":" + str(int((height/w_scale)/2)*2)
if w_scale > 1:
video_cmd.extend(['-vf', 'scale=' + scale])
w_scale = width / float(scale.split(':')[0])
h_scale = height / float(scale.split(':')[1])
if w_scale > h_scale: # widescreen, Scale by width only.
scale = scale.split(':')[0] + ":" + str(int((height / w_scale) / 2) * 2)
if w_scale > 1:
video_cmd.extend(['-vf', 'scale=' + scale])
else: # lower or mathcing ratio, scale by height only.
scale = str(int((width/h_scale)/2)*2) + ":" + scale.split(':')[1]
if h_scale > 1:
video_cmd.extend(['-vf', 'scale=' + scale])
scale = str(int((width / h_scale) / 2) * 2) + ":" + scale.split(':')[1]
if h_scale > 1:
video_cmd.extend(['-vf', 'scale=' + scale])
if core.VBITRATE:
video_cmd.extend(['-b:v', str(core.VBITRATE)])
if core.VPRESET:
@ -238,7 +254,7 @@ def buildCommands(file, newDir, movieName, bitbucket):
if video_cmd[1] == 'copy' and any(i in video_cmd for i in no_copy):
video_cmd[1] = core.VCODEC
if core.VCODEC == 'copy': # force copy. therefore ignore all other video transcoding.
video_cmd = ['-c:v', 'copy']
video_cmd = ['-c:v', 'copy']
map_cmd.extend(['-map', '0:' + str(video["index"])])
break # Only one video needed
@ -246,12 +262,12 @@ def buildCommands(file, newDir, movieName, bitbucket):
a_mapped = []
if audioStreams:
try:
audio1 = [ item for item in audioStreams if item["tags"]["language"] == core.ALANGUAGE ]
audio1 = [item for item in audioStreams if item["tags"]["language"] == core.ALANGUAGE]
except: # no language tags. Assume only 1 language.
audio1 = audioStreams
audio2 = [ item for item in audio1 if item["codec_name"] in core.ACODEC_ALLOW ]
audio2 = [item for item in audio1 if item["codec_name"] in core.ACODEC_ALLOW]
try:
audio3 = [ item for item in audioStreams if item["tags"]["language"] != core.ALANGUAGE ]
audio3 = [item for item in audioStreams if item["tags"]["language"] != core.ALANGUAGE]
except:
audio3 = []
@ -259,21 +275,25 @@ def buildCommands(file, newDir, movieName, bitbucket):
map_cmd.extend(['-map', '0:' + str(audio2[0]["index"])])
a_mapped.extend([audio2[0]["index"]])
try:
bitrate = int(audio2[0]["bit_rate"])/1000
except: bitrate = 0
bitrate = int(audio2[0]["bit_rate"]) / 1000
except:
bitrate = 0
try:
channels = int(audio2[0]["channels"])
except: channels = 0
except:
channels = 0
audio_cmd.extend(['-c:a:' + str(used_audio), 'copy'])
elif audio1: # right language wrong codec.
map_cmd.extend(['-map', '0:' + str(audio1[0]["index"])])
a_mapped.extend([audio1[0]["index"]])
try:
bitrate = int(audio1[0]["bit_rate"])/1000
except: bitrate = 0
bitrate = int(audio1[0]["bit_rate"]) / 1000
except:
bitrate = 0
try:
channels = int(audio1[0]["channels"])
except: channels = 0
except:
channels = 0
if core.ACODEC:
audio_cmd.extend(['-c:a:' + str(used_audio), core.ACODEC])
else:
@ -282,11 +302,13 @@ def buildCommands(file, newDir, movieName, bitbucket):
map_cmd.extend(['-map', '0:' + str(audio3[0]["index"])])
a_mapped.extend([audio3[0]["index"]])
try:
bitrate = int(audio3[0]["bit_rate"])/1000
except: bitrate = 0
bitrate = int(audio3[0]["bit_rate"]) / 1000
except:
bitrate = 0
try:
channels = int(audio3[0]["channels"])
except: channels = 0
except:
channels = 0
if core.ACODEC:
audio_cmd.extend(['-c:a:' + str(used_audio), core.ACODEC])
else:
@ -309,26 +331,30 @@ def buildCommands(file, newDir, movieName, bitbucket):
if core.ACODEC2_ALLOW:
used_audio += 1
audio4 = [ item for item in audio1 if item["codec_name"] in core.ACODEC2_ALLOW ]
audio4 = [item for item in audio1 if item["codec_name"] in core.ACODEC2_ALLOW]
if audio4: # right language and codec.
map_cmd.extend(['-map', '0:' + str(audio4[0]["index"])])
a_mapped.extend([audio4[0]["index"]])
try:
bitrate = int(audio4[0]["bit_rate"])/1000
except: bitrate = 0
bitrate = int(audio4[0]["bit_rate"]) / 1000
except:
bitrate = 0
try:
channels = int(audio4[0]["channels"])
except: channels = 0
except:
channels = 0
audio_cmd2.extend(['-c:a:' + str(used_audio), 'copy'])
elif audio1: # right language wrong codec.
map_cmd.extend(['-map', '0:' + str(audio1[0]["index"])])
a_mapped.extend([audio1[0]["index"]])
try:
bitrate = int(audio1[0]["bit_rate"])/1000
except: bitrate = 0
bitrate = int(audio1[0]["bit_rate"]) / 1000
except:
bitrate = 0
try:
channels = int(audio1[0]["channels"])
except: channels = 0
except:
channels = 0
if core.ACODEC2:
audio_cmd2.extend(['-c:a:' + str(used_audio), core.ACODEC2])
else:
@ -337,11 +363,13 @@ def buildCommands(file, newDir, movieName, bitbucket):
map_cmd.extend(['-map', '0:' + str(audio3[0]["index"])])
a_mapped.extend([audio3[0]["index"]])
try:
bitrate = int(audio3[0]["bit_rate"])/1000
except: bitrate = 0
bitrate = int(audio3[0]["bit_rate"]) / 1000
except:
bitrate = 0
try:
channels = int(audio3[0]["channels"])
except: channels = 0
except:
channels = 0
if core.ACODEC2:
audio_cmd2.extend(['-c:a:' + str(used_audio), core.ACODEC2])
else:
@ -371,11 +399,13 @@ def buildCommands(file, newDir, movieName, bitbucket):
map_cmd.extend(['-map', '0:' + str(audio["index"])])
audio_cmd3 = []
try:
bitrate = int(audio["bit_rate"])/1000
except: bitrate = 0
bitrate = int(audio["bit_rate"]) / 1000
except:
bitrate = 0
try:
channels = int(audio["channels"])
except: channels = 0
except:
channels = 0
if audio["codec_name"] in core.ACODEC3_ALLOW:
audio_cmd3.extend(['-c:a:' + str(used_audio), 'copy'])
else:
@ -406,8 +436,9 @@ def buildCommands(file, newDir, movieName, bitbucket):
n = 0
for lan in core.SLANGUAGES:
try:
subs1 = [ item for item in subStreams if item["tags"]["language"] == lan ]
except: subs1 = []
subs1 = [item for item in subStreams if item["tags"]["language"] == lan]
except:
subs1 = []
if core.BURN and not subs1 and not burnt and os.path.isfile(file):
for subfile in get_subs(file):
if lan in os.path.split(subfile)[1]:
@ -426,7 +457,7 @@ def buildCommands(file, newDir, movieName, bitbucket):
break
map_cmd.extend(['-map', '0:' + str(sub["index"])])
s_mapped.extend([sub["index"]])
if core.SINCLUDE:
for sub in subStreams:
if not core.ALLOWSUBS:
@ -434,7 +465,7 @@ def buildCommands(file, newDir, movieName, bitbucket):
if sub["index"] in s_mapped:
continue
map_cmd.extend(['-map', '0:' + str(sub["index"])])
s_mapped.extend([sub["index"]])
s_mapped.extend([sub["index"]])
if core.OUTPUTFASTSTART:
other_cmd.extend(['-movflags', '+faststart'])
@ -446,7 +477,7 @@ def buildCommands(file, newDir, movieName, bitbucket):
if core.GENERALOPTS:
command.extend(core.GENERALOPTS)
command.extend([ '-i', inputFile])
command.extend(['-i', inputFile])
if core.SEMBED and os.path.isfile(file):
for subfile in get_subs(file):
@ -461,7 +492,7 @@ def buildCommands(file, newDir, movieName, bitbucket):
if not core.ALLOWSUBS or (not s_mapped and not n):
sub_cmd.extend(['-sn'])
else:
else:
if core.SCODEC:
sub_cmd.extend(['-c:s', core.SCODEC])
else:
@ -478,6 +509,7 @@ def buildCommands(file, newDir, movieName, bitbucket):
command = core.NICENESS + command
return command
def get_subs(file):
filepaths = []
subExt = ['.srt', '.sub', '.idx']
@ -486,9 +518,10 @@ def get_subs(file):
for dirname, dirs, filenames in os.walk(dir):
for filename in filenames:
filepaths.extend([os.path.join(dirname, filename)])
subfiles = [ item for item in filepaths if os.path.splitext(item)[1] in subExt and name in item ]
subfiles = [item for item in filepaths if os.path.splitext(item)[1] in subExt and name in item]
return subfiles
def extract_subs(file, newfilePath, bitbucket):
video_details, result = getVideoDetails(file)
if not video_details:
@ -501,34 +534,39 @@ def extract_subs(file, newfilePath, bitbucket):
name = os.path.splitext(os.path.split(newfilePath)[1])[0]
try:
subStreams = [item for item in video_details["streams"] if item["codec_type"] == "subtitle" and item["tags"]["language"] in core.SLANGUAGES and item["codec_name"] != "hdmv_pgs_subtitle" and item["codec_name"] != "pgssub"]
subStreams = [item for item in video_details["streams"] if
item["codec_type"] == "subtitle" and item["tags"]["language"] in core.SLANGUAGES and item[
"codec_name"] != "hdmv_pgs_subtitle" and item["codec_name"] != "pgssub"]
except:
subStreams = [item for item in video_details["streams"] if item["codec_type"] == "subtitle" and item["codec_name"] != "hdmv_pgs_subtitle" and item["codec_name"] != "pgssub"]
subStreams = [item for item in video_details["streams"] if
item["codec_type"] == "subtitle" and item["codec_name"] != "hdmv_pgs_subtitle" and item[
"codec_name"] != "pgssub"]
num = len(subStreams)
for n in range(num):
sub = subStreams[n]
idx = sub["index"]
try:
lan = sub["tags"]["language"]
lan = sub["tags"]["language"]
except:
lan = "unk"
lan = "unk"
if num == 1:
outputFile = os.path.join(subdir, "%s.srt" %(name))
if os.path.isfile(outputFile):
outputFile = os.path.join(subdir, "%s.%s.srt" %(name, n))
outputFile = os.path.join(subdir, "%s.srt" % (name))
if os.path.isfile(outputFile):
outputFile = os.path.join(subdir, "%s.%s.srt" % (name, n))
else:
outputFile = os.path.join(subdir, "%s.%s.srt" %(name, lan))
if os.path.isfile(outputFile):
outputFile = os.path.join(subdir, "%s.%s.%s.srt" %(name, lan, n))
outputFile = os.path.join(subdir, "%s.%s.srt" % (name, lan))
if os.path.isfile(outputFile):
outputFile = os.path.join(subdir, "%s.%s.%s.srt" % (name, lan, n))
command = [core.FFMPEG, '-loglevel', 'warning', '-i', file, '-vn', '-an', '-codec:' + str(idx), 'srt', outputFile]
command = [core.FFMPEG, '-loglevel', 'warning', '-i', file, '-vn', '-an', '-codec:' + str(idx), 'srt',
outputFile]
if platform.system() != 'Windows':
command = core.NICENESS + command
logger.info("Extracting %s subtitle from: %s" % (lan, file))
print_cmd(command)
result = 1 # set result to failed in case call fails.
result = 1 # set result to failed in case call fails.
try:
proc = subprocess.Popen(command, stdout=bitbucket, stderr=bitbucket)
proc.communicate()
@ -539,11 +577,13 @@ def extract_subs(file, newfilePath, bitbucket):
if result == 0:
try:
shutil.copymode(file, outputFile)
except: pass
except:
pass
logger.info("Extracting %s subtitle from %s has succeeded" % (lan, file))
else:
logger.error("Extracting subtitles has failed")
def processList(List, newDir, bitbucket):
remList = []
newList = []
@ -562,7 +602,7 @@ def processList(List, newDir, bitbucket):
logger.debug("Found VIDEO_TS image file: %s" % (item), "TRANSCODER")
if not vtsPath:
try:
vtsPath = re.match("(.+VIDEO_TS)",item).groups()[0]
vtsPath = re.match("(.+VIDEO_TS)", item).groups()[0]
except:
vtsPath = os.path.split(item)[0]
remList.append(item)
@ -571,7 +611,8 @@ def processList(List, newDir, bitbucket):
elif core.CONCAT and re.match(".+[cC][dD][0-9].", item):
remList.append(item)
combine.append(item)
else: continue
else:
continue
if vtsPath:
newList.extend(combineVTS(vtsPath))
if combine:
@ -589,7 +630,8 @@ def processList(List, newDir, bitbucket):
newList = []
remList = []
logger.error("Failed extracting .vob files from disk image. Stopping transcoding.", "TRANSCODER")
return List, remList, newList, success
return List, remList, newList, success
def ripISO(item, newDir, bitbucket):
newFiles = []
@ -606,13 +648,14 @@ def ripISO(item, newDir, bitbucket):
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=bitbucket)
out, err = proc.communicate()
result = proc.returncode
fileList = [ re.match(".+(VIDEO_TS[\\\/]VTS_[0-9][0-9]_[0-9].[Vv][Oo][Bb])", line).groups()[0] for line in out.splitlines() if re.match(".+VIDEO_TS[\\\/]VTS_[0-9][0-9]_[0-9].[Vv][Oo][Bb]", line) ]
fileList = [re.match(".+(VIDEO_TS[\\\/]VTS_[0-9][0-9]_[0-9].[Vv][Oo][Bb])", line).groups()[0] for line in
out.splitlines() if re.match(".+VIDEO_TS[\\\/]VTS_[0-9][0-9]_[0-9].[Vv][Oo][Bb]", line)]
combined = []
for n in range(99):
concat = []
m = 1
while True:
vtsName = 'VIDEO_TS%sVTS_%02d_%d.VOB' % (os.sep, n+1, m)
vtsName = 'VIDEO_TS%sVTS_%02d_%d.VOB' % (os.sep, n + 1, m)
if vtsName in fileList:
concat.append(vtsName)
m += 1
@ -623,11 +666,11 @@ def ripISO(item, newDir, bitbucket):
if core.CONCAT:
combined.extend(concat)
continue
name = '%s.cd%s' % (os.path.splitext(os.path.split(item)[1])[0] ,str(n+1))
newFiles.append({item: {'name': name , 'files': concat}})
name = '%s.cd%s' % (os.path.splitext(os.path.split(item)[1])[0], str(n + 1))
newFiles.append({item: {'name': name, 'files': concat}})
if core.CONCAT:
name = os.path.splitext(os.path.split(item)[1])[0]
newFiles.append({item: {'name': name , 'files': combined}})
newFiles.append({item: {'name': name, 'files': combined}})
if not newFiles:
logger.error("No VIDEO_TS folder found in image file %s" % (item), "TRANSCODER")
newFiles = [failure_dir]
@ -636,6 +679,7 @@ def ripISO(item, newDir, bitbucket):
newFiles = [failure_dir]
return newFiles
def combineVTS(vtsPath):
newFiles = []
combined = ''
@ -643,7 +687,7 @@ def combineVTS(vtsPath):
concat = ''
m = 1
while True:
vtsName = 'VTS_%02d_%d.VOB' % (n+1, m)
vtsName = 'VTS_%02d_%d.VOB' % (n + 1, m)
if os.path.isfile(os.path.join(vtsPath, vtsName)):
concat = concat + os.path.join(vtsPath, vtsName) + '|'
m += 1
@ -659,12 +703,14 @@ def combineVTS(vtsPath):
newFiles.append('concat:%s' % combined[:-1])
return newFiles
def combineCD(combine):
newFiles = []
for item in set([ re.match("(.+)[cC][dD][0-9].",item).groups()[0] for item in combine ]):
for item in set([re.match("(.+)[cC][dD][0-9].", item).groups()[0] for item in combine]):
concat = ''
for n in range(99):
files = [ file for file in combine if n+1 == int(re.match(".+[cC][dD]([0-9]+).",file).groups()[0]) and item in file ]
files = [file for file in combine if
n + 1 == int(re.match(".+[cC][dD]([0-9]+).", file).groups()[0]) and item in file]
if files:
concat = concat + files[0] + '|'
else:
@ -673,17 +719,19 @@ def combineCD(combine):
newFiles.append('concat:%s' % concat[:-1])
return newFiles
def print_cmd(command):
cmd = ""
for item in command:
cmd = cmd + " " + str(item)
logger.debug("calling command:%s" % (cmd))
def Transcode_directory(dirName):
if not core.FFMPEG:
return 1, dirName
logger.info("Checking for files to be transcoded")
final_result = 0 # initialize as successful
final_result = 0 # initialize as successful
if core.OUTPUTVIDEOPATH:
newDir = core.OUTPUTVIDEOPATH
makeDir(newDir)
@ -713,17 +761,17 @@ def Transcode_directory(dirName):
if core.SEXTRACT and isinstance(file, str):
extract_subs(file, newfilePath, bitbucket)
try: # Try to remove the file that we're transcoding to just in case. (ffmpeg will return an error if it already exists for some reason)
try: # Try to remove the file that we're transcoding to just in case. (ffmpeg will return an error if it already exists for some reason)
os.remove(newfilePath)
except OSError, e:
if e.errno != errno.ENOENT: # Ignore the error if it's just telling us that the file doesn't exist
if e.errno != errno.ENOENT: # Ignore the error if it's just telling us that the file doesn't exist
logger.debug("Error when removing transcoding target: %s" % (e))
except Exception, e:
logger.debug("Error when removing transcoding target: %s" % (e))
logger.info("Transcoding video: %s" % (newfilePath))
print_cmd(command)
result = 1 # set result to failed in case call fails.
result = 1 # set result to failed in case call fails.
try:
if isinstance(file, str):
proc = subprocess.Popen(command, stdout=bitbucket, stderr=bitbucket)
@ -752,12 +800,14 @@ def Transcode_directory(dirName):
if result == 0:
try:
shutil.copymode(file, newfilePath)
except: pass
except:
pass
logger.info("Transcoding of video to %s succeeded" % (newfilePath))
if os.path.isfile(newfilePath) and (file in newList or not core.DUPLICATE):
try:
os.unlink(file)
except: pass
except:
pass
else:
logger.error("Transcoding of video to %s failed with result %s" % (newfilePath, str(result)))
# this will be 0 (successful) it all are successful, else will return a positive integer for failure.
@ -766,8 +816,9 @@ def Transcode_directory(dirName):
for file in remList:
try:
os.unlink(file)
except: pass
if not os.listdir(newDir): #this is an empty directory and we didn't transcode into it.
except:
pass
if not os.listdir(newDir): # this is an empty directory and we didn't transcode into it.
os.rmdir(newDir)
newDir = dirName
if not core.PROCESSOUTPUT and core.DUPLICATE: # We postprocess the original files to CP/SB