Browse Source

First Commit

剑断了 2 years ago
parent
commit
395e1a0d3c
8 changed files with 876 additions and 0 deletions
  1. 5 0
      .gitignore
  2. BIN
      FKBili.ico
  3. 120 0
      FileOperator.py
  4. 149 0
      MainWindow.py
  5. 314 0
      MainWindow.ui
  6. 66 0
      TitleSpider.py
  7. 0 0
      icon.py
  8. 222 0
      main.py

+ 5 - 0
.gitignore

@@ -0,0 +1,5 @@
+/dist/
+/build/
+/.idea/
+/main.spec
+/setupconfig.iss

BIN
FKBili.ico


+ 120 - 0
FileOperator.py

@@ -0,0 +1,120 @@
+# -*- coding = utf-8 -*-
+# @Time : 2022/6/22 12:29
+# @Author : 刘正阳
+# @File : FileOperator.py
+# @Software : PyCharm
+import os
+import re
+import shutil
+
+'''
+传入path值,读取当前path一级目录下的.dvi文件,返回[isDviFounded,bid,aid,title]列表
+'''
+global file_name
+
+
+def GetDviInfo(path):
+    isDviFounded = False
+    file_type = '.dvi'
+    dviFile = None
+    bid = None
+    aid = None
+    title = None
+    description = None
+
+    filelist = os.listdir(path)
+    for file in filelist:
+        if file_type in file:
+            isDviFounded = True
+            dviFile = os.path.join(path, file)
+
+    if isDviFounded is False:
+        return [isDviFounded, bid, aid, title]
+    else:
+        with open(dviFile, encoding='UTF-8') as f:
+            lines = f.readlines()
+            s = str(lines[0])
+
+            findBid = re.compile(r'"Bid":"(.*?)"')
+            findDviTitle = re.compile(r'"Title":"(.*?)"')
+            findAid = re.compile(r'"Aid":"(.*?)"')
+
+            bid = re.findall(findBid, s)[0]
+            aid = re.findall(findAid, s)[0]
+            title = re.findall(findDviTitle, s)[0]
+            for s in title:
+                cut = ['|', '\\', '/', ':', '?', '"', '<', '>']
+                if s in cut:
+                    title = title.replace(s, ' ')
+            return [isDviFounded, bid, aid, title]
+
+
+def FindAllMp4Files(path):
+    fileTypeList = ['mp4', 'MP4', 'mP4', 'Mp4']
+    fileList = []  # 存储要copy的文件全名
+    fileNamelist = []
+    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)
+                fileNamelist.append(file)
+    return [fileList, fileNamelist]
+
+
+# return fileList
+def CopyFile(srcFileList, dstFolder):
+    for file in srcFileList:
+        shutil.copy(file, dstFolder)
+
+
+def MoveFile(srcFileList, dstFolder):
+    for file in srcFileList:
+        shutil.move(file, dstFolder)
+
+
+# 排序用到的key
+def get_series(dataList):
+    return int(dataList.split('_')[1])
+
+
+def DoRename(path, fileName):
+    # 获取文件名
+    filName = fileName
+
+    # 读取该文件
+    with open(filName, encoding='UTF-8') as f:
+        lines = f.readlines()  # 新文件名按行保存
+
+    fileList = os.listdir(path)  # 该文件夹下所有的文件(包括文件夹)
+
+    fileList.sort(key=get_series)
+
+    i = 1
+    for files in fileList:  # 遍历所有文件
+        oldDir = os.path.join(path, files)  # 原来的文件路径
+        if os.path.isdir(oldDir):  # 如果是文件夹则跳过
+            continue
+        filetype = os.path.splitext(files)[1]  # 文件扩展名
+        newDir = os.path.join(path, str(i) + '. ' + lines[i].strip('\n') + filetype)  # 新的文件路径
+        os.rename(oldDir, newDir)  # 重命名
+        i = i + 1
+
+
+def DeleteTxt(delDir, delName):
+    delList = os.listdir(delDir)
+    for f in delList:
+        if f == delName:
+            filePath = os.path.join(delDir, f)
+            if os.path.isfile(filePath):
+                os.remove(filePath)
+
+
+def DeleteDir(delDir):
+    os.system(f"attrib -r {delDir}")
+    shutil.rmtree(delDir, True)
+
+
+def RenameDir(name):
+    os.rename()

