From d235fef3915af3d029404dcf1242c0652a975267 Mon Sep 17 00:00:00 2001 From: timmy61109 <38396747+timmy61109@users.noreply.github.com> Date: Tue, 24 Dec 2019 23:58:55 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=8E=A1=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E6=AD=A4=E6=8F=90=E4=BA=A4=E5=B0=87README=E6=AA=94?= =?UTF-8?q?=E8=BD=89=E6=88=90Markdown?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.rst => README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.rst => README.md (100%) diff --git a/README.rst b/README.md similarity index 100% rename from README.rst rename to README.md From 7bafee40482c8f9ce4ebdb8edfdbccc78f6df486 Mon Sep 17 00:00:00 2001 From: timmy61109 <38396747+timmy61109@users.noreply.github.com> Date: Tue, 24 Dec 2019 23:59:35 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=8E=A1=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E6=AD=A4=E6=8F=90=E4=BA=A4=E5=B0=87=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E6=88=90=E7=AC=A6=E5=90=88Markdown=E8=AA=9E=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 03f1e81..bf92a9b 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,23 @@ -| - NAME ==== - - A Python wrapper around the MediaInfo command line utility - - -| +A Python wrapper around the MediaInfo command line utility SYNOPSIS ======== -.. code-block:: - - - from MediaInfo import MediaInfo - - info = Mediainfo(filename = '/media/test.ts') - infoData = info.getInfo() - - info = Mediainfo(filename = '/media/test.ts', cmd = '/usr/bin/ffprobe') - infoData = info.getInfo() +```Python +from MediaInfo import MediaInfo - info = Mediainfo(filename = '/media/test.ts', cmd = '/usr/bin/mediainfo') - infoData = info.getInfo() +info = Mediainfo(filename = '/media/test.ts') +infoData = info.getInfo() +info = Mediainfo(filename = '/media/test.ts', cmd = '/usr/bin/ffprobe') +infoData = info.getInfo() -| +info = Mediainfo(filename = '/media/test.ts', cmd = '/usr/bin/mediainfo') +infoData = info.getInfo() +``` DESCRIPTION =========== - MediaInfo gets information of media through ffprobe by default. Alternatively, ffprobe and mediainfo are also supported in configuration. \ No newline at end of file +MediaInfo gets information of media through ffprobe by default. Alternatively, ffprobe and mediainfo are also supported in configuration. From f7e39c4beb98751ad81f8b01766a1c0f9c96f01a Mon Sep 17 00:00:00 2001 From: timmy61109 <38396747+timmy61109@users.noreply.github.com> Date: Wed, 25 Dec 2019 00:00:56 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=8E=A1=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E6=AD=A4=E6=8F=90=E4=BA=A4=E5=B0=87=E5=88=9D=E6=AD=A5?= =?UTF-8?q?=E9=A2=A8=E6=A0=BC=E5=8C=96=E7=A8=8B=E5=BC=8F=E7=A2=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MediaInfo.py | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/MediaInfo.py b/MediaInfo.py index b11ba3d..50ae65f 100644 --- a/MediaInfo.py +++ b/MediaInfo.py @@ -1,13 +1,20 @@ #!/usr/bin/env python3 - -# author : renpeng -# github : https://github.com/laodifang -# description : media information -# date : 2015-09-24 - -import os, sys, re, subprocess, json - -class MediaInfo : +""" +MediaInfo. + +author : renpeng +github : https://github.com/laodifang +description : media information +date : 2015-09-24 +""" +import os +import sys +import re +import subprocess +import json + + +class MediaInfo: def __init__(self, **kwargs) : self.filename = kwargs.get('filename') self.cmd = kwargs.get('cmd') @@ -22,7 +29,7 @@ def __init__(self, **kwargs) : self.cmd = cmdpath + '/mediainfo' elif os.path.isdir(cmdpath) and 'ffprobe' in os.listdir(cmdpath) : self.cmd = cmdpath + '/ffprobe' - + if self.cmd == None : self.cmd = '' @@ -36,7 +43,7 @@ def getInfo(self) : self._ffmpegGetInfo() elif cmdName == 'mediainfo' : self._mediainfoGetInfo() - + return self.info @@ -90,7 +97,7 @@ def _ffmpegGetInfoJson(self, sourceString) : mediaInfo['videoFrameRate'] = infoDict.get('streams')[videoStreamIndex].get('r_frame_rate') mediaInfo['videoFrameCount'] = infoDict.get('streams')[videoStreamIndex].get('nb_read_frames') - if mediaInfo.get('haveAudio') : + if mediaInfo.get('haveAudio') : mediaInfo['audioCodec'] = infoDict.get('streams')[audioStreamIndex].get('codec_name') mediaInfo['audioCodecProfile'] = infoDict.get('streams')[audioStreamIndex].get('profile') mediaInfo['audioDuration'] = infoDict.get('streams')[audioStreamIndex].get('duration') @@ -127,11 +134,11 @@ def _mediainfoGetInfo(self) : def _mediainfoGetInfoRegex(self, sourceString) : mediaInfo = dict() - + general = re.search("(^General\n.*?\n\n)", sourceString, re.S) if general : generalInfo = general.group(0) - + container = re.search("Format\s*:\s*([\w\_\-\\\/\. ]+)\n", generalInfo, re.S) fileSize = re.search("File size\s*:\s*(\d+)\.?\d*\n", generalInfo, re.S) duration = re.search("Duration\s*:\s*(\d+)\.?\d*\n", generalInfo, re.S) @@ -192,7 +199,7 @@ def _mediainfoGetInfoRegex(self, sourceString) : audioChannel = re.search("Channel\(s\)\s*:\s*(\d+)\n", audioInfo, re.S) samplingRate = re.search("Sampling rate\s*:\s*([\w\_\-\\\/\@\. ]+)\n", audioInfo, re.S) audioSamplingRate = re.search("\d+", samplingRate.group(1), re.S) - + if audioCodec : mediaInfo['audioCodec'] = audioCodec.group(0) if audioCodecProfile : From 33a0f43cffdfe1351d3b06f21ab2eaf01384c892 Mon Sep 17 00:00:00 2001 From: timmy61109 <38396747+timmy61109@users.noreply.github.com> Date: Wed, 25 Dec 2019 00:01:10 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=8E=A1=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E6=AD=A4=E6=8F=90=E4=BA=A4=E5=B0=87=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=BF=BD=E7=95=A5=E5=90=8D=E5=96=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3e2dace --- /dev/null +++ b/.gitignore @@ -0,0 +1,111 @@ +# 不紀錄多媒體的資料,以防Git掛掉 +/MultimediaDatabase/.temp/* +/MultimediaDatabase/.mmdb/* +*.mp4 +*.mp3 +*.vob + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ From dcc5710014e703e849c04c33a2bf9c6a91cc0c44 Mon Sep 17 00:00:00 2001 From: timmy61109 <38396747+timmy61109@users.noreply.github.com> Date: Wed, 25 Dec 2019 15:30:52 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=8E=A1=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E6=AD=A4=E6=8F=90=E4=BA=A4=E5=B0=87=E9=A2=A8=E6=A0=BC?= =?UTF-8?q?=E5=8C=96=E8=AE=8A=E6=95=B8=E3=80=81=E5=87=BD=E5=BC=8F=E8=88=87?= =?UTF-8?q?=E5=B8=83=E6=9E=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MediaInfo.py | 189 +++++++++++++++++++++++++-------------------------- 1 file changed, 94 insertions(+), 95 deletions(-) diff --git a/MediaInfo.py b/MediaInfo.py index 50ae65f..5b59a02 100644 --- a/MediaInfo.py +++ b/MediaInfo.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 """ -MediaInfo. +mediainfo. author : renpeng github : https://github.com/laodifang @@ -8,64 +8,63 @@ date : 2015-09-24 """ import os -import sys import re import subprocess import json class MediaInfo: - def __init__(self, **kwargs) : + def __init__(self, **kwargs): self.filename = kwargs.get('filename') - self.cmd = kwargs.get('cmd') - self.info = dict() + self.cmd = kwargs.get('cmd') + self.info = dict() - if self.filename == None : + if self.filename is None: self.filename = '' - if self.cmd == None : - for cmdpath in os.environ['PATH'].split(':') : - if os.path.isdir(cmdpath) and 'mediainfo' in os.listdir(cmdpath) : + if self.cmd is None: + for cmdpath in os.environ['PATH'].split(':'): + if os.path.isdir(cmdpath) and 'mediainfo' in os.listdir(cmdpath): self.cmd = cmdpath + '/mediainfo' - elif os.path.isdir(cmdpath) and 'ffprobe' in os.listdir(cmdpath) : + elif os.path.isdir(cmdpath) and 'ffprobe' in os.listdir(cmdpath): self.cmd = cmdpath + '/ffprobe' - if self.cmd == None : + if self.cmd is None: self.cmd = '' - def getInfo(self) : - if not os.path.exists(self.filename) or not os.path.exists(self.cmd) : + def getInfo(self): + if not os.path.exists(self.filename) or not os.path.exists(self.cmd): return None cmdName = os.path.basename(self.cmd) - if cmdName == 'ffprobe' : + if cmdName == 'ffprobe': self._ffmpegGetInfo() - elif cmdName == 'mediainfo' : + elif cmdName == 'mediainfo': self._mediainfoGetInfo() return self.info - def _ffmpegGetInfo(self) : - cmd = self.cmd + ' -loglevel quiet -print_format json -show_format -show_streams -show_error -count_frames -i ' + self.filename + def _ffmpegGetInfo(self): + cmd = self.cmd + ' -loglevel quiet -print_format json -show_format -show_streams -show_error -count_frames -i ' + self.filename outputBytes = '' - try : + try: outputBytes = subprocess.check_output(cmd, shell = True) - except subprocess.CalledProcessError as e : + except subprocess.CalledProcessError as e: return '' outputText = outputBytes.decode('utf-8') self.info = self._ffmpegGetInfoJson(outputText) - def _ffmpegGetInfoJson(self, sourceString) : + def _ffmpegGetInfoJson(self, sourceString): mediaInfo = dict() infoDict = dict() - try : + try: infoDict = json.loads(sourceString) - except json.JSONDecodeError as err : + except json.JSONDecodeError as err: return mediaInfo mediaInfo['container'] = infoDict.get('format').get('format_name') @@ -73,58 +72,58 @@ def _ffmpegGetInfoJson(self, sourceString) : mediaInfo['duration'] = infoDict.get('format').get('duration') mediaInfo['bitrate'] = infoDict.get('format').get('bit_rate') - videoStreamIndex = None - audioStreamIndex = None + videostreamindex = None + audiostreamindex = None - for item in infoDict.get('streams') : + for item in infoDict.get('streams'): codec_type = item.get('codec_type') - if codec_type == 'video' : - videoStreamIndex = item.get('index') + if codec_type == 'video': + videostreamindex = item.get('index') mediaInfo['haveVideo'] = 1 - elif codec_type == 'audio' : - audioStreamIndex = item.get('index') + elif codec_type == 'audio': + audiostreamindex = item.get('index') mediaInfo['haveAudio'] = 1 - if mediaInfo.get('haveVideo') : - mediaInfo['videoCodec'] = infoDict.get('streams')[videoStreamIndex].get('codec_name') - mediaInfo['videoCodecProfile'] = infoDict.get('streams')[videoStreamIndex].get('profile') - mediaInfo['videoDuration'] = infoDict.get('streams')[videoStreamIndex].get('duration') - mediaInfo['videoBitrate'] = infoDict.get('streams')[videoStreamIndex].get('bit_rate') - mediaInfo['videoWidth'] = infoDict.get('streams')[videoStreamIndex].get('width') - mediaInfo['videoHeight'] = infoDict.get('streams')[videoStreamIndex].get('height') - mediaInfo['videoAspectRatio'] = infoDict.get('streams')[videoStreamIndex].get('display_aspect_ratio') - mediaInfo['videoFrameRate'] = infoDict.get('streams')[videoStreamIndex].get('r_frame_rate') - mediaInfo['videoFrameCount'] = infoDict.get('streams')[videoStreamIndex].get('nb_read_frames') - - if mediaInfo.get('haveAudio') : - mediaInfo['audioCodec'] = infoDict.get('streams')[audioStreamIndex].get('codec_name') - mediaInfo['audioCodecProfile'] = infoDict.get('streams')[audioStreamIndex].get('profile') - mediaInfo['audioDuration'] = infoDict.get('streams')[audioStreamIndex].get('duration') - mediaInfo['audioBitrate'] = infoDict.get('streams')[audioStreamIndex].get('bit_rate') - mediaInfo['audioChannel'] = infoDict.get('streams')[audioStreamIndex].get('channels') - mediaInfo['audioSamplingRate'] = infoDict.get('streams')[audioStreamIndex].get('sample_rate') - mediaInfo['audioFrameCount'] = infoDict.get('streams')[audioStreamIndex].get('nb_read_frames') + if mediaInfo.get('haveVideo'): + mediaInfo['videoCodec'] = infoDict.get('streams')[videostreamindex].get('codec_name') + mediaInfo['videoCodecProfile'] = infoDict.get('streams')[videostreamindex].get('profile') + mediaInfo['videoDuration'] = infoDict.get('streams')[videostreamindex].get('duration') + mediaInfo['videoBitrate'] = infoDict.get('streams')[videostreamindex].get('bit_rate') + mediaInfo['videoWidth'] = infoDict.get('streams')[videostreamindex].get('width') + mediaInfo['videoHeight'] = infoDict.get('streams')[videostreamindex].get('height') + mediaInfo['videoAspectRatio'] = infoDict.get('streams')[videostreamindex].get('display_aspect_ratio') + mediaInfo['videoFrameRate'] = infoDict.get('streams')[videostreamindex].get('r_frame_rate') + mediaInfo['videoFrameCount'] = infoDict.get('streams')[videostreamindex].get('nb_read_frames') + + if mediaInfo.get('haveAudio'): + mediaInfo['audioCodec'] = infoDict.get('streams')[audiostreamindex].get('codec_name') + mediaInfo['audioCodecProfile'] = infoDict.get('streams')[audiostreamindex].get('profile') + mediaInfo['audioDuration'] = infoDict.get('streams')[audiostreamindex].get('duration') + mediaInfo['audioBitrate'] = infoDict.get('streams')[audiostreamindex].get('bit_rate') + mediaInfo['audioChannel'] = infoDict.get('streams')[audiostreamindex].get('channels') + mediaInfo['audioSamplingRate'] = infoDict.get('streams')[audiostreamindex].get('sample_rate') + mediaInfo['audioFrameCount'] = infoDict.get('streams')[audiostreamindex].get('nb_read_frames') return mediaInfo - def _mediainfoGetInfo(self) : - prevPath = os.getcwd() - newPath = os.path.abspath(os.path.dirname(self.filename)) - file = os.path.basename(self.filename) + 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 + cmd = self.cmd + ' -f ' + file outputBytes = '' - try : + try: os.chdir(newPath) - try : + try: outputBytes = subprocess.check_output(cmd, shell = True) - except subprocess.CalledProcessError as e : + except subprocess.CalledProcessError as e: return '' outputText = outputBytes.decode('utf-8') - except IOError : + except IOError: os.chdir(prevPath) return '' finally: @@ -132,85 +131,85 @@ def _mediainfoGetInfo(self) : self.info = self._mediainfoGetInfoRegex(outputText) - def _mediainfoGetInfoRegex(self, sourceString) : + def _mediainfoGetInfoRegex(self, sourceString): mediaInfo = dict() - general = re.search("(^General\n.*?\n\n)", sourceString, re.S) - if general : + general = re.search("(^General\n.*?\n\n)", sourceString, re.S) + if general: generalInfo = general.group(0) container = re.search("Format\s*:\s*([\w\_\-\\\/\. ]+)\n", generalInfo, re.S) - fileSize = re.search("File size\s*:\s*(\d+)\.?\d*\n", generalInfo, re.S) - duration = re.search("Duration\s*:\s*(\d+)\.?\d*\n", generalInfo, re.S) - bitrate = re.search("Overall bit rate\s*:\s*(\d+)\.?\d*\n", generalInfo, re.S) + fileSize = re.search("File size\s*:\s*(\d+)\.?\d*\n", generalInfo, re.S) + duration = re.search("Duration\s*:\s*(\d+)\.?\d*\n", generalInfo, re.S) + bitrate = re.search("Overall bit rate\s*:\s*(\d+)\.?\d*\n", generalInfo, re.S) mediaInfo['container'] = container.group(1) mediaInfo['fileSize'] = fileSize.group(1) mediaInfo['duration'] = (str)((float)(duration.group(1))/1000) mediaInfo['bitrate'] = bitrate.group(1) - video = re.search("(\nVideo[\s\#\d]*\n.*?\n\n)", sourceString, re.S) - if video : + video = re.search("(\nVideo[\s\#\d]*\n.*?\n\n)", sourceString, re.S) + if video: mediaInfo['haveVideo'] = 1 videoInfo = video.group(0) - videoCodec = re.search("Codec\s*:\s*([\w\_\-\\\/\. ]+)\n", videoInfo, re.S) + videoCodec = re.search("Codec\s*:\s*([\w\_\-\\\/\. ]+)\n", videoInfo, re.S) videoCodecProfile = re.search("Codec profile\s*:\s*([\w\_\-\\\/\@\. ]+)\n", videoInfo, re.S) - videoDuration = re.search("Duration\s*:\s*(\d+)\.?\d*\n", videoInfo, re.S) - videoBitrate = re.search("Bit rate\s*:\s*(\d+)\n", videoInfo, re.S) - videoWidth = re.search("Width\s*:\s*(\d+)\n", videoInfo, re.S) - videoHeight = re.search("Height\s*:\s*(\d+)\n", videoInfo, re.S) + videoDuration = re.search("Duration\s*:\s*(\d+)\.?\d*\n", videoInfo, re.S) + videoBitrate = re.search("Bit rate\s*:\s*(\d+)\n", videoInfo, re.S) + videoWidth = re.search("Width\s*:\s*(\d+)\n", videoInfo, re.S) + videoHeight = re.search("Height\s*:\s*(\d+)\n", videoInfo, re.S) videoAspectRatio = re.search("Display aspect ratio\s*:\s*([\d\.]+)\n", videoInfo, re.S) - videoFrameRate = re.search("Frame rate\s*:\s*([\d\.]+)\n", videoInfo, re.S) + videoFrameRate = re.search("Frame rate\s*:\s*([\d\.]+)\n", videoInfo, re.S) videoFrameCount = re.search("Frame count\s*:\s*(\d+)\.?\d*\n", videoInfo, re.S) - if videoCodec : + if videoCodec: mediaInfo['videoCodec'] = videoCodec.group(1) - if videoCodecProfile : + if videoCodecProfile: mediaInfo['videoCodecProfile'] = videoCodecProfile.group(1) - if videoDuration : + if videoDuration: mediaInfo['videoDuration'] = (str)((float)(videoDuration.group(1))/1000) - if videoBitrate : + if videoBitrate: mediaInfo['videoBitrate'] = videoBitrate.group(1) - if videoWidth : + if videoWidth: mediaInfo['videoWidth'] = (int)(videoWidth.group(1)) - if videoHeight : + if videoHeight: mediaInfo['videoHeight'] = (int)(videoHeight.group(1)) - if videoAspectRatio : + if videoAspectRatio: mediaInfo['videoAspectRatio'] = videoAspectRatio.group(1) - if videoFrameRate : + if videoFrameRate: mediaInfo['videoFrameRate'] = videoFrameRate.group(1) - if videoFrameCount : + if videoFrameCount: mediaInfo['videoFrameCount'] = videoFrameCount.group(1) - audio = re.search("(\nAudio[\s\#\d]*\n.*?\n\n)", sourceString, re.S) - if audio : + audio = re.search("(\nAudio[\s\#\d]*\n.*?\n\n)", sourceString, re.S) + if audio: mediaInfo['haveAudio'] = 1 audioInfo = audio.group(0) - tmpAudioCodec = re.search("Codec\s*:\s*([\w\_\-\\\/ ]+)\n", audioInfo, re.S) - audioCodec = re.search("\w+", tmpAudioCodec.group(1), re.S) + 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 : + if audioCodecProfile is None: audioCodecProfile = re.search("Format profile\s*:\s*([\w\_\-\\\/\@\. ]+)\n", audioInfo, re.S) - audioDuration = re.search("Duration\s*:\s*(\d+)\.?\d*\n", audioInfo, re.S) - audioBitrate = re.search("Bit rate\s*:\s*(\d+)\n", audioInfo, re.S) - audioChannel = re.search("Channel\(s\)\s*:\s*(\d+)\n", audioInfo, re.S) - samplingRate = re.search("Sampling rate\s*:\s*([\w\_\-\\\/\@\. ]+)\n", audioInfo, re.S) + audioDuration = re.search("Duration\s*:\s*(\d+)\.?\d*\n", audioInfo, re.S) + audioBitrate = re.search("Bit rate\s*:\s*(\d+)\n", audioInfo, re.S) + audioChannel = re.search("Channel\(s\)\s*:\s*(\d+)\n", audioInfo, re.S) + samplingRate = re.search("Sampling rate\s*:\s*([\w\_\-\\\/\@\. ]+)\n", audioInfo, re.S) audioSamplingRate = re.search("\d+", samplingRate.group(1), re.S) - if audioCodec : + if audioCodec: mediaInfo['audioCodec'] = audioCodec.group(0) - if audioCodecProfile : + if audioCodecProfile: mediaInfo['audioCodecProfile'] = audioCodecProfile.group(1) - if audioDuration : + if audioDuration: mediaInfo['audioDuration'] = (str)((float)(audioDuration.group(1))/1000) - if audioBitrate : + if audioBitrate: mediaInfo['audioBitrate'] = audioBitrate.group(1) - if audioChannel : + if audioChannel: mediaInfo['audioChannel'] = audioChannel.group(1) - if audioSamplingRate : + if audioSamplingRate: mediaInfo['audioSamplingRate'] = audioSamplingRate.group(0) return mediaInfo From ccda41647ae0bfb5817490ae51cef1463225ee2f Mon Sep 17 00:00:00 2001 From: timmy61109 <38396747+timmy61109@users.noreply.github.com> Date: Thu, 26 Dec 2019 16:37:23 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=8E=A1=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E6=AD=A4=E6=8F=90=E4=BA=A4=E5=B0=87=E5=86=8D=E6=AC=A1?= =?UTF-8?q?Lint=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MediaInfo.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/MediaInfo.py b/MediaInfo.py index 5b59a02..cf628a7 100644 --- a/MediaInfo.py +++ b/MediaInfo.py @@ -1,11 +1,12 @@ #!/usr/bin/env python3 """ -mediainfo. +multimedia information. -author : renpeng -github : https://github.com/laodifang -description : media information -date : 2015-09-24 +author: renpeng +author: timmy61109 +github: https://github.com/laodifang +description: multimedia information +date: 2015-09-24 """ import os import re @@ -36,26 +37,29 @@ def getInfo(self): if not os.path.exists(self.filename) or not os.path.exists(self.cmd): return None - cmdName = os.path.basename(self.cmd) + cmdname = os.path.basename(self.cmd) - if cmdName == 'ffprobe': + if cmdname == 'ffprobe': self._ffmpegGetInfo() - elif cmdName == 'mediainfo': + elif cmdname == 'mediainfo': self._mediainfoGetInfo() return self.info def _ffmpegGetInfo(self): - cmd = self.cmd + ' -loglevel quiet -print_format json -show_format -show_streams -show_error -count_frames -i ' + self.filename - outputBytes = '' + 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) + outputbytes = subprocess.check_output(cmd, shell = True) except subprocess.CalledProcessError as e: return '' - outputText = outputBytes.decode('utf-8') + outputText = outputbytes.decode('utf-8') self.info = self._ffmpegGetInfoJson(outputText) def _ffmpegGetInfoJson(self, sourceString): @@ -113,16 +117,16 @@ def _mediainfoGetInfo(self): file = os.path.basename(self.filename) cmd = self.cmd + ' -f ' + file - outputBytes = '' + outputbytes = '' try: os.chdir(newPath) try: - outputBytes = subprocess.check_output(cmd, shell = True) + outputbytes = subprocess.check_output(cmd, shell = True) except subprocess.CalledProcessError as e: return '' - outputText = outputBytes.decode('utf-8') + outputText = outputbytes.decode('utf-8') except IOError: os.chdir(prevPath) return '' From 838501e82f7026db8170a1368ec1ef5b0a30f275 Mon Sep 17 00:00:00 2001 From: timmy61109 <38396747+timmy61109@users.noreply.github.com> Date: Wed, 19 May 2021 21:00:09 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=8E=A1=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E6=AD=A4=E6=8F=90=E4=BA=A4=E5=B0=87=E5=86=8D=E6=AC=A1?= =?UTF-8?q?Lint=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改項目: 模組: 議題 --- MediaInfo.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/MediaInfo.py b/MediaInfo.py index cf628a7..9de6cec 100644 --- a/MediaInfo.py +++ b/MediaInfo.py @@ -1,6 +1,4 @@ -#!/usr/bin/env python3 -""" -multimedia information. +"""multimedia information. author: renpeng author: timmy61109 @@ -98,7 +96,7 @@ def _ffmpegGetInfoJson(self, sourceString): mediaInfo['videoHeight'] = infoDict.get('streams')[videostreamindex].get('height') mediaInfo['videoAspectRatio'] = infoDict.get('streams')[videostreamindex].get('display_aspect_ratio') mediaInfo['videoFrameRate'] = infoDict.get('streams')[videostreamindex].get('r_frame_rate') - mediaInfo['videoFrameCount'] = infoDict.get('streams')[videostreamindex].get('nb_read_frames') + mediaInfo['videoFrameCount'] = infoDict.get('streams')[videostreamindex].get('nb_read_frames') if mediaInfo.get('haveAudio'): mediaInfo['audioCodec'] = infoDict.get('streams')[audiostreamindex].get('codec_name') @@ -107,7 +105,7 @@ def _ffmpegGetInfoJson(self, sourceString): mediaInfo['audioBitrate'] = infoDict.get('streams')[audiostreamindex].get('bit_rate') mediaInfo['audioChannel'] = infoDict.get('streams')[audiostreamindex].get('channels') mediaInfo['audioSamplingRate'] = infoDict.get('streams')[audiostreamindex].get('sample_rate') - mediaInfo['audioFrameCount'] = infoDict.get('streams')[audiostreamindex].get('nb_read_frames') + mediaInfo['audioFrameCount'] = infoDict.get('streams')[audiostreamindex].get('nb_read_frames') return mediaInfo