Browse Source

增加新版解密的支持,用户不再需要使用旧版的uwp应用了

剑断了 2 years ago
parent
commit
c68338597d
2 changed files with 75 additions and 16 deletions
  1. 69 15
      FileOperator.py
  2. 6 1
      main.py

+ 69 - 15
FileOperator.py

@@ -69,6 +69,69 @@ def FindAllMp4Files(path):
     return [fileList, fileNamelist]
     return [fileList, fileNamelist]
 
 
 
 
+def FindSpecialMp4Files(path, aID):
+    # 提取出含有指定特征的fileList
+    fileTypeList = ['mp4', 'MP4', 'mP4', 'Mp4']
+    fileList = []  # 存储要copy的文件全名
+    fileNameList = []
+    # 获取要被命名的文件,包含了文件夹有其它文件或文件夹的情况
+    for dirPath, dirNames, fileNames in os.walk(path):
+        for file in fileNames:
+            if aID in file and file.split('.')[-1] in fileTypeList:  #
+                oldName = os.path.join(dirPath, file)  # 文件全名
+                if os.path.isdir(oldName):
+                    continue
+                fileList.append(oldName)
+                fileNameList.append(file)
+
+    return [fileList, fileNameList]
+
+
+# 检测文件是否加密 是则解密
+def DecryptMp4(path, aID):
+    isEncrypted = None
+    s = None
+    encryptedFile = None
+    decryptedFile = None
+    countEncChar = 0  # 检测'xff'数量
+    countDecChar = 0  # 检测'x00'数量
+
+    fileList = FindSpecialMp4Files(path, aID)[0]
+
+    testFile = fileList[0]
+    with open(testFile, "rb") as f:
+        s = str(f.readline())[3:14]
+    f.close()
+    sList = s.split('\\')  # ['xff', 'xff', 'xff']
+    for item in sList:
+        if 'xff' in item:
+            countEncChar += 1
+        if 'x00' in item:
+            countDecChar += 1
+
+    if countEncChar == 3:
+        isEncrypted = True  # 加密
+    if countDecChar == 3:
+        isEncrypted = False  # 未加密
+
+    if isEncrypted is None:
+        return
+
+    if not isEncrypted:  # 如果未加密
+        pass
+    else:  # 如果加密则解密
+        for file in fileList:
+            encryptedFile = open(file, 'rb')
+            encryptedFile.seek(3)
+            byte = encryptedFile.read()
+
+            with open(file, 'wb') as decryptedFile:
+                decryptedFile.write(byte)
+
+        encryptedFile.close()
+        decryptedFile.close()
+
+
 # return fileList
 # return fileList
 def CopyFile(srcFileList, dstFolder):
 def CopyFile(srcFileList, dstFolder):
     for file in srcFileList:
     for file in srcFileList:
@@ -92,26 +155,17 @@ def DoRename(path, fileName, aID):
     with open(filName, encoding='UTF-8') as f:
     with open(filName, encoding='UTF-8') as f:
         lines = f.readlines()  # 新文件名按行保存
         lines = f.readlines()  # 新文件名按行保存
 
 
-    # 提取出含有指定特征的fileList
-    fileTypeList = ['mp4', 'MP4', 'mP4', 'Mp4']
-    fileList = []  # 存储要copy的文件全名
-    # 获取要被命名的文件,包含了文件夹有其它文件或文件夹的情况
-
-    for dirPath, dirNames, fileNames in os.walk(path):
-        for file in fileNames:
-            if aID in file and file.split('.')[-1] in fileTypeList:  #
-                oldName = os.path.join(dirPath, file)  # 文件全名
-                if os.path.isdir(oldName):
-                    continue
-                fileList.append(oldName)
+    fileList = FindSpecialMp4Files(path, aID)[0]  # 存储要copy的文件全名
 
 
     fileList.sort(key=GetSeries)
     fileList.sort(key=GetSeries)
     # fileList = set(fileList)  # 防止文件重复
     # fileList = set(fileList)  # 防止文件重复
-
+    index = 0
+    frontIndex = 0
     for oldDir in fileList:
     for oldDir in fileList:
         filetype = '.' + oldDir.split('.')[-1]
         filetype = '.' + oldDir.split('.')[-1]
-        index = int(oldDir.split('_')[-2]) - 1
-        newDir = os.path.join(path, str(index + 1) + '. ' + lines[index].strip('\n') + filetype)  # 新的文件路径
+        frontIndex = int(oldDir.split('_')[-2])
+        newDir = os.path.join(path, str(frontIndex) + '. ' + lines[index].strip('\n') + filetype)  # 新的文件路径
+        index += 1
         os.rename(oldDir, newDir)  # 重命名
         os.rename(oldDir, newDir)  # 重命名
 
 
 
 

+ 6 - 1
main.py

@@ -220,11 +220,16 @@ class MainApp(QMainWindow, Ui_MainWindow):
                     s += (item + '\n')
                     s += (item + '\n')
                 self.Log(s)
                 self.Log(s)
 
 
-                # 复制
+
 
 
                 if os.path.isdir(outputPath) is False:
                 if os.path.isdir(outputPath) is False:
                     self.Log('输出目录的路径存在非法输入!')
                     self.Log('输出目录的路径存在非法输入!')
                 else:
                 else:
+                    # 解密
+                    self.Log("开始解密...")
+                    FileOperator.DecryptMp4(downloadPath, dviInfoList[2])
+                    self.Log("解密完毕!")
+                    # 复制
                     self.CopyOrMove(self.isCopyOutput, mp4List, outputPath)
                     self.CopyOrMove(self.isCopyOutput, mp4List, outputPath)
 
 
                     # 重命名
                     # 重命名