Skip to content

Commit e863ad7

Browse files
authored
Merge branch 'EstrellaXD:3.1-dev' into 3.1-dev
2 parents fd47999 + ca676f9 commit e863ad7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2785
-1374
lines changed

.github/workflows/build.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
test:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v3
15+
- uses: actions/checkout@v4
1616
- name: Set up Python 3.11
1717
uses: actions/setup-python@v3
1818
with:
@@ -32,7 +32,7 @@ jobs:
3232
runs-on: ubuntu-latest
3333
steps:
3434
- name: Checkout
35-
uses: actions/checkout@v3
35+
uses: actions/checkout@v4
3636
- name: If release
3737
id: release
3838
run: |
@@ -86,7 +86,7 @@ jobs:
8686
node-version: [ 18 ]
8787
steps:
8888
- name: Checkout
89-
uses: actions/checkout@v3
89+
uses: actions/checkout@v4
9090

9191
- uses: pnpm/action-setup@v2
9292
with:
@@ -117,7 +117,7 @@ jobs:
117117
needs: [ build-webui, version-info ]
118118
steps:
119119
- name: Checkout
120-
uses: actions/checkout@v3
120+
uses: actions/checkout@v4
121121

122122
- name: Create Version info via tag
123123
working-directory: ./backend/src
@@ -224,7 +224,7 @@ jobs:
224224
version: ${{ needs.version-info.outputs.version }}
225225
steps:
226226
- name: Checkout code
227-
uses: actions/checkout@v3
227+
uses: actions/checkout@v4
228228

229229
- name: Download artifact webui
230230
uses: actions/download-artifact@v3

backend/src/module/api/rss.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ async def download_collection(data: Bangumi):
194194
@router.post(
195195
"/subscribe", response_model=APIResponse, dependencies=[Depends(get_current_user)]
196196
)
197-
async def subscribe(data: Bangumi):
197+
async def subscribe(data: Bangumi, rss: RSSItem):
198198
with SeasonCollector() as collector:
199-
resp = collector.subscribe_season(data)
199+
resp = collector.subscribe_season(data, parser=rss.parser)
200200
return u_response(resp)

backend/src/module/checker/checker.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def check_downloader() -> bool:
5959
else f"{settings.downloader.host}"
6060
)
6161
response = requests.get(url, timeout=2)
62-
if settings.downloader.type in response.text.lower():
62+
# if settings.downloader.type in response.text.lower():
63+
if "qbittorrent" in response.text.lower() or "vuetorrent" in response.text.lower():
6364
with DownloadClient() as client:
6465
if client.authed:
6566
return True

backend/src/module/manager/collector.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@ def collect_season(self, bangumi: Bangumi, link: str = None):
4646
)
4747

4848
@staticmethod
49-
def subscribe_season(data: Bangumi):
49+
def subscribe_season(data: Bangumi, parser: str = "mikan"):
5050
with RSSEngine() as engine:
5151
data.added = True
5252
data.eps_collect = True
5353
engine.add_rss(
54-
rss_link=data.rss_link, name=data.official_title, aggregate=False
54+
rss_link=data.rss_link,
55+
name=data.official_title,
56+
aggregate=False,
57+
parser=parser,
5558
)
5659
engine.bangumi.add(data)
5760
result = engine.download_bangumi(data)

backend/src/module/models/config.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from os.path import expandvars
22
from typing import Literal
33

4-
from pydantic import BaseModel, Field
4+
from pydantic import BaseModel, Field, validator
55

66

77
class Program(BaseModel):
@@ -102,6 +102,12 @@ class ExperimentalOpenAI(BaseModel):
102102
"", description="Azure OpenAI deployment id, ignored when api type is openai"
103103
)
104104

105+
@validator("api_base")
106+
def validate_api_base(cls, value: str):
107+
if value == "https://api.openai.com/":
108+
return "https://api.openai.com/v1"
109+
return value
110+
105111

106112
class Config(BaseModel):
107113
program: Program = Program()

backend/src/module/parser/analyser/raw_parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def clean_sub(sub: str | None) -> str | None:
131131

132132

133133
def process(raw_title: str):
134-
raw_title = raw_title.strip()
134+
raw_title = raw_title.strip().replace("\n", "")
135135
content_title = pre_process(raw_title)
136136
# 预处理标题
137137
group = get_group(content_title)

backend/src/module/parser/analyser/torrent_parser.py

