Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions MediaInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def __init__(self, **kwargs) :
self.filename = kwargs.get('filename')
self.cmd = kwargs.get('cmd')
self.info = dict()
self.infoDict = dict()

if self.filename == None :
self.filename = ''
Expand Down Expand Up @@ -41,12 +42,15 @@ def getInfo(self) :


def _ffmpegGetInfo(self) :
cmd = self.cmd + ' -loglevel quiet -print_format json -show_format -show_streams -show_error -count_frames -i ' + self.filename
cmd = [self.cmd, "-loglevel", "quiet", "-print_format", "json",
"-show_format", "-show_streams", "-show_error",
#"-count_frames",
"-i", self.filename]
outputBytes = ''

try :
outputBytes = subprocess.check_output(cmd, shell = True)
except subprocess.CalledProcessError as e :
outputBytes = subprocess.check_output(cmd, shell=False)
except subprocess.CalledProcessError as e:
return ''

outputText = outputBytes.decode('utf-8')
Expand All @@ -58,6 +62,7 @@ def _ffmpegGetInfoJson(self, sourceString) :

try :
infoDict = json.loads(sourceString)
self.infoDict = infoDict
except json.JSONDecodeError as err :
return mediaInfo

Expand Down Expand Up @@ -102,26 +107,14 @@ def _ffmpegGetInfoJson(self, sourceString) :
return mediaInfo

def _mediainfoGetInfo(self) :
prevPath = os.getcwd()
newPath = os.path.abspath(os.path.dirname(self.filename))
file = os.path.basename(self.filename)

cmd = self.cmd + ' -f ' + file
outputBytes = ''
file_ = os.path.abspath(self.filename)
cmd = [self.cmd, "-f", file_]

try :
os.chdir(newPath)
try :
outputBytes = subprocess.check_output(cmd, shell = True)
except subprocess.CalledProcessError as e :
return ''

outputBytes = subprocess.check_output(cmd, shell=False)
outputText = outputBytes.decode('utf-8')
except IOError :
os.chdir(prevPath)
except Exception:
return ''
finally:
os.chdir(prevPath)

self.info = self._mediainfoGetInfoRegex(outputText)

Expand Down Expand Up @@ -181,7 +174,14 @@ def _mediainfoGetInfoRegex(self, sourceString) :
mediaInfo['haveAudio'] = 1
audioInfo = audio.group(0)

tmpAudioCodec = re.search("Codec\s*:\s*([\w\_\-\\\/ ]+)\n", audioInfo, re.S)
tmpAudioCodec = re.search("Codec ID/Hint\s*:\s*([\w\_\-\\\/ ]+)\n", audioInfo, re.S)

if not tmpAudioCodec:
tmpAudioCodec = re.search("Codec ID\s*:\s*([\w\_\-\\\/ ]+)\n", audioInfo, re.S)

if not tmpAudioCodec:
tmpAudioCodec = re.search("Codec\s*:\s*([\w\_\-\\\/ ]+)\n", audioInfo, re.S)

audioCodec = re.search("\w+", tmpAudioCodec.group(1), re.S)
audioCodecProfile = re.search("Codec profile\s*:\s*([\w\_\-\\\/\@\. ]+)\n", audioInfo, re.S)
if audioCodecProfile is None :
Expand Down