Skip to content

Commit 7bcc28f

Browse files
authored
v2.4.5: 修正搜索页面的tag标签的正则表达式,增加自动关闭无意义PR的工作流 (#170)
1 parent 6ab7456 commit 7bcc28f

File tree

6 files changed

+77
-21
lines changed

6 files changed

+77
-21
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Close specific PR
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'usage/workflow_download.py'
7+
types: [opened, ]
8+
9+
jobs:
10+
close_pr:
11+
env:
12+
comment: |
13+
To prevent beginners from mistakenly submitting PRs,
14+
if your PR only modifies the usage/workflow_download.py file,
15+
it will be automatically closed.
16+
If you really want to submit a PR, please reopen it yourself.
17+
Make sure you know what you are doing!
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v3
22+
23+
- name: Close PR
24+
run: |
25+
PR_TITLE=$(jq -r ".pull_request.title" $GITHUB_EVENT_PATH)
26+
echo "PR_TITLE: $PR_TITLE"
27+
gh pr comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --body '${{ env.comment }}'
28+
gh pr close ${{ github.event.pull_request.number }} --repo ${{ github.repository }}
29+
env:
30+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,13 @@ $ jmcomic 422866
9393

9494
* config:存放配置文件
9595
* docs:项目文档
96+
9697
* src:存放源代码
9798

9899
* jmcomic:`jmcomic`模块
99-
* tests:测试目录,存放测试代码,使用unittest
100-
* usage:用法目录,存放示例/使用代码
100+
101+
* tests:测试目录,存放测试代码,使用unittest
102+
* usage:用法目录,存放示例/使用代码
101103

102104
## 感谢以下项目
103105

src/jmcomic/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# 被依赖方 <--- 使用方
33
# config <--- entity <--- toolkit <--- client <--- option <--- downloader
44

5-
__version__ = '2.4.4'
5+
__version__ = '2.4.5'
66

77
from .api import *
88
from .jm_plugin import *

src/jmcomic/jm_entity.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class JmBaseEntity:
77

8-
def save_to_file(self, filepath):
8+
def to_file(self, filepath):
99
from common import PackerUtil
1010
PackerUtil.pack(self, filepath)
1111

@@ -21,6 +21,10 @@ def is_photo(cls):
2121
def is_album(cls):
2222
return False
2323

24+
@classmethod
25+
def is_page(cls):
26+
return False
27+
2428

2529
class IndexedEntity:
2630
def getindex(self, index: int):
@@ -508,6 +512,10 @@ def __getitem__(self, item) -> Union[ContentItem, List[ContentItem]]:
508512
def getindex(self, index: int):
509513
return self.content[index]
510514

515+
@classmethod
516+
def is_page(cls):
517+
return True
518+
511519

512520
class JmSearchPage(JmPageContent):
513521

src/jmcomic/jm_option.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,6 @@ def __init__(self,
176176
plugins: Dict,
177177
filepath=None,
178178
):
179-
# 版本号
180-
self.version = JmModuleConfig.JM_OPTION_VER
181179
# 路径规则配置
182180
self.dir_rule = DirRule(**dir_rule)
183181
# 客户端配置
@@ -203,16 +201,6 @@ def decide_image_batch_count(self, photo: JmPhotoDetail):
203201
def decide_photo_batch_count(self, album: JmAlbumDetail):
204202
return self.download.threading.photo
205203

206-
def decide_image_save_dir(self, photo) -> str:
207-
# 使用 self.dir_rule 决定 save_dir
208-
save_dir = self.dir_rule.decide_image_save_dir(
209-
photo.from_album,
210-
photo
211-
)
212-
213-
mkdir_if_not_exists(save_dir)
214-
return save_dir
215-
216204
def decide_album_dir(self, album: JmAlbumDetail) -> str:
217205
"""
218206
该方法目前仅在 plugin-zip 中使用,不建议外部调用
@@ -234,19 +222,40 @@ def decide_album_dir(self, album: JmAlbumDetail) -> str:
234222
from os.path import join
235223
return join(*dir_layer)
236224

237-
def decide_image_suffix(self, image: JmImageDetail):
225+
# noinspection PyMethodMayBeStatic
226+
def decide_image_filename(self, image: JmImageDetail) -> str:
227+
"""
228+
返回图片的文件名,不包含后缀
229+
默认返回禁漫的图片文件名,例如:00001 (.jpg)
230+
"""
231+
return image.filename_without_suffix
232+
233+
def decide_image_suffix(self, image: JmImageDetail) -> str:
234+
"""
235+
返回图片的后缀,如果返回的后缀和原后缀不一致,则会进行图片格式转换
236+
"""
238237
# 动图则使用原后缀
239238
if image.is_gif:
240239
return image.img_file_suffix
241240

242241
# 非动图,以配置为先
243242
return self.download.image.suffix or image.img_file_suffix
244243

244+
def decide_image_save_dir(self, photo) -> str:
245+
# 使用 self.dir_rule 决定 save_dir
246+
save_dir = self.dir_rule.decide_image_save_dir(
247+
photo.from_album,
248+
photo
249+
)
250+
251+
mkdir_if_not_exists(save_dir)
252+
return save_dir
253+
245254
def decide_image_filepath(self, image: JmImageDetail, consider_custom_suffix=True) -> str:
246255
# 通过拼接生成绝对路径
247256
save_dir = self.decide_image_save_dir(image.from_photo)
248257
suffix = self.decide_image_suffix(image) if consider_custom_suffix else image.img_file_suffix
249-
return os.path.join(save_dir, image.filename_without_suffix + suffix)
258+
return os.path.join(save_dir, self.decide_image_filename(image) + suffix)
250259

251260
def decide_download_cache(self, _image: JmImageDetail) -> bool:
252261
return self.download.cache
@@ -322,7 +331,7 @@ def compatible_with_old_versions(cls, dic):
322331

323332
def deconstruct(self) -> Dict:
324333
return {
325-
'version': self.version,
334+
'version': JmModuleConfig.JM_OPTION_VER,
326335
'log': JmModuleConfig.flag_enable_jm_log,
327336
'dir_rule': {
328337
'rule': self.dir_rule.rule_dsl,
@@ -415,7 +424,7 @@ def decide_domain():
415424

416425
client: AbstractJmClient = clazz(
417426
postman=postman,
418-
domain_list=decide_domain(),
427+
domain_list=domain,
419428
retry_times=retry_times,
420429
)
421430

src/jmcomic/jm_toolkit.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,13 @@ def format_url(cls, path, domain):
187187

188188
return f'{JmModuleConfig.PROT}{domain}{path}'
189189

190+
@classmethod
191+
def format_album_url(cls, aid, domain='18comic.vip'):
192+
"""
193+
把album_id变为可访问的URL,方便print打印后用浏览器访问
194+
"""
195+
return cls.format_url(f'/album/{aid}/', domain)
196+
190197
class DSLReplacer:
191198

192199
def __init__(self):
@@ -271,7 +278,7 @@ class JmPageTool:
271278
)
272279

273280
# 用来查找tag列表
274-
pattern_html_search_tag_list = compile(r'<a href=".*?">(.*?)</a>')
281+
pattern_html_search_tag_list = compile(r'<a[^>]*?>(.*?)</a>')
275282

276283
# 查找错误,例如 [错误,關鍵字過短,請至少輸入兩個字以上。]
277284
pattern_html_search_error = compile(r'<fieldset>\n<legend>(.*?)</legend>\n<div class=.*?>\n(.*?)\n</div>\n</fieldset>')

0 commit comments

Comments
 (0)