The ultimate choice for IOS reading | source reading conversion | open source reading | IOS self-signing

Environment: IOS wants to use Changyuan Reading.
Problem: After changing to a new mobile phone and Yuanyuan Reading is removed from the shelves, there is no good APP for reading novels.
Solution: Self-signed APP + Changing Source Warehouse book source.

Final preview: https://rc.real9.cn/

Background: Ever since I changed to a new iPhone, I couldn’t use Changyuan Reading, so I used it for my own use. It turned out that the current book sources are developing very fast. The old version of the Source Reading APP does not support the syntax of some book sources, so I After repeatedly summarizing and comparing, I wrote a python program for automatic conversion, as shown in the link above.

Solution process: self-signed APP + conversion of book sources


1. Download ipa:

I won’t include the download address.

2. Self-signed IPA:

Regarding how to self-sign, you can use Easy Sign or All-Around Sign. For beginners, forget it if you don’t know anything.

3. Convert book sources

3.1 Obtain book sources

The source warehouse is no longer provided. Search by yourself:
https://yuedu.miaogongzi.net/

3.2 Conversion rules

Since the version of this APP is around 2021, many new versions of book sources do not support it. We need to convert it. I spent some time summarizing some conversion rules:

The most common rule is that a.1@text is not supported. To convert, please refer to the following for other information.

书源类型
0    文本
2    视频
3    漫画
1    音频
-------------------------------
#    选择ID
.     选择元素 class之类
>     子元素
~     第二个,兄弟元素,同级关系
p:nth-child(2) 父元素的第n个子元素
[]    属性选择器            [class^=book] 选择class以book开头的元素
!    倒序选择器            img:!-1 选择最后一个img元素
||      列组合选择器            col||td 选择col和td元素
 ( )    分组选择器            (div,p) 选择所有div和p
