importos
importsys
importxlwt
from moviepy.editor importVideoFileClip
file_dir = u"G:/视频目录/" #定义文件目录
classFileCheck():
def __init__(self):
self.file_dir =file_dir
defget_filesize(self,filename):
u"""获取文件大小(M: 兆)
"""file_byte =os.path.getsize(filename)
returnself.sizeConvert(file_byte)
defget_file_times(self,filename):
u"""获取视频时长(s:秒)
"""clip =VideoFileClip(filename)
file_time =self.timeConvert(clip.duration)
returnfile_time
def sizeConvert(self,size):#单位换算
K, M, G = 1024, 1024**2, 1024**3
if size >=G:
return str(size/G)+‘G Bytes‘
elif size >=M:
return str(size/M)+‘M Bytes‘
elif size >=K:
return str(size/K)+‘K Bytes‘
else:
return str(size)+‘Bytes‘
def timeConvert(self,size):#单位换算
M, H = 60, 60**2
if size
return str(size)+u‘秒‘
if size
return u‘%s分钟%s秒‘%(int(size/M),int(size%M))
else:
hour = int(size/H)
mine = int(size%H/M)
second = int(size%H%M)
tim_srt = u‘%s小时%s分钟%s秒‘%(hour,mine,second)
returntim_srt
defget_all_file(self):
u"""获取视频下所有的文件
"""
for root, dirs, files inos.walk(file_dir):
return files #当前路径下所有非目录子文件
参考连接:https://www.cnblogs.com/haiyan123/p/9263288.html
原文地址:https://www.cnblogs.com/tdm8/p/10281229.html