Skip to content

Commit 5f0243f

Browse files
authored
v1.9.0: 支持登录禁漫、优化正则表达式 (#20)
1 parent 0c8b3f4 commit 5f0243f

13 files changed

+98
-354
lines changed

.github/workflows/action_run_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
matrix:
1414
python-version: [ 3.7, 3.8, 3.9, "3.10", "3.11" ]
15-
os: [ ubuntu-latest, macos-latest ]
15+
os: [ ubuntu-latest ]
1616
runs-on: ${{ matrix.os }}
1717
timeout-minutes: 5
1818

.github/workflows/action_workflow_local.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ jobs:
3636
pip install -e ./
3737
3838
- name: 运行下载脚本
39+
env:
40+
JM_USERNAME: ${{ secrets.JM_USERNAME }}
41+
JM_PASSWORD: ${{ secrets.JM_PASSWORD }}
3942
run: |
4043
cd ./usage/
4144
python jmcomic_workflows.py

assets/config/workflow_option.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,4 @@ client_config:
2020
- cffi
2121
- cffi_Session
2222
meta_data:
23-
proxies: null
24-
allow_redirects: true
2523
cookies: null

src/jmcomic/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# 模块依赖关系如下:
22
# 被依赖方 <--- 使用方
3-
# config <--- entity <--- toolkit <--- client <--- service <--- option
3+
# config <--- entity <--- toolkit <--- client <--- option
44

5-
__version__ = '1.8.0'
5+
__version__ = '1.9.0'
66

77
from .api import *

src/jmcomic/jm_client.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,37 @@ def get_jmcomic_url(self, postman=None):
192192
def get_jmcomic_url_all(self, postman=None):
193193
return JmModuleConfig.get_jmcomic_url_all(postman or self)
194194

195+
def login(self,
196+
username,
197+
password,
198+
refresh_client_cookies=True,
199+
id_remember='on',
200+
login_remember='on',
201+
):
202+
203+
data = {
204+
'username': username,
205+
'password': password,
206+
'id_remember': id_remember,
207+
'login_remember': login_remember,
208+
'submit_login': '',
209+
}
210+
211+
resp = self \
212+
.get_root_postman() \
213+
.post(self.of_api_url('/login'),
214+
data=data,
215+
allow_redirects=False,
216+
)
217+
218+
if resp.status_code != 301:
219+
raise AssertionError(f'登录失败,状态码为{resp.status_code}')
220+
221+
if refresh_client_cookies is True:
222+
self['cookies'] = resp.cookies
223+
224+
return resp
225+
195226
@classmethod
196227
def require_resp_success_else_raise(cls, resp, url):
197228
# 1. 是否 album_missing
@@ -212,28 +243,3 @@ def check_special_html(cls, html: str, url=None):
212243
return
213244

214245
raise AssertionError(f'{error_msg}' + f': {url}' if url is not None else '')
215-
216-
217-
# 爬取策略
218-
class FetchStrategy:
219-
220-
def __init__(self,
221-
from_index,
222-
photo_len,
223-
resp_getter,
224-
resp_consumer,
225-
):
226-
self.from_index = from_index
227-
self.photo_len = photo_len
228-
self.resp_getter = resp_getter
229-
self.resp_consumer = resp_consumer
230-
231-
def do_fetch(self):
232-
raise NotImplementedError
233-
234-
def args(self):
235-
return (self.from_index,
236-
self.photo_len,
237-
self.resp_getter,
238-
self.resp_consumer,
239-
)

src/jmcomic/jm_config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def domain(cls, postman=None):
3838
这样一来,配置文件也不用配置域名了,一切都在运行时动态获取。
3939
"""
4040
if cls._DOMAIN is None:
41-
cls._DOMAIN = cls.get_jmcomic_url(postman).replace(cls.PROT, '')
41+
from .jm_toolkit import JmcomicText
42+
cls._DOMAIN = JmcomicText.parse_to_jm_domain(cls.get_jmcomic_url(postman))
4243

4344
return cls._DOMAIN # jmcomic默认域名
4445

@@ -81,7 +82,8 @@ def get_jmcomic_url(cls, postman=None):
8182
from common import Postmans
8283
postman = Postmans.get_impl_clazz('cffi_Session').create()
8384

84-
url = postman.with_redirect_catching().get(cls.JM_REDIRECT_URL)
85+
resp = postman.get(cls.JM_REDIRECT_URL)
86+
url = resp.url
8587
cls.jm_debug('获取禁漫地址', f'[{cls.JM_REDIRECT_URL}] → [{url}]')
8688
return url
8789

src/jmcomic/jm_entity.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ def is_single_album(self) -> bool:
126126
return self._series_id == 0
127127

128128
@property
129-
def keyword_list(self) -> List[str]:
129+
def keywords(self) -> List[str]:
130+
if self.from_album is not None:
131+
return self.from_album.keywords
132+
130133
return self._keywords.split(',')
131134

132135
@property
@@ -204,6 +207,7 @@ def __init__(self,
204207
episode_list,
205208
page_count,
206209
author_list,
210+
keywords_list,
207211
pub_date,
208212
update_date,
209213
):
@@ -212,6 +216,7 @@ def __init__(self,
212216
self.title: str = title
213217
self.page_count = int(page_count)
214218
self._author_list: List[str] = author_list
219+
self._keywords_list: List[str] = keywords_list
215220
self.pub_date: str = pub_date # 发布日期
216221
self.update_date: str = update_date # 更新日期
217222

@@ -254,6 +259,10 @@ def author(self):
254259
return self._author_list[0]
255260
return JmModuleConfig.default_author
256261

262+
@property
263+
def keywords(self) -> List[str]:
264+
return self._keywords_list
265+
257266
def get_id(self):
258267
return self.album_id
259268

src/jmcomic/jm_option.py

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .jm_service import *
1+
from .jm_client import *
22

33

44
class JmOptionAdvice:
@@ -431,58 +431,6 @@ def handle_postman():
431431

432432
return client
433433

434-
"""
435-
下面的方法是对【CdnOption】的支持,已弃用
436-
"""
437-
438-
def build_cdn_option(self, use_multi_thread_strategy=True):
439-
440-
return CdnConfig.create(
441-
cdn_domain=self.client_config.get('domain', JmModuleConfig.domain()),
442-
fetch_strategy=MultiThreadFetch if use_multi_thread_strategy else InOrderFetch,
443-
cdn_image_suffix=None,
444-
use_cache=self.download_use_disk_cache,
445-
decode_image=self.download_image_then_decode
446-
)
447-
448-
def build_cdn_crawler(self, use_multi_thread_strategy=True):
449-
return CdnFetchService(self.build_cdn_option(use_multi_thread_strategy),
450-
self.build_jm_client())
451-
452-
def build_cdn_request(self,
453-
photo_id: str,
454-
scramble_id=str(JmModuleConfig.SCRAMBLE_10),
455-
from_index=1,
456-
photo_len=None,
457-
use_default=False
458-
) -> CdnRequest:
459-
return CdnRequest.create(
460-
photo_id,
461-
self.build_save_path_provider(use_default, None if use_default else photo_id),
462-
scramble_id,
463-
from_index,
464-
photo_len,
465-
)
466-
467-
def build_save_path_provider(self,
468-
use_all_default_save_path,
469-
photo_id=None,
470-
) -> CdnRequest.SavePathProvider:
471-
472-
if use_all_default_save_path is True:
473-
# 不通过请求获取 photo 的信息,相当于使用【空本子】和【空集】
474-
photo_detail = None
475-
else:
476-
# 通过请求获得 photo 的本子信息
477-
photo_detail = self.build_jm_client().get_photo_detail(photo_id)
478-
479-
def save_path_provider(url, _suffix: str, _index, _is_decode):
480-
return '{0}{1}{2}'.format(self.decide_image_save_dir(photo_detail),
481-
of_file_name(url, trim_suffix=True),
482-
self.download_convert_image_suffix or _suffix)
483-
484-
return save_path_provider
485-
486434

487435
def _register_yaml_constructor():
488436
from yaml import add_constructor, Loader, Node

0 commit comments

Comments
 (0)