Skip to content

Commit

Permalink
拆分文件,防止文件过长无法正常维护以及修复功能 (#89)
Browse files Browse the repository at this point in the history
* 将设置移动到单文件上

* 将epub/cbz/login功能分离并格式化代码

* 尽可能向前支持配置文件

* 进一步拆分,修复范围下载不会下载结束话数

* 删除cbz使用的Pinyin库(bug多)

* 增加请求502停止重试以及调整cbz功能

* Update README.md

* 完成合并要求
  • Loading branch information
misaka10843 authored Jan 28, 2024
1 parent f7b4d65 commit b070e3f
Show file tree
Hide file tree
Showing 17 changed files with 882 additions and 775 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# These are supported funding model platforms

custom: ['https://afdian.net/@sakura_society']
custom: [ 'https://afdian.net/@sakura_society' ]
7 changes: 4 additions & 3 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ Describe the bug in detail so that everyone can understand it
清晰描述复现步骤,让别人也能看到问题
Clearly describe the reproduction steps so that others can see the problem
-->
1.
2.
3.

1.
2.
3.

### 📄 [异常/日志]信息([Exception/Log] Information)

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: python compile(Linux&Windows)

on:
release:
types: [published]
types: [ published ]
push:
branches:
- master
Expand Down
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# 贡献者公约

## 我们的承诺
Expand Down Expand Up @@ -74,15 +73,20 @@

## 参见

本行为准则改编自 [Contributor Covenant][homepage] 2.1 版, 参见 [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]
本行为准则改编自 [Contributor Covenant][homepage] 2.1 版,
参见 [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]

社区处理方针灵感来源于 [Mozilla's code of conduct enforcement ladder][Mozilla CoC]

有关本行为准则的常见问题的答案,参见 [https://www.contributor-covenant.org/faq][FAQ]
其他语言翻译参见 [https://www.contributor-covenant.org/translations][translations]

[homepage]: https://www.contributor-covenant.org

[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html

[Mozilla CoC]: https://github.com/mozilla/diversity

[FAQ]: https://www.contributor-covenant.org/faq

[translations]: https://www.contributor-covenant.org/translations
32 changes: 17 additions & 15 deletions Image_stitching.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
# -*- coding:utf-8 -*-


from PIL import Image


import os



from PIL import Image


def file_name(file_dir):
L = []
for root, dirs, files in os.walk(file_dir):
for file in files:
if os.path.splitext(file)[1] == '.png': # 假设漫画全部都是png格式
L.append(os.path.join(root, file)) # 输出为数组
return L


def join(png1, png2, NewImageName, SavePath):
img1, img2 = Image.open(png1), Image.open(png2)
size1, size2 = img1.size, img2.size # 获取两个图片长宽
joint = Image.new('RGB', (size1[0]+size2[0], size1[1]))
joint = Image.new('RGB', (size1[0] + size2[0], size1[1]))
loc1, loc2 = (0, 0), (size1[0], 0)
joint.paste(img2, loc1) #如需要左到右拼接,只要将img2改成img1,img1改成img2即可
joint.paste(img2, loc1) # 如需要左到右拼接,只要将img2改成img1,img1改成img2即可
joint.paste(img1, loc2)
joint.save('%s%s.png' % (SavePath,NewImageName)) # 输出
joint.save('%s%s.png' % (SavePath, NewImageName)) # 输出


def main():
ImgPath = input("图片文件夹位置(以/结尾):")
SavePath = input("拼接后图片存放的位置(以/结尾):")
image = file_name("ImgPath") # 获取当前目录下指定文件
j = 0
for i in image:
NewImage = "%s-%s"%(j+1,j) #拼接之后的图片的文件名
join(image[j], image[j+1],NewImage,SavePath) # 如果是第一次就直接两图合并
j = j + 1
NewImage = "%s-%s" % (j + 1, j) # 拼接之后的图片的文件名
join(image[j], image[j + 1], NewImage, SavePath) # 如果是第一次就直接两图合并
j = j + 1


if __name__ == '__main__':
main()
60 changes: 41 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
**请注意,在提交ISSUE前,请确保@misaka10843,以防止长时间未查看!**
> [!WARNING]
> **在2023.1.28更新之后,cbz功能的保存路径被改变,请所有使用cbz功能的用户最好[查看修改内容](https://github.com/misaka10843/copymanga-downloader/pull/89#issue-2104150068)了解新路径以及元信息问题!**
**因为尽可能缓解copymanga服务器压力,此程序限制了每分钟只能访问15次API,还请理解!**

**如果需要稳定的下载器,请使用tachidesk以及配套的插件进行下载,本仓库仅为方便命令行直接下载而创建的**
> [!NOTE]
> **请注意,在提交ISSUE前,请确保@misaka10843,以防止长时间未查看!**
>
> **因为尽可能缓解copymanga服务器压力,此程序限制了每分钟只能访问15次API,还请理解!**
# copymanga-downloader

![Head diagram](https://s2.loli.net/2022/03/30/b4eM9gArp5q2VKu.png)

## 前言💭

推荐在模拟器/WSA/安卓手机中安装[tachiyomi](https://github.com/tachiyomiorg/tachiyomi),与[Copymanga插件](https://github.com/stevenyomi/copymanga),并使用tachiyomi下载!
推荐在模拟器/WSA/安卓手机中安装[tachiyomi](https://github.com/tachiyomiorg/tachiyomi)
[Copymanga插件](https://github.com/stevenyomi/copymanga)并使用tachiyomi下载!

因为这样可以尽可能的保证下载稳定与订阅系统正常

此程序只是方便下载,而不是进行订阅操作(下载与订阅系统不稳定)


**我们已经正式基本支持命令行参数下载并且完全重构啦!**

请看[命令行参数](https://github.com/misaka10843/copymanga-downloader#%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%8F%82%E6%95%B0%EF%B8%8F)[重大更新](https://github.com/misaka10843/copymanga-downloader#%E9%87%8D%E5%A4%A7%E6%9B%B4%E6%96%B0-)的部分!
请看[命令行参数](https://github.com/misaka10843/copymanga-downloader#%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%8F%82%E6%95%B0%EF%B8%8F)
[重大更新](https://github.com/misaka10843/copymanga-downloader#%E9%87%8D%E5%A4%A7%E6%9B%B4%E6%96%B0-)的部分!

## 下载

Expand Down Expand Up @@ -53,7 +56,6 @@ or

![image](https://user-images.githubusercontent.com/69132853/229278511-3b2fe97b-5e01-4df0-9a23-d276de440472.png)


## 技术栈 ⚒️

![python](https://img.shields.io/badge/Python-3.0+-326c9c?style=for-the-badge&logo=Python&logoColor=326c9c)
Expand All @@ -79,9 +81,12 @@ or

(如果不是那就重新下载一遍,如果还有的话就发**issuse**吧qwq)

如果您是安卓用户,那么您可以使用[tachiyomi](https://github.com/tachiyomiorg/tachiyomi)客户端尝试下载(但是需要安装 `copymanga`的插件)
如果您是安卓用户,那么您可以使用[tachiyomi](https://github.com/tachiyomiorg/tachiyomi)
客户端尝试下载(但是需要安装 `copymanga`的插件)

如果您需要**从右到左**的拼接图片,并且两张为一组的话,您可以尝试使用[这个版本](https://github.com/misaka10843/copymanga-downloader/releases/tag/v2.2)中的 `Image_stitching.exe`来实现(只提供简单功能,并未做出优化)
如果您需要**从右到左**的拼接图片,
并且两张为一组的话,您可以尝试使用[这个版本](https://github.com/misaka10843/copymanga-downloader/releases/tag/v2.2)
中的 `Image_stitching.exe`来实现(只提供简单功能,并未做出优化)

如果发现无法获取/下载的时候,请多试几次,如果不行的话请重新设置一下配置,选择您能访问的API地址

Expand All @@ -91,7 +96,8 @@ or

详细请看[copymanga-downloader自动推送到kindle的使用教程](https://www.pursuecode.cn/archives/1705162565893)

请注意,在实现转换为epub时使用了第三方库[KCC](https://github.com/ciromattia/kcc/),您需要自行在[kcc/releases](https://github.com/ciromattia/kcc/releases)下载对应平台的执行程序
请注意,在实现转换为epub时使用了第三方库[KCC](https://github.com/ciromattia/kcc/)
,您需要自行在[kcc/releases](https://github.com/ciromattia/kcc/releases)下载对应平台的执行程序

(windows平台需要下载`kcc_c2e_{版本号}.exe`)

Expand Down Expand Up @@ -135,7 +141,6 @@ options:

![img](https://s2.loli.net/2023/01/06/FWklObHX6523CYs.png)


### 命令示例

#### 如果我想下载*別哭啊魔王醬*的第一话
Expand All @@ -158,7 +163,8 @@ options:

`python main.py --MangaPath xinglingganying --MangaStart 1 --MangaEnd 38`

**(注意!虽然说是下载全话,其实就是将范围定在了1话-最新话,所以如果下载其他漫画的全话请参考漫画更新到多少话了,然后再替换38)**
**(注意!虽然说是下载全话,其实就是将范围定在了1话-最新话,所以如果下载其他漫画的全话请参考漫画更新到多少话了,然后再替换38)
**

## 更新 🔬

Expand Down Expand Up @@ -186,7 +192,8 @@ options:

2022/3/29: 在 [@zhongfly](https://github.com/zhongfly) 帮助下支持了一些功能,并~~可能~~修复了问题,而且还顺便帮忙优化了下代码www

2022/3/24: 暂时支持设置一个功能(但是大概率无法下载,请注意,如果出现问题请在[这里](https://github.com/misaka10843/copymanga-downloader/issues/)提交相关信息
2022/3/24: 暂时支持设置一个功能(
但是大概率无法下载,请注意,如果出现问题请在[这里](https://github.com/misaka10843/copymanga-downloader/issues/)提交相关信息

2022/2/25: 修复copymanga的url问题(copymanga.com似乎已经被弃用,已更换到copymanga.net)

Expand All @@ -198,23 +205,36 @@ options:

## 放几张截图qwq(时效性不敢保证)

第一次初始化
更改设置

![image](https://github.com/misaka10843/copymanga-downloader/assets/69132853/c3c97f7c-7202-4f17-acf3-6b06edd556b8)

下载进度条

![image](https://github.com/misaka10843/copymanga-downloader/assets/69132853/f618f9cc-58d6-4bc8-a86d-1a67ff37b2ec)

漫画搜索

![image](https://github.com/misaka10843/copymanga-downloader/assets/69132853/583b0d12-9017-4115-b210-2a13d7fc7027)


![图片.png](https://s2.loli.net/2022/03/31/qKhZVtbguEAwQcJ.png)

## 如何使用 🖥️

### 立即使用(Windows)

1.点击[这里](https://github.com/misaka10843/copymanga-downloader/releases/latest)下载最新的从作者电脑中编译的exe版本,或者下载GitHub中的编译文件[actions](https://github.com/misaka10843/copymanga-downloader/actions/)(稳定无法保证)
1.点击[这里](https://github.com/misaka10843/copymanga-downloader/releases/latest)
下载最新的从作者电脑中编译的exe版本,或者下载GitHub中的编译文件[actions](https://github.com/misaka10843/copymanga-downloader/actions/)(
稳定无法保证)

2.将此程序放入一个空文件夹(不放也没问题,就是数据会写到当前文件夹中)

3.直接双击exe即可qwq

### 立即使用(Linux,无法保证能否运行)

1.点击[actions](https://github.com/misaka10843/copymanga-downloader/actions)选择最新的编译(100%同步更新,但不能保障是否能运行)
1.点击[actions](https://github.com/misaka10843/copymanga-downloader/actions)选择最新的编译(
100%同步更新,但不能保障是否能运行)

2.下载 `附件`中的 `copymanga-download-Linux`压缩包

Expand All @@ -227,6 +247,7 @@ options:
### 编译/原代码使用(所有系统均支持)

⭐️ 建议pip安装(如果有本地有多个Python版本,建议用pipx安装)

```bash
# macOS安装pipx
brew install pipx
Expand Down Expand Up @@ -274,7 +295,8 @@ pipx install git+https://ghproxy.com/https://github.com/misaka10843/copymanga-do

3.找到类似 `comics?limit=12&offset=0&free_type=1&ordering=-datetime_modifier`的文件(?)后点击

4.在**请求标头**中找到 `authorization: Token {各有各的不同}`,复制 `Token {各有各的不同}`即可,如 `Token 1293asd123s8adhh2juhsada2`
4.在**请求标头**中找到 `authorization: Token {各有各的不同}`,复制 `Token {各有各的不同}`
即可,如 `Token 1293asd123s8adhh2juhsada2`

图片([大图查看](https://i.loli.net/2021/11/18/Tv85D4a7GO9jNbn.png)):

Expand Down
37 changes: 37 additions & 0 deletions cbz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import zipfile

import config


def create_cbz(index, title, manga_name, save_dir, cbz_dir, path_word):
xml_data = f'<?xml version="1.0"?>' \
'<ComicInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' \
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' \
f'<Title>{title}</Title>' \
f'<Series>{manga_name}</Series>' \
f'<Number>{index}</Number>' \
f'</ComicInfo>'
with open(os.path.join(os.path.join(config.SETTINGS['download_path'], save_dir), "ComicInfo.xml"), "w",
encoding='utf8') as file:
file.write(xml_data)

start_dir = os.path.join(config.SETTINGS['download_path'], save_dir)
file_name = f"{manga_name}-{title}.cbz"
cbz_dir = os.path.join(cbz_dir, path_word)
file_path = os.path.join(cbz_dir, file_name)

# 检测漫画保存目录是否存在
if not os.path.exists(cbz_dir):
os.makedirs(cbz_dir)

# 只添加指定类型的文件到zip文件中
allowed_ext = ['.xml', '.jpg', '.png', '.jpeg', '.webp']
with zipfile.ZipFile(file_path, 'w', zipfile.ZIP_DEFLATED) as zip_file:
for dir_path, dir_names, filenames in os.walk(start_dir):
fpath = dir_path.replace(start_dir, '')
fpath = fpath and fpath + os.sep or ''
for filename in filenames:
ext = os.path.splitext(filename)[1].lower()
if ext in allowed_ext:
zip_file.write(os.path.join(dir_path, filename), fpath + filename)
76 changes: 76 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import datetime

SETTINGS = {
"download_path": None,
"authorization": None,
"use_oversea_cdn": None,
"use_webp": None,
"proxies": None,
"api_url": None,
"HC": None,
"CBZ": None,
"cbz_path": None,
"api_time": 0.0,
"API_COUNTER": 0,
"loginPattern": "0",
"salt": None,
"username": None,
"password": None,
"send_to_kindle": None,
"kcc_cmd": None,
"email_address": None,
"email_passwd": None,
"kindle_address": None,
"email_smtp_address": None
}

# '''
# "epub_and_mail_to_kindle": None,
# "kcc_cmd": None,
# "email_address": None,
# "email_passwd": None,
# "kindle_address": None,
# '''

# 全局化设置,备份,防止命令行参数导致设置错位
OG_SETTINGS = {
"download_path": None,
"authorization": None,
"use_oversea_cdn": None,
"use_webp": None,
"proxies": None,
"api_url": None,
"HC": None,
"CBZ": None,
"cbz_path": None,
"api_time": 0.0,
"API_COUNTER": 0,
"loginPattern": "0",
"salt": None,
"username": None,
"password": None,
"send_to_kindle": None,
"kcc_cmd": None,
"email_address": None,
"email_passwd": None,
"kindle_address": None,
"email_smtp_address": None
}

# 全局化headers,节省空间

API_HEADER = {
'User-Agent': '"User-Agent" to "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, '
'like Gecko) Chrome/102.0.5005.124 Safari/537.36 Edg/102.0.1245.44"',
'version': datetime.datetime.now().strftime("%Y.%m.%d"),
'region': '0',
'webp': '0',
"platform": "1",
"referer": "https://www.copymanga.site/"
}

PROXIES = {}

API_COUNTER = 0
IMG_API_COUNTER = 0
IMG_CURRENT_TIME = 0
Loading

0 comments on commit b070e3f

Please sign in to comment.