Skip to content

Commit

Permalink
批量下载
Browse files Browse the repository at this point in the history
  • Loading branch information
tonquer committed Jun 30, 2024
1 parent efd2584 commit f9e4688
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 42 deletions.
26 changes: 16 additions & 10 deletions src/interface/ui_download_some.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QHBoxLayout, QHeaderView, QPushButton,
QSizePolicy, QSpacerItem, QTableWidget, QTableWidgetItem,
QVBoxLayout, QWidget)
from PySide6.QtWidgets import (QApplication, QHBoxLayout, QHeaderView, QLabel,
QPushButton, QSizePolicy, QSpacerItem, QTableWidget,
QTableWidgetItem, QVBoxLayout, QWidget)

class Ui_DownloadSome(object):
def setupUi(self, DownloadSome):
if not DownloadSome.objectName():
DownloadSome.setObjectName(u"DownloadSome")
DownloadSome.resize(446, 300)
DownloadSome.resize(755, 300)
self.verticalLayout = QVBoxLayout(DownloadSome)
self.verticalLayout.setObjectName(u"verticalLayout")
self.horizontalLayout = QHBoxLayout()
Expand All @@ -32,6 +32,11 @@ def setupUi(self, DownloadSome):

self.horizontalLayout.addItem(self.horizontalSpacer)

self.totalLabel = QLabel(DownloadSome)
self.totalLabel.setObjectName(u"totalLabel")

self.horizontalLayout.addWidget(self.totalLabel)

self.inputButton = QPushButton(DownloadSome)
self.inputButton.setObjectName(u"inputButton")

Expand All @@ -47,16 +52,16 @@ def setupUi(self, DownloadSome):

self.horizontalLayout.addWidget(self.cleanButton)

self.downButton = QPushButton(DownloadSome)
self.downButton.setObjectName(u"downButton")

self.horizontalLayout.addWidget(self.downButton)

self.nasButton = QPushButton(DownloadSome)
self.nasButton.setObjectName(u"nasButton")

self.horizontalLayout.addWidget(self.nasButton)

self.downButton = QPushButton(DownloadSome)
self.downButton.setObjectName(u"downButton")

self.horizontalLayout.addWidget(self.downButton)


self.verticalLayout.addLayout(self.horizontalLayout)

Expand All @@ -83,11 +88,12 @@ def setupUi(self, DownloadSome):

def retranslateUi(self, DownloadSome):
DownloadSome.setWindowTitle(QCoreApplication.translate("DownloadSome", u"Form", None))
self.totalLabel.setText("")
self.inputButton.setText(QCoreApplication.translate("DownloadSome", u"\u6279\u91cf\u8f93\u5165JM\u53f7", None))
self.loadInfoButton.setText(QCoreApplication.translate("DownloadSome", u"\u83b7\u53d6\u4fe1\u606f", None))
self.cleanButton.setText(QCoreApplication.translate("DownloadSome", u"\u6e05\u7a7a", None))
self.downButton.setText(QCoreApplication.translate("DownloadSome", u"\u4e0b\u8f7d", None))
self.nasButton.setText(QCoreApplication.translate("DownloadSome", u"\u4e0a\u4f20", None))
self.downButton.setText(QCoreApplication.translate("DownloadSome", u"\u4e0b\u8f7d", None))
___qtablewidgetitem = self.tableWidget.horizontalHeaderItem(0)
___qtablewidgetitem.setText(QCoreApplication.translate("DownloadSome", u"JM\u53f7", None));
___qtablewidgetitem1 = self.tableWidget.horizontalHeaderItem(1)
Expand Down
4 changes: 3 additions & 1 deletion src/tools/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ def server(self):
return Server()

def GetBook(self, bookId) -> BookInfo:
return self.books.get(bookId)
if not bookId:
return
return self.books.get(int(bookId))

def UpdateBookInfoList(self, bookList):
for info in bookList:
Expand Down
2 changes: 2 additions & 0 deletions src/tools/str.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class Str:
ImportLocal = 153 # 导入本地漫画中
NotUpdateEps = 154 # 没有可更新的章节
CurRead = 155 # 正在看
CopyIdAndTitle = 156 # 复制ID和标题


@classmethod
Expand Down Expand Up @@ -500,6 +501,7 @@ def Reload(cls):
cls.strDict[cls.ImportLocal] = QCoreApplication.translate("cls.obj", "导入到本地漫画中", None)
cls.strDict[cls.NotUpdateEps] = QCoreApplication.translate("cls.obj", "没有可更新章节", None)
cls.strDict[cls.CurRead] = QCoreApplication.translate("cls.obj", "正在看", None)
cls.strDict[cls.CopyIdAndTitle] = QCoreApplication.translate("cls.obj", "复制ID和标题", None)

@classmethod
def GetStr(cls, enumType, defualt=""):
Expand Down
84 changes: 78 additions & 6 deletions src/view/download/download_some_view.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os
from functools import partial