,      多个选择器            .item, .active 选择item和active类
*       通用元素选择器        *.item 选择所有类名包含item的元素
n      表达式选择器            li:nth-child(3n) 按序选择li元素,每个li元素的父元素中的第 3、6、9、12等序号
a.-1@text     改为a:nth-last-child(1)@text
a.1@text         a:nth-child(1)@text```

### 3.3 步骤3.3

3.3 Convert book sources

Now let’s start the conversion. The stupid way is to use Notepad to replace it. I wrote a python script to automatically replace it.

import json
import requests

def replace_selectors(json_data):
    # 替换选择器的函数
    def replace_selector(selector):
        if "." in selector and "@" in selector:
            parts = selector.split('.')
            tag = parts[0]
            selector_part = parts[1]
            if "@" in selector_part:
                num, at_text = selector_part.split('@', 1)
                if ":" in num:
                    num, tag_after_colon = num.split(':', 1)
                    num = f"{num}@{tag_after_colon}"
                if num.replace("-", "").replace(".", "").isdigit():
                    num = "1" if num == "0" else num  # 处理小数点后面是0的情况
                    if num.startswith("-"):
                        num = num[1:]
                        return f"{tag}:nth-last-child({num})@{at_text}"
                    else:
                        return f"{tag}:nth-child({num})@{at_text}"
        return selector

    # 处理列表类型的 JSON 数据
    if isinstance(json_data, list):
        for item in json_data:
            replace_selectors(item)
        return

    # 遍历字典类型的 JSON 数据,查找并替换选择器
    for key, value in json_data.items():
        if isinstance(value, str):
            if "@" in value:
                value = replace_selector(value)
            json_data[key] = value
        elif isinstance(value, dict):
            replace_selectors(value)
        elif isinstance(value, list):
            for item in value:
                if isinstance(item, dict):
                    replace_selectors(item)

    # 增加替换规则,当"ruleExplore": []时,替换为"ruleExplore": "##"
    if "ruleExplore" in json_data and not json_data["ruleExplore"]:
        json_data["ruleExplore"] = "##"

if __name__ == "__main__":
    # 用户输入 JSON 文件的 URL
    json_url = input("请输入 JSON 文件的 URL: ")

    # 下载 JSON 数据
    response = requests.get(json_url)
    json_data = response.json()

    # 替换选择器
    replace_selectors(json_data)

    # 提取文件名,并保存 JSON 内容到文件
    file_name = json_url.split('/')[-1]
    with open(file_name, 'w', encoding='utf-8') as file:
        json.dump(json_data, file, indent=4, ensure_ascii=False)

    print(f"JSON 内容已按照新的替换原则进行替换并保存为文件:{file_name}")

4. Online conversion

Local conversion is a bit troublesome. When I play on my mobile phone, my computer is not always with me, so I changed the above code to the web version. I just copy and import these converted connections into the APP clipboard. The effect is as follows:

Insert image description here

Insert image description here

Insert image description here

4.1 web version source code:

import json
import os
import requests
from flask import Flask, render_template, request, send_from_directory, url_for
from werkzeug.utils import secure_filename

app = Flask(__name__)

def replace_selectors(json_data):
    # 替换选择器的函数
    def replace_selector(selector):
        if "." in selector and "@" in selector:
            parts = selector.split('.')
            tag = parts[0]
            selector_part = parts[1]
            if "@" in selector_part:
                num, at_text = selector_part.split('@', 1)
                if ":" in num:
                    num, tag_after_colon = num.split(':', 1)
                    num = f"{num}@{tag_after_colon}"
                if num.replace("-", "").replace(".", "").isdigit():
                    num = "1" if num == "0" else num  # 处理小数点后面是0的情况
                    if num.startswith("-"):
                        num = num[1:]
                        return f"{tag}:nth-last-child({num})@{at_text}"
                    else:
                        return f"{tag}:nth-child({num})@{at_text}"
        return selector

    # 处理列表类型的 JSON 数据
    if isinstance(json_data, list):
        for item in json_data:
            replace_selectors(item)
        return

    # 遍历字典类型的 JSON 数据,查找并替换选择器
    for key, value in json_data.items():
        if isinstance(value, str):
            if "@" in value:
                value = replace_selector(value)
            json_data[key] = value
        elif isinstance(value, dict):
            replace_selectors(value)
        elif isinstance(value, list):
            for item in value:
                if isinstance(item, dict):
                    replace_selectors(item)
    
    # 增加替换规则,当"ruleExplore": []时,替换为"ruleExplore": "##"
    if "ruleExplore" in json_data and not json_data["ruleExplore"]:
        json_data["ruleExplore"] = "##"

if __name__ == "__main__":
    @app.route('/', methods=['GET', 'POST'])
    def index():
        if request.method == 'POST':
            json_url = request.form['json_url']
            response = requests.get(json_url)
            json_data = response.json()
            replace_selectors(json_data)

            # 提取文件名,并保存 JSON 内容到文件
            file_name = json_url.split('/')[-1]
            json_dir = os.path.join(os.path.dirname(__file__), 'json')
            if not os.path.exists(json_dir):
                os.makedirs(json_dir)

            json_path = os.path.join(json_dir, file_name)
            with open(json_path, 'w', encoding='utf-8') as file:
                json.dump(json_data, file, indent=4, ensure_ascii=False)

            # 生成下载链接
            download_link = url_for('download', file_name=file_name)

            return render_template('result.html', json_data=json_data, download_link=download_link)
        return render_template('form.html')

    @app.route('/json/<path:file_name>', methods=['GET'])
    def download(file_name):
        json_dir = os.path.join(os.path.dirname(__file__), 'json')
        file_path = os.path.join(json_dir, file_name)
        return send_from_directory(json_dir, file_name, as_attachment=True)


    app.run(host='0.0.0.0', port=5000, debug=True)

4.2 I also wrote a docker version

docker pull realwang/booksource_transios:latest
docker run -d  --name transios -p 5000:5000 booksource_transios

# 使用python3环境作为基础镜像
FROM python:3

# 设置工作目录
WORKDIR /app

# 安装git,用于从GitHub下载代码
#RUN apt-get update && apt-get install -y git

# 从GitHub下载代码
RUN git clone https://ghproxy.com/https://github.com/wangrui1573/booksource_transIOS.git /app

# 切换到代码目录
WORKDIR /app

# 安装python依赖
RUN pip install --no-cache-dir -r requirements.txt

# 将容器5000端口映射到主机的5000端口
EXPOSE 5000

# 启动Python应用程序
CMD ["python", "api/conv_book_web.py"]


# docker run -d -p 5000:5000 booksource_transios

Source code: https://github.com/wangrui1573/booksource_transIOS

Guess you like

Origin blog.csdn.net/wangrui1573/article/details/131898637