+34-33
Original file line numberDiff line numberDiff line change
@@ -69,36 +69,37 @@ def torrent_parser(
6969
file_type: str = "media",
7070
) -> EpisodeFile | SubtitleFile:
7171
media_path = get_path_basename(torrent_path)
72-
for rule in RULES:
73-
if torrent_name:
74-
match_obj = re.match(rule, torrent_name, re.I)
75-
else:
76-
match_obj = re.match(rule, media_path, re.I)
77-
if match_obj:
78-
group, title = get_group(match_obj.group(1))
79-
if not season:
80-
title, season = get_season_and_title(title)
81-
else:
82-
title, _ = get_season_and_title(title)
83-
episode = int(match_obj.group(2))
84-
suffix = Path(torrent_path).suffix
85-
if file_type == "media":
86-
return EpisodeFile(
87-
media_path=torrent_path,
88-
group=group,
89-
title=title,
90-
season=season,
91-
episode=episode,
92-
suffix=suffix,
93-
)
94-
elif file_type == "subtitle":
95-
language = get_subtitle_lang(media_path)
96-
return SubtitleFile(
97-
media_path=torrent_path,
98-
group=group,
99-
title=title,
100-
season=season,
101-
language=language,
102-
episode=episode,
103-
suffix=suffix,
104-
)
72+
match_names = [torrent_name, media_path]
73+
if torrent_name is None:
74+
match_names = match_names[1:]
75+
for match_name in match_names:
76+
for rule in RULES:
77+
match_obj = re.match(rule, match_name, re.I)
78+
if match_obj:
79+
group, title = get_group(match_obj.group(1))
80+
if not season:
81+
title, season = get_season_and_title(title)
82+
else:
83+
title, _ = get_season_and_title(title)
84+
episode = int(match_obj.group(2))
85+
suffix = Path(torrent_path).suffix
86+
if file_type == "media":
87+
return EpisodeFile(
88+
media_path=torrent_path,
89+
group=group,
90+
title=title,
91+
season=season,
92+
episode=episode,
93+
suffix=suffix,
94+
)
95+
elif file_type == "subtitle":
96+
language = get_subtitle_lang(media_path)
97+
return SubtitleFile(
98+
media_path=torrent_path,
99+
group=group,
100+
title=title,
101+
season=season,
102+
language=language,
103+
episode=episode,
104+
suffix=suffix,
105+
)
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from module.models.config import ExperimentalOpenAI
2+
3+
4+
def test_experimental_openai_validate_api_base():
5+
config = ExperimentalOpenAI(api_type="openai", api_base="https://api.openai.com/")
6+
assert config.api_base == "https://api.openai.com/v1"
7+
8+
config = ExperimentalOpenAI(api_base="https://api.openai.com/")
9+
assert config.api_base == "https://api.openai.com/v1"
10+
11+
config = ExperimentalOpenAI(
12+
api_type="azure", api_base="https://custom-api-base.com"
13+
)
14+
assert config.api_base == "https://custom-api-base.com"

docs/config/proxy.md

+52
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,55 @@ AB 支持 HTTP 代理和 SOCKS5 代理,通过设置代理可以解决一些网
3131
| port | 代理端口 | 整数 | 代理端口 |
3232
| username | 代理用户名 | 字符串 | 代理用户名 |
3333
| password | 代理密码 | 字符串 | 代理密码 |
34+
35+
## 反向代理
36+
37+
- 使用蜜柑计划的新域名 `mikanime.tv` 替换rss订阅中 `mikanani.me` 部分
38+
- 使用 CloudFlare Worker 进行反代,并且替换 RSS 中所有的 `mikanani.me` 域名。
39+
40+
## CloudFlare Workers
41+
42+
根据 OpenAI 被墙的经验,我们也可以通过反向代理的方式解决。具体如何申请域名绑定 CloudFlare 在此不再赘述。在 Workers 中添加如下代码即可以用你自己的域名访问蜜柑计划并且解析下载 RSS 链接中的种子。
43+
44+
```js
45+
const TELEGRAPH_URL = 'https://mikanani.me';
46+
const MY_DOMAIN = 'https://yourdomain.com'
47+
48+
addEventListener('fetch', event => {
49+
event.respondWith(handleRequest(event.request))
50+
})
51+
52+
async function handleRequest(request) {
53+
const url = new URL(request.url);
54+
url.host = TELEGRAPH_URL.replace(/^https?:\/\//, '');
55+
56+
const modifiedRequest = new Request(url.toString(), {
57+
headers: request.headers,
58+
method: request.method,
59+
body: request.body,
60+
redirect: 'manual'
61+
});
62+
63+
const response = await fetch(modifiedRequest);
64+
const contentType = response.headers.get('Content-Type') || '';
65+
66+
// 如果内容类型是 RSS,才进行替换操作
67+
if (contentType.includes('application/xml')) {
68+
const text = await response.text();
69+
const replacedText = text.replace(/https?:\/\/mikanani\.me/g, MY_DOMAIN);
70+
const modifiedResponse = new Response(replacedText, response);
71+
72+
// 添加允许跨域访问的响应头
73+
modifiedResponse.headers.set('Access-Control-Allow-Origin', '*');
74+
75+
return modifiedResponse;
76+
} else {
77+
const modifiedResponse = new Response(response.body, response);
78+
79+
// 添加允许跨域访问的响应头
80+
modifiedResponse.headers.set('Access-Control-Allow-Origin', '*');
81+
82+
return modifiedResponse;
83+
}
84+
}
85+
```

webui/.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"i18n-ally.localesPaths": ["src/i18n"],
33
"commentTranslate.targetLanguage": "zh-CN",
44
"i18n-ally.sourceLanguage": "en",
5-
"typescript.tsdk": "node_modules/typescript/lib"
5+
"typescript.tsdk": "node_modules/typescript/lib",
6+
"i18n-ally.keystyle": "nested"
67
}

webui/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,13 @@
4848
"@unocss/preset-rem-to-px": "^0.51.13",
4949
"@unocss/reset": "^0.51.13",
5050
"@vitejs/plugin-vue": "^4.2.0",
51+
"@vitejs/plugin-vue-jsx": "^3.1.0",
5152
"@vue/runtime-dom": "^3.3.4",
5253
"eslint": "^8.41.0",
5354
"eslint-config-prettier": "^8.8.0",
5455
"eslint-plugin-storybook": "^0.6.12",
5556
"husky": "^8.0.3",
5657
"prettier": "^2.8.8",
57-
"react": "^18.2.0",
58-
"react-dom": "^18.2.0",
5958
"sass": "^1.62.1",
6059
"storybook": "^7.0.12",
6160
"typescript": "^4.9.5",

0 commit comments

Comments
 (0)