from PySide6 import QtWidgets
from PySide6.QtCore import Signal
from PySide6.QtWidgets import QFileDialog, QHeaderView, QAbstractItemView, QWidget
from PySide6.QtGui import QCursor
from PySide6.QtWidgets import QFileDialog, QHeaderView, QAbstractItemView, QWidget, QMessageBox

from component.dialog.base_mask_dialog import BaseMaskDialog
from config import config
Expand Down Expand Up @@ -59,6 +62,8 @@ def __init__(self):
self.tableWidget.doubleClicked.connect(self.OpenBookInfo)
self.tableWidget.horizontalHeader().sectionClicked.connect(self.Sort)

self.nasButton.clicked.connect(self.ShowMenu)

def SwitchCurrent(self, **kwargs):
refresh = kwargs.get("refresh")
pass
Expand Down Expand Up @@ -113,6 +118,7 @@ def Start(self):
self.SetEnable(False)
self.loadingBook = []
self.completeBook = []
self.UpdateTotalLabel()
self.completeNum = 0
for v in self.allBookInfo.values():
if v.epsLen <= 0:
Expand All @@ -129,17 +135,19 @@ def Clean(self):
self.allBookInfo.clear()
self.loadingBook = []
self.completeBook = []
self.UpdateTotalLabel()
pass

def StartGetBookInfo(self):
if self.completeNum <= 0:
self.SetEnable(True)
self.UpdateTotalLabel()
return
if not self.loadingBook:
return

bookId = self.loadingBook.pop(0)
info = BookMgr().books.get(bookId)
info = BookMgr().GetBook(bookId)
item = self.allBookInfo[bookId]
if info and info.pageInfo.epsInfo:
item.st = Str.Success
Expand All @@ -160,7 +168,7 @@ def OpenBookBack(self, raw, bookId):
self.StartGetBookInfo()
return
if st == Status.Ok:
info = BookMgr().books.get(bookId)
info = BookMgr().GetBook(bookId)
if not info:
item.st = Str.NotFoundBook
self.UpdateTable(bookId)
Expand Down Expand Up @@ -219,9 +227,73 @@ def UpdateTableRow(self):
if info:
info.rowCount = i

def UpdateTotalLabel(self):
suc = 0
total = 0
for v in self.allBookInfo.values():
if v.epsLen > 0:
suc += 1
total += 1
self.totalLabel.setText("({}/{})".format(suc, total))
return

def Download(self):
suc = 0
for v in self.allBookInfo.values():
if v.epsLen > 0:
suc += 1
if suc <= 0:
return
isDownload = QMessageBox.information(self, '下载', "是否下载{}本".format(suc), QtWidgets.QMessageBox.Yes|QtWidgets.QMessageBox.No)
if isDownload != QtWidgets.QMessageBox.Yes:
return
for v in self.allBookInfo.values():
if v.epsLen > 0:
bookInfo = BookMgr().GetBook(v.bookId)
if not bookInfo:
continue
epsIds = list(bookInfo.pageInfo.epsInfo.keys())
QtOwner().downloadView.AddDownload(v.bookId, epsIds)
QtOwner().ShowMsg(Str.GetStr(Str.AddDownload))
pass


def AddNas(self):

def ShowMenu(self):
toolMenu = QMenu(self.nasButton)
toolMenu.clear()
nasDict = QtOwner().owner.nasView.nasDict
action = toolMenu.addAction(Str.GetStr(Str.NetNas))
action.setEnabled(False)

if not nasDict:
action = toolMenu.addAction(Str.GetStr(Str.CvSpace))
action.setEnabled(False)
else:
for k, v in nasDict.items():
action = toolMenu.addAction(v.showTitle)
action.triggered.connect(partial(self.AddNas, k))
toolMenu.exec(QCursor().pos())

def AddNas(self, nasId):
suc = 0
for v in self.allBookInfo.values():
if v.epsLen > 0:
suc += 1
if suc <= 0:
return

nasDict = QtOwner().owner.nasView.nasDict
nasInfo = nasDict.get(nasId)
if not nasInfo:
return
nasTitle = nasInfo.showTitle
isDownload = QMessageBox.information(self, '上传', "是否上传{}本到({})".format(suc, nasTitle), QtWidgets.QMessageBox.Yes|QtWidgets.QMessageBox.No)
if isDownload != QtWidgets.QMessageBox.Yes:
return
for v in self.allBookInfo.values():
if v.epsLen > 0:
bookInfo = BookMgr().GetBook(v.bookId)
if not bookInfo:
continue
QtOwner().nasView.AddNasUploadCache(nasId, v.bookId)
QtOwner().ShowMsg(Str.GetStr(Str.CvAddUpload))
pass
33 changes: 30 additions & 3 deletions src/view/download/download_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from PySide6 import QtWidgets
from PySide6.QtCore import Qt, QTimer, QUrl
from PySide6.QtGui import QCursor, QDesktopServices, QAction
from PySide6.QtWidgets import QHeaderView, QAbstractItemView, QMenu, QTableWidgetItem, QMessageBox
from PySide6.QtWidgets import QHeaderView, QAbstractItemView, QMenu, QTableWidgetItem, QMessageBox, QApplication

from config import config
from config.setting import Setting
Expand Down Expand Up @@ -173,7 +173,7 @@ def SwitchCurrent(self, **kwargs):
def AddDownload(self, bookId, downloadIds, isWaifu2x=False):
if not downloadIds:
return

bookId = str(bookId)
if bookId not in self.downloadDict:
task = DownloadItem()
task.bookId = bookId
Expand Down Expand Up @@ -269,6 +269,9 @@ def SelectMenu(self, pos):
removeAction = QAction(Str.GetStr(Str.DeleteRecord), self)
removeAction.triggered.connect(self.DelRecording)

copyAction = QAction(Str.GetStr(Str.CopyIdAndTitle), self)
copyAction.triggered.connect(self.CopyIdAndTitle)

removeFileAction = QAction(Str.GetStr(Str.DeleteRecordFile), self)
removeFileAction.triggered.connect(self.DelRecordingAndFile)

Expand Down Expand Up @@ -329,7 +332,7 @@ def SelectMenu(self, pos):
action.setEnabled(False)
else:
for k, v in nasDict.items():
action = nas.addAction(v.title)
action = nas.addAction(v.showTitle)
if QtOwner().nasView.IsInUpload(k, bookId):
action.setEnabled(False)
action.triggered.connect(partial(self.NasUploadHandler, title, k, bookId))
Expand All @@ -343,6 +346,7 @@ def SelectMenu(self, pos):
menu.addAction(pauseConvertAction)

menu.addAction(addLocalAction)
menu.addAction(copyAction)
menu.addAction(removeAction)
menu.addAction(removeFileAction)
menu.exec_(QCursor.pos())
Expand Down Expand Up @@ -487,12 +491,35 @@ def DelRecording(self):
selectRows.add(index.row())
if not selectRows:
return
isRun = QMessageBox.information(self, '删除', "是否删除记录", QtWidgets.QMessageBox.Yes|QtWidgets.QMessageBox.No)
if isRun != QtWidgets.QMessageBox.Yes:
return

for row in sorted(selectRows, reverse=True):
col = 0
bookId = self.tableWidget.item(row, col).text()
self.RemoveRecord(bookId)
self.UpdateTableRow()

def CopyIdAndTitle(self):
selected = self.tableWidget.selectedIndexes()
selectRows = set()
for index in selected:
selectRows.add(index.row())
if not selectRows:
return
text = ""
for row in sorted(selectRows, reverse=True):
col = 0
bookId = self.tableWidget.item(row, col).text()
info = self.downloadDict.get(bookId)
text += "JM{}-{}\r\n".format(bookId, info.title)
clipboard = QApplication.clipboard()
data = text.strip("\r\n")
clipboard.setText(data)
QtOwner().ShowMsg(Str.GetStr(Str.CopySuc))
return

def DelRecordingAndFile(self):
isClear = QMessageBox.information(self, '删除记录', "是否删除记录和文件", QtWidgets.QMessageBox.Yes|QtWidgets.QMessageBox.No)
if isClear != QtWidgets.QMessageBox.Yes:
Expand Down
2 changes: 1 addition & 1 deletion src/view/info/book_eps_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def OpenEpsInfoBack(self, raw):

def UpdateEpsInfo(self):
self.listWidget.clear()
info = BookMgr().books.get(self.bookId)
info = BookMgr().GetBook(self.bookId)
if not info:
return
downloadEpsId = QtOwner().downloadView.GetDownloadEpsId(self.bookId)
Expand Down
6 changes: 3 additions & 3 deletions src/view/info/book_info_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def OpenBookBack(self, raw):
QtOwner().CloseLoading()
self.ClearTags()
self.autorList.clear()
info = BookMgr().books.get(self.bookId)
info = BookMgr().GetBook(self.bookId)
st = raw["st"]
self.UpdateDownloadEps()
if info:
Expand Down Expand Up @@ -305,7 +305,7 @@ def GetEpsBack(self, raw):

def UpdateEpsData(self):
self.epsListWidget.clear()
info = BookMgr().books.get(self.bookId)
info = BookMgr().GetBook(self.bookId)
if not info:
return
assert isinstance(info, BookInfo)
Expand Down Expand Up @@ -541,7 +541,7 @@ def ShowMenu(self):
action.setEnabled(False)
else:
for k, v in nasDict.items():
action = toolMenu.addAction(v.title)
action = toolMenu.addAction(v.showTitle)
if QtOwner().nasView.IsInUpload(k, self.bookId):
action.setEnabled(False)
action.triggered.connect(partial(self.NasUploadHandler, k, self.bookId))
Expand Down
8 changes: 7 additions & 1 deletion src/view/nas/nas_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,10 @@ def __init__(self):
self.is_waifu2x = 0

self.tick = int(time.time())
self.dirty = True
self.dirty = True

@property
def showTitle(self):
if self.is_waifu2x:
return self.title + "(waifu2x)"
return self.title
Loading

0 comments on commit f9e4688

Please sign in to comment.