|
@@ -10,7 +10,7 @@ import shutil
|
|
'''
|
|
'''
|
|
传入path值,读取当前path一级目录下的.dvi文件,返回[isDviFounded,bid,aid,title]列表
|
|
传入path值,读取当前path一级目录下的.dvi文件,返回[isDviFounded,bid,aid,title]列表
|
|
'''
|
|
'''
|
|
-global file_name
|
|
|
|
|
|
+global localFileName
|
|
|
|
|
|
|
|
|
|
def GetDviInfo(path):
|
|
def GetDviInfo(path):
|
|
@@ -49,7 +49,12 @@ def GetDviInfo(path):
|
|
return [isDviFounded, bid, aid, title]
|
|
return [isDviFounded, bid, aid, title]
|
|
|
|
|
|
|
|
|
|
|
|
+def GetFileSeries(fileList):
|
|
|
|
+ return int(fileList.split('\\')[-2])
|
|
|
|
+
|
|
|
|
+
|
|
def FindAllMp4Files(path):
|
|
def FindAllMp4Files(path):
|
|
|
|
+ # 这里是不需要对输出结果排序的,因为在移动这些文件后,DoRename调用被移动的文件,会排好序
|
|
fileTypeList = ['mp4', 'MP4', 'mP4', 'Mp4']
|
|
fileTypeList = ['mp4', 'MP4', 'mP4', 'Mp4']
|
|
fileList = [] # 存储要copy的文件全名
|
|
fileList = [] # 存储要copy的文件全名
|
|
fileNamelist = []
|
|
fileNamelist = []
|
|
@@ -75,33 +80,71 @@ def MoveFile(srcFileList, dstFolder):
|
|
|
|
|
|
|
|
|
|
# 排序用到的key
|
|
# 排序用到的key
|
|
-def get_series(dataList):
|
|
|
|
|
|
+def GetSeries(dataList):
|
|
return int(dataList.split('_')[1])
|
|
return int(dataList.split('_')[1])
|
|
|
|
|
|
|
|
|
|
def DoRename(path, fileName):
|
|
def DoRename(path, fileName):
|
|
- # 获取文件名
|
|
|
|
|
|
+ # 获取.txt文件名
|
|
filName = fileName
|
|
filName = fileName
|
|
-
|
|
|
|
- # 读取该文件
|
|
|
|
|
|
+ # 读取.txt文件
|
|
with open(filName, encoding='UTF-8') as f:
|
|
with open(filName, encoding='UTF-8') as f:
|
|
lines = f.readlines() # 新文件名按行保存
|
|
lines = f.readlines() # 新文件名按行保存
|
|
-
|
|
|
|
fileList = os.listdir(path) # 该文件夹下所有的文件(包括文件夹)
|
|
fileList = os.listdir(path) # 该文件夹下所有的文件(包括文件夹)
|
|
-
|
|
|
|
- fileList.sort(key=get_series)
|
|
|
|
-
|
|
|
|
- i = 1
|
|
|
|
|
|
+ fileList.sort(key=GetSeries)
|
|
|
|
+ i = 0
|
|
for files in fileList: # 遍历所有文件
|
|
for files in fileList: # 遍历所有文件
|
|
oldDir = os.path.join(path, files) # 原来的文件路径
|
|
oldDir = os.path.join(path, files) # 原来的文件路径
|
|
if os.path.isdir(oldDir): # 如果是文件夹则跳过
|
|
if os.path.isdir(oldDir): # 如果是文件夹则跳过
|
|
continue
|
|
continue
|
|
filetype = os.path.splitext(files)[1] # 文件扩展名
|
|
filetype = os.path.splitext(files)[1] # 文件扩展名
|
|
- newDir = os.path.join(path, str(i) + '. ' + lines[i].strip('\n') + filetype) # 新的文件路径
|
|
|
|
|
|
+ newDir = os.path.join(path, str(i+1) + '. ' + lines[i].strip('\n') + filetype) # 新的文件路径
|
|
os.rename(oldDir, newDir) # 重命名
|
|
os.rename(oldDir, newDir) # 重命名
|
|
i = i + 1
|
|
i = i + 1
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def GetInfoList(path):
|
|
|
|
+ fileTypeList = ['info']
|
|
|
|
+ fileList = [] # 含路径的文件名
|
|
|
|
+
|
|
|
|
+ for dirPath, dirNames, fileNames in os.walk(path):
|
|
|
|
+ for file in fileNames:
|
|
|
|
+ fileType = file.split('.')[-1]
|
|
|
|
+ if fileType in fileTypeList:
|
|
|
|
+ file_fullname = os.path.join(dirPath, file) # 文件名
|
|
|
|
+ fileList.append(file_fullname)
|
|
|
|
+ fileList.sort(key=GetFileSeries) # 这里必须排序
|
|
|
|
+ return fileList
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def GetLocalVideoTitle(path):
|
|
|
|
+ fileList = GetInfoList(path)
|
|
|
|
+ print(fileList)
|
|
|
|
+ titleList = []
|
|
|
|
+ findVideoTitle = re.compile(r'"PartName":"(.*?)"')
|
|
|
|
+ for infoFile in fileList:
|
|
|
|
+ with open(infoFile, encoding='UTF-8') as f:
|
|
|
|
+ lines = f.readlines()
|
|
|
|
+ s = str(lines[0])
|
|
|
|
+ videoTitle = re.findall(findVideoTitle, s)[0]
|
|
|
|
+ titleList.append(videoTitle)
|
|
|
|
+ return titleList
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def GetTxt(dataList, localTitle):
|
|
|
|
+ fileTitle = localTitle + ".txt" # 合成.txt格式 文件名
|
|
|
|
+
|
|
|
|
+ nameFile = open(fileTitle, "w", encoding="utf-8") # 写入文件
|
|
|
|
+ j = 0
|
|
|
|
+ for item in dataList:
|
|
|
|
+ j += 1
|
|
|
|
+ nameFile.write(item + "\n")
|
|
|
|
+ nameFile.close()
|
|
|
|
+ return fileTitle
|
|
|
|
+
|
|
|
|
+
|
|
def DeleteTxt(delDir, delName):
|
|
def DeleteTxt(delDir, delName):
|
|
delList = os.listdir(delDir)
|
|
delList = os.listdir(delDir)
|
|
for f in delList:
|
|
for f in delList:
|