Skip to content

Commit 2e1ad6d

Browse files
authored
Merge-build: v2.7.1
2 parents 90a261f + 4fa4d57 commit 2e1ad6d

File tree

18 files changed

+216
-57
lines changed

18 files changed

+216
-57
lines changed

ComicSpider/settings.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
# Configure a delay for requests for the same website (default: 0)
3434
# See https://docs.scrapy.org/en/latest/topics/settings.html#download-delay
3535
# See also autothrottle settings and docs
36+
AUTOTHROTTLE_ENABLED = True
37+
AUTOTHROTTLE_START_DELAY = 1 # 初始延迟1秒
38+
AUTOTHROTTLE_MAX_DELAY = 20 # 最大延迟60秒
39+
AUTOTHROTTLE_TARGET_CONCURRENCY = 5.0 # 目标并发数
40+
# AUTOTHROTTLE_DEBUG = True # 开启调试查看调整过程
41+
3642
DOWNLOAD_DELAY = 0.5
3743
# The download delay setting will honor only one of:
3844
#CONCURRENT_REQUESTS_PER_DOMAIN = 16

ComicSpider/spiders/basecomicspider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def frame_book_print(self, rets, fm=None, url=None, extra=None, make_preview=Fal
6565
# 向gui传送rets并赋值需要比exp_txt(crawl_only的flag) 和 PreviewBookInfoEnd 早才行
6666
if make_preview:
6767
self(f"[PreviewBookInfoEnd]{url}")
68-
self(f"""<hr><p class="theme-text">{''.join(self.exp_txt)}
68+
self(f"""<hr><p class="theme-text">{''.join(self.exp_txt)}<br>
6969
{font_color(extra, cls='theme-tip')}</p><br>""")
7070
self("[ShowKeepBooks]") # 由于 keep_books 现放在 gui 上,所以最后用 flag 形式触发
7171
else:
@@ -80,7 +80,7 @@ def frame_section_print(self, rets, fm, print_limit=5, extra=None):
8080
batch = formatted_items[i:i + print_limit]
8181
self(", ".join(batch))
8282
self(rets)
83-
self(f"""<hr><p class="theme-text">{''.join(self.exp_txt)}{font_color(extra, cls='theme-highlight')}</p><br>""")
83+
self(f"""<hr><p class="theme-text">{''.join(self.exp_txt)}<br>{font_color(extra, cls='theme-highlight')}</p>""")
8484
return rets
8585

8686

GUI/browser_window.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,62 @@ def __init__(self, parent=None):
4949
self.setPage(custom_page)
5050

5151

52+
class ZoomManager:
53+
_default = 1.0
54+
_step = 0.05
55+
_min = 0.25
56+
_max = 5.0
57+
58+
def __init__(self, browser):
59+
self.browser = browser
60+
self.view = browser.view
61+
self._current = self._default
62+
self.browser.zoomInBtn.clicked.connect(self._on_zoom_in_clicked)
63+
self.browser.zoomOutBtn.clicked.connect(self._on_zoom_out_clicked)
64+
self.view.loadFinished.connect(self._on_load_finished)
65+
66+
@property
67+
def current(self):
68+
return self._current
69+
70+
@property
71+
def can_zoom_in(self):
72+
return self._current < self._max - 1e-6
73+
74+
@property
75+
def can_zoom_out(self):
76+
return self._current > self._min + 1e-6
77+
78+
def set_zoom(self, factor: float):
79+
factor = round(max(self._min, min(self._max, factor)), 2)
80+
self._current = factor
81+
try:
82+
self.view.setZoomFactor(factor)
83+
except Exception:
84+
self.view.page().setZoomFactor(factor)
85+
86+
def reset(self):
87+
self.set_zoom(self._default)
88+
89+
def _on_load_finished(self, ok: bool):
90+
if ok:
91+
self.set_zoom(self._current)
92+
93+
def _on_zoom_in_clicked(self):
94+
if self.can_zoom_in:
95+
self.set_zoom(self._current + self._step)
96+
self._update_zoom_buttons()
97+
98+
def _on_zoom_out_clicked(self):
99+
if self.can_zoom_out:
100+
self.set_zoom(self._current - self._step)
101+
self._update_zoom_buttons()
102+
103+
def _update_zoom_buttons(self):
104+
self.browser.zoomInBtn.setEnabled(self.can_zoom_in)
105+
self.browser.zoomOutBtn.setEnabled(self.can_zoom_out)
106+
107+
52108
class BrowserWindow(QMainWindow, Ui_browser):
53109
def __init__(self, gui, proxies: str = None):
54110
super(BrowserWindow, self).__init__()
@@ -68,6 +124,7 @@ def __init__(self, gui, proxies: str = None):
68124
self.load_home()
69125
self.output = []
70126
self.setupUi(self)
127+
self.zoom_mgr = ZoomManager(self)
71128

72129
def set_env_mode(self):
73130
index = self.gui.chooseBox.currentIndex()
@@ -128,6 +185,8 @@ def set_btn(self):
128185
self.refreshBtn.setIcon(FIF.SYNC)
129186
self.copyBtn.setIcon(FIF.COPY)
130187
self.ensureBtn.setIcon(FIF.DOWNLOAD)
188+
self.zoomInBtn.setIcon(FIF.ZOOM_IN)
189+
self.zoomOutBtn.setIcon(FIF.ZOOM_OUT)
131190
# logic
132191
self.homeBtn.clicked.connect(self.load_home)
133192
self.backBtn.clicked.connect(self.view.back)

GUI/gui.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
GuiQueuesManger, refresh_state, crawl_what,
3131
PreviewHtml, TmpFormatHtml
3232
)
33+
from utils.redViewer_tools import show_max
3334
from utils.website import spider_utils_map, InfoMinix
3435
from utils.sql import SqlUtils
3536

@@ -54,6 +55,7 @@ class SpiderGUI(QMainWindow, MitmMainWindow):
5455
web_is_r18 = False
5556
spiderUtils = None
5657
sut = None
58+
bsm: dict = None # books show max
5759

5860
p_crawler: Process = None
5961
p_qm: Process = None
@@ -131,16 +133,20 @@ def finish_setup(self):
131133
self.previewInit = True
132134
self.previewSecondInit = False
133135
self.BrowserWindow = None
136+
self.bsm = None
134137

135138
def chooseBox_changed_handle(index):
136139
if index not in SPIDERS.keys() and index != 0:
137140
self.retrybtn.setEnabled(True)
138141
self.preprocess_mgr.handle_choosebox_changed(index)
139142
return
140143
self.spiderUtils = spider_utils_map[index]
144+
rmt_s2c = True
141145
if index in SPECIAL_WEBSITES_IDXES:
142146
self.web_is_r18 = True
143147
self.sut = self.spiderUtils(conf)
148+
rmt_s2c = False
149+
FluentMonkeyPatch.rbutton_menu_textBrowser(self.textBrowser, index, rmt_s2c)
144150
self.searchinput.setStatusTip(QCoreApplication.translate("MainWindow", STATUS_TIP[index]))
145151
self.searchinput.setEnabled(True)
146152
FluentMonkeyPatch.rbutton_menu_lineEdit(self.searchinput)
@@ -587,7 +593,7 @@ def hook_exception(self, exc_type, exc_value, exc_traceback):
587593
self.say(font_color(rf"<br>{self.res.global_err_hook} <br>[{conf.log_path}\GUI.log]<br>", cls='theme-err', size=5))
588594

589595
def do_publish(self):
590-
with open(ori_path.joinpath('assets/pubilsh_helper.html')) as f:
596+
with open(ori_path.joinpath('assets/pubilsh_helper.html'), encoding='utf-8') as f:
591597
format_text = f.read()
592598
html = format_text.replace("{bs_theme}", bs_theme()) \
593599
.replace("{publish_url}", self.spiderUtils.publish_url)
@@ -601,6 +607,7 @@ def do_publish(self):
601607
self.BrowserWindow.show()
602608

603609
def tpd(self, texts):
610+
"""transfer publish-page domians"""
604611
self.BrowserWindow.domain_v = DomainToolView(self)
605612
CustomFlyout.make(
606613
view=self.BrowserWindow.domain_v, target=self.BrowserWindow, parent=self.BrowserWindow
@@ -617,3 +624,12 @@ def open_url_by_browser(self, url):
617624
self.BrowserWindow.setGeometry(rect)
618625
self.BrowserWindow.view.load(QUrl(url))
619626
self.BrowserWindow.show()
627+
628+
def show_max(self):
629+
self.bsm = self.bsm or show_max()
630+
bc_name = self.book_choose[0].name
631+
bookShow = self.bsm.get(bc_name) or self.bsm.get(self.searchinput.text().strip())
632+
if bookShow:
633+
self.say(font_color(bookShow.show, cls='theme-tip', size=4), ignore_http=True)
634+
635+
# ---

GUI/thread/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ def run(self):
142142
self.gui.show_keep_books()
143143
elif '[httpok]' in _:
144144
self.print_signal.emit('[httpok]' + _.replace('[httpok]', ''))
145+
elif _.endswith(f"{res.SPIDER.SayToGui.frame_section_print_extra}</font></p>"):
146+
self.print_signal.emit(_)
147+
self.gui.show_max()
145148
else:
146149
self.print_signal.emit(_)
147150
self.msleep(2)

GUI/tools/domain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def handle(self, text):
5454
with open(t_f, 'w', encoding='utf-8') as f:
5555
f.write(_domain)
5656
prefix_tip = tools_res.doamin_success_tip % (_domain, t_f)
57-
sc = 6
57+
sc = 4
5858
InfoBar.success(
5959
title='', content=f"{prefix_tip}{tools_res.reboot_tip % str(sc)}",
6060
orient=Qt.Horizontal, isClosable=True, position=InfoBarPosition.TOP,

GUI/tools/rv_tool.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ def deploy(self):
179179
_.show()
180180

181181
def show_max(self):
182-
self.table_fv = CustomFlyout.make(TableFlyoutView(show_max(), self), self.sv_path_card, self)
182+
self.toolWin.gui.bsm = self.toolWin.gui.bsm or show_max()
183+
self.table_fv = CustomFlyout.make(TableFlyoutView(self.toolWin.gui.bsm, self), self.sv_path_card, self)
183184

184185
def combine_then_mv(self):
185186
done = combine_then_mv(conf.sv_path, conf.sv_path.joinpath("web"))

GUI/uic/browser.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ def setupUi(self, browser):
9595
self.addressEdit.setMinimumSize(QtCore.QSize(500, 0))
9696
self.addressEdit.setObjectName("addressEdit")
9797
self.horizontalLayout_2.addWidget(self.addressEdit)
98+
self.zoomInBtn = TransparentToolButton(self.groupBox)
99+
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
100+
sizePolicy.setHorizontalStretch(0)
101+
sizePolicy.setVerticalStretch(0)
102+
sizePolicy.setHeightForWidth(self.zoomInBtn.sizePolicy().hasHeightForWidth())
103+
self.zoomInBtn.setSizePolicy(sizePolicy)
104+
self.zoomInBtn.setMaximumSize(QtCore.QSize(25, 16777215))
105+
self.zoomInBtn.setObjectName("zoomInBtn")
106+
self.horizontalLayout_2.addWidget(self.zoomInBtn)
107+
self.zoomOutBtn = TransparentToolButton(self.groupBox)
108+
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
109+
sizePolicy.setHorizontalStretch(0)
110+
sizePolicy.setVerticalStretch(0)
111+
sizePolicy.setHeightForWidth(self.zoomOutBtn.sizePolicy().hasHeightForWidth())
112+
self.zoomOutBtn.setSizePolicy(sizePolicy)
113+
self.zoomOutBtn.setMaximumSize(QtCore.QSize(25, 16777215))
114+
self.zoomOutBtn.setObjectName("zoomOutBtn")
115+
self.horizontalLayout_2.addWidget(self.zoomOutBtn)
98116
spacerItem = QtWidgets.QSpacerItem(632, 15, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
99117
self.horizontalLayout_2.addItem(spacerItem)
100118
self.copyBtn = TransparentToolButton(self.groupBox)

GUI/uic/qfluent/__init__.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Action, RoundMenu, FluentIcon, PushButton, Flyout, FlyoutAnimationType
55
)
66
from assets import res as ori_res
7-
7+
from utils import extract_eps_range, conf
88
from .components import *
99

1010
__all__ = [
@@ -100,6 +100,38 @@ def _showNumberKeypad():
100100
event.accept()
101101
line_edit.contextMenuEvent = types.MethodType(new_context_menu, line_edit)
102102

103+
@staticmethod
104+
def rbutton_menu_textBrowser(textBrowser, cb_idx, s2c=False):
105+
"""cb_idx: chooseBox index
106+
s2c: send to chooseinput"""
107+
def custom_context_menu(self, event):
108+
cursor = self.textCursor()
109+
selected_text = cursor.selectedText()
110+
fluent_menu = RoundMenu(parent=self)
111+
copy_action = Action(FluentIcon.COPY, text=self.tr("COPY"), triggered=self.copy)
112+
select_all_action = Action(self.tr("Select all"), triggered=self.selectAll)
113+
fluent_menu.addAction(copy_action)
114+
fluent_menu.addAction(select_all_action)
115+
if selected_text:
116+
fluent_menu.addSeparator()
117+
if s2c and textBrowser.gui.next_btn.text() != ori_res.GUI.Uic.next_btnDefaultText:
118+
custom_action = Action(FIF.PENCIL_INK, "解析选中项发至序号输入框",
119+
triggered=lambda: send_to_chooseinput(selected_text))
120+
fluent_menu.addAction(custom_action)
121+
custom_action = Action(text="将选中文本加进预设",
122+
triggered=lambda: set_to_completer(selected_text))
123+
fluent_menu.addAction(custom_action)
124+
fluent_menu.exec(event.globalPos())
125+
event.accept()
126+
def send_to_chooseinput(text):
127+
out_text = extract_eps_range(text)
128+
textBrowser.gui.chooseinput.setText(out_text)
129+
def set_to_completer(text):
130+
conf.completer[cb_idx].insert(0, text)
131+
conf.update()
132+
textBrowser.gui.set_completer()
133+
textBrowser.contextMenuEvent = types.MethodType(custom_context_menu, textBrowser)
134+
103135
@staticmethod
104136
def rbutton_menu_WebEngine(browserWindow):
105137
def custom_context_menu(self, event):

GUI/uic/qfluent/components/cust.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ class TableFlyoutView(FlyoutViewBase):
212212
def __init__(self, data, parent=None):
213213
super().__init__(parent)
214214
self.rvInterface = parent
215+
self.gui = parent.toolWin.gui
215216
p_width = parent.width()
216217
p_height = parent.height()
217218
self.width = int(p_width * 0.8)
@@ -231,10 +232,10 @@ def __init__(self, data, parent=None):
231232
self.closeBtn.clicked.connect(self.closed)
232233
self.delBtn = PrimaryPushButton(FluentIcon.DELETE, "删除选中记录", self)
233234
self.delBtn.clicked.connect(self.delete_selected_record)
234-
self.sendBtn = PrimaryPushButton(FluentIcon.SEND, "发送选中记录至输入框", self)
235-
self.sendBtn.clicked.connect(self.send_selected_record)
235+
self.searchBtn = PrimaryPushButton(FluentIcon.SEARCH, "搜索选中记录", self)
236+
self.searchBtn.clicked.connect(self.send_selected_record)
236237
second_row.addWidget(self.delBtn)
237-
second_row.addWidget(self.sendBtn)
238+
second_row.addWidget(self.searchBtn)
238239
second_row.addItem(spacerItem)
239240
second_row.addWidget(self.closeBtn)
240241

@@ -243,7 +244,7 @@ def __init__(self, data, parent=None):
243244
# 必须设置视图尺寸
244245
self.setFixedSize(self.width, self.height)
245246

246-
def set_table(self, data: t.List[BookShow]):
247+
def set_table(self, data: t.Dict[str, BookShow]):
247248
self.tableView = TableView(self)
248249
self.tableView.setBorderRadius(15)
249250
self.tableView.setWordWrap(False)
@@ -254,14 +255,16 @@ def set_table(self, data: t.List[BookShow]):
254255
# 设置数据模型
255256
model = QStandardItemModel()
256257
model.setHorizontalHeaderLabels(["漫画", "已阅最新章节", "已下载最新章节"])
257-
for book in data:
258+
for book in data.values():
258259
row = [
259260
QStandardItem(book.name),
260261
QStandardItem(book.show_max),
261262
QStandardItem(book.dl_max)
262263
]
263264
model.appendRow(row)
264265
self.tableView.setModel(model)
266+
self.tableView.setSortingEnabled(True)
267+
self.tableView.horizontalHeader().setSortIndicatorShown(True)
265268
self.tableView.horizontalHeader().setStretchLastSection(True)
266269
# 调整列宽
267270
self.tableView.setColumnWidth(0, int(tb_width * 0.5))
@@ -291,21 +294,29 @@ def send_selected_record(self):
291294
selection_model = self.tableView.selectionModel()
292295
if not selection_model.hasSelection():
293296
InfoBar.warning(
294-
title='', content='请先选择要发送的记录',
295-
orient=Qt.Horizontal, isClosable=True, position=InfoBarPosition.BOTTOM_LEFT,
296-
duration=5000, parent=self.rvInterface
297+
title='', content='请先选择行',
298+
orient=Qt.Horizontal, isClosable=True, position=InfoBarPosition.BOTTOM_RIGHT,
299+
duration=5000, parent=self.rvInterface.table_fv
300+
)
301+
return
302+
elif self.gui.chooseBox.currentIndex() == 0:
303+
InfoBar.warning(
304+
title='', content='请先选择搜索源',
305+
orient=Qt.Horizontal, isClosable=True, position=InfoBarPosition.BOTTOM_RIGHT,
306+
duration=5000, parent=self.rvInterface.table_fv
297307
)
298308
return
299309
selected_indexes = selection_model.selectedRows()
300310
row = selected_indexes[0].row()
301311
model = self.tableView.model()
302312
book_name = model.item(row, 0).text()
303313
def do():
304-
self.rvInterface.toolWin.gui.searchinput.setText(book_name)
314+
self.gui.searchinput.setText(book_name)
315+
self.gui.next_btn.click()
305316
InfoBar.info(
306-
title='', content=f'「{book_name}已发至输入框',
317+
title='', content=f'「{book_name}已发至输入框进行搜索中',
307318
orient=Qt.Horizontal, isClosable=True, position=InfoBarPosition.BOTTOM,
308-
duration=2000, parent=self.rvInterface.toolWin.gui.textBrowser
319+
duration=2000, parent=self.gui.textBrowser
309320
)
310321
QTimer.singleShot(10, do)
311322
self.rvInterface.table_fv.close()

0 commit comments

Comments
 (0)