From 8d7ffc5c81eeebbbe4d09d8337b2b93718789961 Mon Sep 17 00:00:00 2001 From: Gavin Hurlbut Date: Sun, 7 Jul 2019 13:15:44 -0700 Subject: [PATCH 1/4] Handle filenames with spaces in them --- MediaInfo.py | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/MediaInfo.py b/MediaInfo.py index b11ba3d..b74ab0a 100644 --- a/MediaInfo.py +++ b/MediaInfo.py @@ -41,12 +41,14 @@ 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') @@ -102,26 +104,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) From 419d987854c803f3be4097104bd645c56e1557f4 Mon Sep 17 00:00:00 2001 From: Gavin Hurlbut Date: Sun, 7 Jul 2019 17:51:38 -0700 Subject: [PATCH 2/4] Give access to the raw JSON from ffprobe --- MediaInfo.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MediaInfo.py b/MediaInfo.py index b74ab0a..41c037f 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 = '' @@ -60,6 +61,7 @@ def _ffmpegGetInfoJson(self, sourceString) : try : infoDict = json.loads(sourceString) + self.infoDict = infoDict except json.JSONDecodeError as err : return mediaInfo From 38e170052408094ee853e4ef4e8f5edab87134b0 Mon Sep 17 00:00:00 2001 From: Gavin Hurlbut Date: Thu, 1 Aug 2019 22:27:44 -0700 Subject: [PATCH 3/4] Add for Codec ID/Hint, Codec ID in Audio --- MediaInfo.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/MediaInfo.py b/MediaInfo.py index 41c037f..7f3553e 100644 --- a/MediaInfo.py +++ b/MediaInfo.py @@ -173,7 +173,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 : From 9ac47bb96d2c56fc60d377dabdc9921bcabafa34 Mon Sep 17 00:00:00 2001 From: Gavin Hurlbut Date: Fri, 2 Aug 2019 00:43:30 -0700 Subject: [PATCH 4/4] Counting frames is too damned slow right now. --- MediaInfo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MediaInfo.py b/MediaInfo.py index 7f3553e..1cba98b 100644 --- a/MediaInfo.py +++ b/MediaInfo.py @@ -44,7 +44,8 @@ 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] + #"-count_frames", + "-i", self.filename] outputBytes = '' try :