Skip to content

Instantly share code, notes, and snippets.

@neilzheng
Created November 16, 2017 00:05
Show Gist options
  • Save neilzheng/d969e6dbd410efaf02a78c8329f7cc86 to your computer and use it in GitHub Desktop.
Save neilzheng/d969e6dbd410efaf02a78c8329f7cc86 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import glob
def parse_block(f, info):
block = {}
line = f.readline().strip()
if not line:
return None
block_name = line
while True:
line = f.readline().strip()
if not line:
break
vars = line.split(':')
block[vars[0].strip()] = vars[1].strip()
info[block_name] = block
return block
def parse_info(filename):
mediainfo = {}
mediainfo["filename"] = filename[:-4]
with open(filename, encoding='utf-8') as finfo:
while parse_block(finfo, mediainfo):
pass
return mediainfo
if __name__ == '__main__':
filelist = glob.glob("*.mp4.txt")
mapper = {}
with open("mapper.txt", encoding='utf-8') as fmap:
for line in fmap:
item = line.split(',')
mapper[item[1].strip().lower()] = item[0].strip()
allinfos = [parse_info(file) for file in filelist]
print("课程名,文件名,视频编码格式,X分辨率,Y分辨率,播放时长,平均码率,最大码率")
for info in allinfos:
videoinfo = info.get('Video', None)
if videoinfo:
max_bitrate = videoinfo.get('Maximum bit rate', '无')
print("{},{},{},{},{},{},{},{}".format(mapper.get(info["filename"].lower(), '无'),
info["filename"],
videoinfo['Format'],
videoinfo['Width'],
videoinfo['Height'],
videoinfo.get('Duration', '无'),
videoinfo.get('Bit rate', '无'),
max_bitrate))
else:
print("{},{},无,无,无,无,无,无".format(mapper.get(info["filename"].lower(), '无'), info["filename"]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment