mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-07-06 05:01:10 -07:00
PEP8 Variable in function should be lowercase
This commit is contained in:
parent
39f8949ede
commit
97e1ed71b3
15 changed files with 977 additions and 953 deletions
|
@ -17,10 +17,10 @@ from core.nzbToMediaUtil import makeDir
|
|||
|
||||
|
||||
def isVideoGood(videofile, status):
|
||||
fileNameExt = os.path.basename(videofile)
|
||||
fileName, fileExt = os.path.splitext(fileNameExt)
|
||||
file_name_ext = os.path.basename(videofile)
|
||||
file_name, file_ext = os.path.splitext(file_name_ext)
|
||||
disable = False
|
||||
if fileExt not in core.MEDIACONTAINER or not core.FFPROBE or not core.CHECK_MEDIA or fileExt in ['.iso'] or (status > 0 and core.NOEXTRACTFAILED):
|
||||
if file_ext not in core.MEDIACONTAINER or not core.FFPROBE or not core.CHECK_MEDIA or file_ext in ['.iso'] or (status > 0 and core.NOEXTRACTFAILED):
|
||||
disable = True
|
||||
else:
|
||||
test_details, res = getVideoDetails(core.TEST_FILE)
|
||||
|
@ -28,9 +28,9 @@ def isVideoGood(videofile, status):
|
|||
disable = True
|
||||
logger.info("DISABLED: ffprobe failed to analyse test file. Stopping corruption check.", 'TRANSCODER')
|
||||
if test_details.get("streams"):
|
||||
vidStreams = [item for item in test_details["streams"] if "codec_type" in item and item["codec_type"] == "video"]
|
||||
audStreams = [item for item in test_details["streams"] if "codec_type" in item and item["codec_type"] == "audio"]
|
||||
if not (len(vidStreams) > 0 and len(audStreams) > 0):
|
||||
vid_streams = [item for item in test_details["streams"] if "codec_type" in item and item["codec_type"] == "video"]
|
||||
aud_streams = [item for item in test_details["streams"] if "codec_type" in item and item["codec_type"] == "audio"]
|
||||
if not (len(vid_streams) > 0 and len(aud_streams) > 0):
|
||||
disable = True
|
||||
logger.info("DISABLED: ffprobe failed to analyse streams from test file. Stopping corruption check.",
|
||||
'TRANSCODER')
|
||||
|
@ -40,25 +40,25 @@ def isVideoGood(videofile, status):
|
|||
else:
|
||||
return True
|
||||
|
||||
logger.info('Checking [{0}] for corruption, please stand by ...'.format(fileNameExt), 'TRANSCODER')
|
||||
logger.info('Checking [{0}] for corruption, please stand by ...'.format(file_name_ext), 'TRANSCODER')
|
||||
video_details, result = getVideoDetails(videofile)
|
||||
|
||||
if result != 0:
|
||||
logger.error("FAILED: [{0}] is corrupted!".format(fileNameExt), 'TRANSCODER')
|
||||
logger.error("FAILED: [{0}] is corrupted!".format(file_name_ext), 'TRANSCODER')
|
||||
return False
|
||||
if video_details.get("error"):
|
||||
logger.info("FAILED: [{0}] returned error [{1}].".format(fileNameExt, video_details.get("error")), 'TRANSCODER')
|
||||
logger.info("FAILED: [{0}] returned error [{1}].".format(file_name_ext, video_details.get("error")), 'TRANSCODER')
|
||||
return False
|
||||
if video_details.get("streams"):
|
||||
videoStreams = [item for item in video_details["streams"] if item["codec_type"] == "video"]
|
||||
audioStreams = [item for item in video_details["streams"] if item["codec_type"] == "audio"]
|
||||
if len(videoStreams) > 0 and len(audioStreams) > 0:
|
||||
logger.info("SUCCESS: [{0}] has no corruption.".format(fileNameExt), 'TRANSCODER')
|
||||
video_streams = [item for item in video_details["streams"] if item["codec_type"] == "video"]
|
||||
audio_streams = [item for item in video_details["streams"] if item["codec_type"] == "audio"]
|
||||
if len(video_streams) > 0 and len(audio_streams) > 0:
|
||||
logger.info("SUCCESS: [{0}] has no corruption.".format(file_name_ext), 'TRANSCODER')
|
||||
return True
|
||||
else:
|
||||
logger.info("FAILED: [{0}] has {1} video streams and {2} audio streams. "
|
||||
"Assume corruption.".format
|
||||
(fileNameExt, len(videoStreams), len(audioStreams)), 'TRANSCODER')
|
||||
(file_name_ext, len(video_streams), len(audio_streams)), 'TRANSCODER')
|
||||
return False
|
||||
|
||||
|
||||
|
@ -118,7 +118,7 @@ def getVideoDetails(videofile, img=None, bitbucket=None):
|
|||
|
||||
def buildCommands(file, newDir, movieName, bitbucket):
|
||||
if isinstance(file, string_types):
|
||||
inputFile = file
|
||||
input_file = file
|
||||
if 'concat:' in file:
|
||||
file = file.split('|')[0].replace('concat:', '')
|
||||
video_details, result = getVideoDetails(file)
|
||||
|
@ -137,10 +137,10 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
|||
img, data = next(iteritems(file))
|
||||
name = data['name']
|
||||
video_details, result = getVideoDetails(data['files'][0], img, bitbucket)
|
||||
inputFile = '-'
|
||||
input_file = '-'
|
||||
file = '-'
|
||||
|
||||
newfilePath = os.path.normpath(os.path.join(newDir, name) + core.VEXTENSION)
|
||||
newfile_path = os.path.normpath(os.path.join(newDir, name) + core.VEXTENSION)
|
||||
|
||||
map_cmd = []
|
||||
video_cmd = []
|
||||
|
@ -152,9 +152,9 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
|||
|
||||
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 = []
|
||||
video_streams = []
|
||||
audio_streams = []
|
||||
sub_streams = []
|
||||
|
||||
map_cmd.extend(['-map', '0'])
|
||||
if core.VCODEC:
|
||||
|
@ -201,15 +201,15 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
|||
other_cmd.extend(['-movflags', '+faststart'])
|
||||
|
||||
else:
|
||||
videoStreams = [item for item in video_details["streams"] if item["codec_type"] == "video"]
|
||||
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"]
|
||||
video_streams = [item for item in video_details["streams"] if item["codec_type"] == "video"]
|
||||
audio_streams = [item for item in video_details["streams"] if item["codec_type"] == "audio"]
|
||||
sub_streams = [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
|
||||
sub_streams = [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:
|
||||
for video in video_streams:
|
||||
codec = video["codec_name"]
|
||||
fr = video.get("avg_frame_rate", 0)
|
||||
width = video.get("width", 0)
|
||||
|
@ -257,24 +257,24 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
|||
used_audio = 0
|
||||
a_mapped = []
|
||||
commentary = []
|
||||
if audioStreams:
|
||||
for i, val in reversed(list(enumerate(audioStreams))):
|
||||
if audio_streams:
|
||||
for i, val in reversed(list(enumerate(audio_streams))):
|
||||
try:
|
||||
if "Commentary" in val.get("tags").get("title"): # Split out commentry tracks.
|
||||
commentary.append(val)
|
||||
del audioStreams[i]
|
||||
del audio_streams[i]
|
||||
except:
|
||||
continue
|
||||
try:
|
||||
audio1 = [item for item in audioStreams if item["tags"]["language"] == core.ALANGUAGE]
|
||||
audio1 = [item for item in audio_streams if item["tags"]["language"] == core.ALANGUAGE]
|
||||
except: # no language tags. Assume only 1 language.
|
||||
audio1 = audioStreams
|
||||
audio1 = audio_streams
|
||||
try:
|
||||
audio2 = [item for item in audio1 if item["codec_name"] in core.ACODEC_ALLOW]
|
||||
except:
|
||||
audio2 = []
|
||||
try:
|
||||
audio3 = [item for item in audioStreams if item["tags"]["language"] != core.ALANGUAGE]
|
||||
audio3 = [item for item in audio_streams if item["tags"]["language"] != core.ALANGUAGE]
|
||||
except:
|
||||
audio3 = []
|
||||
try:
|
||||
|
@ -384,8 +384,8 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
|||
audio_cmd.extend(audio_cmd2)
|
||||
|
||||
if core.AINCLUDE and core.ACODEC3:
|
||||
audioStreams.extend(commentary) #add commentry tracks back here.
|
||||
for audio in audioStreams:
|
||||
audio_streams.extend(commentary) #add commentry tracks back here.
|
||||
for audio in audio_streams:
|
||||
if audio["index"] in a_mapped:
|
||||
continue
|
||||
used_audio += 1
|
||||
|
@ -422,7 +422,7 @@ 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]
|
||||
subs1 = [item for item in sub_streams if item["tags"]["language"] == lan]
|
||||
except:
|
||||
subs1 = []
|
||||
if core.BURN and not subs1 and not burnt and os.path.isfile(file):
|
||||
|
@ -431,13 +431,13 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
|||
video_cmd.extend(['-vf', 'subtitles={subs}'.format(subs=subfile)])
|
||||
burnt = 1
|
||||
for sub in subs1:
|
||||
if core.BURN and not burnt and os.path.isfile(inputFile):
|
||||
if core.BURN and not burnt and os.path.isfile(input_file):
|
||||
subloc = 0
|
||||
for index in range(len(subStreams)):
|
||||
if subStreams[index]["index"] == sub["index"]:
|
||||
for index in range(len(sub_streams)):
|
||||
if sub_streams[index]["index"] == sub["index"]:
|
||||
subloc = index
|
||||
break
|
||||
video_cmd.extend(['-vf', 'subtitles={sub}:si={loc}'.format(sub=inputFile, loc=subloc)])
|
||||
video_cmd.extend(['-vf', 'subtitles={sub}:si={loc}'.format(sub=input_file, loc=subloc)])
|
||||
burnt = 1
|
||||
if not core.ALLOWSUBS:
|
||||
break
|
||||
|
@ -447,7 +447,7 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
|||
s_mapped.extend([sub["index"]])
|
||||
|
||||
if core.SINCLUDE:
|
||||
for sub in subStreams:
|
||||
for sub in sub_streams:
|
||||
if not core.ALLOWSUBS:
|
||||
break
|
||||
if sub["index"] in s_mapped:
|
||||
|
@ -467,7 +467,7 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
|||
if core.GENERALOPTS:
|
||||
command.extend(core.GENERALOPTS)
|
||||
|
||||
command.extend(['-i', inputFile])
|
||||
command.extend(['-i', input_file])
|
||||
|
||||
if core.SEMBED and os.path.isfile(file):
|
||||
for subfile in get_subs(file):
|
||||
|
@ -509,7 +509,7 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
|||
command.extend(sub_cmd)
|
||||
command.extend(meta_cmd)
|
||||
command.extend(other_cmd)
|
||||
command.append(newfilePath)
|
||||
command.append(newfile_path)
|
||||
if platform.system() != 'Windows':
|
||||
command = core.NICENESS + command
|
||||
return command
|
||||
|
@ -517,13 +517,13 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
|||
|
||||
def get_subs(file):
|
||||
filepaths = []
|
||||
subExt = ['.srt', '.sub', '.idx']
|
||||
sub_ext = ['.srt', '.sub', '.idx']
|
||||
name = os.path.splitext(os.path.split(file)[1])[0]
|
||||
dir = os.path.split(file)[0]
|
||||
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 sub_ext and name in item]
|
||||
return subfiles
|
||||
|
||||
|
||||
|
@ -539,30 +539,30 @@ 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
|
||||
sub_streams = [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
|
||||
sub_streams = [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)
|
||||
num = len(sub_streams)
|
||||
for n in range(num):
|
||||
sub = subStreams[n]
|
||||
sub = sub_streams[n]
|
||||
idx = sub["index"]
|
||||
lan = sub.get("tags", {}).get("language", "unk")
|
||||
|
||||
if num == 1:
|
||||
outputFile = os.path.join(subdir, "{0}.srt".format(name))
|
||||
if os.path.isfile(outputFile):
|
||||
outputFile = os.path.join(subdir, "{0}.{1}.srt".format(name, n))
|
||||
output_file = os.path.join(subdir, "{0}.srt".format(name))
|
||||
if os.path.isfile(output_file):
|
||||
output_file = os.path.join(subdir, "{0}.{1}.srt".format(name, n))
|
||||
else:
|
||||
outputFile = os.path.join(subdir, "{0}.{1}.srt".format(name, lan))
|
||||
if os.path.isfile(outputFile):
|
||||
outputFile = os.path.join(subdir, "{0}.{1}.{2}.srt".format(name, lan, n))
|
||||
output_file = os.path.join(subdir, "{0}.{1}.srt".format(name, lan))
|
||||
if os.path.isfile(output_file):
|
||||
output_file = os.path.join(subdir, "{0}.{1}.{2}.srt".format(name, lan, n))
|
||||
|
||||
command = [core.FFMPEG, '-loglevel', 'warning', '-i', file, '-vn', '-an',
|
||||
'-codec:{index}'.format(index=idx), 'srt', outputFile]
|
||||
'-codec:{index}'.format(index=idx), 'srt', output_file]
|
||||
if platform.system() != 'Windows':
|
||||
command = core.NICENESS + command
|
||||
|
||||
|
@ -578,7 +578,7 @@ def extract_subs(file, newfilePath, bitbucket):
|
|||
|
||||
if result == 0:
|
||||
try:
|
||||
shutil.copymode(file, outputFile)
|
||||
shutil.copymode(file, output_file)
|
||||
except:
|
||||
pass
|
||||
logger.info("Extracting {0} subtitle from {1} has succeeded".format(lan, file))
|
||||
|
@ -587,76 +587,76 @@ def extract_subs(file, newfilePath, bitbucket):
|
|||
|
||||
|
||||
def processList(List, newDir, bitbucket):
|
||||
remList = []
|
||||
newList = []
|
||||
rem_list = []
|
||||
new_list = []
|
||||
combine = []
|
||||
vtsPath = None
|
||||
vts_path = None
|
||||
success = True
|
||||
for item in List:
|
||||
ext = os.path.splitext(item)[1].lower()
|
||||
if ext in ['.iso', '.bin', '.img'] and ext not in core.IGNOREEXTENSIONS:
|
||||
logger.debug("Attempting to rip disk image: {0}".format(item), "TRANSCODER")
|
||||
newList.extend(ripISO(item, newDir, bitbucket))
|
||||
remList.append(item)
|
||||
new_list.extend(ripISO(item, newDir, bitbucket))
|
||||
rem_list.append(item)
|
||||
elif re.match(".+VTS_[0-9][0-9]_[0-9].[Vv][Oo][Bb]", item) and '.vob' not in core.IGNOREEXTENSIONS:
|
||||
logger.debug("Found VIDEO_TS image file: {0}".format(item), "TRANSCODER")
|
||||
if not vtsPath:
|
||||
if not vts_path:
|
||||
try:
|
||||
vtsPath = re.match("(.+VIDEO_TS)", item).groups()[0]
|
||||
vts_path = re.match("(.+VIDEO_TS)", item).groups()[0]
|
||||
except:
|
||||
vtsPath = os.path.split(item)[0]
|
||||
remList.append(item)
|
||||
vts_path = os.path.split(item)[0]
|
||||
rem_list.append(item)
|
||||
elif re.match(".+VIDEO_TS.", item) or re.match(".+VTS_[0-9][0-9]_[0-9].", item):
|
||||
remList.append(item)
|
||||
rem_list.append(item)
|
||||
elif core.CONCAT and re.match(".+[cC][dD][0-9].", item):
|
||||
remList.append(item)
|
||||
rem_list.append(item)
|
||||
combine.append(item)
|
||||
else:
|
||||
continue
|
||||
if vtsPath:
|
||||
newList.extend(combineVTS(vtsPath))
|
||||
if vts_path:
|
||||
new_list.extend(combineVTS(vts_path))
|
||||
if combine:
|
||||
newList.extend(combineCD(combine))
|
||||
for file in newList:
|
||||
new_list.extend(combineCD(combine))
|
||||
for file in new_list:
|
||||
if isinstance(file, string_types) and 'concat:' not in file and not os.path.isfile(file):
|
||||
success = False
|
||||
break
|
||||
if success and newList:
|
||||
List.extend(newList)
|
||||
for item in remList:
|
||||
if success and new_list:
|
||||
List.extend(new_list)
|
||||
for item in rem_list:
|
||||
List.remove(item)
|
||||
logger.debug("Successfully extracted .vob file {0} from disk image".format(newList[0]), "TRANSCODER")
|
||||
elif newList and not success:
|
||||
newList = []
|
||||
remList = []
|
||||
logger.debug("Successfully extracted .vob file {0} from disk image".format(new_list[0]), "TRANSCODER")
|
||||
elif new_list and not success:
|
||||
new_list = []
|
||||
rem_list = []
|
||||
logger.error("Failed extracting .vob files from disk image. Stopping transcoding.", "TRANSCODER")
|
||||
return List, remList, newList, success
|
||||
return List, rem_list, new_list, success
|
||||
|
||||
|
||||
def ripISO(item, newDir, bitbucket):
|
||||
newFiles = []
|
||||
new_files = []
|
||||
failure_dir = 'failure'
|
||||
# Mount the ISO in your OS and call combineVTS.
|
||||
if not core.SEVENZIP:
|
||||
logger.error("No 7zip installed. Can't extract image file {0}".format(item), "TRANSCODER")
|
||||
newFiles = [failure_dir]
|
||||
return newFiles
|
||||
new_files = [failure_dir]
|
||||
return new_files
|
||||
cmd = [core.SEVENZIP, 'l', item]
|
||||
try:
|
||||
logger.debug("Attempting to extract .vob from image file {0}".format(item), "TRANSCODER")
|
||||
print_cmd(cmd)
|
||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=bitbucket)
|
||||
out, err = proc.communicate()
|
||||
fileList = [re.match(".+(VIDEO_TS[\\\/]VTS_[0-9][0-9]_[0-9].[Vv][Oo][Bb])", line).groups()[0] for line in
|
||||
file_list = [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{0}VTS_{1:02d}_{2:d}.VOB'.format(os.sep, n + 1, m)
|
||||
if vtsName in fileList:
|
||||
concat.append(vtsName)
|
||||
vts_name = 'VIDEO_TS{0}VTS_{1:02d}_{2:d}.VOB'.format(os.sep, n + 1, m)
|
||||
if vts_name in file_list:
|
||||
concat.append(vts_name)
|
||||
m += 1
|
||||
else:
|
||||
break
|
||||
|
@ -668,29 +668,29 @@ def ripISO(item, newDir, bitbucket):
|
|||
name = '{name}.cd{x}'.format(
|
||||
name=os.path.splitext(os.path.split(item)[1])[0], x=n + 1
|
||||
)
|
||||
newFiles.append({item: {'name': name, 'files': concat}})
|
||||
new_files.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}})
|
||||
if not newFiles:
|
||||
new_files.append({item: {'name': name, 'files': combined}})
|
||||
if not new_files:
|
||||
logger.error("No VIDEO_TS folder found in image file {0}".format(item), "TRANSCODER")
|
||||
newFiles = [failure_dir]
|
||||
new_files = [failure_dir]
|
||||
except:
|
||||
logger.error("Failed to extract from image file {0}".format(item), "TRANSCODER")
|
||||
newFiles = [failure_dir]
|
||||
return newFiles
|
||||
new_files = [failure_dir]
|
||||
return new_files
|
||||
|
||||
|
||||
def combineVTS(vtsPath):
|
||||
newFiles = []
|
||||
new_files = []
|
||||
combined = ''
|
||||
for n in range(99):
|
||||
concat = ''
|
||||
m = 1
|
||||
while True:
|
||||
vtsName = 'VTS_{0:02d}_{1:d}.VOB'.format(n + 1, m)
|
||||
if os.path.isfile(os.path.join(vtsPath, vtsName)):
|
||||
concat += '{file}|'.format(file=os.path.join(vtsPath, vtsName))
|
||||
vts_name = 'VTS_{0:02d}_{1:d}.VOB'.format(n + 1, m)
|
||||
if os.path.isfile(os.path.join(vtsPath, vts_name)):
|
||||
concat += '{file}|'.format(file=os.path.join(vtsPath, vts_name))
|
||||
m += 1
|
||||
else:
|
||||
break
|
||||
|
@ -699,14 +699,14 @@ def combineVTS(vtsPath):
|
|||
if core.CONCAT:
|
||||
combined += '{files}|'.format(files=concat)
|
||||
continue
|
||||
newFiles.append('concat:{0}'.format(concat[:-1]))
|
||||
new_files.append('concat:{0}'.format(concat[:-1]))
|
||||
if core.CONCAT:
|
||||
newFiles.append('concat:{0}'.format(combined[:-1]))
|
||||
return newFiles
|
||||
new_files.append('concat:{0}'.format(combined[:-1]))
|
||||
return new_files
|
||||
|
||||
|
||||
def combineCD(combine):
|
||||
newFiles = []
|
||||
new_files = []
|
||||
for item in set([re.match("(.+)[cC][dD][0-9].", item).groups()[0] for item in combine]):
|
||||
concat = ''
|
||||
for n in range(99):
|
||||
|
@ -717,8 +717,8 @@ def combineCD(combine):
|
|||
else:
|
||||
break
|
||||
if concat:
|
||||
newFiles.append('concat:{0}'.format(concat[:-1]))
|
||||
return newFiles
|
||||
new_files.append('concat:{0}'.format(concat[:-1]))
|
||||
return new_files
|
||||
|
||||
|
||||
def print_cmd(command):
|
||||
|
@ -734,43 +734,43 @@ def Transcode_directory(dirName):
|
|||
logger.info("Checking for files to be transcoded")
|
||||
final_result = 0 # initialize as successful
|
||||
if core.OUTPUTVIDEOPATH:
|
||||
newDir = core.OUTPUTVIDEOPATH
|
||||
makeDir(newDir)
|
||||
new_dir = core.OUTPUTVIDEOPATH
|
||||
makeDir(new_dir)
|
||||
name = os.path.splitext(os.path.split(dirName)[1])[0]
|
||||
newDir = os.path.join(newDir, name)
|
||||
makeDir(newDir)
|
||||
new_dir = os.path.join(new_dir, name)
|
||||
makeDir(new_dir)
|
||||
else:
|
||||
newDir = dirName
|
||||
new_dir = dirName
|
||||
if platform.system() == 'Windows':
|
||||
bitbucket = open('NUL')
|
||||
else:
|
||||
bitbucket = open('/dev/null')
|
||||
movieName = os.path.splitext(os.path.split(dirName)[1])[0]
|
||||
List = core.listMediaFiles(dirName, media=True, audio=False, meta=False, archives=False)
|
||||
List, remList, newList, success = processList(List, newDir, bitbucket)
|
||||
movie_name = os.path.splitext(os.path.split(dirName)[1])[0]
|
||||
file_list = core.listMediaFiles(dirName, media=True, audio=False, meta=False, archives=False)
|
||||
file_list, rem_list, new_list, success = processList(file_list, new_dir, bitbucket)
|
||||
if not success:
|
||||
bitbucket.close()
|
||||
return 1, dirName
|
||||
|
||||
for file in List:
|
||||
for file in file_list:
|
||||
if isinstance(file, string_types) and os.path.splitext(file)[1] in core.IGNOREEXTENSIONS:
|
||||
continue
|
||||
command = buildCommands(file, newDir, movieName, bitbucket)
|
||||
newfilePath = command[-1]
|
||||
command = buildCommands(file, new_dir, movie_name, bitbucket)
|
||||
newfile_path = command[-1]
|
||||
|
||||
# transcoding files may remove the original file, so make sure to extract subtitles first
|
||||
if core.SEXTRACT and isinstance(file, string_types):
|
||||
extract_subs(file, newfilePath, bitbucket)
|
||||
extract_subs(file, newfile_path, 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)
|
||||
os.remove(newfilePath)
|
||||
os.remove(newfile_path)
|
||||
except OSError as e:
|
||||
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: {0}".format(e))
|
||||
except Exception as e:
|
||||
logger.debug("Error when removing transcoding target: {0}".format(e))
|
||||
|
||||
logger.info("Transcoding video: {0}".format(newfilePath))
|
||||
logger.info("Transcoding video: {0}".format(newfile_path))
|
||||
print_cmd(command)
|
||||
result = 1 # set result to failed in case call fails.
|
||||
try:
|
||||
|
@ -787,42 +787,42 @@ def Transcode_directory(dirName):
|
|||
proc.communicate()
|
||||
result = proc.returncode
|
||||
except:
|
||||
logger.error("Transcoding of video {0} has failed".format(newfilePath))
|
||||
logger.error("Transcoding of video {0} has failed".format(newfile_path))
|
||||
|
||||
if core.SUBSDIR and result == 0 and isinstance(file, string_types):
|
||||
for sub in get_subs(file):
|
||||
name = os.path.splitext(os.path.split(file)[1])[0]
|
||||
subname = os.path.split(sub)[1]
|
||||
newname = os.path.splitext(os.path.split(newfilePath)[1])[0]
|
||||
newname = os.path.splitext(os.path.split(newfile_path)[1])[0]
|
||||
newpath = os.path.join(core.SUBSDIR, subname.replace(name, newname))
|
||||
if not os.path.isfile(newpath):
|
||||
os.rename(sub, newpath)
|
||||
|
||||
if result == 0:
|
||||
try:
|
||||
shutil.copymode(file, newfilePath)
|
||||
shutil.copymode(file, newfile_path)
|
||||
except:
|
||||
pass
|
||||
logger.info("Transcoding of video to {0} succeeded".format(newfilePath))
|
||||
if os.path.isfile(newfilePath) and (file in newList or not core.DUPLICATE):
|
||||
logger.info("Transcoding of video to {0} succeeded".format(newfile_path))
|
||||
if os.path.isfile(newfile_path) and (file in new_list or not core.DUPLICATE):
|
||||
try:
|
||||
os.unlink(file)
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
logger.error("Transcoding of video to {0} failed with result {1}".format(newfilePath, result))
|
||||
logger.error("Transcoding of video to {0} failed with result {1}".format(newfile_path, result))
|
||||
# this will be 0 (successful) it all are successful, else will return a positive integer for failure.
|
||||
final_result = final_result + result
|
||||
if final_result == 0 and not core.DUPLICATE:
|
||||
for file in remList:
|
||||
for file in rem_list:
|
||||
try:
|
||||
os.unlink(file)
|
||||
except:
|
||||
pass
|
||||
if not os.listdir(text_type(newDir)): # this is an empty directory and we didn't transcode into it.
|
||||
os.rmdir(newDir)
|
||||
newDir = dirName
|
||||
if not os.listdir(text_type(new_dir)): # this is an empty directory and we didn't transcode into it.
|
||||
os.rmdir(new_dir)
|
||||
new_dir = dirName
|
||||
if not core.PROCESSOUTPUT and core.DUPLICATE: # We postprocess the original files to CP/SB
|
||||
newDir = dirName
|
||||
new_dir = dirName
|
||||
bitbucket.close()
|
||||
return final_result, newDir
|
||||
return final_result, new_dir
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue