diff --git a/MediaInfo.py b/MediaInfo.py index b11ba3d..1cba98b 100644 --- a/MediaInfo.py +++ b/MediaInfo.py @@ -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 = '' @@ -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') @@ -58,6 +62,7 @@ def _ffmpegGetInfoJson(self, sourceString) : try : infoDict = json.loads(sourceString) + self.infoDict = infoDict except json.JSONDecodeError as err : return mediaInfo @@ -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) @@ -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 :