Skip to content

Commit 50f085b

Browse files
authored
v2.0.1: 临时优化正则表达式,并增加关于配置禁漫域名的示例option (#42)
1 parent d9a6940 commit 50f085b

File tree

6 files changed

+24
-9
lines changed

6 files changed

+24
-9
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ jmcomic.download_album('422866') # 传入要下载的album的id,即可下载
5050

5151
* Python >= 3.7
5252
* 项目只有代码注释,没有API文档。因此想深入高级地使用,自行看源码和改造代码叭 ^^_
53-
* JM不是前后端分离的网站,因此本api是通过正则表达式解析HTML网页的信息(详见`JmcomicText`),进而实现的下载图片。
5453

5554
## 项目文件夹介绍
5655

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
client:
2+
domain:
3+
- jm-comic.org
4+
- jm-comic2.cc

src/jmcomic/__init__.py

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

5-
__version__ = '2.0.0'
5+
__version__ = '2.0.1'
66

77
from .api import *

src/jmcomic/jm_entity.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def __init__(self,
104104
):
105105
self.photo_id: str = photo_id
106106
self.scramble_id: str = scramble_id
107-
self.title: str = title
107+
self.title: str = str(title).strip()
108108
self.sort: int = int(sort)
109109
self._keywords: str = keywords
110110
self._series_id: int = int(series_id)
@@ -134,6 +134,10 @@ def keywords(self) -> List[str]:
134134

135135
return self._keywords.split(',')
136136

137+
@property
138+
def indextitle(self):
139+
return f'第{self.album_index}{self.title}'
140+
137141
@property
138142
def album_id(self) -> str:
139143
return self.photo_id if self.is_single_album else str(self._series_id)

src/jmcomic/jm_option.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ class DirRule:
6969
'Bd_Aid_Pindex', # 禁漫网站的默认下载方式
7070
# 根目录 / Album-作者 / Album-标题 / Photo-序号 /
7171
'Bd_Aauthor_Atitle_Pindex',
72+
# 根目录 / Photo-序号&标题 /
73+
'Bd_Pindextitle',
74+
# 根目录 / Photo-自定义类属性 /
75+
'Bd_Aauthor_Atitle_Pcustomfield', # 使用自定义类属性前,需替换 JmcomicText的 PhotoClass / AlbumClass
7276
]
7377

7478
RuleFunc = Callable[[Union[JmAlbumDetail, JmPhotoDetail, None]], str]

src/jmcomic/jm_toolkit.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class JmcomicText:
2121
pattern_html_album_album_id = compile('<span class="number">.*?:JM(\d+)</span>')
2222
pattern_html_album_scramble_id = compile('var scramble_id = (\d+);')
2323
pattern_html_album_title = compile('panel-heading[\s\S]*?<h1>(.*?)</h1>')
24-
pattern_html_album_episode_list = compile('<a href=".*?" data-album="(\d+)">\n'
25-
'<li.*>\n(\d+)話\n(.*)\n'
24+
pattern_html_album_episode_list = compile('data-album="(\d+)">\n *?<li.*?>\n *'
25+
'(\d+)話\n(.*)\n *'
2626
'<[\s\S]*?>(\d+-\d+-\d+).*?')
2727
pattern_html_album_page_count = compile('<span class="pagecount">.*?:(\d+)</span>')
2828
pattern_html_album_pub_date = compile('>上架日期 : (.*?)</span>')
@@ -87,20 +87,24 @@ def analyse_jm_pub_html(cls, html: str, domain_keyword=('jm', 'comic')) -> List[
8787
domain_ls
8888
))
8989

90+
# 可以替换下面两个类为用户自定义的、二次继承的类
91+
PhotoClass = JmPhotoDetail
92+
AlbumClass = JmAlbumDetail
93+
9094
@classmethod
91-
def analyse_jm_photo_html(cls, html: str) -> JmPhotoDetail:
95+
def analyse_jm_photo_html(cls, html: str) -> PhotoClass:
9296
return cls.reflect_new_instance(
9397
html,
9498
"pattern_html_photo_",
95-
JmPhotoDetail
99+
cls.PhotoClass
96100
)
97101

98102
@classmethod
99-
def analyse_jm_album_html(cls, html: str) -> JmAlbumDetail:
103+
def analyse_jm_album_html(cls, html: str) -> AlbumClass:
100104
return cls.reflect_new_instance(
101105
html,
102106
"pattern_html_album_",
103-
JmAlbumDetail
107+
cls.AlbumClass
104108
)
105109

106110
@classmethod

0 commit comments

Comments
 (0)