Closed Yatogaii closed 4 weeks ago
我本地添加了一个 main.py 文件,可以正常的进入下载流程,但是每一个图片都会下载失败,我觉得可能是从命令行执行模块的话无法正常执行init.py里的代码,所以会报错。
我本地添加的main.py内容如下:
# comic/__main__.py
from .jm_option import *
import argparse
from .api import *
def main():
parser = argparse.ArgumentParser(description='Comic Downloader')
parser.add_argument('-d', '--download_album', type=str, help='Album ID to download', required=True)
args = parser.parse_args()
album_id = args.download_album
if args.download_album:
if album_id.isdigit() and len(album_id) == 6:
jm_log('album.before', f"Downloading album {album_id} from the comic module.")
download_album(album_id)
else:
jm_log('album.before', "Please provide right album id!")
else:
jm_log('album.before', "No album ID provided for download.")
if __name__ == "__main__":
main()
这样执行给出的错误是这里的 e 没有被初始化所导致的UnboundLocalError
:
https://github.com/hect0x7/JMComic-Crawler-Python/blob/c50ca791f9ffa5a1e469325c986a81af8f8230fd/src/jmcomic/jm_downloader.py#L125
缩进代码至 Except 块内,重新执行会抛出一个新的异常: PIL.UnidentifiedImageError
。
有什么建议吗,我觉得这个功能如果能实现的话还挺方便的。
我没太看懂你的意思 首先,你想用这样的命令行下载本子:
python3 -m jmcomic download {id}
为什么不使用已有的jmcomic命令?
jmcomic {id}
以及,你添加了一个 main.py文件,你添加到哪里?添加了会怎么样?我没看出来这个文件你要怎么使用
不如先看看PIL.UnidentifiedImageError
这个异常,你搜一下有没有解决方案
e 没有被初始化所导致的UnboundLocalError,这个确实是个bug
不好意思之前有点忙现在才想起来回复。
确实可以直接使用jmcomic {id} 下载本子,不需要画蛇添足的python3 -m jmcomic 来调用了,是我疏忽了没想到有这个用法,所谓的main.py也都是为了添加python3 -m jmcomic
这个入口而添加的,可以忽略。
PIL.UnidentifiedImageError
这个异常的话,我之后在同样的环境下在python文件中调用和在CLI中直接使用 jmcomic {id} 来下载都不会触发,所以我觉得这个异常应该不怎么影响当前的运行。
最后感谢作者的工作,提供了很大的便利🙏🏻🙏🏻🙏🏻
新功能请求
It would greatly enhance the usability of our comic management tool if we could integrate a feature to download comics directly from the command line. Example: Executii\ng
python3 -m jmcomic download {id}
will download {id} directly to the current work directory.