Exemple #1
0
def download_task(mag: MangaDownloader, params):
    title = mag.getTitle()
    print(f'开始下载漫画 "{title}"')
    if params["episode"]:
        ep_list = mag.getIndex()
        ep_len = len(ep_list)
        ep_P = set()
        for P in params["episode"].split(','):
            if '-' in P:
                start, end = P.split('-')
                for i in range(int(start), int(end) + 1):
                    if i <= ep_len:
                        ep_P.add(i - 1)
            else:
                if int(P) <= ep_len:
                    ep_P.add(int(P) - 1)
        download = mag.downloadIndexes(ep_P, params["path"])
    else:
        download = mag.downloadAll(params["path"])

    for ret in download:
        print_format(ret.name, '<', 30)
        if ret.code == MangaDownloader.DownloadCode.Ok:
            print(' 下载成功')
        elif ret.code == MangaDownloader.DownloadCode.Locked:
            print(' 没有解锁')
        elif ret.code == MangaDownloader.DownloadCode.Error:
            print(' 下载失败')
    print('下载任务结束')
Exemple #2
0
def download_task(task, path: str):
    if configData:
        mag = MangaDownloader(task[0], configData["users"][0]["cookieDatas"])
    else:
        mag = MangaDownloader(task[0])

    title = mag.getTitle()
    print(f'开始下载漫画 "{title}"')
    if task[1] == 'a':
        mag.downloadAll(path)
    else:
        ep_list = mag.getIndex()
        ep_len = len(ep_list)
        ep_P = set()
        for P in task[1].split(','):
            if '-' in P:
                start, end = P.split('-')
                for i in range(int(start), int(end) + 1):
                    if i <= ep_len:
                        ep_P.add(i - 1)
            else:
                if int(P) <= ep_len:
                    ep_P.add(int(P) - 1)

        if path.endswith('/'):
            dpath = path + title
        else:
            dpath = path + '/' + title
        os.makedirs(dpath)
        bq = len(str(mag.getNum()))
        for x in ep_P:
            name = ep_list[x]["title"]
            if name.replace(' ', '') == '':
                name = ep_list[x]["short_title"]
            if not ep_list[x]["is_locked"]:
                mag.download(ep_list[x]['id'],
                             f'{dpath}/{ep_list[x]["ord"]:0>{bq}}-{name}')
                print(f'{ep_list[x]["ord"]:0>{bq}}-{name} 下载完成')
            else:
                print(f'{ep_list[x]["ord"]:0>{bq}}-{name} 目前需要解锁')
    print('下载任务结束')

    if task[2]:
        import fitz, glob
        print("正在合并下载图片为pdf")
        if path.endswith('/'):
            dpath = path + title
        else:
            dpath = path + '/' + title
        doc = fitz.open()
        for name in glob.glob(f'{dpath}/*/*.jpg'):
            imgdoc = fitz.open(name)
            pdfbytes = imgdoc.convertToPDF()
            imgpdf = fitz.open("pdf", pdfbytes)
            doc.insertPDF(imgpdf)
        doc.save(f'{dpath}/{title}.pdf')
        print(f'文件保存至{dpath}/{title}.pdf')
Exemple #3
0
def download_task(mag: MangaDownloader, task, path: str):
    mag.setComicId(task[0])
    title = mag.getTitle()
    print(f'开始下载漫画 "{title}"')
    if task[1] == 'a':
        mag.downloadAll(path)
    else:
        ep_list = mag.getIndex()
        ep_len = len(ep_list)
        ep_P = set()
        for P in task[1].split(','):
            if '-' in P:
                start, end = P.split('-')
                for i in range(int(start), int(end) + 1):
                    if i <= ep_len:
                        ep_P.add(i - 1)
            else:
                if int(P) <= ep_len:
                    ep_P.add(int(P) - 1)

    for ret in mag.downloadIndexes(ep_P, path):
        print_format(ret.name, '<', 30)
        if ret.code == MangaDownloader.DownloadCode.Ok:
            print(' 下载成功')
        elif ret.code == MangaDownloader.DownloadCode.Locked:
            print(' 没有解锁')
        elif ret.code == MangaDownloader.DownloadCode.Error:
            print(' 下载失败')
    print('下载任务结束')

    if task[2]:
        import fitz, glob
        print("正在合并下载图片为pdf")
        path = os.path.join(path, title)
        doc = fitz.open()
        for name in glob.glob(os.path.join(path, "*", "*.jpg")):
            imgdoc = fitz.open(name)
            pdfbytes = imgdoc.convertToPDF()
            imgpdf = fitz.open("pdf", pdfbytes)
            doc.insertPDF(imgpdf)
        path = os.path.join(path, title + ".pdf")
        doc.save(path)
        print(f'文件保存至{path}')
Exemple #4
0
def download_task(task, path: str):
    if configData:
        mag = MangaDownloader(task[0], configData["users"][0]["cookieDatas"])
    else:
        mag = MangaDownloader(task[0])

    title = mag.getTitle()
    print(f'开始下载漫画 "{title}"')
    if task[1] == 'a':
        mag.downloadAll(path)
    else:
        ep_list = mag.getIndex()
        ep_len = len(ep_list)
        ep_P = set()
        for P in task[1].split(','):
            if '-' in P:
                start, end = P.split('-')
                for i in range(int(start), int(end) + 1):
                    if i <= ep_len:
                        ep_P.add(i - 1)
            else:
                if int(P) <= ep_len:
                    ep_P.add(int(P) - 1)
        mag.downloadIndexes(ep_P, path)

    print('下载任务结束')

    if task[2]:
        import fitz, glob
        print("正在合并下载图片为pdf")
        path = os.path.join(path, title)
        doc = fitz.open()
        for name in glob.glob(f'{path}/*/*.jpg'):
            imgdoc = fitz.open(name)
            pdfbytes = imgdoc.convertToPDF()
            imgpdf = fitz.open("pdf", pdfbytes)
            doc.insertPDF(imgpdf)
        doc.save(f'{path}/{title}.pdf')
        print(f'文件保存至{path}/{title}.pdf')