我正在开发视频播放器,它扫描用户的视频文件并尝试从文件名中识别它们。如果视频是电影,我想获得它的名称和视频的质量,如果是电视节目,我想获得节目的名称、季节编号、剧集编号和视频质量。
我在谷歌上搜索了一些示例文件名并制作了简单的脚本来尝试获取信息,但是我很难处理异常情况,例如在质量之前有剧集名称,当文件具有“PROPER”之类的标签时,或者如果用户已将视频的来源(如“BluRay”)置于质量之前。
如果有更熟练的正则表达式的人会提供一些帮助,我将不胜感激。
谢谢!
import re
names = [
"The.Newsroom.2012.S02E06.720p.HDTV.x264-KILLERS.mkv",
"Breaking.Bad.S05E10.Buried.HDTV.XviD-AFG.avi",
"Breaking.Bad.S05E10.Buried.720p.HDTV.x264-AFG.mkv", #Incorrectly nonHD
"Dexter.S08E08.HDTV.XviD-AFG.avi",
"Dexter.S08E07.1080p.HDTV.x264-QCF.mkv",
"Dexter S08E07 720p HDTV x264-QCF.mkv",
"The.Great.Gatsby.2013.BluRay.1080p.DTS.x264-CHD.mkv", #Incorrectly nonHD
"The Forbidden Girl 2013 BRRIP Xvid AC3-BHRG.avi",
"Pain.&.Gain.2013.720p.BluRay.DD5.1.x264-HiDt.mkv",
"Band.of.Brothers.S01E02.Day.of.Days.DVDRip.XviD-AC3-BAGS.avi",
"Dexter.S08E06.PROPER.720p.HDTV.x264-IMMERSE.mkv", #Incorrectly nonHD
"Dexter S08E06 PROPER 720p HDTV x264-IMMERSE.mkv" #Incorrectly nonHD
]
for name in names:
tv = re.findall(r"(.*?)[ |.]S([\d+]{1,2})E([\d+]{1,2})[ |.]([\d+]{3,4}p|)", name) #FIXME: Get quality also after "PROPER/EPTITLE/.."
if len(tv)>0:
print("---------- TV ----------")
print("Show: "+tv[0][0].replace(".", " "))
print("Season: "+str(int(tv[0][1])))
print("Episode: "+str(int(tv[0][2])))
print("Quality: "+(tv[0][3] if len(tv[0][3])>0 else "nonHD"))
else:
movie = re.findall(r"(.*?[ |.][\d+]{4})[ |.]([\d+]{3,4}p|)", name) #FIXME: Get quality also after "BluRay/HDTV/HDDVD/.."
if len(movie)>0:
print("--------- MOVIE --------")
print("Title: "+movie[0][0].replace(".", " "))
print("Quality: "+(movie[0][1] if len(movie[0][1])>0 else "nonHD"))
else:
print("error")