mirror of
https://github.com/hect0x7/JMComic-Crawler-Python.git
synced 2025-11-04 14:49:43 +08:00
v2.2.11: 修复命令行模式下option未配置的问题,优化GitHub Actions工作流,更新common依赖版本 (#134)
This commit is contained in:
parent
f6f2d273a7
commit
c5810d9535
8
.github/workflows/download_dispatch.yml
vendored
8
.github/workflows/download_dispatch.yml
vendored
@ -6,7 +6,12 @@ on:
|
|||||||
JM_ALBUM_IDS:
|
JM_ALBUM_IDS:
|
||||||
type: string
|
type: string
|
||||||
description: 本子id(多个id用-隔开,如 '123-456-789')
|
description: 本子id(多个id用-隔开,如 '123-456-789')
|
||||||
required: true
|
required: false
|
||||||
|
|
||||||
|
JM_PHOTO_IDS:
|
||||||
|
type: string
|
||||||
|
description: 章节id(可以单独下载某个本子的某个章节,多个id用-隔开(同上))
|
||||||
|
required: false
|
||||||
|
|
||||||
DIR_RULE:
|
DIR_RULE:
|
||||||
type: string
|
type: string
|
||||||
@ -45,6 +50,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
# 工作流输入
|
# 工作流输入
|
||||||
JM_ALBUM_IDS: ${{ github.event.inputs.JM_ALBUM_IDS }}
|
JM_ALBUM_IDS: ${{ github.event.inputs.JM_ALBUM_IDS }}
|
||||||
|
JM_PHOTO_IDS: ${{ github.event.inputs.JM_PHOTO_IDS }}
|
||||||
DIR_RULE: ${{ github.event.inputs.DIR_RULE }}
|
DIR_RULE: ${{ github.event.inputs.DIR_RULE }}
|
||||||
ZIP_NAME: ${{ github.event.inputs.ZIP_NAME }}
|
ZIP_NAME: ${{ github.event.inputs.ZIP_NAME }}
|
||||||
UPLOAD_NAME: ${{ github.event.inputs.UPLOAD_NAME }}
|
UPLOAD_NAME: ${{ github.event.inputs.UPLOAD_NAME }}
|
||||||
|
|||||||
2
setup.py
2
setup.py
@ -27,7 +27,7 @@ setup(
|
|||||||
package_dir={"": "src"},
|
package_dir={"": "src"},
|
||||||
python_requires=">=3.7",
|
python_requires=">=3.7",
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'commonX>=0.5.3',
|
'commonX>=0.5.6',
|
||||||
'curl_cffi',
|
'curl_cffi',
|
||||||
'PyYAML',
|
'PyYAML',
|
||||||
'Pillow',
|
'Pillow',
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
# 被依赖方 <--- 使用方
|
# 被依赖方 <--- 使用方
|
||||||
# config <--- entity <--- toolkit <--- client <--- option <--- downloader
|
# config <--- entity <--- toolkit <--- client <--- option <--- downloader
|
||||||
|
|
||||||
__version__ = '2.2.9'
|
__version__ = '2.2.11'
|
||||||
|
|
||||||
from .api import *
|
from .api import *
|
||||||
from .jm_plugin import *
|
from .jm_plugin import *
|
||||||
|
|||||||
@ -8,7 +8,7 @@ $ jmcomic 123 456 p333 --option="D:/option.yml"
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
import os.path
|
import os.path
|
||||||
from typing import List
|
from typing import List, Optional
|
||||||
|
|
||||||
|
|
||||||
def get_env(name, default):
|
def get_env(name, default):
|
||||||
@ -23,7 +23,7 @@ def get_env(name, default):
|
|||||||
class JmcomicUI:
|
class JmcomicUI:
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.option_path = None
|
self.option_path: Optional[str] = None
|
||||||
self.raw_id_list: List[str] = []
|
self.raw_id_list: List[str] = []
|
||||||
self.album_id_list: List[str] = []
|
self.album_id_list: List[str] = []
|
||||||
self.photo_id_list: List[str] = []
|
self.photo_id_list: List[str] = []
|
||||||
@ -42,13 +42,16 @@ class JmcomicUI:
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--option',
|
'--option',
|
||||||
help='path to the option file, you can also specify it by env `JM_OPTION_PATH`',
|
help='path to the option file, you can also specify it by env `JM_OPTION_PATH`',
|
||||||
default=get_env('JM_OPTION_PATH', './option.yml'),
|
default=get_env('JM_OPTION_PATH', None),
|
||||||
)
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
if args.option is not None:
|
||||||
self.option_path = os.path.abspath(args.option)
|
self.option_path = os.path.abspath(args.option)
|
||||||
self.raw_id_list = args.id_list
|
else:
|
||||||
|
self.option_path = None
|
||||||
|
|
||||||
|
self.raw_id_list = args.id_list
|
||||||
self.parse_raw_id()
|
self.parse_raw_id()
|
||||||
|
|
||||||
def parse_raw_id(self):
|
def parse_raw_id(self):
|
||||||
@ -75,17 +78,22 @@ class JmcomicUI:
|
|||||||
from .api import jm_debug
|
from .api import jm_debug
|
||||||
jm_debug('command_line',
|
jm_debug('command_line',
|
||||||
f'start downloading...\n'
|
f'start downloading...\n'
|
||||||
f'- using option: [{self.option_path}]\n'
|
f'- using option: [{self.option_path or "default"}]\n'
|
||||||
f'to be downloaded: \n'
|
f'to be downloaded: \n'
|
||||||
f'- album: {self.album_id_list}\n'
|
f'- album: {self.album_id_list}\n'
|
||||||
f'- photo: {self.photo_id_list}')
|
f'- photo: {self.photo_id_list}')
|
||||||
self.run()
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
from .api import download_album, download_photo, create_option
|
|
||||||
from common import MultiTaskLauncher
|
|
||||||
|
|
||||||
|
from .api import create_option, JmOption
|
||||||
|
if self.option_path is not None:
|
||||||
option = create_option(self.option_path)
|
option = create_option(self.option_path)
|
||||||
|
else:
|
||||||
|
option = JmOption.default()
|
||||||
|
|
||||||
|
self.run(option)
|
||||||
|
|
||||||
|
def run(self, option):
|
||||||
|
from .api import download_album, download_photo
|
||||||
|
from common import MultiTaskLauncher
|
||||||
|
|
||||||
if len(self.album_id_list) == 0:
|
if len(self.album_id_list) == 0:
|
||||||
download_photo(self.photo_id_list, option)
|
download_photo(self.photo_id_list, option)
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
from jmcomic import *
|
from jmcomic import *
|
||||||
|
from jmcomic.cl import get_env, JmcomicUI
|
||||||
|
|
||||||
# 下方填入你要下载的本子的id,一行一个。
|
# 下方填入你要下载的本子的id,一行一个。
|
||||||
# 每行的首尾可以有空白字符
|
# 每行的首尾可以有空白字符
|
||||||
@ -12,12 +13,18 @@ jm_albums = '''
|
|||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
# 单独下载章节
|
||||||
|
jm_photos = '''
|
||||||
|
|
||||||
def get_jm_album_ids():
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
def get_id_set(env_name):
|
||||||
aid_set = set()
|
aid_set = set()
|
||||||
for text in [
|
for text in [
|
||||||
jm_albums,
|
jm_albums,
|
||||||
(get_env('JM_ALBUM_IDS') or '').replace('-', '\n'),
|
(get_env(env_name, '')).replace('-', '\n'),
|
||||||
]:
|
]:
|
||||||
aid_set.update(str_to_set(text))
|
aid_set.update(str_to_set(text))
|
||||||
|
|
||||||
@ -25,8 +32,14 @@ def get_jm_album_ids():
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# 下载漫画
|
album_id_set = get_id_set('JM_ALBUM_IDS')
|
||||||
download_album(get_jm_album_ids(), option=get_option())
|
photo_id_set = get_id_set('JM_PHOTO_IDS')
|
||||||
|
|
||||||
|
helper = JmcomicUI()
|
||||||
|
helper.album_id_list = list(album_id_set)
|
||||||
|
helper.photo_id_list = list(photo_id_set)
|
||||||
|
|
||||||
|
helper.run(get_option())
|
||||||
|
|
||||||
|
|
||||||
def get_option():
|
def get_option():
|
||||||
@ -39,18 +52,14 @@ def get_option():
|
|||||||
# 覆盖client实现类,实现把请求错误的html下载到文件,方便GitHub Actions下载查看日志
|
# 覆盖client实现类,实现把请求错误的html下载到文件,方便GitHub Actions下载查看日志
|
||||||
hook_debug(option)
|
hook_debug(option)
|
||||||
|
|
||||||
# 启用 client 的缓存
|
|
||||||
client = option.build_jm_client()
|
|
||||||
client.enable_cache()
|
|
||||||
|
|
||||||
# 登录,如果有配置的话
|
# 登录,如果有配置的话
|
||||||
login_if_configured(client)
|
login_if_configured(option.build_jm_client())
|
||||||
|
|
||||||
return option
|
return option
|
||||||
|
|
||||||
|
|
||||||
def cover_option_config(option: JmOption):
|
def cover_option_config(option: JmOption):
|
||||||
dir_rule = get_env('DIR_RULE')
|
dir_rule = get_env('DIR_RULE', None)
|
||||||
if dir_rule is not None:
|
if dir_rule is not None:
|
||||||
the_old = option.dir_rule
|
the_old = option.dir_rule
|
||||||
the_new = DirRule(dir_rule, base_dir=the_old.base_dir)
|
the_new = DirRule(dir_rule, base_dir=the_old.base_dir)
|
||||||
@ -64,8 +73,8 @@ def login_if_configured(client):
|
|||||||
# 配置的方式很简单,网页上点一点就可以了
|
# 配置的方式很简单,网页上点一点就可以了
|
||||||
# 具体做法请去看官方教程:https://docs.github.com/en/actions/security-guides/encrypted-secrets
|
# 具体做法请去看官方教程:https://docs.github.com/en/actions/security-guides/encrypted-secrets
|
||||||
# 萌新注意!!!如果你想 `开源` 你的禁漫帐号,你也可以直接把账号密码写到下面的代码😅
|
# 萌新注意!!!如果你想 `开源` 你的禁漫帐号,你也可以直接把账号密码写到下面的代码😅
|
||||||
username = get_env('JM_USERNAME')
|
username = get_env('JM_USERNAME', None)
|
||||||
password = get_env('JM_PASSWORD')
|
password = get_env('JM_PASSWORD', None)
|
||||||
if username is not None and password is not None:
|
if username is not None and password is not None:
|
||||||
client.login(username, password, True)
|
client.login(username, password, True)
|
||||||
print_eye_catching(f'登录禁漫成功')
|
print_eye_catching(f'登录禁漫成功')
|
||||||
@ -73,7 +82,7 @@ def login_if_configured(client):
|
|||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
def hook_debug(option):
|
def hook_debug(option):
|
||||||
jm_download_dir = get_env('JM_DOWNLOAD_DIR') or workspace()
|
jm_download_dir = get_env('JM_DOWNLOAD_DIR', workspace())
|
||||||
mkdir_if_not_exists(jm_download_dir)
|
mkdir_if_not_exists(jm_download_dir)
|
||||||
|
|
||||||
class RaiseErrorAwareClient(JmHtmlClient):
|
class RaiseErrorAwareClient(JmHtmlClient):
|
||||||
@ -91,15 +100,5 @@ def hook_debug(option):
|
|||||||
JmModuleConfig.CLASS_CLIENT_IMPL['html'] = RaiseErrorAwareClient
|
JmModuleConfig.CLASS_CLIENT_IMPL['html'] = RaiseErrorAwareClient
|
||||||
|
|
||||||
|
|
||||||
def get_env(name):
|
|
||||||
import os
|
|
||||||
value = os.getenv(name, None)
|
|
||||||
|
|
||||||
if value is None or value == '':
|
|
||||||
return None
|
|
||||||
|
|
||||||
return value
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user