+ 149 - 0
MainWindow.py

@@ -0,0 +1,149 @@
+# -*- coding: utf-8 -*-
+
+# Form implementation generated from reading ui file 'MainWindow.ui'
+#
+# Created by: PyQt5 UI code generator 5.15.4
+#
+# WARNING: Any manual changes made to this file will be lost when pyuic5 is
+# run again.  Do not edit this file unless you know what you are doing.
+
+
+from PyQt5 import QtCore, QtGui, QtWidgets
+
+
+class Ui_MainWindow(object):
+    def setupUi(self, MainWindow):
+        MainWindow.setObjectName("MainWindow")
+        MainWindow.resize(1045, 301)
+        font = QtGui.QFont()
+        font.setFamily("微软雅黑")
+        font.setBold(True)
+        font.setWeight(75)
+        MainWindow.setFont(font)
+        self.centralwidget = QtWidgets.QWidget(MainWindow)
+        self.centralwidget.setObjectName("centralwidget")
+        self.downloadDirButton = QtWidgets.QPushButton(self.centralwidget)
+        self.downloadDirButton.setGeometry(QtCore.QRect(630, 40, 31, 28))
+        font = QtGui.QFont()
+        font.setFamily("微软雅黑")
+        font.setBold(True)
+        font.setWeight(75)
+        self.downloadDirButton.setFont(font)
+        self.downloadDirButton.setAutoRepeat(False)
+        self.downloadDirButton.setObjectName("downloadDirButton")
+        self.downloadDirLabel = QtWidgets.QLabel(self.centralwidget)
+        self.downloadDirLabel.setGeometry(QtCore.QRect(50, 41, 111, 32))
+        self.downloadDirLabel.setObjectName("downloadDirLabel")
+        self.outputDirLable = QtWidgets.QLabel(self.centralwidget)
+        self.outputDirLable.setGeometry(QtCore.QRect(50, 80, 91, 32))
+        self.outputDirLable.setObjectName("outputDirLable")
+        self.outputDirEdit = QtWidgets.QTextEdit(self.centralwidget)
+        self.outputDirEdit.setGeometry(QtCore.QRect(167, 78, 451, 32))
+        self.outputDirEdit.setStyleSheet("rgb(255, 0, 0)")
+        self.outputDirEdit.setDocumentTitle("")
+        self.outputDirEdit.setObjectName("outputDirEdit")
+        self.downloadDirEdit = QtWidgets.QTextEdit(self.centralwidget)
+        self.downloadDirEdit.setGeometry(QtCore.QRect(167, 39, 451, 32))
+        self.downloadDirEdit.setDocumentTitle("")
+        self.downloadDirEdit.setObjectName("downloadDirEdit")
+        self.outputDirButton = QtWidgets.QPushButton(self.centralwidget)
+        self.outputDirButton.setGeometry(QtCore.QRect(630, 79, 31, 28))
+        font = QtGui.QFont()
+        font.setFamily("微软雅黑")
+        self.outputDirButton.setFont(font)
+        self.outputDirButton.setAutoRepeat(False)
+        self.outputDirButton.setObjectName("outputDirButton")
+        self.renameButton = QtWidgets.QPushButton(self.centralwidget)
+        self.renameButton.setGeometry(QtCore.QRect(50, 121, 681, 41))
+        font = QtGui.QFont()
+        font.setFamily("微软雅黑")
+        self.renameButton.setFont(font)
+        self.renameButton.setObjectName("renameButton")
+        self.copyToOutput = QtWidgets.QCheckBox(self.centralwidget)
+        self.copyToOutput.setGeometry(QtCore.QRect(510, 170, 181, 25))
+        font = QtGui.QFont()
+        font.setFamily("阿里巴巴普惠体 R")
+        self.copyToOutput.setFont(font)
+        self.copyToOutput.setObjectName("copyToOutput")
+        self.txtFileCheckBox = QtWidgets.QCheckBox(self.centralwidget)
+        self.txtFileCheckBox.setGeometry(QtCore.QRect(380, 180, 110, 25))
+        font = QtGui.QFont()
+        font.setFamily("阿里巴巴普惠体 R")
+        self.txtFileCheckBox.setFont(font)
+        self.txtFileCheckBox.setObjectName("txtFileCheckBox")
+        self.progressBar = QtWidgets.QProgressBar(self.centralwidget)
+        self.progressBar.setGeometry(QtCore.QRect(50, 220, 731, 27))
+        self.progressBar.setProperty("value", 99)
+        self.progressBar.setObjectName("progressBar")
+        self.activityLogEdit = QtWidgets.QPlainTextEdit(self.centralwidget)
+        self.activityLogEdit.setGeometry(QtCore.QRect(780, 30, 251, 231))
+        font = QtGui.QFont()
+        font.setFamily("阿里巴巴普惠体 R")
+        font.setPointSize(7)
+        font.setBold(False)
+        font.setWeight(50)
+        self.activityLogEdit.setFont(font)
+        self.activityLogEdit.setTabChangesFocus(False)
+        self.activityLogEdit.setReadOnly(False)
+        self.activityLogEdit.setPlainText("")
+        self.activityLogEdit.setObjectName("activityLogEdit")
+        self.activityLabel = QtWidgets.QLabel(self.centralwidget)
+        self.activityLabel.setGeometry(QtCore.QRect(870, 10, 72, 15))
+        self.activityLabel.setObjectName("activityLabel")
+        self.moveToOutput = QtWidgets.QCheckBox(self.centralwidget)
+        self.moveToOutput.setGeometry(QtCore.QRect(510, 190, 181, 25))
+        font = QtGui.QFont()
+        font.setFamily("阿里巴巴普惠体 R")
+        self.moveToOutput.setFont(font)
+        self.moveToOutput.setObjectName("moveToOutput")
+        self.deleteFileCheckBox = QtWidgets.QCheckBox(self.centralwidget)
+        self.deleteFileCheckBox.setGeometry(QtCore.QRect(160, 180, 211, 25))
+        font = QtGui.QFont()
+        font.setFamily("阿里巴巴普惠体 R")
+        self.deleteFileCheckBox.setFont(font)
+        self.deleteFileCheckBox.setObjectName("deleteFileCheckBox")
+        self.label = QtWidgets.QLabel(self.centralwidget)
+        self.label.setGeometry(QtCore.QRect(190, 10, 431, 21))
+        font = QtGui.QFont()
+        font.setFamily("微软雅黑")
+        font.setPointSize(12)
+        font.setBold(True)
+        font.setItalic(False)
+        font.setWeight(75)
+        self.label.setFont(font)
+        self.label.setStyleSheet("color:rgb(255, 0, 0)")
+        self.label.setObjectName("label")
+        MainWindow.setCentralWidget(self.centralwidget)
+        self.statusbar = QtWidgets.QStatusBar(MainWindow)
+        self.statusbar.setObjectName("statusbar")
+        MainWindow.setStatusBar(self.statusbar)
+        self.menubar = QtWidgets.QMenuBar(MainWindow)
+        self.menubar.setGeometry(QtCore.QRect(0, 0, 1045, 26))
+        self.menubar.setObjectName("menubar")
+        MainWindow.setMenuBar(self.menubar)
+
+        self.retranslateUi(MainWindow)
+        QtCore.QMetaObject.connectSlotsByName(MainWindow)
+
+    def retranslateUi(self, MainWindow):
+        _translate = QtCore.QCoreApplication.translate
+        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
+        self.downloadDirButton.setText(_translate("MainWindow", "..."))
+        self.downloadDirLabel.setText(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
+"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
+"p, li { white-space: pre-wrap; }\n"
+"</style></head><body style=\" font-family:\'微软雅黑\'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
+"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">UWP下载目录:</p></body></html>"))
+        self.outputDirLable.setText(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
+"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
+"p, li { white-space: pre-wrap; }\n"
+"</style></head><body style=\" font-family:\'微软雅黑\'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
+"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">输出文件夹:</p></body></html>"))
+        self.outputDirButton.setText(_translate("MainWindow", "..."))
+        self.renameButton.setText(_translate("MainWindow", "一键爬取+重命名"))
+        self.copyToOutput.setText(_translate("MainWindow", "以复制文件的方式输出"))
+        self.txtFileCheckBox.setText(_translate("MainWindow", "保存.txt文件"))
+        self.activityLabel.setText(_translate("MainWindow", "活动日志"))
+        self.moveToOutput.setText(_translate("MainWindow", "以移动文件的方式输出"))
+        self.deleteFileCheckBox.setText(_translate("MainWindow", "重命名完成后删除源文件夹"))
+        self.label.setText(_translate("MainWindow", "使用前请关闭代理服务并确保网络环境通畅哦!"))

+ 314 - 0
MainWindow.ui

@@ -0,0 +1,314 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>1045</width>
+    <height>301</height>
+   </rect>
+  </property>
+  <property name="font">
+   <font>
+    <family>微软雅黑</family>
+    <weight>75</weight>
+    <bold>true</bold>
+   </font>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralwidget">
+   <widget class="QPushButton" name="downloadDirButton">
+    <property name="geometry">
+     <rect>
+      <x>630</x>
+      <y>40</y>
+      <width>31</width>
+      <height>28</height>
+     </rect>
+    </property>
+    <property name="font">
+     <font>
+      <family>微软雅黑</family>
+      <weight>75</weight>
+      <bold>true</bold>
+     </font>
+    </property>
+    <property name="text">
+     <string>...</string>
+    </property>
+    <property name="autoRepeat">
+     <bool>false</bool>
+    </property>
+   </widget>
+   <widget class="QLabel" name="downloadDirLabel">
+    <property name="geometry">
+     <rect>
+      <x>50</x>
+      <y>41</y>
+      <width>111</width>
+      <height>32</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
+&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
+p, li { white-space: pre-wrap; }
+&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'微软雅黑'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
+&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;UWP下载目录:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+    </property>
+   </widget>
+   <widget class="QLabel" name="outputDirLable">
+    <property name="geometry">
+     <rect>
+      <x>50</x>
+      <y>80</y>
+      <width>91</width>
+      <height>32</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
+&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
+p, li { white-space: pre-wrap; }
+&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'微软雅黑'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
+&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;输出文件夹:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+    </property>
+   </widget>
+   <widget class="QTextEdit" name="outputDirEdit">
+    <property name="geometry">
+     <rect>
+      <x>167</x>
+      <y>78</y>
+      <width>451</width>
+      <height>32</height>
+     </rect>
+    </property>
+    <property name="styleSheet">
+     <string notr="true">rgb(255, 0, 0)</string>
+    </property>
+    <property name="documentTitle">
+     <string/>
+    </property>
+   </widget>
+   <widget class="QTextEdit" name="downloadDirEdit">
+    <property name="geometry">
+     <rect>
+      <x>167</x>
+      <y>39</y>
+      <width>451</width>
+      <height>32</height>
+     </rect>
+    </property>
+    <property name="documentTitle">
+     <string/>
+    </property>
+   </widget>
+   <widget class="QPushButton" name="outputDirButton">
+    <property name="geometry">
+     <rect>
+      <x>630</x>
+      <y>79</y>
+      <width>31</width>
+      <height>28</height>
+     </rect>
+    </property>
+    <property name="font">
+     <font>
+      <family>微软雅黑</family>
+     </font>
+    </property>
+    <property name="text">
+     <string>...</string>
+    </property>
+    <property name="autoRepeat">
+     <bool>false</bool>
+    </property>
+   </widget>
+   <widget class="QPushButton" name="renameButton">
+    <property name="geometry">
+     <rect>
+      <x>50</x>
+      <y>121</y>
+      <width>681</width>
+      <height>41</height>
+     </rect>
+    </property>
+    <property name="font">
+     <font>
+      <family>微软雅黑</family>
+     </font>
+    </property>
+    <property name="text">
+     <string>一键爬取+重命名</string>
+    </property>
+   </widget>
+   <widget class="QCheckBox" name="copyToOutput">
+    <property name="geometry">
+     <rect>
+      <x>510</x>
+      <y>170</y>
+      <width>181</width>
+      <height>25</height>
+     </rect>
+    </property>
+    <property name="font">
+     <font>
+      <family>阿里巴巴普惠体 R</family>
+     </font>
+    </property>
+    <property name="text">
+     <string>以复制文件的方式输出</string>
+    </property>
+   </widget>
+   <widget class="QCheckBox" name="txtFileCheckBox">
+    <property name="geometry">
+     <rect>
+      <x>380</x>
+      <y>180</y>
+      <width>110</width>
+      <height>25</height>
+     </rect>
+    </property>
+    <property name="font">
+     <font>
+      <family>阿里巴巴普惠体 R</family>
+     </font>
+    </property>
+    <property name="text">
+     <string>保存.txt文件</string>
+    </property>
+   </widget>
+   <widget class="QProgressBar" name="progressBar">
+    <property name="geometry">
+     <rect>
+      <x>50</x>
+      <y>220</y>
+      <width>731</width>
+      <height>27</height>
+     </rect>
+    </property>
+    <property name="value">
+     <number>99</number>
+    </property>
+   </widget>
+   <widget class="QPlainTextEdit" name="activityLogEdit">
+    <property name="geometry">
+     <rect>
+      <x>780</x>
+      <y>30</y>
+      <width>251</width>
+      <height>231</height>
+     </rect>
+    </property>
+    <property name="font">
+     <font>
+      <family>阿里巴巴普惠体 R</family>
+      <pointsize>7</pointsize>
+      <weight>50</weight>
+      <bold>false</bold>
+     </font>
+    </property>
+    <property name="tabChangesFocus">
+     <bool>false</bool>
+    </property>
+    <property name="readOnly">
+     <bool>false</bool>
+    </property>
+    <property name="plainText">
+     <string/>
+    </property>
+   </widget>
+   <widget class="QLabel" name="activityLabel">
+    <property name="geometry">
+     <rect>
+      <x>870</x>
+      <y>10</y>
+      <width>72</width>
+      <height>15</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>活动日志</string>
+    </property>
+   </widget>
+   <widget class="QCheckBox" name="moveToOutput">
+    <property name="geometry">
+     <rect>
+      <x>510</x>
+      <y>190</y>
+      <width>181</width>
+      <height>25</height>
+     </rect>
+    </property>
+    <property name="font">
+     <font>
+      <family>阿里巴巴普惠体 R</family>
+     </font>
+    </property>
+    <property name="text">
+     <string>以移动文件的方式输出</string>
+    </property>
+   </widget>
+   <widget class="QCheckBox" name="deleteFileCheckBox">
+    <property name="geometry">
+     <rect>
+      <x>160</x>
+      <y>180</y>
+      <width>211</width>
+      <height>25</height>
+     </rect>
+    </property>
+    <property name="font">
+     <font>
+      <family>阿里巴巴普惠体 R</family>
+     </font>
+    </property>
+    <property name="text">
+     <string>重命名完成后删除源文件夹</string>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label">
+    <property name="geometry">
+     <rect>
+      <x>190</x>
+      <y>10</y>
+      <width>431</width>
+      <height>21</height>
+     </rect>
+    </property>
+    <property name="font">
+     <font>
+      <family>微软雅黑</family>
+      <pointsize>12</pointsize>
+      <weight>75</weight>
+      <italic>false</italic>
+      <bold>true</bold>
+     </font>
+    </property>
+    <property name="styleSheet">
+     <string notr="true">color:rgb(255, 0, 0)</string>
+    </property>
+    <property name="text">
+     <string>使用前请关闭代理服务并确保网络环境通畅哦!</string>
+    </property>
+   </widget>
+  </widget>
+  <widget class="QStatusBar" name="statusbar"/>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>1045</width>
+     <height>26</height>
+    </rect>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 66 - 0
TitleSpider.py

@@ -0,0 +1,66 @@
+# -*- coding = utf-8 -*-
+# @Time : 2022/6/21 15:33
+# @Author : 刘正阳
+# @File : TitleSpider.py
+# @Software : PyCharm
+
+import requests
+import re
+from bs4 import BeautifulSoup
+
+findLink = re.compile(r'"part":"(.*?)","duratio')
+
+global fileName
+
+
+# 获取网页数据,传入参数:网址
+def FinData(url):
+    dataList = []
+    getUrl = requests.get(url=url)
+    bsHtml = BeautifulSoup(getUrl.text, "html.parser")
+    global urlTitle
+    urlTitleList = bsHtml.get_text().title().split('\n', 1)
+    urlTitle = urlTitleList[0][:-30].lstrip()
+    dataList.append(str(urlTitle))
+    bsFinData = bsHtml.select('script')
+    bsData = ''
+
+    # 筛选列表数据
+    for i in bsFinData:
+        bsData = str(i)
+        if 'window.__INITIAL_STATE__={' in bsData:
+            break
+
+    # 正则查找,返回列表
+    reList = re.findall(findLink, bsData)
+    dataList += reList
+
+    return dataList, urlTitle
+
+
+def saveAsTxt(video_list):
+    fileTitle = urlTitle + ".txt"  # 合成.txt格式 文件名
+
+    # 去除标题中的Windows不兼容的的命名字
+    for s in fileTitle:
+        cut = ['|', '\\', '/', ':', '?', '"', '<', '>']
+        if s in cut:
+            fileTitle = fileTitle.replace(s, ' ')
+
+    nameFile = open(fileTitle, "w", encoding="utf-8")  # 写入文件
+    j = 0
+    for i in video_list:
+        j += 1
+        nameFile.write(i + "\n")
+    nameFile.close()
+    return fileTitle
+
+
+def GetTxt(bid):
+    global fileName
+    urlPart = 'https://www.bilibili.com/video/'
+    bv = bid
+    url = urlPart + bv
+
+    dataList, urlTile = FinData(url)
+    fileName = saveAsTxt(dataList)

File diff suppressed because it is too large
+ 0 - 0
icon.py


+ 222 - 0
main.py

@@ -0,0 +1,222 @@
+import base64
+import datetime
+import os
+import threading
+from PyQt5.QtWidgets import *
+from PyQt5.QtGui import *
+import FileOperator
+from MainWindow import Ui_MainWindow
+from icon import img
+import TitleSpider
+
+
+def GetSeries(dataList):
+    return int(dataList.split('_')[1])
+
+
+class MainApp(QMainWindow, Ui_MainWindow):
+
+    def __init__(self):
+        QMainWindow.__init__(self)
+        self.setupUi(self)
+
+        self.SetBaseInfo()
+        self.InitMenuBar()
+        self.HandleButtons()
+        self.SetUI()
+        self.setFixedSize(self.width(), self.height())
+        self.SetLogText()
+        self.progressBar.setValue(0)
+        self.InitCheckBox()
+
+    def InitCheckBox(self):
+        # self.txtFileCheckBox.setChecked(True)  # 默认保存Txt
+        # self.deleteFileCheckBox.setChecked(False)  # 默认保留源目录
+        # self.copyToOutput.setChecked(True)  # 默认使用复制的方式
+        self.txtFileCheckBox.setChecked(False)  # 默认不保存Txt
+        self.deleteFileCheckBox.setChecked(True)  # 默认不保留源目录
+        self.moveToOutput.setChecked(True)  # 默认不使用复制的方式
+
+    def MutiThreadCopy(self, mp4List, outputPath):
+        t = threading.Thread(target=FileOperator.CopyFile, args=(mp4List, outputPath))
+        t.start()
+        t.join()
+
+    def MutiThreadMove(self, mp4List, outputPath):
+        t = threading.Thread(target=FileOperator.MoveFile, args=(mp4List, outputPath))
+        t.start()
+        t.join()
+
+    def CheckIsChecked(self):
+        self.isSaveTxt = self.txtFileCheckBox.isChecked()
+        self.isDeleteDir = self.deleteFileCheckBox.isChecked()
+
+        if self.copyToOutput.isChecked() or self.moveToOutput.isChecked():
+            pass
+        else:
+            QMessageBox.critical(self, "错误", "请至少勾选一种输出方式!")
+
+        if self.copyToOutput.isChecked():
+            self.isCopyOutput = True
+        else:
+            self.isCopyOutput = False
+
+        if self.moveToOutput.isChecked():
+            self.isMoveOutput = True
+        else:
+            self.isMoveOutput = False
+
+    def SetLogText(self):
+        self.activityLogEdit.setReadOnly(True)
+
+    def Log(self, msg):
+        self.statusbar.showMessage(msg)
+        self.activityLogEdit.appendPlainText('[{0}]'.format(str(datetime.datetime.now())[0:19]))
+        self.activityLogEdit.appendPlainText(msg)
+        self.activityLogEdit.appendPlainText('')
+
+    def LogOnBar(self, msg):
+        self.statusbar.showMessage(msg)
+
+    def HandleButtons(self):
+        self.downloadDirButton.clicked.connect(self.OpenDownloadDir)
+        self.outputDirButton.clicked.connect(self.OpenOutputDir)
+        self.renameButton.clicked.connect(self.RenameFile)
+
+        self.copyToOutput.clicked.connect(self.DisableMove)
+        self.moveToOutput.clicked.connect(self.DisableCopy)
+
+    def DisableCopy(self):
+        if self.copyToOutput.isChecked():
+            self.copyToOutput.setChecked(False)
+
+    def DisableMove(self):
+        if self.moveToOutput.isChecked():
+            self.moveToOutput.setChecked(False)
+
+    def InitMenuBar(self):
+        # 添加menu“帮助”的事件
+        aboutAction = QAction('&关于', self)
+        # aboutAction.setStatusTip('关于')
+        aboutAction.triggered.connect(self.ShowAboutDialog)
+
+        # 已有菜单栏,此处只需要添加菜单
+        mainPageMenu = self.menubar.addMenu('&主页')
+        helpMenu = self.menubar.addMenu('&帮助')
+
+        # 菜单绑定之前添加的事件
+        helpMenu.addAction(aboutAction)
+
+    # 设置UI
+    def SetUI(self):
+        tmp = open('tmp.png', "wb+")
+        tmp.write(base64.b64decode(img))
+        tmp.close()
+        icon = QIcon('tmp.png')
+        os.remove("tmp.png")
+        self.setWindowIcon(icon)
+
+    def ShowAboutDialog(self):
+        about_text = "<p>描述:这是一个致力于解决BiliBiLi UWP版下载视频的名称十分反人类的痛点的软件</p><p>版本:1.0</p><p>@Author:LZY</p><p>@github:love" \
+                     "-in-cpp</p> "
+        QMessageBox.about(self, '说明', about_text)
+
+    def OpenDownloadDir(self):
+        dName = QFileDialog.getExistingDirectory(self, '选择文件夹', '/')
+        self.downloadDirEdit.setText(dName)
+
+    def OpenOutputDir(self):
+        dName = QFileDialog.getExistingDirectory(self, '选择文件夹', '/')
+        self.outputDirEdit.setText(dName)
+
+    def SetBaseInfo(self):
+        self.setWindowTitle('BiliBili UWP版视频下载整理工具')
+        self.downloadDirEdit.setToolTip(r"例如:E:\BiliDownload\44938322")
+        self.downloadDirEdit.setPlaceholderText("路径请具体到下载的视频对应的单个文件夹,暂不支持批量处理")
+        self.outputDirEdit.setPlaceholderText("您希望处理后的文件被保存到的地方")
+
+    # def FindFiles(self,downloadPath):
+
+    def RenameFile(self):
+        self.CheckIsChecked()
+        # 进入目录查找dvi文件
+        downloadPath = self.downloadDirEdit.toPlainText()
+
+        if os.path.isdir(downloadPath) is False:
+            self.Log('UWP下载目录的路径存在非法输入!')
+
+        else:
+            self.Log("进入目录:{0}".format(downloadPath))
+            dviInfoList = FileOperator.GetDviInfo(downloadPath)  # 获取dvi文件信息
+            if dviInfoList[0] is False:
+                self.Log('没有找到.dvi文件!请检查下载目录后重试!')
+
+            else:
+
+                self.Log("开始爬取BV:{0}, 标题:{1} 的所有视频标题,请稍后...".format(dviInfoList[1], dviInfoList[3]))
+                TitleSpider.GetTxt(dviInfoList[1])  # 调用爬虫
+                global fileName
+                fileName = TitleSpider.fileName
+                self.LogOnBar('已成功爬取文件:  {0} !  注:只显示部分文件名'.format(fileName[0:35]))
+                self.Log('已成功爬取文件:  {0} !'.format(fileName))
+
+                # 找到所有downloadPath的.mp4文件
+                mp4List = FileOperator.FindAllMp4Files(downloadPath)[0]  # mp4真正在的地方
+
+                # Log
+                mp4nameList = FileOperator.FindAllMp4Files(downloadPath)[1]
+                mp4nameList.sort(key=GetSeries)
+                s = "查询到以下mp4文件:\n"
+                for item in mp4nameList:
+                    s += (item + '\n')
+                self.Log(s)
+
+                # 复制
+                outputPath = self.outputDirEdit.toPlainText()
+                if os.path.isdir(outputPath) is False:
+                    self.Log('输出目录的路径存在非法输入!')
+                else:
+                    self.CopyOrMove(self.isCopyOutput, mp4List, outputPath)
+
+                    # 重命名
+                    self.Log("开始重命名...")
+                    FileOperator.DoRename(outputPath, fileName)
+                    self.Log("重命名完毕!")
+
+                    # 进度条100%
+                    self.progressBar.setValue(100)
+                    # 是否保存.txt文件
+                    if self.isSaveTxt is True:
+                        pass
+                    else:
+                        self.Log("正在删除程序运行过程中产生的.txt文件")
+                        FileOperator.DeleteTxt(os.getcwd(), fileName)
+                        self.Log("删除.txt文件成功!")
+                    # 是否删除源文件夹
+                    if self.isDeleteDir is True:
+                        self.Log("正在删除源文件夹")
+                        FileOperator.DeleteDir(downloadPath)
+                        self.Log("删除源文件夹成功!")
+                    else:
+                        pass
+                    # 重命名输出文件夹 搁置
+
+    # 输出方式:复制或移动
+    def CopyOrMove(self, isCopyTo, mp4List, outputPath):
+        if isCopyTo is True:
+            self.Log("进入目录:{0}".format(outputPath))
+            self.Log("开始复制... 这可能需要一段时间...")
+            self.MutiThreadCopy(mp4List, outputPath)  # 多线程复制
+            self.Log("复制完毕!")
+        else:
+            self.Log("进入目录:{0}".format(outputPath))
+            self.Log("开始移动... 这可能需要一段时间...")
+            self.MutiThreadMove(mp4List, outputPath)  # 多线程移动
+            self.Log("移动完毕!")
+
+
+if __name__ == '__main__':
+    app = QApplication([])
+    window = MainApp()
+    window.show()
+    app.exec_()

Some files were not shown because too many files changed in this diff