Skip to content

Commit

Permalink
✨ 时装请求图片格式选项
Browse files Browse the repository at this point in the history
  • Loading branch information
shadlc committed Nov 15, 2024
1 parent ea8def9 commit 29774ba
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 20 deletions.
1 change: 0 additions & 1 deletion src/DownloadManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ def __thread__EpisodeTask(self, curr_id: int, epi: Episode) -> None:
img_url = img["complete_url"]
else:
img_url = img["url"]
img_url = re.sub(r"@[^?]*\?", "", img_url)
match_cpx = re.search(r"[?&]cpx=([^&]*)", img_url)
cpx = match_cpx.group(1) if match_cpx else ""
img_path = epi.downloadImg(index, img_url, cpx)
Expand Down
19 changes: 19 additions & 0 deletions src/Episode.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,25 @@ def _() -> list[dict]:
)
return False

# ?###########################################################
# ? 配置图片下载格式
img_format_list = {
"default": "",
"jpg": "@10000w.jpg",
"webp": "@10000w.webp",
"avif": "@10000w.avif",
"1700jpg": "@1700w.jpg",
"1400jpg": "@1400w.jpg",
"1100jpg": "@1100w.jpg",
"1700webp": "@1700w.webp",
"1400webp": "@1400w.webp",
"1700avif": "@1700w.avif",
"1400avif": "@1400w.avif",
"1100avif": "@1100w.avif",
}
img_format = self.mainGUI.getConfig("img_format")
imgs_urls = [img_url + img_format_list[img_format] for img_url in imgs_urls]

