JMComic-Crawler-Python/usage/workflow_download.py

105 lines
3.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from jmcomic import *
from jmcomic.cl import get_env, JmcomicUI
# 下方填入你要下载的本子的id一行一个。
# 每行的首尾可以有空白字符
# 你也可以填入本子网址程序会识别出本子id
# 例如:
# [https://18comic.vip/album/452859/mana-ディシア-1-原神-中国語-無修正] -> [452859]
#
jm_albums = '''
'''
# 单独下载章节
jm_photos = '''
'''
def get_id_set(env_name):
aid_set = set()
for text in [
jm_albums,
(get_env(env_name, '')).replace('-', '\n'),
]:
aid_set.update(str_to_set(text))
return aid_set
def main():
album_id_set = get_id_set('JM_ALBUM_IDS')
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():
# 读取 option 配置文件
option = create_option('../assets/config/option_workflow_download.yml')
# 支持工作流覆盖配置文件的配置
cover_option_config(option)
# 覆盖client实现类实现把请求错误的html下载到文件方便GitHub Actions下载查看日志
hook_debug(option)
# 登录,如果有配置的话
login_if_configured(option.build_jm_client())
return option
def cover_option_config(option: JmOption):
dir_rule = get_env('DIR_RULE', None)
if dir_rule is not None:
the_old = option.dir_rule
the_new = DirRule(dir_rule, base_dir=the_old.base_dir)
option.dir_rule = the_new
def login_if_configured(client):
# 检查环境变量中是否有禁漫的用户名和密码,如果有则登录
# 禁漫的大部分本子,下载是不需要登录的,少部分敏感题材需要登录
# 如果你希望以登录状态下载本子你需要自己配置一下GitHub Actions的 `secrets`
# 配置的方式很简单,网页上点一点就可以了
# 具体做法请去看官方教程https://docs.github.com/en/actions/security-guides/encrypted-secrets
# 萌新注意!!!如果你想 `开源` 你的禁漫帐号,你也可以直接把账号密码写到下面的代码😅
username = get_env('JM_USERNAME', None)
password = get_env('JM_PASSWORD', None)
if username is not None and password is not None:
client.login(username, password, True)
print_eye_catching(f'登录禁漫成功')
# noinspection PyUnusedLocal
def hook_debug(option):
jm_download_dir = get_env('JM_DOWNLOAD_DIR', workspace())
mkdir_if_not_exists(jm_download_dir)
class RaiseErrorAwareClient(JmHtmlClient):
@classmethod
def raise_request_error(cls, resp, msg=None):
from common import write_text, fix_windir_name
write_text(
f'{jm_download_dir}/{fix_windir_name(resp.url)}',
resp.text
)
return super().raise_request_error(resp, msg)
JmModuleConfig.CLASS_CLIENT_IMPL['html'] = RaiseErrorAwareClient
if __name__ == '__main__':
main()