项目背景
本人常用的机场为了订阅安全,限制每天订阅次数,一旦超过则会重置订阅链接。本项目是为了解决无意识地超过次数限制,避免陷入订阅失效焦虑。
PS: 我用的客户端是 OpenClash,虽然设置每天更新,但是上面会显示套餐余额,每次点击查看套餐余额相当于就订阅了一次
实现功能
统一管理订阅,定时下载并存储订阅信息,自动进行订阅转换,并提供代理服务。
PS: 目前自动订阅转换只支持 clash -> surge, clash -> sufboard,因为我只用到这些,其他没条件测试 (●'◡'●)
快速开始
使用 pip 安装:
$ pip install subscribe-manager
添加配置文件 config.yaml,格式如下:
services:
<your_service_name>:
sensitive_policy:
- check_type: "<check_type>"
keyword: "<keyword>"
target_type: "<target_type>"
auto_transform: "true"
urls:
- uuid: "<your_unique_identifier1>"
url: "<your_original_subscribe_link1>"
- uuid: "<your_unique_identifier2>"
url: "<your_original_subscribe_link2>"
- uuid: "..."
url: "..."
配置文件定义说明:
services: 订阅设置的顶层<your_servie_name>: 服务名称,为方便区分,可以按照机场名来填写sensitive_policy: 敏感策略,考虑到原始订阅内容会包含一些敏感信息,可以设置一些检查策略,进行删除check_type: 目前只开放start,删除指定关键字开头的行keyword: 关键字,配合check_type使用target_type:订阅类型,目前只支持 clash, sufboard, surge- auto_transform: 自动订阅转换,目前只支持 clash -> surfboard, clash -> surge
urls: 设置订阅信息uuid:唯一标识,在下载订阅文件保存时,文件名依此生成url:订阅的原始链接
例子:
添加 example.py :
from subscribe_manager import SubscribeManager
sm = SubscribeManager()
sm.start()
与 example.py 同一目录下, 添加配置文件 config.yaml
services:
myService:
target_type: "clash"
auto_transform: "true"
urls:
- uuid: "aaa"
url: "https://example.com/link/abcdefg"
- uuid: "bbb"
url: "https://example.com/link/hijklmn"
执行后,看到以下目录结构
| config.yaml
| example.py
| subscribe_manager.db
|
\---subscribe
\---myService
aaa_clash.yaml
aaa_surfboard.conf
aaa_surge.conf
bbb_clash.yaml
bbb_surfboard.conf
bbb_surge.conf
数据库 subscribe_manager.db 默认生成在同一目录,存放文件路径,订阅url,订阅信息,订阅文件存放在对应服务名称的文件夹下。
接口服务默认发布在 http://127.0.0.1:8000,以 get 方法调用 http://127.0.0.1:8000/link/<service_name>/<uuid>?target=<target_type>,?target=<target_type>未指定时,默认为 clash。
以本例来说:
| 请求地址 | 结果 |
|---|---|
| http://127.0.0.1:8000/link/myService/aaa | 未指定target,默认返回 aaa_clash.yaml 内容 |
| http://127.0.0.1:8000/link/myService/aaa?target=surge | 返回 aaa_surge.conf 内容 |
SubscribeManager 参数说明:
| 参数名称 | 参数说明 | 默认值 |
|---|---|---|
| max_subscribe_count | 最大订阅次数 | 5 |
| config_file | 配置文件路径 | config.yaml |
| subscribe_save_path | 订阅内容本地保存路径 | subscribe |
| refresh_flag | 是否刷新,服务启动时,是否下载订阅 | True |
| interval_type | 间隔类型 | days |
| interval | 间隔时长 | 1 |
| start_date | 定时开始时间 | 2000-01-01 00:00:00 |
| host | host | 127.0.0.1 |
| port | port | 8000 |
| db_name | 数据库名称 | subscribe_manager.db |
你也可以直接通过命令行的形式直接运行,与上面不同的是,在 config.yaml 中需要额外增加 settings,如果缺失 settings,程序会根据默认值执行
settings:
max_subscribe_count: <your_max_subscribe_count>
subscribe_save_path: "<your_subscribe_save_path>"
refresh_flag: "<your_refresh_flag>"
interval_type: "<your_interval_type>"
interval: <your_interval>
start_date: "<your_start_date>"
host: "<your_host>"
port: <your_port>
db_name: "<your_db_name>"
services:
<your_service_name>:
sensitive_policy:
- check_type: "<check_type>"
keyword: "<keyword>"
target_type: "<target_type>"
auto_transform: "true"
urls:
- uuid: "<your_unique_identifier1>"
url: "<your_original_subscribe_link1>"
- uuid: "<your_unique_identifier2>"
url: "<your_original_subscribe_link2>"
- uuid: "..."
url: "..."
运行命令:
$ sbscmgr --config_file <your_config_file>
如果未指定 --config_file,直接运行,则默认为当前目录的 config.yaml
Metadata
Release files for subscribe-manager 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| subscribe_manager-0.3.3.tar.gz | 14.1 kB | With provenance | Details for subscribe_manager-0.3.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| subscribe_manager-0.3.3-py3-none-any.whl | Python 3 | none | any | Details for subscribe_manager-0.3.3-py3-none-any.whl |
Total release size: 32.7 kB
Release files / subscribe_manager-0.3.3.tar.gz
| Download URL | subscribe_manager-0.3.3.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
367faa9c6a63b0ed8d029db9945733e5e8d5e1c35acc765087e1192dafed80ab
|
|
BLAKE2b-256 checksum How to use checksums |
4842b9d3ec68839764f848bd92e2d7e8998db850424bd2a02a8d433216f3e5f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 4, 2025.
Transparency logRelease files / subscribe_manager-0.3.3-py3-none-any.whl
| Download URL | subscribe_manager-0.3.3-py3-none-any.whl |
|---|---|
| Size | 18.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
21e477a9330ffa1b282118181884c8958d3f9c1a7b8d419102ff0a22a5c9be5e
|
|
BLAKE2b-256 checksum How to use checksums |
8577bc69494de67e6e383479c21ca62c289b403f34e3ce5347befe7f4bf57dd8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 4, 2025.
Transparency logSecurity for subscribe-manager 0.3.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for subscribe_manager-0.3.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 4, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.