# ?###########################################################
# ? 获取图片token
ImageTokenURL = (
Expand Down
10 changes: 5 additions & 5 deletions src/ui/PySide_src/mainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>524</width>
<height>191</height>
<width>98</width>
<height>28</height>
</rect>
</property>
<layout class="QVBoxLayout" name="v_Layout_myLibrary"/>
Expand Down Expand Up @@ -1097,7 +1097,7 @@ li.checked::marker { content: &quot;\2612&quot;; }
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_img_format">
<widget class="QLabel" name="label_epi_rename_rule">
<property name="text">
<string>章节命名规则:</string>
</property>
Expand Down Expand Up @@ -1166,9 +1166,9 @@ li.checked::marker { content: &quot;\2612&quot;; }
</spacer>
</item>
<item>
<widget class="QLabel" name="label_epi_rename_rule">
<widget class="QLabel" name="label_img_format">
<property name="text">
<string>下载图片格式:</string>
<string>请求图片格式:</string>
</property>
</widget>
</item>
Expand Down
18 changes: 9 additions & 9 deletions src/ui/PySide_src/mainWindow_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def setupUi(self, MainWindow):
self.scrollArea_myLibrary.setWidgetResizable(True)
self.scrollAreaWidgetContents_myLibrary = QWidget()
self.scrollAreaWidgetContents_myLibrary.setObjectName(u"scrollAreaWidgetContents_myLibrary")
self.scrollAreaWidgetContents_myLibrary.setGeometry(QRect(0, 0, 524, 191))
self.scrollAreaWidgetContents_myLibrary.setGeometry(QRect(0, 0, 98, 28))
self.v_Layout_myLibrary = QVBoxLayout(self.scrollAreaWidgetContents_myLibrary)
self.v_Layout_myLibrary.setObjectName(u"v_Layout_myLibrary")
self.scrollArea_myLibrary.setWidget(self.scrollAreaWidgetContents_myLibrary)
Expand Down Expand Up @@ -692,10 +692,10 @@ def setupUi(self, MainWindow):
self.h_Layout_save_prefer = QHBoxLayout()
self.h_Layout_save_prefer.setObjectName(u"h_Layout_save_prefer")
self.h_Layout_save_prefer.setContentsMargins(0, 0, 0, 0)
self.label_img_format = QLabel(self.tab_setting)
self.label_img_format.setObjectName(u"label_img_format")
self.label_epi_rename_rule = QLabel(self.tab_setting)
self.label_epi_rename_rule.setObjectName(u"label_epi_rename_rule")

self.h_Layout_save_prefer.addWidget(self.label_img_format)
self.h_Layout_save_prefer.addWidget(self.label_epi_rename_rule)

self.horizontalSpacer = QSpacerItem(20, 20, QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Minimum)

Expand All @@ -715,10 +715,10 @@ def setupUi(self, MainWindow):

self.h_Layout_save_prefer.addItem(self.horizontalSpacer_15)

self.label_epi_rename_rule = QLabel(self.tab_setting)
self.label_epi_rename_rule.setObjectName(u"label_epi_rename_rule")
self.label_img_format = QLabel(self.tab_setting)
self.label_img_format.setObjectName(u"label_img_format")

self.h_Layout_save_prefer.addWidget(self.label_epi_rename_rule)
self.h_Layout_save_prefer.addWidget(self.label_img_format)

self.horizontalSpacer_14 = QSpacerItem(20, 20, QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Minimum)

Expand Down Expand Up @@ -1025,13 +1025,13 @@ def retranslateUi(self, MainWindow):
self.label_6.setText(QCoreApplication.translate("MainWindow", u"\u6587\u4ef6\u9644\u52a0\u4fe1\u606f\uff1a", None))
self.checkBox_exif_info.setText(QCoreApplication.translate("MainWindow", u"\u662f\u5426\u5728\u4fdd\u5b58\u6587\u4ef6\u5c5e\u6027\u4e2d\u8bb0\u5f55\u7ae0\u8282\u6807\u9898\u3001\u4f5c\u8005\u3001\u51fa\u7248\u793e\u7b49\u9644\u52a0\u4fe1\u606f", None))
self.checkBox_save_meta.setText(QCoreApplication.translate("MainWindow", u"\u662f\u5426\u521b\u5efa\u6f2b\u753b\u5143\u6570\u636e\u6587\u4ef6", None))
self.label_img_format.setText(QCoreApplication.translate("MainWindow", u"\u7ae0\u8282\u547d\u540d\u89c4\u5219\uff1a", None))
self.label_epi_rename_rule.setText(QCoreApplication.translate("MainWindow", u"\u7ae0\u8282\u547d\u540d\u89c4\u5219\uff1a", None))
self.comboBox_epi_rename_rule.setItemText(0, QCoreApplication.translate("MainWindow", u"\u77ed\u6807\u9898+\u957f\u6807\u9898", None))
self.comboBox_epi_rename_rule.setItemText(1, QCoreApplication.translate("MainWindow", u"\u5e8f\u53f7+\u957f\u6807\u9898", None))
self.comboBox_epi_rename_rule.setItemText(2, QCoreApplication.translate("MainWindow", u"\u5e8f\u53f7+\u77ed\u6807\u9898+\u957f\u6807\u9898", None))
self.comboBox_epi_rename_rule.setItemText(3, QCoreApplication.translate("MainWindow", u"3\u4f4d\u5e8f\u53f7+\u77ed\u6807\u9898+\u957f\u6807\u9898", None))

self.label_epi_rename_rule.setText(QCoreApplication.translate("MainWindow", u"\u4e0b\u8f7d\u56fe\u7247\u683c\u5f0f\uff1a", None))
self.label_img_format.setText(QCoreApplication.translate("MainWindow", u"\u8bf7\u6c42\u56fe\u7247\u683c\u5f0f\uff1a", None))
self.comboBox_img_format.setItemText(0, QCoreApplication.translate("MainWindow", u"\u539f\u59cb\u683c\u5f0f", None))
self.comboBox_img_format.setItemText(1, QCoreApplication.translate("MainWindow", u"\u5168\u5c3a\u5bf8jpg", None))
self.comboBox_img_format.setItemText(2, QCoreApplication.translate("MainWindow", u"\u5168\u5c3a\u5bf8webp", None))
Expand Down
25 changes: 20 additions & 5 deletions src/ui/SettingUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def _(button: QRadioButton, checked: bool) -> None:
if checked:
self.mainGUI.updateConfig("save_method", button.text())
self.mainGUI.signal_information_box.emit(
"修改成功!重新解析章节后生效"
f"修改成功!重新解析章节后生效"
)

for i in range(self.mainGUI.h_Layout_groupBox_save_method.count()):
Expand Down Expand Up @@ -560,12 +560,12 @@ def _(rename_rule: str) -> None:
############################################################

def init_img_format_setting(self) -> None:
"""绑定下载图片格式设置"""
"""绑定请求图片格式设置"""
img_format_list = {
"default": "原始格式",
"10000jpg": "全尺寸jpg",
"10000webp": "全尺寸webp",
"10000avif": "全尺寸avif",
"jpg": "全尺寸jpg",
"webp": "全尺寸webp",
"avif": "全尺寸avif",
"1700jpg": "1700宽jpg",
"1400jpg": "1400宽jpg",
"1100jpg": "1100宽jpg",
Expand All @@ -582,6 +582,17 @@ def init_img_format_setting(self) -> None:

def _(img_format: str) -> None:
self.mainGUI.updateConfig("img_format", reversed_img_format_list[img_format])
self.mainGUI.signal_information_box.emit(
f"已成功切换图片质量至 [{img_format}]!重新解析章节后生效\n"
f"注意!此设置对Biliplus不一定有效"
)
if self.mainGUI.getConfig("save_method") == "PDF" and (
img_format.endswith("webp")
or img_format.endswith("avif")
):
self.mainGUI.signal_message_box.emit(
f"请注意!PDF格式保存时,非JPG格式文件会被二次压缩为JPG编码存入PDF",
)

self.mainGUI.comboBox_img_format.currentTextChanged.connect(_)

Expand All @@ -596,6 +607,10 @@ def init_hash_check_setting(self) -> None:
self.mainGUI.updateConfig("hash_check", True)

def _(checked: bool) -> None:
if not checked:
self.mainGUI.signal_message_box.emit(
f"请注意!图片下载完整性校验已取消,可能会造成缺页与其它预料之外的严重问题!",
)
self.mainGUI.updateConfig("hash_check", checked)

self.mainGUI.checkBox_hash_check.toggled.connect(_)

0 comments on commit 29774ba

Please sign in to comment.