mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-05-11 18:10:15 +08:00
Compare commits
461 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f571711386 | ||
|
|
e8e8d36a13 | ||
|
|
782a9a4759 | ||
|
|
d0184bd34c | ||
|
|
e4c0643c39 | ||
|
|
305c08c7dd | ||
|
|
9521a3ef09 | ||
|
|
b4c6a206af | ||
|
|
fa7eeec345 | ||
|
|
7350216fc4 | ||
|
|
36122dda31 | ||
|
|
5851673b43 | ||
|
|
0d81105a0b | ||
|
|
b934b0975b | ||
|
|
035b4b0608 | ||
|
|
b98a033cd2 | ||
|
|
c69853ce4b | ||
|
|
e00a440336 | ||
|
|
c0eb6b0600 | ||
|
|
4d1c8c3764 | ||
|
|
62628e526c | ||
|
|
ad7761a785 | ||
|
|
e545b8d900 | ||
|
|
f2f1ecfdf1 | ||
|
|
fdec997ed0 | ||
|
|
9b653ceec9 | ||
|
|
fbaaed1c61 | ||
|
|
639abf67c2 | ||
|
|
1f56ceaea9 | ||
|
|
16a4f61fec | ||
|
|
ea0aba96fd | ||
|
|
4393dad77c | ||
|
|
d099c0e702 | ||
|
|
a299d786fe | ||
|
|
3500f5b9a6 | ||
|
|
64233c89d7 | ||
|
|
8c727da58a | ||
|
|
152a87d109 | ||
|
|
6a2cde0664 | ||
|
|
c86cc2cb51 | ||
|
|
6d7a63ff61 | ||
|
|
c044e59481 | ||
|
|
3c31bf24e5 | ||
|
|
d89c80ac89 | ||
|
|
8236d6c8d7 | ||
|
|
3646540a7f | ||
|
|
c1ecdfc61d | ||
|
|
7587946d51 | ||
|
|
3ad64baaeb | ||
|
|
24c43b53a2 | ||
|
|
53a6a1c691 | ||
|
|
c3ba83c7ca | ||
|
|
d9b349873e | ||
|
|
4dcefb141a | ||
|
|
c674e32046 | ||
|
|
8aa1027aae | ||
|
|
b4cb9c3fb3 | ||
|
|
d82ab5d60d | ||
|
|
979b636eec | ||
|
|
bf8a75b201 | ||
|
|
87111c8736 | ||
|
|
9b97e478aa | ||
|
|
2af7abee3c | ||
|
|
2c8a41ebad | ||
|
|
c632cfd6b9 | ||
|
|
7f05df2fb3 | ||
|
|
ff33432809 | ||
|
|
0a57e69bcf | ||
|
|
7af8b15dbb | ||
|
|
bc4931d971 | ||
|
|
cfb029b6b4 | ||
|
|
6fa50101a6 | ||
|
|
843fbc83f4 | ||
|
|
55f8fb3b66 | ||
|
|
a47774472d | ||
|
|
713f4ca356 | ||
|
|
b06795510a | ||
|
|
0f57ec099a | ||
|
|
8325caabdc | ||
|
|
44d276d7e7 | ||
|
|
935340561b | ||
|
|
a60fde3b91 | ||
|
|
163a855d5c | ||
|
|
c9b1e75361 | ||
|
|
a9932d0866 | ||
|
|
11d29919bf | ||
|
|
4fe755332d | ||
|
|
0095e0f4dd | ||
|
|
322c72ab54 | ||
|
|
4d51459a47 | ||
|
|
d51de30898 | ||
|
|
90f9edbf24 | ||
|
|
8aa10457a7 | ||
|
|
ab584720c6 | ||
|
|
56ad281cb6 | ||
|
|
61281cca02 | ||
|
|
b53dbbc38e | ||
|
|
3f88cfba28 | ||
|
|
e855d8b9af | ||
|
|
171720e629 | ||
|
|
8aa6b33fba | ||
|
|
505fc803db | ||
|
|
b5146620a6 | ||
|
|
7d44f24347 | ||
|
|
4dccc6e860 | ||
|
|
ee6585c737 | ||
|
|
62e5e8a69f | ||
|
|
e942a99ff0 | ||
|
|
b3fe49684b | ||
|
|
dcf1985361 | ||
|
|
8f4f4cc004 | ||
|
|
f49baadb76 | ||
|
|
5233484fc5 | ||
|
|
84c4cc8b5d | ||
|
|
77036eccd8 | ||
|
|
dcdb08ec80 | ||
|
|
cd7f688e78 | ||
|
|
cb12a052ac | ||
|
|
995c359f20 | ||
|
|
690066ad32 | ||
|
|
73942e315a | ||
|
|
48badb3243 | ||
|
|
d5eb12cc4e | ||
|
|
7d7539df4c | ||
|
|
14a8f44f8c | ||
|
|
a7be470f33 | ||
|
|
a677169f60 | ||
|
|
b72ef4f2aa | ||
|
|
403054751b | ||
|
|
b3e5c734d4 | ||
|
|
5732125ff6 | ||
|
|
eb66cf7aad | ||
|
|
a317c35eab | ||
|
|
ab138560c1 | ||
|
|
f0fbad889d | ||
|
|
1323cd5dc6 | ||
|
|
2c43d8e145 | ||
|
|
0214beb679 | ||
|
|
7d73cdef33 | ||
|
|
fcfab2c750 | ||
|
|
e048be17a5 | ||
|
|
024f1de4f1 | ||
|
|
d2c9f7a778 | ||
|
|
1784d2ec61 | ||
|
|
8f4a213f55 | ||
|
|
6a8c684af0 | ||
|
|
aefba83319 | ||
|
|
e411f4062a | ||
|
|
3c6802860d | ||
|
|
3daad5ea90 | ||
|
|
6835c38c24 | ||
|
|
32be9b71d5 | ||
|
|
84bc0e0fb4 | ||
|
|
8105dc9c82 | ||
|
|
840c968454 | ||
|
|
8c5f19a0f4 | ||
|
|
bf813aa906 | ||
|
|
e5ac7f10d4 | ||
|
|
d049e04fa2 | ||
|
|
ef45b08ee5 | ||
|
|
d77644ab16 | ||
|
|
1a90b4a3cb | ||
|
|
9e5d401a85 | ||
|
|
6da6dc2b8c | ||
|
|
2ca7021df0 | ||
|
|
1682cdad37 | ||
|
|
ec5e898feb | ||
|
|
ccf6fb1b36 | ||
|
|
83c8d619d0 | ||
|
|
dd5b8219a1 | ||
|
|
34fd927972 | ||
|
|
6db5ad2697 | ||
|
|
0be1f27970 | ||
|
|
54603798fc | ||
|
|
2f1e947323 | ||
|
|
ef2cfe1c1d | ||
|
|
f8edf79c59 | ||
|
|
dec80b6567 | ||
|
|
4dac9237ef | ||
|
|
12f5f373b3 | ||
|
|
76472770bf | ||
|
|
f5baf77c3c | ||
|
|
126276c727 | ||
|
|
5d6ba83fc5 | ||
|
|
047c3b596d | ||
|
|
2240ff08a1 | ||
|
|
4d6bf56fa0 | ||
|
|
10ad9a5601 | ||
|
|
fb39500428 | ||
|
|
615a52cef9 | ||
|
|
791be0583a | ||
|
|
a324731061 | ||
|
|
539d9cf537 | ||
|
|
699312ff28 | ||
|
|
b92b0ec149 | ||
|
|
51536062f1 | ||
|
|
4c230b4c1e | ||
|
|
a7752ceb17 | ||
|
|
ed59a90d78 | ||
|
|
11d65e7527 | ||
|
|
b6ac5f0f84 | ||
|
|
c336e62885 | ||
|
|
b868cdb25e | ||
|
|
04339539d1 | ||
|
|
2d146880ec | ||
|
|
6eec4ef7f4 | ||
|
|
9841f3dd18 | ||
|
|
03e0118fb7 | ||
|
|
c7c222b357 | ||
|
|
2d8e45cd1b | ||
|
|
e2bd5cc245 | ||
|
|
47ddfec30e | ||
|
|
9344b2a324 | ||
|
|
8496fcccc5 | ||
|
|
c6fa3b9d25 | ||
|
|
ce13987748 | ||
|
|
5221fc4f6a | ||
|
|
d4dc388d3f | ||
|
|
42966c2537 | ||
|
|
7921dcd86b | ||
|
|
4c69bb6c48 | ||
|
|
0aad809c82 | ||
|
|
f514a5a416 | ||
|
|
793a7460c6 | ||
|
|
6dcc979fd5 | ||
|
|
5a07732712 | ||
|
|
61d71b32ff | ||
|
|
ba62ca3d18 | ||
|
|
612271bf0c | ||
|
|
3b99fb5c96 | ||
|
|
bb61f8197c | ||
|
|
b54f04a35b | ||
|
|
d47639bada | ||
|
|
ae9bab2981 | ||
|
|
2116b094ad | ||
|
|
288883a13b | ||
|
|
07c988abae | ||
|
|
fd4a3b5671 | ||
|
|
71adfad94d | ||
|
|
7faaaf3dcd | ||
|
|
25e7db5ac9 | ||
|
|
07bd5f1926 | ||
|
|
9439d02351 | ||
|
|
cbea7ccdf6 | ||
|
|
93661dfde4 | ||
|
|
b98f5351cf | ||
|
|
83a7261fcd | ||
|
|
daa2b7a8cd | ||
|
|
d245fedb3f | ||
|
|
b0fee2cb3c | ||
|
|
9a102056d8 | ||
|
|
3905463940 | ||
|
|
746fde592d | ||
|
|
3e5f5554da | ||
|
|
01fb6e8772 | ||
|
|
b7448232e6 | ||
|
|
05f1a24199 | ||
|
|
4072799c13 | ||
|
|
9744032f93 | ||
|
|
eb9a92d76d | ||
|
|
89a4932823 | ||
|
|
cef06a8894 | ||
|
|
c741edffb0 | ||
|
|
e7c543fcb9 | ||
|
|
2a61720b0a | ||
|
|
73484647ba | ||
|
|
c9d461f8c8 | ||
|
|
9bdc056359 | ||
|
|
6a8a1e799d | ||
|
|
c3c55f3a13 | ||
|
|
6f881a80d6 | ||
|
|
a75c4110a8 | ||
|
|
3e031c6191 | ||
|
|
a4b7ca824e | ||
|
|
ecab2b63c9 | ||
|
|
620e3d55d1 | ||
|
|
3716d7fd47 | ||
|
|
60764d198a | ||
|
|
3178d9da88 | ||
|
|
7264313c9c | ||
|
|
71c36881fb | ||
|
|
5a0f7ae838 | ||
|
|
10fb61bd57 | ||
|
|
6d4b4c6ba7 | ||
|
|
798a737f06 | ||
|
|
0a9e125f89 | ||
|
|
21b3525f23 | ||
|
|
8e842c385d | ||
|
|
8e8a587bca | ||
|
|
155aa2580b | ||
|
|
01aa381848 | ||
|
|
6c13fa02c1 | ||
|
|
c50576b508 | ||
|
|
7bc4a6906a | ||
|
|
c80318f442 | ||
|
|
cd4229a915 | ||
|
|
fbe306ba90 | ||
|
|
0dac3f1b1d | ||
|
|
7a90e6c1a7 | ||
|
|
42a4a8639d | ||
|
|
a687642a6a | ||
|
|
dbba7fc92a | ||
|
|
a0afd86b6a | ||
|
|
22b76f9919 | ||
|
|
c7a869b750 | ||
|
|
00052efbbc | ||
|
|
a36332581a | ||
|
|
8c81e6ae02 | ||
|
|
a7285f2b1a | ||
|
|
271b33ecdc | ||
|
|
b4d07cf6ab | ||
|
|
382035768e | ||
|
|
fcb825c1e2 | ||
|
|
abfeea63f7 | ||
|
|
b0ce7e6531 | ||
|
|
303aa9b580 | ||
|
|
d016d239e3 | ||
|
|
e35838c326 | ||
|
|
de15f9b56e | ||
|
|
560773a11a | ||
|
|
dd6df471dc | ||
|
|
eea5c056f3 | ||
|
|
a2d503b2f5 | ||
|
|
cf13e4a4fa | ||
|
|
45fb8e86bf | ||
|
|
099dcda185 | ||
|
|
c07e12cc5a | ||
|
|
b23f78e94d | ||
|
|
812a9a55d0 | ||
|
|
2e289e80d1 | ||
|
|
0d3dfdcbda | ||
|
|
87eae72f51 | ||
|
|
17fa7101bd | ||
|
|
312bd53079 | ||
|
|
4bc7d47576 | ||
|
|
71445b56f1 | ||
|
|
9ce9e0a4ef | ||
|
|
ae196f1aeb | ||
|
|
38e09b894d | ||
|
|
247d5ff255 | ||
|
|
0091e462fa | ||
|
|
7b314970b5 | ||
|
|
7ac881e3e3 | ||
|
|
8874723632 | ||
|
|
262bda94c4 | ||
|
|
d6e2cab5ef | ||
|
|
6d3e33a05d | ||
|
|
f2d0bec0ac | ||
|
|
dea78f4bfd | ||
|
|
f85f4b1342 | ||
|
|
d03771f8ab | ||
|
|
4b655dfac4 | ||
|
|
cdfcdd80bf | ||
|
|
64d3942ba9 | ||
|
|
16cce73f82 | ||
|
|
846edff84a | ||
|
|
d038bf31d3 | ||
|
|
376a69af5c | ||
|
|
380bb9bb3d | ||
|
|
f59e10ae1d | ||
|
|
c8d2d80cc5 | ||
|
|
f0bb9ddfca | ||
|
|
9ab86e4a85 | ||
|
|
e33f1a3ffc | ||
|
|
e2213e1ef6 | ||
|
|
bbc4a1bfa5 | ||
|
|
61e7ec9a36 | ||
|
|
534ad0bad6 | ||
|
|
db3040a50e | ||
|
|
8dd74e7dd8 | ||
|
|
206cdb2663 | ||
|
|
ca334813b7 | ||
|
|
5fc93ee8e6 | ||
|
|
9cef7b2615 | ||
|
|
a3916207ae | ||
|
|
b6e1702051 | ||
|
|
2cfc8b1ec7 | ||
|
|
2f7570eec1 | ||
|
|
070481cab0 | ||
|
|
26cd2c6cfe | ||
|
|
1ff571eb46 | ||
|
|
d8fcb4d240 | ||
|
|
778f97c1f3 | ||
|
|
1d6d9aa96d | ||
|
|
3bdd96a8ee | ||
|
|
935ad73d32 | ||
|
|
a85d55f3a8 | ||
|
|
d7c659b736 | ||
|
|
e5cedab873 | ||
|
|
3653d73f4f | ||
|
|
4af57ed861 | ||
|
|
10445c6f56 | ||
|
|
dc6051f0b0 | ||
|
|
2a524eaf22 | ||
|
|
9a810f440d | ||
|
|
27ba8db4ea | ||
|
|
7130194d5f | ||
|
|
d70afc36c9 | ||
|
|
78017b8a0e | ||
|
|
e87fdc896c | ||
|
|
7bb6d448ed | ||
|
|
6415fd9286 | ||
|
|
2dd4395698 | ||
|
|
68b6e67a93 | ||
|
|
71b35e39ab | ||
|
|
9ff6015fec | ||
|
|
124817b733 | ||
|
|
8f8f3af7cd | ||
|
|
882fe6cd00 | ||
|
|
18262f98f7 | ||
|
|
fe5a90ac2f | ||
|
|
22869b7932 | ||
|
|
e702c16a74 | ||
|
|
408690c0ae | ||
|
|
4aaf5997df | ||
|
|
f50104bc86 | ||
|
|
ee10fc18a7 | ||
|
|
818ef63aec | ||
|
|
4af374f86d | ||
|
|
277b252ad8 | ||
|
|
cc7671efd0 | ||
|
|
419276eb85 | ||
|
|
7d97b9142a | ||
|
|
c3c041f675 | ||
|
|
d790e6b731 | ||
|
|
8b714a4710 | ||
|
|
1f0d01d2ed | ||
|
|
7727cd4f58 | ||
|
|
bb6b3a57af | ||
|
|
a70a4c272c | ||
|
|
99bd4da54b | ||
|
|
3e09a5e57f | ||
|
|
1375179138 | ||
|
|
a8b1fbbef0 | ||
|
|
d490fcf5af | ||
|
|
cdbe5b2e2f | ||
|
|
15b1c756a7 | ||
|
|
3dfad93977 | ||
|
|
3fcd83b0a7 | ||
|
|
03e48881a6 | ||
|
|
6eb0b4cb5b | ||
|
|
556d8586a7 | ||
|
|
0ce6e51925 | ||
|
|
c2dec7b955 | ||
|
|
b3733ed9ed | ||
|
|
be5106c819 | ||
|
|
4875db08e8 | ||
|
|
f0593996a1 | ||
|
|
6e113cc9c6 | ||
|
|
7ffc5e6624 | ||
|
|
d1689300b9 | ||
|
|
5fc7a7dd8a | ||
|
|
f59609131c | ||
|
|
efd1733b56 | ||
|
|
31289d24e2 | ||
|
|
98be091ca6 | ||
|
|
4bfdf1dede | ||
|
|
c6a43a5dde | ||
|
|
3a20946f62 | ||
|
|
d892400ca7 | ||
|
|
44b7199087 |
15
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
15
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@@ -9,9 +9,9 @@ body:
|
|||||||
请确认以下信息:
|
请确认以下信息:
|
||||||
1. 请按此模板提交issues,不按模板提交的问题将直接关闭。
|
1. 请按此模板提交issues,不按模板提交的问题将直接关闭。
|
||||||
2. 如果你的问题可以直接在以往 issue 或者 Telegram频道 中找到,那么你的 issue 将会被直接关闭。
|
2. 如果你的问题可以直接在以往 issue 或者 Telegram频道 中找到,那么你的 issue 将会被直接关闭。
|
||||||
3. 【提交问题务必描述清楚、附上日志】,描述不清导致无法理解和分析的问题会被直接关闭。
|
3. **$\color{red}{提交问题务必描述清楚、附上日志}$**,描述不清导致无法理解和分析的问题会被直接关闭。
|
||||||
4. 此仓库为后端仓库,如果是前端 WebUI 问题请在[前端仓库](https://github.com/jxxghp/MoviePilot-Frontend)提 issue。
|
4. 此仓库为后端仓库,如果是前端 WebUI 问题请在[前端仓库](https://github.com/jxxghp/MoviePilot-Frontend)提 issue。
|
||||||
5. 【不要通过issues来寻求解决你的环境问题、配置安装类问题、咨询类问题】,否则直接关闭并加入用户黑名单!实在没有精力陪一波又一波的伸手党玩。
|
5. **$\color{red}{不要通过issues来寻求解决你的环境问题、配置安装类问题、咨询类问题}$**,否则直接关闭并加入用户 $\color{red}{黑名单}$ !实在没有精力陪一波又一波的伸手党玩。
|
||||||
- type: checkboxes
|
- type: checkboxes
|
||||||
id: ensure
|
id: ensure
|
||||||
attributes:
|
attributes:
|
||||||
@@ -33,6 +33,16 @@ body:
|
|||||||
description: 遇到问题时程序所在的版本号
|
description: 遇到问题时程序所在的版本号
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
|
- type: dropdown
|
||||||
|
id: environment
|
||||||
|
attributes:
|
||||||
|
label: 运行环境
|
||||||
|
description: 当前程序运行环境
|
||||||
|
options:
|
||||||
|
- Docker
|
||||||
|
- Windows
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
- type: dropdown
|
- type: dropdown
|
||||||
id: type
|
id: type
|
||||||
attributes:
|
attributes:
|
||||||
@@ -41,7 +51,6 @@ body:
|
|||||||
options:
|
options:
|
||||||
- 主程序运行问题
|
- 主程序运行问题
|
||||||
- 插件问题
|
- 插件问题
|
||||||
- Docker或运行环境问题
|
|
||||||
- 其他问题
|
- 其他问题
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
|
|||||||
11
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
11
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
@@ -14,6 +14,16 @@ body:
|
|||||||
description: 目前使用的程序版本
|
description: 目前使用的程序版本
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
|
- type: dropdown
|
||||||
|
id: environment
|
||||||
|
attributes:
|
||||||
|
label: 运行环境
|
||||||
|
description: 当前程序运行环境
|
||||||
|
options:
|
||||||
|
- Docker
|
||||||
|
- Windows
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
- type: dropdown
|
- type: dropdown
|
||||||
id: type
|
id: type
|
||||||
attributes:
|
attributes:
|
||||||
@@ -22,7 +32,6 @@ body:
|
|||||||
options:
|
options:
|
||||||
- 主程序
|
- 主程序
|
||||||
- 插件
|
- 插件
|
||||||
- Docker
|
|
||||||
- 其他
|
- 其他
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
|
|||||||
65
.github/workflows/build.yml
vendored
65
.github/workflows/build.yml
vendored
@@ -55,8 +55,8 @@ jobs:
|
|||||||
MOVIEPILOT_VERSION=${{ env.app_version }}
|
MOVIEPILOT_VERSION=${{ env.app_version }}
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
cache-from: type=gha, scope=${{ github.workflow }}
|
cache-from: type=gha, scope=${{ github.workflow }}-docker
|
||||||
cache-to: type=gha, scope=${{ github.workflow }}
|
cache-to: type=gha, scope=${{ github.workflow }}-docker
|
||||||
|
|
||||||
Windows-build:
|
Windows-build:
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
@@ -96,11 +96,21 @@ jobs:
|
|||||||
New-Item -Path "nginx/temp/__keep__.txt" -ItemType File -Force
|
New-Item -Path "nginx/temp/__keep__.txt" -ItemType File -Force
|
||||||
New-Item -Path "nginx/logs" -ItemType Directory -Force
|
New-Item -Path "nginx/logs" -ItemType Directory -Force
|
||||||
New-Item -Path "nginx/logs/__keep__.txt" -ItemType File -Force
|
New-Item -Path "nginx/logs/__keep__.txt" -ItemType File -Force
|
||||||
|
Invoke-WebRequest -Uri "https://github.com/jxxghp/MoviePilot-Plugins/archive/refs/heads/main.zip" -OutFile "MoviePilot-Plugins-main.zip"
|
||||||
|
Expand-Archive -Path "MoviePilot-Plugins-main.zip" -DestinationPath "MoviePilot-Plugins-main"
|
||||||
|
Move-Item -Path "MoviePilot-Plugins-main/MoviePilot-Plugins-main/plugins/*" -Destination "app/plugins/" -Force
|
||||||
|
Remove-Item -Path "MoviePilot-Plugins-main.zip"
|
||||||
|
Remove-Item -Path "MoviePilot-Plugins-main" -Recurse -Force
|
||||||
|
Invoke-WebRequest -Uri "https://github.com/jxxghp/MoviePilot-Resources/archive/refs/heads/main.zip" -OutFile "MoviePilot-Resources-main.zip"
|
||||||
|
Expand-Archive -Path "MoviePilot-Resources-main.zip" -DestinationPath "MoviePilot-Resources-main"
|
||||||
|
Move-Item -Path "MoviePilot-Resources-main/MoviePilot-Resources-main/resources/*" -Destination "app/helper/" -Force
|
||||||
|
Remove-Item -Path "MoviePilot-Resources-main.zip"
|
||||||
|
Remove-Item -Path "MoviePilot-Resources-main" -Recurse -Force
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
|
|
||||||
- name: Pyinstaller
|
- name: Pyinstaller
|
||||||
run: |
|
run: |
|
||||||
pyinstaller windows.spec
|
pyinstaller frozen.spec
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
|
|
||||||
- name: Upload Windows File
|
- name: Upload Windows File
|
||||||
@@ -109,10 +119,54 @@ jobs:
|
|||||||
name: windows
|
name: windows
|
||||||
path: dist/MoviePilot.exe
|
path: dist/MoviePilot.exe
|
||||||
|
|
||||||
|
Linux-build-amd64:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Build Linux Amd64
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Init Python 3.11.4
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.11.4'
|
||||||
|
cache: 'pip'
|
||||||
|
|
||||||
|
- name: Install Dependent Packages
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install wheel pyinstaller
|
||||||
|
pip install -r requirements.txt
|
||||||
|
|
||||||
|
- name: Prepare Frontend
|
||||||
|
run: |
|
||||||
|
wget https://github.com/jxxghp/MoviePilot-Plugins/archive/refs/heads/main.zip
|
||||||
|
unzip main.zip
|
||||||
|
mv MoviePilot-Plugins-main/plugins/* app/plugins/
|
||||||
|
rm main.zip
|
||||||
|
rm -rf MoviePilot-Plugins-main
|
||||||
|
|
||||||
|
wget https://github.com/jxxghp/MoviePilot-Resources/archive/refs/heads/main.zip
|
||||||
|
unzip main.zip
|
||||||
|
mv MoviePilot-Resources-main/resources/* app/helper/
|
||||||
|
rm main.zip
|
||||||
|
rm -rf MoviePilot-Resources-main
|
||||||
|
|
||||||
|
- name: Pyinstaller
|
||||||
|
run: |
|
||||||
|
pyinstaller frozen.spec
|
||||||
|
mv dist/MoviePilot dist/MoviePilot_Amd64
|
||||||
|
|
||||||
|
- name: Upload Linux File
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: linux-amd64
|
||||||
|
path: dist/MoviePilot_Amd64
|
||||||
|
|
||||||
Create-release:
|
Create-release:
|
||||||
permissions: write-all
|
permissions: write-all
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [ Windows-build, Docker-build ]
|
needs: [ Windows-build, Docker-build, Linux-build-amd64]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
@@ -129,7 +183,8 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
mkdir releases
|
mkdir releases
|
||||||
mv ./windows/MoviePilot.exe ./releases/MoviePilot_v${{ env.app_version }}.exe
|
mv ./windows/MoviePilot.exe ./releases/MoviePilot_Win_v${{ env.app_version }}.exe
|
||||||
|
mv ./linux-amd64/MoviePilot_Amd64 ./releases/MoviePilot_Amd64_v${{ env.app_version }}
|
||||||
|
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
id: create_release
|
id: create_release
|
||||||
|
|||||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -5,6 +5,12 @@ dist/
|
|||||||
nginx/
|
nginx/
|
||||||
test.py
|
test.py
|
||||||
app/helper/sites.py
|
app/helper/sites.py
|
||||||
|
app/helper/*.so
|
||||||
|
app/helper/*.pyd
|
||||||
|
app/helper/*.bin
|
||||||
|
app/plugins/**
|
||||||
|
!app/plugins/__init__.py
|
||||||
config/user.db
|
config/user.db
|
||||||
|
config/sites/**
|
||||||
*.pyc
|
*.pyc
|
||||||
*.log
|
*.log
|
||||||
|
|||||||
12
Dockerfile
12
Dockerfile
@@ -11,8 +11,7 @@ ENV LANG="C.UTF-8" \
|
|||||||
PORT=3001 \
|
PORT=3001 \
|
||||||
NGINX_PORT=3000 \
|
NGINX_PORT=3000 \
|
||||||
PROXY_HOST="" \
|
PROXY_HOST="" \
|
||||||
MOVIEPILOT_AUTO_UPDATE=true \
|
MOVIEPILOT_AUTO_UPDATE=release \
|
||||||
MOVIEPILOT_AUTO_UPDATE_DEV=false \
|
|
||||||
AUTH_SITE="iyuu" \
|
AUTH_SITE="iyuu" \
|
||||||
IYUU_SIGN=""
|
IYUU_SIGN=""
|
||||||
WORKDIR "/app"
|
WORKDIR "/app"
|
||||||
@@ -32,6 +31,8 @@ RUN apt-get update -y \
|
|||||||
jq \
|
jq \
|
||||||
haproxy \
|
haproxy \
|
||||||
fuse3 \
|
fuse3 \
|
||||||
|
rsync \
|
||||||
|
ffmpeg \
|
||||||
&& \
|
&& \
|
||||||
if [ "$(uname -m)" = "x86_64" ]; \
|
if [ "$(uname -m)" = "x86_64" ]; \
|
||||||
then ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1; \
|
then ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1; \
|
||||||
@@ -76,7 +77,12 @@ RUN cp -f /app/nginx.conf /etc/nginx/nginx.template.conf \
|
|||||||
&& locale-gen zh_CN.UTF-8 \
|
&& locale-gen zh_CN.UTF-8 \
|
||||||
&& FRONTEND_VERSION=$(curl -sL "https://api.github.com/repos/jxxghp/MoviePilot-Frontend/releases/latest" | jq -r .tag_name) \
|
&& FRONTEND_VERSION=$(curl -sL "https://api.github.com/repos/jxxghp/MoviePilot-Frontend/releases/latest" | jq -r .tag_name) \
|
||||||
&& curl -sL "https://github.com/jxxghp/MoviePilot-Frontend/releases/download/${FRONTEND_VERSION}/dist.zip" | busybox unzip -d / - \
|
&& curl -sL "https://github.com/jxxghp/MoviePilot-Frontend/releases/download/${FRONTEND_VERSION}/dist.zip" | busybox unzip -d / - \
|
||||||
&& mv /dist /public
|
&& mv /dist /public \
|
||||||
|
&& curl -sL "https://github.com/jxxghp/MoviePilot-Plugins/archive/refs/heads/main.zip" | busybox unzip -d /tmp - \
|
||||||
|
&& mv -f /tmp/MoviePilot-Plugins-main/plugins/* /app/app/plugins/ \
|
||||||
|
&& curl -sL "https://github.com/jxxghp/MoviePilot-Resources/archive/refs/heads/main.zip" | busybox unzip -d /tmp - \
|
||||||
|
&& mv -f /tmp/MoviePilot-Resources-main/resources/* /app/app/helper/ \
|
||||||
|
&& rm -rf /tmp/*
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
VOLUME [ "/config" ]
|
VOLUME [ "/config" ]
|
||||||
ENTRYPOINT [ "/entrypoint" ]
|
ENTRYPOINT [ "/entrypoint" ]
|
||||||
|
|||||||
219
README.md
219
README.md
@@ -7,12 +7,14 @@
|
|||||||
发布频道:https://t.me/moviepilot_channel
|
发布频道:https://t.me/moviepilot_channel
|
||||||
|
|
||||||
## 主要特性
|
## 主要特性
|
||||||
- 前后端分离,基于FastApi + Vue3,前端项目地址:[MoviePilot-Frontend](https://github.com/jxxghp/MoviePilot-Frontend)
|
- 前后端分离,基于FastApi + Vue3,前端项目地址:[MoviePilot-Frontend](https://github.com/jxxghp/MoviePilot-Frontend),API:http://localhost:3001/docs
|
||||||
- 聚焦核心需求,简化功能和设置,部分设置项可直接使用默认值。
|
- 聚焦核心需求,简化功能和设置,部分设置项可直接使用默认值。
|
||||||
- 重新设计了用户界面,更加美观易用。
|
- 重新设计了用户界面,更加美观易用。
|
||||||
|
|
||||||
## 安装
|
## 安装
|
||||||
|
|
||||||
|
### 注意:管理员用户不要使用弱密码!如非必要不要暴露到公网。如被盗取管理账号权限,将会导致站点Cookie等敏感数据泄露!
|
||||||
|
|
||||||
### 1. **安装CookieCloud插件**
|
### 1. **安装CookieCloud插件**
|
||||||
|
|
||||||
站点信息需要通过CookieCloud同步获取,因此需要安装CookieCloud插件,将浏览器中的站点Cookie数据同步到云端后再同步到MoviePilot使用。 插件下载地址请点击 [这里](https://github.com/easychen/CookieCloud/releases)。
|
站点信息需要通过CookieCloud同步获取,因此需要安装CookieCloud插件,将浏览器中的站点Cookie数据同步到云端后再同步到MoviePilot使用。 插件下载地址请点击 [这里](https://github.com/easychen/CookieCloud/releases)。
|
||||||
@@ -41,59 +43,99 @@ MoviePilot需要配套下载器和媒体服务器配合使用。
|
|||||||
|
|
||||||
- Windows
|
- Windows
|
||||||
|
|
||||||
下载 [MoviePilot.exe](https://github.com/jxxghp/MoviePilot/releases),双击运行后自动生成配置文件目录。
|
下载 [MoviePilot.exe](https://github.com/jxxghp/MoviePilot/releases),双击运行后自动生成配置文件目录,访问:http://localhost:3000
|
||||||
|
|
||||||
|
- 群晖套件
|
||||||
|
|
||||||
|
添加套件源:https://spk7.imnks.com/
|
||||||
|
|
||||||
|
- 本地运行
|
||||||
|
|
||||||
|
1) 将工程 [MoviePilot-Plugins](https://github.com/jxxghp/MoviePilot-Plugins) plugins目录下的所有文件复制到`app/plugins`目录
|
||||||
|
2) 将工程 [MoviePilot-Resources](https://github.com/jxxghp/MoviePilot-Resources) resources目录下的所有文件复制到`app/helper`目录
|
||||||
|
3) 执行命令:`pip install -r requirements.txt` 安装依赖
|
||||||
|
4) 执行命令:`PYTHONPATH=. python app/main.py` 启动服务
|
||||||
|
5) 根据前端项目 [MoviePilot-Frontend](https://github.com/jxxghp/MoviePilot-Frontend) 说明,启动前端服务
|
||||||
|
|
||||||
## 配置
|
## 配置
|
||||||
|
|
||||||
项目的所有配置均通过环境变量进行设置,支持两种配置方式:
|
|
||||||
- 在Docker环境变量部分或Wdinows系统环境变量中进行参数配置,如未自动显示配置项则需要手动增加对应环境变量。
|
|
||||||
- 下载 [app.env](https://github.com/jxxghp/MoviePilot/raw/main/config/app.env) 配置文件,修改好配置后放置到配置文件映射路径根目录,配置项可根据说明自主增减。
|
|
||||||
|
|
||||||
配置文件映射路径:`/config`,配置项生效优先级:环境变量 > env文件 > 默认值,**部分参数如路径映射、站点认证、权限端口、时区等必须通过环境变量进行配置**。
|
配置文件映射路径:`/config`,配置项生效优先级:环境变量 > env文件 > 默认值,**部分参数如路径映射、站点认证、权限端口、时区等必须通过环境变量进行配置**。
|
||||||
|
|
||||||
> ❗号标识的为必填项,其它为可选项,可选项可删除配置变量从而使用默认值。
|
> ❗号标识的为必填项,其它为可选项,可选项可删除配置变量从而使用默认值。
|
||||||
|
|
||||||
### 1. **基础设置**
|
### 1. **环境变量**
|
||||||
|
|
||||||
- **❗NGINX_PORT:** WEB服务端口,默认`3000`,可自行修改,不能与API服务端口冲突(仅支持环境变量配置)
|
- **❗NGINX_PORT:** WEB服务端口,默认`3000`,可自行修改,不能与API服务端口冲突
|
||||||
- **❗PORT:** API服务端口,默认`3001`,可自行修改,不能与WEB服务端口冲突(仅支持环境变量配置)
|
- **❗PORT:** API服务端口,默认`3001`,可自行修改,不能与WEB服务端口冲突
|
||||||
- **PUID**:运行程序用户的`uid`,默认`0`(仅支持环境变量配置)
|
- **PUID**:运行程序用户的`uid`,默认`0`
|
||||||
- **PGID**:运行程序用户的`gid`,默认`0`(仅支持环境变量配置)
|
- **PGID**:运行程序用户的`gid`,默认`0`
|
||||||
- **UMASK**:掩码权限,默认`000`,可以考虑设置为`022`(仅支持环境变量配置)
|
- **UMASK**:掩码权限,默认`000`,可以考虑设置为`022`
|
||||||
- **PROXY_HOST:** 网络代理,访问themoviedb或者重启更新需要使用代理访问,格式为`http(s)://ip:port`、`socks5://user:pass@host:port`(仅支持环境变量配置)
|
- **PROXY_HOST:** 网络代理,访问themoviedb或者重启更新需要使用代理访问,格式为`http(s)://ip:port`、`socks5://user:pass@host:port`
|
||||||
- **MOVIEPILOT_AUTO_UPDATE**:重启更新,`true`/`false`,默认`true` **注意:如果出现网络问题可以配置`PROXY_HOST`**(仅支持环境变量配置)
|
- **MOVIEPILOT_AUTO_UPDATE:** 重启时自动更新,`true`/`release`/`dev`/`false`,默认`release`,需要能正常连接Github **注意:如果出现网络问题可以配置`PROXY_HOST`**
|
||||||
- **MOVIEPILOT_AUTO_UPDATE_DEV**:重启时更新到未发布的开发版本代码,`true`/`false`,默认`false`(仅支持环境变量配置)
|
- **AUTO_UPDATE_RESOURCE**:启动时自动检测和更新资源包(站点索引及认证等),`true`/`false`,默认`true`,需要能正常连接Github,仅支持Docker
|
||||||
---
|
- **❗AUTH_SITE:** 认证站点(认证通过后才能使用站点相关功能),支持配置多个认证站点,使用`,`分隔,如:`iyuu,hhclub`,会依次执行认证操作,直到有一个站点认证成功。
|
||||||
- **❗SUPERUSER:** 超级管理员用户名,默认`admin`,安装后使用该用户登录后台管理界面
|
|
||||||
- **❗SUPERUSER_PASSWORD:** 超级管理员初始密码,默认`password`,建议修改为复杂密码
|
配置`AUTH_SITE`后,需要根据下表配置对应站点的认证参数,认证资源`v1.1.1`支持`iyuu`/`hhclub`/`audiences`/`hddolby`/`zmpt`/`freefarm`/`hdfans`/`wintersakura`/`leaves`/`ptba` /`icc2022`/`ptlsp`/`xingtan`/`ptvicomo`/`agsvpt`
|
||||||
|
|
||||||
|
| 站点 | 参数 |
|
||||||
|
|:------------:|:-----------------------------------------------------:|
|
||||||
|
| iyuu | `IYUU_SIGN`:IYUU登录令牌 |
|
||||||
|
| hhclub | `HHCLUB_USERNAME`:用户名<br/>`HHCLUB_PASSKEY`:密钥 |
|
||||||
|
| audiences | `AUDIENCES_UID`:用户ID<br/>`AUDIENCES_PASSKEY`:密钥 |
|
||||||
|
| hddolby | `HDDOLBY_ID`:用户ID<br/>`HDDOLBY_PASSKEY`:密钥 |
|
||||||
|
| zmpt | `ZMPT_UID`:用户ID<br/>`ZMPT_PASSKEY`:密钥 |
|
||||||
|
| freefarm | `FREEFARM_UID`:用户ID<br/>`FREEFARM_PASSKEY`:密钥 |
|
||||||
|
| hdfans | `HDFANS_UID`:用户ID<br/>`HDFANS_PASSKEY`:密钥 |
|
||||||
|
| wintersakura | `WINTERSAKURA_UID`:用户ID<br/>`WINTERSAKURA_PASSKEY`:密钥 |
|
||||||
|
| leaves | `LEAVES_UID`:用户ID<br/>`LEAVES_PASSKEY`:密钥 |
|
||||||
|
| ptba | `PTBA_UID`:用户ID<br/>`PTBA_PASSKEY`:密钥 |
|
||||||
|
| icc2022 | `ICC2022_UID`:用户ID<br/>`ICC2022_PASSKEY`:密钥 |
|
||||||
|
| ptlsp | `PTLSP_UID`:用户ID<br/>`PTLSP_PASSKEY`:密钥 |
|
||||||
|
| xingtan | `XINGTAN_UID`:用户ID<br/>`XINGTAN_PASSKEY`:密钥 |
|
||||||
|
| ptvicomo | `PTVICOMO_UID`:用户ID<br/>`PTVICOMO_PASSKEY`:密钥 |
|
||||||
|
| agsvpt | `AGSVPT_UID`:用户ID<br/>`AGSVPT_PASSKEY`:密钥 |
|
||||||
|
|
||||||
|
|
||||||
|
### 2. **app.env配置文件**
|
||||||
|
|
||||||
|
下载 [app.env 模板](https://github.com/jxxghp/MoviePilot/raw/main/config/app.env),修改后放配置文件目录下,app.env 的所有配置项也可以通过环境变量进行配置。
|
||||||
|
|
||||||
|
- **❗SUPERUSER:** 超级管理员用户名,默认`admin`,安装后使用该用户登录后台管理界面。**注意:1、初始密码为自动生成,需要在首次运行时的后台日志中查看,成功登录后可以设定中修改;2、启动一次后再次修改该值不会生效,除非删除数据库文件!**
|
||||||
- **❗API_TOKEN:** API密钥,默认`moviepilot`,在媒体服务器Webhook、微信回调等地址配置中需要加上`?token=`该值,建议修改为复杂字符串
|
- **❗API_TOKEN:** API密钥,默认`moviepilot`,在媒体服务器Webhook、微信回调等地址配置中需要加上`?token=`该值,建议修改为复杂字符串
|
||||||
- **TMDB_API_DOMAIN:** TMDB API地址,默认`api.themoviedb.org`,也可配置为`api.tmdb.org`或其它中转代理服务地址,能连通即可
|
- **BIG_MEMORY_MODE:** 大内存模式,默认为`false`,开启后会增加缓存数量,占用更多的内存,但响应速度会更快
|
||||||
|
- **GITHUB_TOKEN:** Github token,提高自动更新、插件安装等请求Github Api的限流阈值,格式:ghp_****
|
||||||
|
---
|
||||||
|
- **TMDB_API_DOMAIN:** TMDB API地址,默认`api.themoviedb.org`,也可配置为`api.tmdb.org`、`tmdb.movie-pilot.org` 或其它中转代理服务地址,能连通即可
|
||||||
- **TMDB_IMAGE_DOMAIN:** TMDB图片地址,默认`image.tmdb.org`,可配置为其它中转代理以加速TMDB图片显示,如:`static-mdb.v.geilijiasu.com`
|
- **TMDB_IMAGE_DOMAIN:** TMDB图片地址,默认`image.tmdb.org`,可配置为其它中转代理以加速TMDB图片显示,如:`static-mdb.v.geilijiasu.com`
|
||||||
|
- **WALLPAPER:** 登录首页电影海报,`tmdb`/`bing`,默认`tmdb`
|
||||||
|
- **RECOGNIZE_SOURCE:** 媒体信息识别来源,`themoviedb`/`douban`,默认`themoviedb`,使用`douban`时不支持二级分类
|
||||||
|
- **FANART_ENABLE:** Fanart开关,`true`/`false`,默认`true`,关闭后刮削的图片类型会大幅减少
|
||||||
---
|
---
|
||||||
- **SCRAP_METADATA:** 刮削入库的媒体文件,`true`/`false`,默认`true`
|
- **SCRAP_METADATA:** 刮削入库的媒体文件,`true`/`false`,默认`true`
|
||||||
- **SCRAP_SOURCE:** 刮削元数据及图片使用的数据源,`themoviedb`/`douban`,默认`themoviedb`
|
- **SCRAP_SOURCE:** 刮削元数据及图片使用的数据源,`themoviedb`/`douban`,默认`themoviedb`
|
||||||
- **SCRAP_FOLLOW_TMDB:** 新增已入库媒体是否跟随TMDB信息变化,`true`/`false`,默认`true`
|
- **SCRAP_FOLLOW_TMDB:** 新增已入库媒体是否跟随TMDB信息变化,`true`/`false`,默认`true`,为`false`时即使TMDB信息变化了也会仍然按历史记录中已入库的信息进行刮削
|
||||||
---
|
---
|
||||||
- **❗TRANSFER_TYPE:** 整理转移方式,支持`link`/`copy`/`move`/`softlink`/`rclone_copy`/`rclone_move` **注意:在`link`和`softlink`转移方式下,转移后的文件会继承源文件的权限掩码,不受`UMASK`影响;rclone需要自行映射rclone配置目录到容器中或在容器内完成rclone配置,节点名称必须为:`MP`**
|
|
||||||
- **❗LIBRARY_PATH:** 媒体库目录,多个目录使用`,`分隔
|
- **❗LIBRARY_PATH:** 媒体库目录,多个目录使用`,`分隔
|
||||||
- **LIBRARY_MOVIE_NAME:** 电影媒体库目录名称(不是完整路径),默认`电影`
|
- **LIBRARY_MOVIE_NAME:** 电影媒体库目录名称(不是完整路径),默认`电影`
|
||||||
- **LIBRARY_TV_NAME:** 电视剧媒体库目录称(不是完整路径),默认`电视剧`
|
- **LIBRARY_TV_NAME:** 电视剧媒体库目录称(不是完整路径),默认`电视剧`
|
||||||
- **LIBRARY_ANIME_NAME:** 动漫媒体库目录称(不是完整路径),默认`电视剧/动漫`
|
- **LIBRARY_ANIME_NAME:** 动漫媒体库目录称(不是完整路径),默认`电视剧/动漫`
|
||||||
- **LIBRARY_CATEGORY:** 媒体库二级分类开关,`true`/`false`,默认`false`,开启后会根据配置 [category.yaml](https://github.com/jxxghp/MoviePilot/raw/main/config/category.yaml) 自动在媒体库目录下建立二级目录分类
|
- **LIBRARY_CATEGORY:** 媒体库二级分类开关,`true`/`false`,默认`false`,开启后会根据配置 [category.yaml](https://github.com/jxxghp/MoviePilot/raw/main/config/category.yaml) 自动在媒体库目录下建立二级目录分类
|
||||||
|
- **❗TRANSFER_TYPE:** 整理转移方式,支持`link`/`copy`/`move`/`softlink`/`rclone_copy`/`rclone_move` **注意:在`link`和`softlink`转移方式下,转移后的文件会继承源文件的权限掩码,不受`UMASK`影响;rclone需要自行映射rclone配置目录到容器中或在容器内完成rclone配置,节点名称必须为:`MP`**
|
||||||
|
- **OVERWRITE_MODE:** 转移覆盖模式,默认为`size`,支持`nerver`/`size`/`always`/`latest`,分别表示`不覆盖同名文件`/`同名文件根据文件大小覆盖(大覆盖小)`/`总是覆盖同名文件`/`仅保留最新版本,删除旧版本文件(包括非同名文件)`
|
||||||
---
|
---
|
||||||
- **❗COOKIECLOUD_HOST:** CookieCloud服务器地址,格式:`http(s)://ip:port`,不配置默认使用内建服务器`https://movie-pilot.org/cookiecloud`
|
- **❗COOKIECLOUD_HOST:** CookieCloud服务器地址,格式:`http(s)://ip:port`,不配置默认使用内建服务器`https://movie-pilot.org/cookiecloud`
|
||||||
- **❗COOKIECLOUD_KEY:** CookieCloud用户KEY
|
- **❗COOKIECLOUD_KEY:** CookieCloud用户KEY
|
||||||
- **❗COOKIECLOUD_PASSWORD:** CookieCloud端对端加密密码
|
- **❗COOKIECLOUD_PASSWORD:** CookieCloud端对端加密密码
|
||||||
- **❗COOKIECLOUD_INTERVAL:** CookieCloud同步间隔(分钟)
|
- **❗COOKIECLOUD_INTERVAL:** CookieCloud同步间隔(分钟)
|
||||||
- **❗USER_AGENT:** CookieCloud保存Cookie对应的浏览器UA,建议配置,设置后可增加连接站点的成功率,同步站点后可以在管理界面中修改
|
- **❗USER_AGENT:** CookieCloud保存Cookie对应的浏览器UA,建议配置,设置后可增加连接站点的成功率,同步站点后可以在管理界面中修改
|
||||||
- **OCR_HOST:** OCR识别服务器地址,格式:`http(s)://ip:port`,用于识别站点验证码实现自动登录获取Cookie等,不配置默认使用内建服务器`https://movie-pilot.org`,可使用 [这个镜像](https://hub.docker.com/r/jxxghp/moviepilot-ocr) 自行搭建。
|
|
||||||
---
|
---
|
||||||
- **SUBSCRIBE_MODE:** 订阅模式,`rss`/`spider`,默认`spider`,`rss`模式通过定时刷新RSS来匹配订阅(RSS地址会自动获取,也可手动维护),对站点压力小,同时可设置订阅刷新周期,24小时运行,但订阅和下载通知不能过滤和显示免费,推荐使用rss模式。
|
- **SUBSCRIBE_MODE:** 订阅模式,`rss`/`spider`,默认`spider`,`rss`模式通过定时刷新RSS来匹配订阅(RSS地址会自动获取,也可手动维护),对站点压力小,同时可设置订阅刷新周期,24小时运行,但订阅和下载通知不能过滤和显示免费,推荐使用rss模式。
|
||||||
- **SUBSCRIBE_RSS_INTERVAL:** RSS订阅模式刷新时间间隔(分钟),默认`30`分钟,不能小于5分钟。
|
- **SUBSCRIBE_RSS_INTERVAL:** RSS订阅模式刷新时间间隔(分钟),默认`30`分钟,不能小于5分钟。
|
||||||
- **SUBSCRIBE_SEARCH:** 订阅搜索,`true`/`false`,默认`false`,开启后会每隔24小时对所有订阅进行全量搜索,以补齐缺失剧集(一般情况下正常订阅即可,订阅搜索只做为兜底,会增加站点压力,不建议开启)。
|
- **SUBSCRIBE_SEARCH:** 订阅搜索,`true`/`false`,默认`false`,开启后会每隔24小时对所有订阅进行全量搜索,以补齐缺失剧集(一般情况下正常订阅即可,订阅搜索只做为兜底,会增加站点压力,不建议开启)。
|
||||||
- **SEARCH_SOURCE:** 媒体信息搜索来源,`themoviedb`/`douban`,默认`themoviedb`
|
- **AUTO_DOWNLOAD_USER:** 远程交互搜索时自动择优下载的用户ID(消息通知渠道的用户ID),多个用户使用,分割,设置为 all 代表全部用户自动择优下载,未设置需要手动选择资源或者回复`0`才自动择优下载
|
||||||
|
---
|
||||||
|
- **OCR_HOST:** OCR识别服务器地址,格式:`http(s)://ip:port`,用于识别站点验证码实现自动登录获取Cookie等,不配置默认使用内建服务器`https://movie-pilot.org`,可使用 [这个镜像](https://hub.docker.com/r/jxxghp/moviepilot-ocr) 自行搭建。
|
||||||
---
|
---
|
||||||
- **AUTO_DOWNLOAD_USER:** 远程交互搜索时自动择优下载的用户ID,多个用户使用,分割,未设置需要选择资源或者回复`0`
|
|
||||||
- **❗MESSAGER:** 消息通知渠道,支持 `telegram`/`wechat`/`slack`/`synologychat`,开启多个渠道时使用`,`分隔。同时还需要配置对应渠道的环境变量,非对应渠道的变量可删除,推荐使用`telegram`
|
- **❗MESSAGER:** 消息通知渠道,支持 `telegram`/`wechat`/`slack`/`synologychat`,开启多个渠道时使用`,`分隔。同时还需要配置对应渠道的环境变量,非对应渠道的变量可删除,推荐使用`telegram`
|
||||||
|
|
||||||
- `wechat`设置项:
|
- `wechat`设置项:
|
||||||
@@ -123,7 +165,6 @@ MoviePilot需要配套下载器和媒体服务器配合使用。
|
|||||||
|
|
||||||
- **SYNOLOGYCHAT_WEBHOOK:** 在Synology Chat中创建机器人,获取机器人`传入URL`
|
- **SYNOLOGYCHAT_WEBHOOK:** 在Synology Chat中创建机器人,获取机器人`传入URL`
|
||||||
- **SYNOLOGYCHAT_TOKEN:** SynologyChat机器人`令牌`
|
- **SYNOLOGYCHAT_TOKEN:** SynologyChat机器人`令牌`
|
||||||
|
|
||||||
---
|
---
|
||||||
- **❗DOWNLOAD_PATH:** 下载保存目录,**注意:需要将`moviepilot`及`下载器`的映射路径保持一致**,否则会导致下载文件无法转移
|
- **❗DOWNLOAD_PATH:** 下载保存目录,**注意:需要将`moviepilot`及`下载器`的映射路径保持一致**,否则会导致下载文件无法转移
|
||||||
- **DOWNLOAD_MOVIE_PATH:** 电影下载保存目录路径,不设置则下载到`DOWNLOAD_PATH`
|
- **DOWNLOAD_MOVIE_PATH:** 电影下载保存目录路径,不设置则下载到`DOWNLOAD_PATH`
|
||||||
@@ -131,8 +172,7 @@ MoviePilot需要配套下载器和媒体服务器配合使用。
|
|||||||
- **DOWNLOAD_ANIME_PATH:** 动漫下载保存目录路径,不设置则下载到`DOWNLOAD_PATH`
|
- **DOWNLOAD_ANIME_PATH:** 动漫下载保存目录路径,不设置则下载到`DOWNLOAD_PATH`
|
||||||
- **DOWNLOAD_CATEGORY:** 下载二级分类开关,`true`/`false`,默认`false`,开启后会根据配置 [category.yaml](https://github.com/jxxghp/MoviePilot/raw/main/config/category.yaml) 自动在下载目录下建立二级目录分类
|
- **DOWNLOAD_CATEGORY:** 下载二级分类开关,`true`/`false`,默认`false`,开启后会根据配置 [category.yaml](https://github.com/jxxghp/MoviePilot/raw/main/config/category.yaml) 自动在下载目录下建立二级目录分类
|
||||||
- **DOWNLOAD_SUBTITLE:** 下载站点字幕,`true`/`false`,默认`true`
|
- **DOWNLOAD_SUBTITLE:** 下载站点字幕,`true`/`false`,默认`true`
|
||||||
- **DOWNLOADER_MONITOR:** 下载器监控,`true`/`false`,默认为`true`,开启后下载完成时才会自动整理入库
|
---
|
||||||
- **TORRENT_TAG:** 下载器种子标签,默认为`MOVIEPILOT`,设置后只有MoviePilot添加的下载才会处理,留空所有下载器中的任务均会处理
|
|
||||||
- **❗DOWNLOADER:** 下载器,支持`qbittorrent`/`transmission`,QB版本号要求>= 4.3.9,TR版本号要求>= 3.0,同时还需要配置对应渠道的环境变量,非对应渠道的变量可删除,推荐使用`qbittorrent`
|
- **❗DOWNLOADER:** 下载器,支持`qbittorrent`/`transmission`,QB版本号要求>= 4.3.9,TR版本号要求>= 3.0,同时还需要配置对应渠道的环境变量,非对应渠道的变量可删除,推荐使用`qbittorrent`
|
||||||
|
|
||||||
- `qbittorrent`设置项:
|
- `qbittorrent`设置项:
|
||||||
@@ -141,106 +181,85 @@ MoviePilot需要配套下载器和媒体服务器配合使用。
|
|||||||
- **QB_USER:** qbittorrent用户名
|
- **QB_USER:** qbittorrent用户名
|
||||||
- **QB_PASSWORD:** qbittorrent密码
|
- **QB_PASSWORD:** qbittorrent密码
|
||||||
- **QB_CATEGORY:** qbittorrent分类自动管理,`true`/`false`,默认`false`,开启后会将下载二级分类传递到下载器,由下载器管理下载目录,需要同步开启`DOWNLOAD_CATEGORY`
|
- **QB_CATEGORY:** qbittorrent分类自动管理,`true`/`false`,默认`false`,开启后会将下载二级分类传递到下载器,由下载器管理下载目录,需要同步开启`DOWNLOAD_CATEGORY`
|
||||||
|
- **QB_SEQUENTIAL:** qbittorrent按顺序下载,`true`/`false`,默认`true`
|
||||||
|
- **QB_FORCE_RESUME:** qbittorrent忽略队列限制,强制继续,`true`/`false`,默认 `false`
|
||||||
|
|
||||||
- `transmission`设置项:
|
- `transmission`设置项:
|
||||||
|
|
||||||
- **TR_HOST:** transmission地址,格式:`ip:port`,https需要添加`https://`前缀
|
- **TR_HOST:** transmission地址,格式:`ip:port`,https需要添加`https://`前缀
|
||||||
- **TR_USER:** transmission用户名
|
- **TR_USER:** transmission用户名
|
||||||
- **TR_PASSWORD:** transmission密码
|
- **TR_PASSWORD:** transmission密码
|
||||||
|
- **DOWNLOADER_MONITOR:** 下载器监控,`true`/`false`,默认为`true`,开启后下载完成时才会自动整理入库
|
||||||
|
- **TORRENT_TAG:** 下载器种子标签,默认为`MOVIEPILOT`,设置后只有MoviePilot添加的下载才会处理,留空所有下载器中的任务均会处理
|
||||||
---
|
---
|
||||||
- **REFRESH_MEDIASERVER:** 入库后是否刷新媒体服务器,`true`/`false`,默认`true`
|
|
||||||
- **❗MEDIASERVER:** 媒体服务器,支持`emby`/`jellyfin`/`plex`,同时开启多个使用`,`分隔。还需要配置对应媒体服务器的环境变量,非对应媒体服务器的变量可删除,推荐使用`emby`
|
- **❗MEDIASERVER:** 媒体服务器,支持`emby`/`jellyfin`/`plex`,同时开启多个使用`,`分隔。还需要配置对应媒体服务器的环境变量,非对应媒体服务器的变量可删除,推荐使用`emby`
|
||||||
|
|
||||||
- `emby`设置项:
|
- `emby`设置项:
|
||||||
|
|
||||||
- **EMBY_HOST:** Emby服务器地址,格式:`ip:port`,https需要添加`https://`前缀
|
- **EMBY_HOST:** Emby服务器地址,格式:`ip:port`,https需要添加`https://`前缀
|
||||||
|
- **EMBY_PLAY_HOST:** EMBY外网地址,格式:`http(s)://DOMAIN:PORT`,未设置时使用`EMBY_HOST`
|
||||||
- **EMBY_API_KEY:** Emby Api Key,在`设置->高级->API密钥`处生成
|
- **EMBY_API_KEY:** Emby Api Key,在`设置->高级->API密钥`处生成
|
||||||
|
|
||||||
- `jellyfin`设置项:
|
- `jellyfin`设置项:
|
||||||
|
|
||||||
- **JELLYFIN_HOST:** Jellyfin服务器地址,格式:`ip:port`,https需要添加`https://`前缀
|
- **JELLYFIN_HOST:** Jellyfin服务器地址,格式:`ip:port`,https需要添加`https://`前缀
|
||||||
|
- **JELLYFIN_PLAY_HOST:** Jellyfin外网地址,格式:`http(s)://DOMAIN:PORT`,未设置时使用`JELLYFIN_HOST`
|
||||||
- **JELLYFIN_API_KEY:** Jellyfin Api Key,在`设置->高级->API密钥`处生成
|
- **JELLYFIN_API_KEY:** Jellyfin Api Key,在`设置->高级->API密钥`处生成
|
||||||
|
|
||||||
- `plex`设置项:
|
- `plex`设置项:
|
||||||
|
|
||||||
- **PLEX_HOST:** Plex服务器地址,格式:`ip:port`,https需要添加`https://`前缀
|
- **PLEX_HOST:** Plex服务器地址,格式:`ip:port`,https需要添加`https://`前缀
|
||||||
|
- **PLEX_PLAY_HOST:** Plex外网地址,格式:`http(s)://DOMAIN:PORT`,未设置时使用`PLEX_HOST`
|
||||||
- **PLEX_TOKEN:** Plex网页Url中的`X-Plex-Token`,通过浏览器F12->网络从请求URL中获取
|
- **PLEX_TOKEN:** Plex网页Url中的`X-Plex-Token`,通过浏览器F12->网络从请求URL中获取
|
||||||
|
|
||||||
- **MEDIASERVER_SYNC_INTERVAL:** 媒体服务器同步间隔(小时),默认`6`,留空则不同步
|
- **MEDIASERVER_SYNC_INTERVAL:** 媒体服务器同步间隔(小时),默认`6`,留空则不同步
|
||||||
- **MEDIASERVER_SYNC_BLACKLIST:** 媒体服务器同步黑名单,多个媒体库名称使用,分割
|
- **MEDIASERVER_SYNC_BLACKLIST:** 媒体服务器同步黑名单,多个媒体库名称使用,分割
|
||||||
|
---
|
||||||
|
- **MOVIE_RENAME_FORMAT:** 电影重命名格式,基于jinjia2语法
|
||||||
|
|
||||||
|
`MOVIE_RENAME_FORMAT`支持的配置项:
|
||||||
|
|
||||||
### 2. **用户认证**
|
> `title`: TMDB/豆瓣中的标题
|
||||||
|
> `original_title`: TMDB/豆瓣中的原语种标题
|
||||||
|
> `name`: 从文件名中识别的名称(同时存在中英文时,优先使用中文)
|
||||||
|
> `en_name`:从文件名中识别的英文名称(可能为空)
|
||||||
|
> `original_name`: 原文件名(包括文件外缀)
|
||||||
|
> `year`: 年份
|
||||||
|
> `resourceType`:资源类型
|
||||||
|
> `effect`:特效
|
||||||
|
> `edition`: 版本(资源类型+特效)
|
||||||
|
> `videoFormat`: 分辨率
|
||||||
|
> `releaseGroup`: 制作组/字幕组
|
||||||
|
> `customization`: 自定义占位符
|
||||||
|
> `videoCodec`: 视频编码
|
||||||
|
> `audioCodec`: 音频编码
|
||||||
|
> `tmdbid`: TMDB ID(非TMDB识别源时为空)
|
||||||
|
> `imdbid`: IMDB ID(可能为空)
|
||||||
|
> `doubanid`:豆瓣ID(非豆瓣识别源时为空)
|
||||||
|
> `part`:段/节
|
||||||
|
> `fileExt`:文件扩展名
|
||||||
|
> `customization`:自定义占位符
|
||||||
|
|
||||||
|
`MOVIE_RENAME_FORMAT`默认配置格式:
|
||||||
|
|
||||||
|
```
|
||||||
|
{{title}}{% if year %} ({{year}}){% endif %}/{{title}}{% if year %} ({{year}}){% endif %}{% if part %}-{{part}}{% endif %}{% if videoFormat %} - {{videoFormat}}{% endif %}{{fileExt}}
|
||||||
|
```
|
||||||
|
|
||||||
`MoviePilot`需要认证后才能使用,配置`AUTH_SITE`后,需要根据下表配置对应站点的认证参数(**仅能通过环境变量配置**)
|
- **TV_RENAME_FORMAT:** 电视剧重命名格式,基于jinjia2语法
|
||||||
|
|
||||||
- **❗AUTH_SITE:** 认证站点,支持`iyuu`/`hhclub`/`audiences`/`hddolby`/`zmpt`/`freefarm`/`hdfans`/`wintersakura`/`leaves`/`1ptba`/`icc2022`/`ptlsp`/`xingtan`
|
|
||||||
|
|
||||||
| 站点 | 参数 |
|
|
||||||
|:------------:|:-----------------------------------------------------:|
|
|
||||||
| iyuu | `IYUU_SIGN`:IYUU登录令牌 |
|
|
||||||
| hhclub | `HHCLUB_USERNAME`:用户名<br/>`HHCLUB_PASSKEY`:密钥 |
|
|
||||||
| audiences | `AUDIENCES_UID`:用户ID<br/>`AUDIENCES_PASSKEY`:密钥 |
|
|
||||||
| hddolby | `HDDOLBY_ID`:用户ID<br/>`HDDOLBY_PASSKEY`:密钥 |
|
|
||||||
| zmpt | `ZMPT_UID`:用户ID<br/>`ZMPT_PASSKEY`:密钥 |
|
|
||||||
| freefarm | `FREEFARM_UID`:用户ID<br/>`FREEFARM_PASSKEY`:密钥 |
|
|
||||||
| hdfans | `HDFANS_UID`:用户ID<br/>`HDFANS_PASSKEY`:密钥 |
|
|
||||||
| wintersakura | `WINTERSAKURA_UID`:用户ID<br/>`WINTERSAKURA_PASSKEY`:密钥 |
|
|
||||||
| leaves | `LEAVES_UID`:用户ID<br/>`LEAVES_PASSKEY`:密钥 |
|
|
||||||
| 1ptba | `1PTBA_UID`:用户ID<br/>`1PTBA_PASSKEY`:密钥 |
|
|
||||||
| icc2022 | `ICC2022_UID`:用户ID<br/>`ICC2022_PASSKEY`:密钥 |
|
|
||||||
| ptlsp | `PTLSP_UID`:用户ID<br/>`PTLSP_PASSKEY`:密钥 |
|
|
||||||
| xingtan | `XINGTAN_UID`:用户ID<br/>`XINGTAN_PASSKEY`:密钥 |
|
|
||||||
|
|
||||||
|
|
||||||
### 2. **进阶配置**
|
|
||||||
|
|
||||||
- **BIG_MEMORY_MODE:** 大内存模式,默认为`false`,开启后会占用更多的内存,但响应速度会更快
|
|
||||||
|
|
||||||
- **MOVIE_RENAME_FORMAT:** 电影重命名格式
|
|
||||||
|
|
||||||
`MOVIE_RENAME_FORMAT`支持的配置项:
|
|
||||||
|
|
||||||
> `title`: 标题
|
|
||||||
> `original_name`: 原文件名
|
|
||||||
> `original_title`: 原语种标题
|
|
||||||
> `name`: 识别名称
|
|
||||||
> `year`: 年份
|
|
||||||
> `resourceType`:资源类型
|
|
||||||
> `effect`:特效
|
|
||||||
> `edition`: 版本(资源类型+特效)
|
|
||||||
> `videoFormat`: 分辨率
|
|
||||||
> `releaseGroup`: 制作组/字幕组
|
|
||||||
> `customization`: 自定义占位符
|
|
||||||
> `videoCodec`: 视频编码
|
|
||||||
> `audioCodec`: 音频编码
|
|
||||||
> `tmdbid`: TMDBID
|
|
||||||
> `imdbid`: IMDBID
|
|
||||||
> `part`:段/节
|
|
||||||
> `fileExt`:文件扩展名
|
|
||||||
|
|
||||||
`MOVIE_RENAME_FORMAT`默认配置格式:
|
|
||||||
|
|
||||||
```
|
|
||||||
{{title}}{% if year %} ({{year}}){% endif %}/{{title}}{% if year %} ({{year}}){% endif %}{% if part %}-{{part}}{% endif %}{% if videoFormat %} - {{videoFormat}}{% endif %}{{fileExt}}
|
|
||||||
```
|
|
||||||
|
|
||||||
- **TV_RENAME_FORMAT:** 电视剧重命名格式
|
|
||||||
|
|
||||||
`TV_RENAME_FORMAT`额外支持的配置项:
|
|
||||||
|
|
||||||
> `season`: 季号
|
|
||||||
> `episode`: 集号
|
|
||||||
> `season_episode`: 季集 SxxExx
|
|
||||||
> `episode_title`: 集标题
|
|
||||||
|
|
||||||
`TV_RENAME_FORMAT`默认配置格式:
|
|
||||||
|
|
||||||
```
|
|
||||||
{{title}}{% if year %} ({{year}}){% endif %}/Season {{season}}/{{title}} - {{season_episode}}{% if part %}-{{part}}{% endif %}{% if episode %} - 第 {{episode}} 集{% endif %}{{fileExt}}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
`TV_RENAME_FORMAT`额外支持的配置项:
|
||||||
|
|
||||||
|
> `season`: 季号
|
||||||
|
> `episode`: 集号
|
||||||
|
> `season_episode`: 季集 SxxExx
|
||||||
|
> `episode_title`: 集标题
|
||||||
|
|
||||||
|
`TV_RENAME_FORMAT`默认配置格式:
|
||||||
|
|
||||||
|
```
|
||||||
|
{{title}}{% if year %} ({{year}}){% endif %}/Season {{season}}/{{title}} - {{season_episode}}{% if part %}-{{part}}{% endif %}{% if episode %} - 第 {{episode}} 集{% endif %}{{fileExt}}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### 3. **优先级规则**
|
### 3. **优先级规则**
|
||||||
|
|
||||||
@@ -248,6 +267,10 @@ MoviePilot需要配套下载器和媒体服务器配合使用。
|
|||||||
- 符合任一层级规则的资源将被标识选中,匹配成功的层级做为该资源的优先级,排越前面优先级超高
|
- 符合任一层级规则的资源将被标识选中,匹配成功的层级做为该资源的优先级,排越前面优先级超高
|
||||||
- 不符合过滤规则所有层级规则的资源将不会被选中
|
- 不符合过滤规则所有层级规则的资源将不会被选中
|
||||||
|
|
||||||
|
### 4. **插件扩展**
|
||||||
|
|
||||||
|
- **PLUGIN_MARKET:** 插件市场仓库地址,仅支持Github仓库`main`分支,多个地址使用`,`分隔,默认为官方插件仓库:`https://github.com/jxxghp/MoviePilot-Plugins` ,通过查看[MoviePilot-Plugins](https://github.com/jxxghp/MoviePilot-Plugins)项目的fork,或者查看频道置顶了解更多第三方插件仓库。
|
||||||
|
|
||||||
|
|
||||||
## 使用
|
## 使用
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
|
||||||
from app.api.endpoints import login, user, site, message, webhook, subscribe, \
|
from app.api.endpoints import login, user, site, message, webhook, subscribe, \
|
||||||
media, douban, search, plugin, tmdb, history, system, download, dashboard, filebrowser, transfer
|
media, douban, search, plugin, tmdb, history, system, download, dashboard, filebrowser, transfer, mediaserver
|
||||||
|
|
||||||
api_router = APIRouter()
|
api_router = APIRouter()
|
||||||
api_router.include_router(login.router, prefix="/login", tags=["login"])
|
api_router.include_router(login.router, prefix="/login", tags=["login"])
|
||||||
@@ -21,3 +21,4 @@ api_router.include_router(download.router, prefix="/download", tags=["download"]
|
|||||||
api_router.include_router(dashboard.router, prefix="/dashboard", tags=["dashboard"])
|
api_router.include_router(dashboard.router, prefix="/dashboard", tags=["dashboard"])
|
||||||
api_router.include_router(filebrowser.router, prefix="/filebrowser", tags=["filebrowser"])
|
api_router.include_router(filebrowser.router, prefix="/filebrowser", tags=["filebrowser"])
|
||||||
api_router.include_router(transfer.router, prefix="/transfer", tags=["transfer"])
|
api_router.include_router(transfer.router, prefix="/transfer", tags=["transfer"])
|
||||||
|
api_router.include_router(mediaserver.router, prefix="/mediaserver", tags=["mediaserver"])
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
from pathlib import Path
|
|
||||||
from typing import Any, List, Optional
|
from typing import Any, List, Optional
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
@@ -7,7 +6,7 @@ from sqlalchemy.orm import Session
|
|||||||
from app import schemas
|
from app import schemas
|
||||||
from app.chain.dashboard import DashboardChain
|
from app.chain.dashboard import DashboardChain
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.core.security import verify_token
|
from app.core.security import verify_token, verify_uri_token
|
||||||
from app.db import get_db
|
from app.db import get_db
|
||||||
from app.db.models.transferhistory import TransferHistory
|
from app.db.models.transferhistory import TransferHistory
|
||||||
from app.scheduler import Scheduler
|
from app.scheduler import Scheduler
|
||||||
@@ -35,6 +34,14 @@ def statistic(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
|||||||
return schemas.Statistic()
|
return schemas.Statistic()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/statistic2", summary="媒体数量统计(API_TOKEN)", response_model=schemas.Statistic)
|
||||||
|
def statistic2(_: str = Depends(verify_uri_token)) -> Any:
|
||||||
|
"""
|
||||||
|
查询媒体数量统计信息 API_TOKEN认证(?token=xxx)
|
||||||
|
"""
|
||||||
|
return statistic()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/storage", summary="存储空间", response_model=schemas.Storage)
|
@router.get("/storage", summary="存储空间", response_model=schemas.Storage)
|
||||||
def storage(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
def storage(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
@@ -47,6 +54,14 @@ def storage(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/storage2", summary="存储空间(API_TOKEN)", response_model=schemas.Storage)
|
||||||
|
def storage2(_: str = Depends(verify_uri_token)) -> Any:
|
||||||
|
"""
|
||||||
|
查询存储空间信息 API_TOKEN认证(?token=xxx)
|
||||||
|
"""
|
||||||
|
return storage()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/processes", summary="进程信息", response_model=List[schemas.ProcessInfo])
|
@router.get("/processes", summary="进程信息", response_model=List[schemas.ProcessInfo])
|
||||||
def processes(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
def processes(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
@@ -61,7 +76,7 @@ def downloader(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
|||||||
查询下载器信息
|
查询下载器信息
|
||||||
"""
|
"""
|
||||||
transfer_info = DashboardChain().downloader_info()
|
transfer_info = DashboardChain().downloader_info()
|
||||||
free_space = SystemUtils.free_space(Path(settings.DOWNLOAD_PATH))
|
free_space = SystemUtils.free_space(settings.SAVE_PATH)
|
||||||
if transfer_info:
|
if transfer_info:
|
||||||
return schemas.DownloaderInfo(
|
return schemas.DownloaderInfo(
|
||||||
download_speed=transfer_info.download_speed,
|
download_speed=transfer_info.download_speed,
|
||||||
@@ -74,6 +89,14 @@ def downloader(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
|||||||
return schemas.DownloaderInfo()
|
return schemas.DownloaderInfo()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/downloader2", summary="下载器信息(API_TOKEN)", response_model=schemas.DownloaderInfo)
|
||||||
|
def downloader2(_: str = Depends(verify_uri_token)) -> Any:
|
||||||
|
"""
|
||||||
|
查询下载器信息 API_TOKEN认证(?token=xxx)
|
||||||
|
"""
|
||||||
|
return downloader()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/schedule", summary="后台服务", response_model=List[schemas.ScheduleInfo])
|
@router.get("/schedule", summary="后台服务", response_model=List[schemas.ScheduleInfo])
|
||||||
def schedule(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
def schedule(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
@@ -82,6 +105,14 @@ def schedule(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
|||||||
return Scheduler().list()
|
return Scheduler().list()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/schedule2", summary="后台服务(API_TOKEN)", response_model=List[schemas.ScheduleInfo])
|
||||||
|
def schedule2(_: str = Depends(verify_uri_token)) -> Any:
|
||||||
|
"""
|
||||||
|
查询下载器信息 API_TOKEN认证(?token=xxx)
|
||||||
|
"""
|
||||||
|
return schedule()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/transfer", summary="文件整理统计", response_model=List[int])
|
@router.get("/transfer", summary="文件整理统计", response_model=List[int])
|
||||||
def transfer(days: int = 7, db: Session = Depends(get_db),
|
def transfer(days: int = 7, db: Session = Depends(get_db),
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
@@ -100,9 +131,25 @@ def cpu(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
|||||||
return SystemUtils.cpu_usage()
|
return SystemUtils.cpu_usage()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/cpu2", summary="获取当前CPU使用率(API_TOKEN)", response_model=int)
|
||||||
|
def cpu2(_: str = Depends(verify_uri_token)) -> Any:
|
||||||
|
"""
|
||||||
|
获取当前CPU使用率 API_TOKEN认证(?token=xxx)
|
||||||
|
"""
|
||||||
|
return cpu()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/memory", summary="获取当前内存使用量和使用率", response_model=List[int])
|
@router.get("/memory", summary="获取当前内存使用量和使用率", response_model=List[int])
|
||||||
def memory(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
def memory(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
获取当前内存使用率
|
获取当前内存使用率
|
||||||
"""
|
"""
|
||||||
return SystemUtils.memory_usage()
|
return SystemUtils.memory_usage()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/memory2", summary="获取当前内存使用量和使用率(API_TOKEN)", response_model=List[int])
|
||||||
|
def memory2(_: str = Depends(verify_uri_token)) -> Any:
|
||||||
|
"""
|
||||||
|
获取当前内存使用率 API_TOKEN认证(?token=xxx)
|
||||||
|
"""
|
||||||
|
return memory()
|
||||||
|
|||||||
@@ -28,20 +28,6 @@ def douban_img(imgurl: str) -> Any:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@router.get("/recognize/{doubanid}", summary="豆瓣ID识别", response_model=schemas.Context)
|
|
||||||
def recognize_doubanid(doubanid: str,
|
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
|
||||||
"""
|
|
||||||
根据豆瓣ID识别媒体信息
|
|
||||||
"""
|
|
||||||
# 识别媒体信息
|
|
||||||
context = DoubanChain().recognize_by_doubanid(doubanid=doubanid)
|
|
||||||
if context:
|
|
||||||
return context.to_dict()
|
|
||||||
else:
|
|
||||||
return schemas.Context()
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/showing", summary="豆瓣正在热映", response_model=List[schemas.MediaInfo])
|
@router.get("/showing", summary="豆瓣正在热映", response_model=List[schemas.MediaInfo])
|
||||||
def movie_showing(page: int = 1,
|
def movie_showing(page: int = 1,
|
||||||
count: int = 30,
|
count: int = 30,
|
||||||
@@ -141,6 +127,69 @@ def tv_animation(page: int = 1,
|
|||||||
return [MediaInfo(douban_info=tv).to_dict() for tv in tvs]
|
return [MediaInfo(douban_info=tv).to_dict() for tv in tvs]
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/movie_hot", summary="豆瓣热门电影", response_model=List[schemas.MediaInfo])
|
||||||
|
def movie_hot(page: int = 1,
|
||||||
|
count: int = 30,
|
||||||
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
|
"""
|
||||||
|
热门电影
|
||||||
|
"""
|
||||||
|
movies = DoubanChain().movie_hot(page=page, count=count)
|
||||||
|
return [MediaInfo(douban_info=movie).to_dict() for movie in movies]
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/tv_hot", summary="豆瓣热门电视剧", response_model=List[schemas.MediaInfo])
|
||||||
|
def tv_hot(page: int = 1,
|
||||||
|
count: int = 30,
|
||||||
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
|
"""
|
||||||
|
热门电视剧
|
||||||
|
"""
|
||||||
|
tvs = DoubanChain().tv_hot(page=page, count=count)
|
||||||
|
return [MediaInfo(douban_info=tv).to_dict() for tv in tvs]
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/credits/{doubanid}/{type_name}", summary="豆瓣演员阵容", response_model=List[schemas.DoubanPerson])
|
||||||
|
def douban_credits(doubanid: str,
|
||||||
|
type_name: str,
|
||||||
|
page: int = 1,
|
||||||
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
|
"""
|
||||||
|
根据TMDBID查询演员阵容,type_name: 电影/电视剧
|
||||||
|
"""
|
||||||
|
mediatype = MediaType(type_name)
|
||||||
|
if mediatype == MediaType.MOVIE:
|
||||||
|
doubaninfos = DoubanChain().movie_credits(doubanid=doubanid, page=page)
|
||||||
|
elif mediatype == MediaType.TV:
|
||||||
|
doubaninfos = DoubanChain().tv_credits(doubanid=doubanid, page=page)
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
if not doubaninfos:
|
||||||
|
return []
|
||||||
|
else:
|
||||||
|
return [schemas.DoubanPerson(**doubaninfo) for doubaninfo in doubaninfos]
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/recommend/{doubanid}/{type_name}", summary="豆瓣推荐电影/电视剧", response_model=List[schemas.MediaInfo])
|
||||||
|
def douban_recommend(doubanid: str,
|
||||||
|
type_name: str,
|
||||||
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
|
"""
|
||||||
|
根据豆瓣ID查询推荐电影/电视剧,type_name: 电影/电视剧
|
||||||
|
"""
|
||||||
|
mediatype = MediaType(type_name)
|
||||||
|
if mediatype == MediaType.MOVIE:
|
||||||
|
doubaninfos = DoubanChain().movie_recommend(doubanid=doubanid)
|
||||||
|
elif mediatype == MediaType.TV:
|
||||||
|
doubaninfos = DoubanChain().tv_recommend(doubanid=doubanid)
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
if not doubaninfos:
|
||||||
|
return []
|
||||||
|
else:
|
||||||
|
return [MediaInfo(douban_info=doubaninfo).to_dict() for doubaninfo in doubaninfos]
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{doubanid}", summary="查询豆瓣详情", response_model=schemas.MediaInfo)
|
@router.get("/{doubanid}", summary="查询豆瓣详情", response_model=schemas.MediaInfo)
|
||||||
def douban_info(doubanid: str,
|
def douban_info(doubanid: str,
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
from typing import Any, List
|
from typing import Any, List
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, Depends
|
||||||
|
|
||||||
from app import schemas
|
from app import schemas
|
||||||
from app.chain.douban import DoubanChain
|
|
||||||
from app.chain.download import DownloadChain
|
from app.chain.download import DownloadChain
|
||||||
from app.chain.media import MediaChain
|
|
||||||
from app.core.context import MediaInfo, Context, TorrentInfo
|
from app.core.context import MediaInfo, Context, TorrentInfo
|
||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo
|
||||||
from app.core.security import verify_token
|
from app.core.security import verify_token
|
||||||
from app.schemas import NotExistMediaInfo, MediaType
|
from app.db.models.user import User
|
||||||
|
from app.db.userauth import get_current_active_user
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@@ -27,6 +26,7 @@ def read_downloading(
|
|||||||
def add_downloading(
|
def add_downloading(
|
||||||
media_in: schemas.MediaInfo,
|
media_in: schemas.MediaInfo,
|
||||||
torrent_in: schemas.TorrentInfo,
|
torrent_in: schemas.TorrentInfo,
|
||||||
|
current_user: User = Depends(get_current_active_user),
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
添加下载任务
|
添加下载任务
|
||||||
@@ -45,46 +45,12 @@ def add_downloading(
|
|||||||
media_info=mediainfo,
|
media_info=mediainfo,
|
||||||
torrent_info=torrentinfo
|
torrent_info=torrentinfo
|
||||||
)
|
)
|
||||||
did = DownloadChain().download_single(context=context)
|
did = DownloadChain().download_single(context=context, username=current_user.name)
|
||||||
return schemas.Response(success=True if did else False, data={
|
return schemas.Response(success=True if did else False, data={
|
||||||
"download_id": did
|
"download_id": did
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@router.post("/notexists", summary="查询缺失媒体信息", response_model=List[NotExistMediaInfo])
|
|
||||||
def exists(media_in: schemas.MediaInfo,
|
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
|
||||||
"""
|
|
||||||
查询缺失媒体信息
|
|
||||||
"""
|
|
||||||
# 媒体信息
|
|
||||||
mediainfo = MediaInfo()
|
|
||||||
meta = MetaInfo(title=media_in.title)
|
|
||||||
if media_in.tmdb_id:
|
|
||||||
mediainfo.from_dict(media_in.dict())
|
|
||||||
elif media_in.douban_id:
|
|
||||||
context = DoubanChain().recognize_by_doubanid(doubanid=media_in.douban_id)
|
|
||||||
if context:
|
|
||||||
mediainfo = context.media_info
|
|
||||||
meta = context.meta_info
|
|
||||||
else:
|
|
||||||
context = MediaChain().recognize_by_title(title=f"{media_in.title} {media_in.year}")
|
|
||||||
if context:
|
|
||||||
mediainfo = context.media_info
|
|
||||||
meta = context.meta_info
|
|
||||||
# 查询缺失信息
|
|
||||||
if not mediainfo or not mediainfo.tmdb_id:
|
|
||||||
raise HTTPException(status_code=404, detail="媒体信息不存在")
|
|
||||||
exist_flag, no_exists = DownloadChain().get_no_exists_info(meta=meta, mediainfo=mediainfo)
|
|
||||||
if mediainfo.type == MediaType.MOVIE:
|
|
||||||
# 电影已存在时返回空列表,存在时返回空对像列表
|
|
||||||
return [] if exist_flag else [NotExistMediaInfo()]
|
|
||||||
elif no_exists and no_exists.get(mediainfo.tmdb_id):
|
|
||||||
# 电视剧返回缺失的剧集
|
|
||||||
return list(no_exists.get(mediainfo.tmdb_id).values())
|
|
||||||
return []
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/start/{hashString}", summary="开始任务", response_model=schemas.Response)
|
@router.get("/start/{hashString}", summary="开始任务", response_model=schemas.Response)
|
||||||
def start_downloading(
|
def start_downloading(
|
||||||
hashString: str,
|
hashString: str,
|
||||||
@@ -101,7 +67,7 @@ def stop_downloading(
|
|||||||
hashString: str,
|
hashString: str,
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
控制下载任务
|
暂停下载任务
|
||||||
"""
|
"""
|
||||||
ret = DownloadChain().set_downloading(hashString, "stop")
|
ret = DownloadChain().set_downloading(hashString, "stop")
|
||||||
return schemas.Response(success=True if ret else False)
|
return schemas.Response(success=True if ret else False)
|
||||||
@@ -112,7 +78,7 @@ def remove_downloading(
|
|||||||
hashString: str,
|
hashString: str,
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
控制下载任务
|
删除下载任务
|
||||||
"""
|
"""
|
||||||
ret = DownloadChain().remove_downloading(hashString)
|
ret = DownloadChain().remove_downloading(hashString)
|
||||||
return schemas.Response(success=True if ret else False)
|
return schemas.Response(success=True if ret else False)
|
||||||
|
|||||||
@@ -42,17 +42,26 @@ def delete_download_history(history_in: schemas.DownloadHistory,
|
|||||||
def transfer_history(title: str = None,
|
def transfer_history(title: str = None,
|
||||||
page: int = 1,
|
page: int = 1,
|
||||||
count: int = 30,
|
count: int = 30,
|
||||||
|
status: bool = None,
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
查询转移历史记录
|
查询转移历史记录
|
||||||
"""
|
"""
|
||||||
|
if title == "失败":
|
||||||
|
title = None
|
||||||
|
status = False
|
||||||
|
elif title == "成功":
|
||||||
|
title = None
|
||||||
|
status = True
|
||||||
|
|
||||||
if title:
|
if title:
|
||||||
total = TransferHistory.count_by_title(db, title)
|
total = TransferHistory.count_by_title(db, title=title, status=status)
|
||||||
result = TransferHistory.list_by_title(db, title, page, count)
|
result = TransferHistory.list_by_title(db, title=title, page=page,
|
||||||
|
count=count, status=status)
|
||||||
else:
|
else:
|
||||||
result = TransferHistory.list_by_page(db, page, count)
|
result = TransferHistory.list_by_page(db, page=page, count=count, status=status)
|
||||||
total = TransferHistory.count(db)
|
total = TransferHistory.count(db, status=status)
|
||||||
|
|
||||||
return schemas.Response(success=True,
|
return schemas.Response(success=True,
|
||||||
data={
|
data={
|
||||||
@@ -75,10 +84,14 @@ def delete_transfer_history(history_in: schemas.TransferHistory,
|
|||||||
return schemas.Response(success=False, msg="记录不存在")
|
return schemas.Response(success=False, msg="记录不存在")
|
||||||
# 册除媒体库文件
|
# 册除媒体库文件
|
||||||
if deletedest and history.dest:
|
if deletedest and history.dest:
|
||||||
TransferChain().delete_files(Path(history.dest))
|
state, msg = TransferChain().delete_files(Path(history.dest))
|
||||||
|
if not state:
|
||||||
|
return schemas.Response(success=False, msg=msg)
|
||||||
# 删除源文件
|
# 删除源文件
|
||||||
if deletesrc and history.src:
|
if deletesrc and history.src:
|
||||||
TransferChain().delete_files(Path(history.src))
|
state, msg = TransferChain().delete_files(Path(history.src))
|
||||||
|
if not state:
|
||||||
|
return schemas.Response(success=False, msg=msg)
|
||||||
# 发送事件
|
# 发送事件
|
||||||
eventmanager.send_event(
|
eventmanager.send_event(
|
||||||
EventType.DownloadFileDeleted,
|
EventType.DownloadFileDeleted,
|
||||||
|
|||||||
@@ -34,12 +34,13 @@ async def login_access_token(
|
|||||||
)
|
)
|
||||||
if not user:
|
if not user:
|
||||||
# 请求协助认证
|
# 请求协助认证
|
||||||
logger.warn("登录用户本地不匹配,尝试辅助认证 ...")
|
logger.warn(f"登录用户 {form_data.username} 本地用户名或密码不匹配,尝试辅助认证 ...")
|
||||||
token = UserChain().user_authenticate(form_data.username, form_data.password)
|
token = UserChain().user_authenticate(form_data.username, form_data.password)
|
||||||
if not token:
|
if not token:
|
||||||
|
logger.warn(f"用户 {form_data.username} 登录失败!")
|
||||||
raise HTTPException(status_code=401, detail="用户名或密码不正确")
|
raise HTTPException(status_code=401, detail="用户名或密码不正确")
|
||||||
else:
|
else:
|
||||||
logger.info(f"辅助认证成功,用户信息: {token}")
|
logger.info(f"用户 {form_data.username} 辅助认证成功,用户信息: {token},以普通用户登录...")
|
||||||
# 加入用户信息表
|
# 加入用户信息表
|
||||||
user = User.get_by_name(db=db, name=form_data.username)
|
user = User.get_by_name(db=db, name=form_data.username)
|
||||||
if not user:
|
if not user:
|
||||||
@@ -47,11 +48,17 @@ async def login_access_token(
|
|||||||
user = User(name=form_data.username, is_active=True,
|
user = User(name=form_data.username, is_active=True,
|
||||||
is_superuser=False, hashed_password=get_password_hash(token))
|
is_superuser=False, hashed_password=get_password_hash(token))
|
||||||
user.create(db)
|
user.create(db)
|
||||||
|
else:
|
||||||
|
# 普通用户权限
|
||||||
|
user.is_superuser = False
|
||||||
elif not user.is_active:
|
elif not user.is_active:
|
||||||
raise HTTPException(status_code=403, detail="用户未启用")
|
raise HTTPException(status_code=403, detail="用户未启用")
|
||||||
|
logger.info(f"用户 {user.name} 登录成功!")
|
||||||
return schemas.Token(
|
return schemas.Token(
|
||||||
access_token=security.create_access_token(
|
access_token=security.create_access_token(
|
||||||
user.id,
|
userid=user.id,
|
||||||
|
username=user.name,
|
||||||
|
super_user=user.is_superuser,
|
||||||
expires_delta=timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
|
expires_delta=timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
|
||||||
),
|
),
|
||||||
token_type="bearer",
|
token_type="bearer",
|
||||||
@@ -61,6 +68,18 @@ async def login_access_token(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/wallpaper", summary="登录页面电影海报", response_model=schemas.Response)
|
||||||
|
def wallpaper() -> Any:
|
||||||
|
"""
|
||||||
|
获取登录页面电影海报
|
||||||
|
"""
|
||||||
|
if settings.WALLPAPER == "tmdb":
|
||||||
|
return tmdb_wallpaper()
|
||||||
|
elif settings.WALLPAPER == "bing":
|
||||||
|
return bing_wallpaper()
|
||||||
|
return schemas.Response(success=False)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/bing", summary="Bing每日壁纸", response_model=schemas.Response)
|
@router.get("/bing", summary="Bing每日壁纸", response_model=schemas.Response)
|
||||||
def bing_wallpaper() -> Any:
|
def bing_wallpaper() -> Any:
|
||||||
"""
|
"""
|
||||||
@@ -68,8 +87,10 @@ def bing_wallpaper() -> Any:
|
|||||||
"""
|
"""
|
||||||
url = WebUtils.get_bing_wallpaper()
|
url = WebUtils.get_bing_wallpaper()
|
||||||
if url:
|
if url:
|
||||||
return schemas.Response(success=False,
|
return schemas.Response(
|
||||||
message=url)
|
success=True,
|
||||||
|
message=url
|
||||||
|
)
|
||||||
return schemas.Response(success=False)
|
return schemas.Response(success=False)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,13 @@
|
|||||||
from typing import List, Any
|
from typing import List, Any
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
from sqlalchemy.orm import Session
|
|
||||||
|
|
||||||
from app import schemas
|
from app import schemas
|
||||||
from app.chain.douban import DoubanChain
|
|
||||||
from app.chain.media import MediaChain
|
from app.chain.media import MediaChain
|
||||||
from app.chain.tmdb import TmdbChain
|
from app.core.config import settings
|
||||||
from app.core.context import MediaInfo
|
from app.core.context import Context
|
||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo
|
||||||
from app.core.security import verify_token
|
from app.core.security import verify_token, verify_uri_token
|
||||||
from app.db import get_db
|
|
||||||
from app.db.mediaserver_oper import MediaServerOper
|
|
||||||
from app.schemas import MediaType
|
from app.schemas import MediaType
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
@@ -25,15 +21,27 @@ def recognize(title: str,
|
|||||||
根据标题、副标题识别媒体信息
|
根据标题、副标题识别媒体信息
|
||||||
"""
|
"""
|
||||||
# 识别媒体信息
|
# 识别媒体信息
|
||||||
context = MediaChain().recognize_by_title(title=title, subtitle=subtitle)
|
metainfo = MetaInfo(title, subtitle)
|
||||||
if context:
|
mediainfo = MediaChain().recognize_by_meta(metainfo)
|
||||||
return context.to_dict()
|
if mediainfo:
|
||||||
|
return Context(meta_info=metainfo, media_info=mediainfo).to_dict()
|
||||||
return schemas.Context()
|
return schemas.Context()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/recognize2", summary="识别种子媒体信息(API_TOKEN)", response_model=schemas.Context)
|
||||||
|
def recognize2(title: str,
|
||||||
|
subtitle: str = None,
|
||||||
|
_: str = Depends(verify_uri_token)) -> Any:
|
||||||
|
"""
|
||||||
|
根据标题、副标题识别媒体信息 API_TOKEN认证(?token=xxx)
|
||||||
|
"""
|
||||||
|
# 识别媒体信息
|
||||||
|
return recognize(title, subtitle)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/recognize_file", summary="识别媒体信息(文件)", response_model=schemas.Context)
|
@router.get("/recognize_file", summary="识别媒体信息(文件)", response_model=schemas.Context)
|
||||||
def recognize(path: str,
|
def recognize_file(path: str,
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
根据文件路径识别媒体信息
|
根据文件路径识别媒体信息
|
||||||
"""
|
"""
|
||||||
@@ -44,6 +52,16 @@ def recognize(path: str,
|
|||||||
return schemas.Context()
|
return schemas.Context()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/recognize_file2", summary="识别文件媒体信息(API_TOKEN)", response_model=schemas.Context)
|
||||||
|
def recognize_file2(path: str,
|
||||||
|
_: str = Depends(verify_uri_token)) -> Any:
|
||||||
|
"""
|
||||||
|
根据文件路径识别媒体信息 API_TOKEN认证(?token=xxx)
|
||||||
|
"""
|
||||||
|
# 识别媒体信息
|
||||||
|
return recognize_file(path)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/search", summary="搜索媒体信息", response_model=List[schemas.MediaInfo])
|
@router.get("/search", summary="搜索媒体信息", response_model=List[schemas.MediaInfo])
|
||||||
def search_by_title(title: str,
|
def search_by_title(title: str,
|
||||||
page: int = 1,
|
page: int = 1,
|
||||||
@@ -58,49 +76,36 @@ def search_by_title(title: str,
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
@router.get("/exists", summary="本地是否存在", response_model=schemas.Response)
|
|
||||||
def exists(title: str = None,
|
|
||||||
year: int = None,
|
|
||||||
mtype: str = None,
|
|
||||||
tmdbid: int = None,
|
|
||||||
season: int = None,
|
|
||||||
db: Session = Depends(get_db),
|
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
|
||||||
"""
|
|
||||||
判断本地是否存在
|
|
||||||
"""
|
|
||||||
meta = MetaInfo(title)
|
|
||||||
if not season:
|
|
||||||
season = meta.begin_season
|
|
||||||
exist = MediaServerOper(db).exists(
|
|
||||||
title=meta.name, year=year, mtype=mtype, tmdbid=tmdbid, season=season
|
|
||||||
)
|
|
||||||
return schemas.Response(success=True if exist else False, data={
|
|
||||||
"item": exist or {}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{mediaid}", summary="查询媒体详情", response_model=schemas.MediaInfo)
|
@router.get("/{mediaid}", summary="查询媒体详情", response_model=schemas.MediaInfo)
|
||||||
def tmdb_info(mediaid: str, type_name: str,
|
def media_info(mediaid: str, type_name: str,
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
根据媒体ID查询themoviedb或豆瓣媒体信息,type_name: 电影/电视剧
|
根据媒体ID查询themoviedb或豆瓣媒体信息,type_name: 电影/电视剧
|
||||||
"""
|
"""
|
||||||
mtype = MediaType(type_name)
|
mtype = MediaType(type_name)
|
||||||
|
tmdbid, doubanid = None, None
|
||||||
if mediaid.startswith("tmdb:"):
|
if mediaid.startswith("tmdb:"):
|
||||||
result = TmdbChain().tmdb_info(int(mediaid[5:]), mtype)
|
tmdbid = int(mediaid[5:])
|
||||||
return MediaInfo(tmdb_info=result).to_dict()
|
|
||||||
elif mediaid.startswith("douban:"):
|
elif mediaid.startswith("douban:"):
|
||||||
# 查询豆瓣信息
|
doubanid = mediaid[7:]
|
||||||
doubaninfo = DoubanChain().douban_info(doubanid=mediaid[7:])
|
if not tmdbid and not doubanid:
|
||||||
if not doubaninfo:
|
|
||||||
return schemas.MediaInfo()
|
|
||||||
result = DoubanChain().recognize_by_doubaninfo(doubaninfo)
|
|
||||||
if result:
|
|
||||||
# TMDB
|
|
||||||
return result.media_info.to_dict()
|
|
||||||
else:
|
|
||||||
# 豆瓣
|
|
||||||
return MediaInfo(douban_info=doubaninfo).to_dict()
|
|
||||||
else:
|
|
||||||
return schemas.MediaInfo()
|
return schemas.MediaInfo()
|
||||||
|
if settings.RECOGNIZE_SOURCE == "themoviedb":
|
||||||
|
if not tmdbid and doubanid:
|
||||||
|
tmdbinfo = MediaChain().get_tmdbinfo_by_doubanid(doubanid=doubanid, mtype=mtype)
|
||||||
|
if tmdbinfo:
|
||||||
|
tmdbid = tmdbinfo.get("id")
|
||||||
|
else:
|
||||||
|
return schemas.MediaInfo()
|
||||||
|
else:
|
||||||
|
if not doubanid and tmdbid:
|
||||||
|
doubaninfo = MediaChain().get_doubaninfo_by_tmdbid(tmdbid=tmdbid, mtype=mtype)
|
||||||
|
if doubaninfo:
|
||||||
|
doubanid = doubaninfo.get("id")
|
||||||
|
else:
|
||||||
|
return schemas.MediaInfo()
|
||||||
|
mediainfo = MediaChain().recognize_media(tmdbid=tmdbid, doubanid=doubanid, mtype=mtype)
|
||||||
|
if mediainfo:
|
||||||
|
MediaChain().obtain_images(mediainfo)
|
||||||
|
return mediainfo.to_dict()
|
||||||
|
return schemas.MediaInfo()
|
||||||
|
|||||||
146
app/api/endpoints/mediaserver.py
Normal file
146
app/api/endpoints/mediaserver.py
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
from typing import Any, List
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from app import schemas
|
||||||
|
from app.chain.download import DownloadChain
|
||||||
|
from app.chain.media import MediaChain
|
||||||
|
from app.chain.mediaserver import MediaServerChain
|
||||||
|
from app.core.config import settings
|
||||||
|
from app.core.metainfo import MetaInfo
|
||||||
|
from app.core.security import verify_token
|
||||||
|
from app.db import get_db
|
||||||
|
from app.db.mediaserver_oper import MediaServerOper
|
||||||
|
from app.db.models import MediaServerItem
|
||||||
|
from app.schemas import MediaType, NotExistMediaInfo
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/play/{itemid}", summary="在线播放")
|
||||||
|
def play_item(itemid: str) -> schemas.Response:
|
||||||
|
"""
|
||||||
|
获取媒体服务器播放页面地址
|
||||||
|
"""
|
||||||
|
if not itemid:
|
||||||
|
return schemas.Response(success=False, msg="参数错误")
|
||||||
|
if not settings.MEDIASERVER:
|
||||||
|
return schemas.Response(success=False, msg="未配置媒体服务器")
|
||||||
|
mediaserver = settings.MEDIASERVER.split(",")[0]
|
||||||
|
play_url = MediaServerChain().get_play_url(server=mediaserver, item_id=itemid)
|
||||||
|
# 重定向到play_url
|
||||||
|
if not play_url:
|
||||||
|
return schemas.Response(success=False, msg="未找到播放地址")
|
||||||
|
return schemas.Response(success=True, data={
|
||||||
|
"url": play_url
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/exists", summary="本地是否存在", response_model=schemas.Response)
|
||||||
|
def exists(title: str = None,
|
||||||
|
year: int = None,
|
||||||
|
mtype: str = None,
|
||||||
|
tmdbid: int = None,
|
||||||
|
season: int = None,
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
|
"""
|
||||||
|
判断本地是否存在
|
||||||
|
"""
|
||||||
|
meta = MetaInfo(title)
|
||||||
|
if not season:
|
||||||
|
season = meta.begin_season
|
||||||
|
# 返回对象
|
||||||
|
ret_info = {}
|
||||||
|
# 本地数据库是否存在
|
||||||
|
exist: MediaServerItem = MediaServerOper(db).exists(
|
||||||
|
title=meta.name, year=year, mtype=mtype, tmdbid=tmdbid, season=season
|
||||||
|
)
|
||||||
|
if exist:
|
||||||
|
ret_info = {
|
||||||
|
"id": exist.item_id
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
else:
|
||||||
|
# 服务器是否存在
|
||||||
|
mediainfo = MediaInfo()
|
||||||
|
mediainfo.from_dict({
|
||||||
|
"title": meta.name,
|
||||||
|
"year": year or meta.year,
|
||||||
|
"type": mtype or meta.type,
|
||||||
|
"tmdb_id": tmdbid,
|
||||||
|
"season": season
|
||||||
|
})
|
||||||
|
exist: schemas.ExistMediaInfo = MediaServerChain().media_exists(
|
||||||
|
mediainfo=mediainfo
|
||||||
|
)
|
||||||
|
if exist:
|
||||||
|
ret_info = {
|
||||||
|
"id": exist.itemid
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
return schemas.Response(success=True if exist else False, data={
|
||||||
|
"item": ret_info
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/notexists", summary="查询缺失媒体信息", response_model=List[schemas.NotExistMediaInfo])
|
||||||
|
def not_exists(media_in: schemas.MediaInfo,
|
||||||
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
|
"""
|
||||||
|
查询缺失媒体信息
|
||||||
|
"""
|
||||||
|
# 媒体信息
|
||||||
|
meta = MetaInfo(title=media_in.title)
|
||||||
|
mtype = MediaType(media_in.type) if media_in.type else None
|
||||||
|
if mtype:
|
||||||
|
meta.type = mtype
|
||||||
|
if media_in.season:
|
||||||
|
meta.begin_season = media_in.season
|
||||||
|
meta.type = MediaType.TV
|
||||||
|
if media_in.year:
|
||||||
|
meta.year = media_in.year
|
||||||
|
if media_in.tmdb_id or media_in.douban_id:
|
||||||
|
mediainfo = MediaChain().recognize_media(meta=meta, mtype=mtype,
|
||||||
|
tmdbid=media_in.tmdb_id, doubanid=media_in.douban_id)
|
||||||
|
else:
|
||||||
|
mediainfo = MediaChain().recognize_by_meta(metainfo=meta)
|
||||||
|
# 查询缺失信息
|
||||||
|
if not mediainfo:
|
||||||
|
raise HTTPException(status_code=404, detail="媒体信息不存在")
|
||||||
|
mediakey = mediainfo.tmdb_id or mediainfo.douban_id
|
||||||
|
exist_flag, no_exists = DownloadChain().get_no_exists_info(meta=meta, mediainfo=mediainfo)
|
||||||
|
if mediainfo.type == MediaType.MOVIE:
|
||||||
|
# 电影已存在时返回空列表,存在时返回空对像列表
|
||||||
|
return [] if exist_flag else [NotExistMediaInfo()]
|
||||||
|
elif no_exists and no_exists.get(mediakey):
|
||||||
|
# 电视剧返回缺失的剧集
|
||||||
|
return list(no_exists.get(mediakey).values())
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/latest", summary="最新入库条目", response_model=List[schemas.MediaServerPlayItem])
|
||||||
|
def latest(count: int = 18,
|
||||||
|
userinfo: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
|
"""
|
||||||
|
获取媒体服务器最新入库条目
|
||||||
|
"""
|
||||||
|
return MediaServerChain().latest(count=count, username=userinfo.username) or []
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/playing", summary="正在播放条目", response_model=List[schemas.MediaServerPlayItem])
|
||||||
|
def playing(count: int = 12,
|
||||||
|
userinfo: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
|
"""
|
||||||
|
获取媒体服务器正在播放条目
|
||||||
|
"""
|
||||||
|
return MediaServerChain().playing(count=count, username=userinfo.username) or []
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/library", summary="媒体库列表", response_model=List[schemas.MediaServerLibrary])
|
||||||
|
def library(userinfo: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
|
"""
|
||||||
|
获取媒体服务器媒体库列表
|
||||||
|
"""
|
||||||
|
return MediaServerChain().librarys(username=userinfo.username) or []
|
||||||
@@ -6,6 +6,7 @@ from app import schemas
|
|||||||
from app.core.plugin import PluginManager
|
from app.core.plugin import PluginManager
|
||||||
from app.core.security import verify_token
|
from app.core.security import verify_token
|
||||||
from app.db.systemconfig_oper import SystemConfigOper
|
from app.db.systemconfig_oper import SystemConfigOper
|
||||||
|
from app.helper.plugin import PluginHelper
|
||||||
from app.schemas.types import SystemConfigKey
|
from app.schemas.types import SystemConfigKey
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
@@ -14,9 +15,33 @@ router = APIRouter()
|
|||||||
@router.get("/", summary="所有插件", response_model=List[schemas.Plugin])
|
@router.get("/", summary="所有插件", response_model=List[schemas.Plugin])
|
||||||
def all_plugins(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
def all_plugins(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
查询所有插件清单
|
查询所有插件清单,包括本地插件和在线插件
|
||||||
"""
|
"""
|
||||||
return PluginManager().get_plugin_apps()
|
plugins = []
|
||||||
|
# 本地插件
|
||||||
|
local_plugins = PluginManager().get_local_plugins()
|
||||||
|
# 在线插件
|
||||||
|
online_plugins = PluginManager().get_online_plugins()
|
||||||
|
if not online_plugins:
|
||||||
|
return local_plugins
|
||||||
|
# 已安装插件IDS
|
||||||
|
installed_ids = [plugin["id"] for plugin in local_plugins if plugin.get("installed")]
|
||||||
|
# 已经安装的本地
|
||||||
|
plugins.extend([plugin for plugin in local_plugins if plugin.get("installed")])
|
||||||
|
# 未安装的线上插件或者有更新的插件
|
||||||
|
for plugin in online_plugins:
|
||||||
|
if plugin["id"] not in installed_ids:
|
||||||
|
plugins.append(plugin)
|
||||||
|
elif plugin.get("has_update"):
|
||||||
|
plugin["installed"] = False
|
||||||
|
plugins.append(plugin)
|
||||||
|
# 本地插件存在但未安装,且本地插件不在online插件中
|
||||||
|
plugin_ids = [plugin["id"] for plugin in plugins]
|
||||||
|
for plugin in local_plugins:
|
||||||
|
if plugin["id"] not in installed_ids \
|
||||||
|
and plugin["id"] not in plugin_ids:
|
||||||
|
plugins.append(plugin)
|
||||||
|
return plugins
|
||||||
|
|
||||||
|
|
||||||
@router.get("/installed", summary="已安装插件", response_model=List[str])
|
@router.get("/installed", summary="已安装插件", response_model=List[str])
|
||||||
@@ -29,19 +54,28 @@ def installed_plugins(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
|||||||
|
|
||||||
@router.get("/install/{plugin_id}", summary="安装插件", response_model=schemas.Response)
|
@router.get("/install/{plugin_id}", summary="安装插件", response_model=schemas.Response)
|
||||||
def install_plugin(plugin_id: str,
|
def install_plugin(plugin_id: str,
|
||||||
|
repo_url: str = "",
|
||||||
|
force: bool = False,
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
安装插件
|
安装插件
|
||||||
"""
|
"""
|
||||||
# 已安装插件
|
# 已安装插件
|
||||||
install_plugins = SystemConfigOper().get(SystemConfigKey.UserInstalledPlugins) or []
|
install_plugins = SystemConfigOper().get(SystemConfigKey.UserInstalledPlugins) or []
|
||||||
|
# 如果是非本地括件,或者强制安装时,则需要下载安装
|
||||||
|
if repo_url and (force or plugin_id not in PluginManager().get_plugin_ids()):
|
||||||
|
# 下载安装
|
||||||
|
state, msg = PluginHelper().install(pid=plugin_id, repo_url=repo_url)
|
||||||
|
if not state:
|
||||||
|
# 安装失败
|
||||||
|
return schemas.Response(success=False, message=msg)
|
||||||
# 安装插件
|
# 安装插件
|
||||||
if plugin_id not in install_plugins:
|
if plugin_id not in install_plugins:
|
||||||
install_plugins.append(plugin_id)
|
install_plugins.append(plugin_id)
|
||||||
# 保存设置
|
# 保存设置
|
||||||
SystemConfigOper().set(SystemConfigKey.UserInstalledPlugins, install_plugins)
|
SystemConfigOper().set(SystemConfigKey.UserInstalledPlugins, install_plugins)
|
||||||
# 重载插件管理器
|
# 重载插件管理器
|
||||||
PluginManager().init_config()
|
PluginManager().init_config()
|
||||||
return schemas.Response(success=True)
|
return schemas.Response(success=True)
|
||||||
|
|
||||||
|
|
||||||
@@ -61,11 +95,23 @@ def plugin_form(plugin_id: str,
|
|||||||
@router.get("/page/{plugin_id}", summary="获取插件数据页面")
|
@router.get("/page/{plugin_id}", summary="获取插件数据页面")
|
||||||
def plugin_page(plugin_id: str, _: schemas.TokenPayload = Depends(verify_token)) -> List[dict]:
|
def plugin_page(plugin_id: str, _: schemas.TokenPayload = Depends(verify_token)) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
根据插件ID获取插件配置信息
|
根据插件ID获取插件数据页面
|
||||||
"""
|
"""
|
||||||
return PluginManager().get_plugin_page(plugin_id)
|
return PluginManager().get_plugin_page(plugin_id)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/reset/{plugin_id}", summary="重置插件配置", response_model=schemas.Response)
|
||||||
|
def reset_plugin(plugin_id: str, _: schemas.TokenPayload = Depends(verify_token)) -> List[dict]:
|
||||||
|
"""
|
||||||
|
根据插件ID重置插件配置
|
||||||
|
"""
|
||||||
|
# 删除配置
|
||||||
|
PluginManager().delete_plugin_config(plugin_id)
|
||||||
|
# 重新生效插件
|
||||||
|
PluginManager().reload_plugin(plugin_id, {})
|
||||||
|
return schemas.Response(success=True)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{plugin_id}", summary="获取插件配置")
|
@router.get("/{plugin_id}", summary="获取插件配置")
|
||||||
def plugin_config(plugin_id: str, _: schemas.TokenPayload = Depends(verify_token)) -> dict:
|
def plugin_config(plugin_id: str, _: schemas.TokenPayload = Depends(verify_token)) -> dict:
|
||||||
"""
|
"""
|
||||||
@@ -78,7 +124,7 @@ def plugin_config(plugin_id: str, _: schemas.TokenPayload = Depends(verify_token
|
|||||||
def set_plugin_config(plugin_id: str, conf: dict,
|
def set_plugin_config(plugin_id: str, conf: dict,
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
根据插件ID获取插件配置信息
|
更新插件配置
|
||||||
"""
|
"""
|
||||||
# 保存配置
|
# 保存配置
|
||||||
PluginManager().save_plugin_config(plugin_id, conf)
|
PluginManager().save_plugin_config(plugin_id, conf)
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ from typing import List, Any
|
|||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
|
|
||||||
from app import schemas
|
from app import schemas
|
||||||
from app.chain.douban import DoubanChain
|
from app.chain.media import MediaChain
|
||||||
from app.chain.search import SearchChain
|
from app.chain.search import SearchChain
|
||||||
|
from app.core.config import settings
|
||||||
from app.core.security import verify_token
|
from app.core.security import verify_token
|
||||||
from app.schemas.types import MediaType
|
from app.schemas.types import MediaType
|
||||||
|
|
||||||
@@ -21,27 +22,36 @@ async def search_latest(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
|||||||
|
|
||||||
|
|
||||||
@router.get("/media/{mediaid}", summary="精确搜索资源", response_model=List[schemas.Context])
|
@router.get("/media/{mediaid}", summary="精确搜索资源", response_model=List[schemas.Context])
|
||||||
def search_by_tmdbid(mediaid: str,
|
def search_by_id(mediaid: str,
|
||||||
mtype: str = None,
|
mtype: str = None,
|
||||||
area: str = "title",
|
area: str = "title",
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
根据TMDBID/豆瓣ID精确搜索站点资源 tmdb:/douban:/
|
根据TMDBID/豆瓣ID精确搜索站点资源 tmdb:/douban:/
|
||||||
"""
|
"""
|
||||||
|
torrents = []
|
||||||
|
if mtype:
|
||||||
|
mtype = MediaType(mtype)
|
||||||
if mediaid.startswith("tmdb:"):
|
if mediaid.startswith("tmdb:"):
|
||||||
tmdbid = int(mediaid.replace("tmdb:", ""))
|
tmdbid = int(mediaid.replace("tmdb:", ""))
|
||||||
if mtype:
|
if settings.RECOGNIZE_SOURCE == "douban":
|
||||||
mtype = MediaType(mtype)
|
# 通过TMDBID识别豆瓣ID
|
||||||
torrents = SearchChain().search_by_tmdbid(tmdbid=tmdbid, mtype=mtype, area=area)
|
doubaninfo = MediaChain().get_doubaninfo_by_tmdbid(tmdbid=tmdbid, mtype=mtype)
|
||||||
|
if doubaninfo:
|
||||||
|
torrents = SearchChain().search_by_id(doubanid=doubaninfo.get("id"),
|
||||||
|
mtype=mtype, area=area)
|
||||||
|
else:
|
||||||
|
torrents = SearchChain().search_by_id(tmdbid=tmdbid, mtype=mtype, area=area)
|
||||||
elif mediaid.startswith("douban:"):
|
elif mediaid.startswith("douban:"):
|
||||||
doubanid = mediaid.replace("douban:", "")
|
doubanid = mediaid.replace("douban:", "")
|
||||||
# 识别豆瓣信息
|
if settings.RECOGNIZE_SOURCE == "themoviedb":
|
||||||
context = DoubanChain().recognize_by_doubanid(doubanid)
|
# 通过豆瓣ID识别TMDBID
|
||||||
if not context or not context.media_info or not context.media_info.tmdb_id:
|
tmdbinfo = MediaChain().get_tmdbinfo_by_doubanid(doubanid=doubanid, mtype=mtype)
|
||||||
return []
|
if tmdbinfo:
|
||||||
torrents = SearchChain().search_by_tmdbid(tmdbid=context.media_info.tmdb_id,
|
torrents = SearchChain().search_by_id(tmdbid=tmdbinfo.get("id"),
|
||||||
mtype=context.media_info.type,
|
mtype=mtype, area=area)
|
||||||
area=area)
|
else:
|
||||||
|
torrents = SearchChain().search_by_id(doubanid=doubanid, mtype=mtype, area=area)
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
return [torrent.to_dict() for torrent in torrents]
|
return [torrent.to_dict() for torrent in torrents]
|
||||||
|
|||||||
@@ -228,10 +228,11 @@ def read_rss_sites(db: Session = Depends(get_db)) -> List[dict]:
|
|||||||
"""
|
"""
|
||||||
# 选中的rss站点
|
# 选中的rss站点
|
||||||
selected_sites = SystemConfigOper().get(SystemConfigKey.RssSites) or []
|
selected_sites = SystemConfigOper().get(SystemConfigKey.RssSites) or []
|
||||||
|
|
||||||
# 所有站点
|
# 所有站点
|
||||||
all_site = Site.list_order_by_pri(db)
|
all_site = Site.list_order_by_pri(db)
|
||||||
if not selected_sites or not all_site:
|
if not selected_sites:
|
||||||
return []
|
return all_site
|
||||||
|
|
||||||
# 选中的rss站点
|
# 选中的rss站点
|
||||||
rss_sites = [site for site in all_site if site and site.id in selected_sites]
|
rss_sites = [site for site in all_site if site and site.id in selected_sites]
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ from sqlalchemy.orm import Session
|
|||||||
from app import schemas
|
from app import schemas
|
||||||
from app.chain.subscribe import SubscribeChain
|
from app.chain.subscribe import SubscribeChain
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.core.security import verify_token
|
from app.core.metainfo import MetaInfo
|
||||||
|
from app.core.security import verify_token, verify_uri_token
|
||||||
from app.db import get_db
|
from app.db import get_db
|
||||||
from app.db.models.subscribe import Subscribe
|
from app.db.models.subscribe import Subscribe
|
||||||
from app.db.models.user import User
|
from app.db.models.user import User
|
||||||
@@ -27,7 +28,7 @@ def start_subscribe_add(title: str, year: str,
|
|||||||
mtype=mtype, tmdbid=tmdbid, season=season, username=username)
|
mtype=mtype, tmdbid=tmdbid, season=season, username=username)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/", summary="所有订阅", response_model=List[schemas.Subscribe])
|
@router.get("/", summary="查询所有订阅", response_model=List[schemas.Subscribe])
|
||||||
def read_subscribes(
|
def read_subscribes(
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
@@ -41,6 +42,14 @@ def read_subscribes(
|
|||||||
return subscribes
|
return subscribes
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/list", summary="查询所有订阅(API_TOKEN)", response_model=List[schemas.Subscribe])
|
||||||
|
def list_subscribes(_: str = Depends(verify_uri_token)) -> Any:
|
||||||
|
"""
|
||||||
|
查询所有订阅 API_TOKEN认证(?token=xxx)
|
||||||
|
"""
|
||||||
|
return read_subscribes()
|
||||||
|
|
||||||
|
|
||||||
@router.post("/", summary="新增订阅", response_model=schemas.Response)
|
@router.post("/", summary="新增订阅", response_model=schemas.Response)
|
||||||
def create_subscribe(
|
def create_subscribe(
|
||||||
*,
|
*,
|
||||||
@@ -55,6 +64,11 @@ def create_subscribe(
|
|||||||
mtype = MediaType(subscribe_in.type)
|
mtype = MediaType(subscribe_in.type)
|
||||||
else:
|
else:
|
||||||
mtype = None
|
mtype = None
|
||||||
|
# 豆瓣标理
|
||||||
|
if subscribe_in.doubanid:
|
||||||
|
meta = MetaInfo(subscribe_in.name)
|
||||||
|
subscribe_in.name = meta.name
|
||||||
|
subscribe_in.season = meta.begin_season
|
||||||
# 标题转换
|
# 标题转换
|
||||||
if subscribe_in.name:
|
if subscribe_in.name:
|
||||||
title = subscribe_in.name
|
title = subscribe_in.name
|
||||||
@@ -68,6 +82,7 @@ def create_subscribe(
|
|||||||
doubanid=subscribe_in.doubanid,
|
doubanid=subscribe_in.doubanid,
|
||||||
username=current_user.name,
|
username=current_user.name,
|
||||||
best_version=subscribe_in.best_version,
|
best_version=subscribe_in.best_version,
|
||||||
|
save_path=subscribe_in.save_path,
|
||||||
exist_ok=True)
|
exist_ok=True)
|
||||||
return schemas.Response(success=True if sid else False, message=message, data={
|
return schemas.Response(success=True if sid else False, message=message, data={
|
||||||
"id": sid
|
"id": sid
|
||||||
@@ -108,23 +123,30 @@ def update_subscribe(
|
|||||||
def subscribe_mediaid(
|
def subscribe_mediaid(
|
||||||
mediaid: str,
|
mediaid: str,
|
||||||
season: int = None,
|
season: int = None,
|
||||||
|
title: str = None,
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
根据TMDBID或豆瓣ID查询订阅 tmdb:/douban:
|
根据TMDBID或豆瓣ID查询订阅 tmdb:/douban:
|
||||||
"""
|
"""
|
||||||
|
result = None
|
||||||
if mediaid.startswith("tmdb:"):
|
if mediaid.startswith("tmdb:"):
|
||||||
tmdbid = mediaid[5:]
|
tmdbid = mediaid[5:]
|
||||||
if not tmdbid or not str(tmdbid).isdigit():
|
if not tmdbid or not str(tmdbid).isdigit():
|
||||||
return Subscribe()
|
return Subscribe()
|
||||||
result = Subscribe.exists(db, int(tmdbid), season)
|
result = Subscribe.exists(db, tmdbid=int(tmdbid), season=season)
|
||||||
elif mediaid.startswith("douban:"):
|
elif mediaid.startswith("douban:"):
|
||||||
doubanid = mediaid[7:]
|
doubanid = mediaid[7:]
|
||||||
if not doubanid:
|
if not doubanid:
|
||||||
return Subscribe()
|
return Subscribe()
|
||||||
result = Subscribe.get_by_doubanid(db, doubanid)
|
result = Subscribe.get_by_doubanid(db, doubanid)
|
||||||
else:
|
|
||||||
result = None
|
if not result and title:
|
||||||
|
meta = MetaInfo(title)
|
||||||
|
if season:
|
||||||
|
meta.begin_season = season
|
||||||
|
result = Subscribe.get_by_title(db, title=meta.name, season=meta.begin_season)
|
||||||
|
|
||||||
if result and result.sites:
|
if result and result.sites:
|
||||||
result.sites = json.loads(result.sites)
|
result.sites = json.loads(result.sites)
|
||||||
|
|
||||||
@@ -194,6 +216,8 @@ def read_subscribe(
|
|||||||
"""
|
"""
|
||||||
根据订阅编号查询订阅信息
|
根据订阅编号查询订阅信息
|
||||||
"""
|
"""
|
||||||
|
if not subscribe_id:
|
||||||
|
return Subscribe()
|
||||||
subscribe = Subscribe.get(db, subscribe_id)
|
subscribe = Subscribe.get(db, subscribe_id)
|
||||||
if subscribe and subscribe.sites:
|
if subscribe and subscribe.sites:
|
||||||
subscribe.sites = json.loads(subscribe.sites)
|
subscribe.sites = json.loads(subscribe.sites)
|
||||||
@@ -241,7 +265,7 @@ def delete_subscribe(
|
|||||||
async def seerr_subscribe(request: Request, background_tasks: BackgroundTasks,
|
async def seerr_subscribe(request: Request, background_tasks: BackgroundTasks,
|
||||||
authorization: str = Header(None)) -> Any:
|
authorization: str = Header(None)) -> Any:
|
||||||
"""
|
"""
|
||||||
Jellyseerr/Overseerr订阅
|
Jellyseerr/Overseerr网络勾子通知订阅
|
||||||
"""
|
"""
|
||||||
if not authorization or authorization != settings.API_TOKEN:
|
if not authorization or authorization != settings.API_TOKEN:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Union
|
from typing import Union, Any
|
||||||
|
|
||||||
import tailer
|
import tailer
|
||||||
from fastapi import APIRouter, HTTPException, Depends
|
from fastapi import APIRouter, HTTPException, Depends, Response
|
||||||
from fastapi.responses import StreamingResponse
|
from fastapi.responses import StreamingResponse
|
||||||
|
|
||||||
from app import schemas
|
from app import schemas
|
||||||
@@ -14,6 +14,7 @@ from app.core.security import verify_token
|
|||||||
from app.db.systemconfig_oper import SystemConfigOper
|
from app.db.systemconfig_oper import SystemConfigOper
|
||||||
from app.helper.message import MessageHelper
|
from app.helper.message import MessageHelper
|
||||||
from app.helper.progress import ProgressHelper
|
from app.helper.progress import ProgressHelper
|
||||||
|
from app.helper.sites import SitesHelper
|
||||||
from app.scheduler import Scheduler
|
from app.scheduler import Scheduler
|
||||||
from app.schemas.types import SystemConfigKey
|
from app.schemas.types import SystemConfigKey
|
||||||
from app.utils.http import RequestUtils
|
from app.utils.http import RequestUtils
|
||||||
@@ -23,6 +24,22 @@ from version import APP_VERSION
|
|||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/img/{imgurl:path}/{proxy}", summary="图片代理")
|
||||||
|
def get_img(imgurl: str, proxy: bool = False) -> Any:
|
||||||
|
"""
|
||||||
|
通过图片代理(使用代理服务器)
|
||||||
|
"""
|
||||||
|
if not imgurl:
|
||||||
|
return None
|
||||||
|
if proxy:
|
||||||
|
response = RequestUtils(ua=settings.USER_AGENT, proxies=settings.PROXY).get_res(url=imgurl)
|
||||||
|
else:
|
||||||
|
response = RequestUtils(ua=settings.USER_AGENT).get_res(url=imgurl)
|
||||||
|
if response:
|
||||||
|
return Response(content=response.content, media_type="image/jpeg")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
@router.get("/env", summary="查询系统环境变量", response_model=schemas.Response)
|
@router.get("/env", summary="查询系统环境变量", response_model=schemas.Response)
|
||||||
def get_env_setting(_: schemas.TokenPayload = Depends(verify_token)):
|
def get_env_setting(_: schemas.TokenPayload = Depends(verify_token)):
|
||||||
"""
|
"""
|
||||||
@@ -32,7 +49,9 @@ def get_env_setting(_: schemas.TokenPayload = Depends(verify_token)):
|
|||||||
exclude={"SECRET_KEY", "SUPERUSER_PASSWORD", "API_TOKEN"}
|
exclude={"SECRET_KEY", "SUPERUSER_PASSWORD", "API_TOKEN"}
|
||||||
)
|
)
|
||||||
info.update({
|
info.update({
|
||||||
"VERSION": APP_VERSION
|
"VERSION": APP_VERSION,
|
||||||
|
"AUTH_VERSION": SitesHelper().auth_version,
|
||||||
|
"INDEXER_VERSION": SitesHelper().indexer_version,
|
||||||
})
|
})
|
||||||
return schemas.Response(success=True,
|
return schemas.Response(success=True,
|
||||||
data=info)
|
data=info)
|
||||||
@@ -104,9 +123,11 @@ def get_message(token: str):
|
|||||||
|
|
||||||
|
|
||||||
@router.get("/logging", summary="实时日志")
|
@router.get("/logging", summary="实时日志")
|
||||||
def get_logging(token: str):
|
def get_logging(token: str, length: int = 50):
|
||||||
"""
|
"""
|
||||||
实时获取系统日志,返回格式为SSE
|
实时获取系统日志
|
||||||
|
length = -1 时, 返回text/plain
|
||||||
|
否则 返回格式SSE
|
||||||
"""
|
"""
|
||||||
if not token or not verify_token(token):
|
if not token or not verify_token(token):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
@@ -114,18 +135,26 @@ def get_logging(token: str):
|
|||||||
detail="认证失败!",
|
detail="认证失败!",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
log_path = settings.LOG_PATH / 'moviepilot.log'
|
||||||
def log_generator():
|
def log_generator():
|
||||||
log_path = settings.LOG_PATH / 'moviepilot.log'
|
|
||||||
# 读取文件末尾50行,不使用tailer模块
|
# 读取文件末尾50行,不使用tailer模块
|
||||||
with open(log_path, 'r', encoding='utf-8') as f:
|
with open(log_path, 'r', encoding='utf-8') as f:
|
||||||
for line in f.readlines()[-50:]:
|
for line in f.readlines()[-max(length, 50):]:
|
||||||
yield 'data: %s\n\n' % line
|
yield 'data: %s\n\n' % line
|
||||||
while True:
|
while True:
|
||||||
for text in tailer.follow(open(log_path, 'r', encoding='utf-8')):
|
for text in tailer.follow(open(log_path, 'r', encoding='utf-8')):
|
||||||
yield 'data: %s\n\n' % (text or '')
|
yield 'data: %s\n\n' % (text or '')
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
return StreamingResponse(log_generator(), media_type="text/event-stream")
|
# 根据length参数返回不同的响应
|
||||||
|
if length == -1:
|
||||||
|
# 返回全部日志作为文本响应
|
||||||
|
with open(log_path, 'r', encoding='utf-8') as f:
|
||||||
|
text = f.read()
|
||||||
|
return Response(content=text, media_type="text/plain")
|
||||||
|
else:
|
||||||
|
# 返回SSE流响应
|
||||||
|
return StreamingResponse(log_generator(), media_type="text/event-stream")
|
||||||
|
|
||||||
|
|
||||||
@router.get("/nettest", summary="测试网络连通性")
|
@router.get("/nettest", summary="测试网络连通性")
|
||||||
@@ -160,7 +189,8 @@ def latest_version(_: schemas.TokenPayload = Depends(verify_token)):
|
|||||||
"""
|
"""
|
||||||
查询Github所有Release版本
|
查询Github所有Release版本
|
||||||
"""
|
"""
|
||||||
version_res = RequestUtils().get_res(f"https://api.github.com/repos/jxxghp/MoviePilot/releases")
|
version_res = RequestUtils(proxies=settings.PROXY, headers=settings.GITHUB_HEADERS).get_res(
|
||||||
|
f"https://api.github.com/repos/jxxghp/MoviePilot/releases")
|
||||||
if version_res:
|
if version_res:
|
||||||
ver_json = version_res.json()
|
ver_json = version_res.json()
|
||||||
if ver_json:
|
if ver_json:
|
||||||
@@ -219,8 +249,5 @@ def execute_command(jobid: str,
|
|||||||
"""
|
"""
|
||||||
if not jobid:
|
if not jobid:
|
||||||
return schemas.Response(success=False, message="命令不能为空!")
|
return schemas.Response(success=False, message="命令不能为空!")
|
||||||
if jobid == "subscribe_search":
|
Scheduler().start(jobid)
|
||||||
Scheduler().start(jobid, state='R')
|
|
||||||
else:
|
|
||||||
Scheduler().start(jobid)
|
|
||||||
return schemas.Response(success=True)
|
return schemas.Response(success=True)
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ def manual_transfer(path: str = None,
|
|||||||
:param type_name: 媒体类型、电影/电视剧
|
:param type_name: 媒体类型、电影/电视剧
|
||||||
:param tmdbid: tmdbid
|
:param tmdbid: tmdbid
|
||||||
:param season: 剧集季号
|
:param season: 剧集季号
|
||||||
:param transfer_type: 转移类型,move/copy
|
:param transfer_type: 转移类型,move/copy 等
|
||||||
:param episode_format: 剧集识别格式
|
:param episode_format: 剧集识别格式
|
||||||
:param episode_detail: 剧集识别详细信息
|
:param episode_detail: 剧集识别详细信息
|
||||||
:param episode_part: 剧集识别分集信息
|
:param episode_part: 剧集识别分集信息
|
||||||
@@ -47,31 +47,34 @@ def manual_transfer(path: str = None,
|
|||||||
:param _: Token校验
|
:param _: Token校验
|
||||||
"""
|
"""
|
||||||
force = False
|
force = False
|
||||||
|
target = Path(target) if target else None
|
||||||
|
transfer = TransferChain()
|
||||||
if logid:
|
if logid:
|
||||||
# 查询历史记录
|
# 查询历史记录
|
||||||
history = TransferHistory.get(db, logid)
|
history: TransferHistory = TransferHistory.get(db, logid)
|
||||||
if not history:
|
if not history:
|
||||||
return schemas.Response(success=False, message=f"历史记录不存在,ID:{logid}")
|
return schemas.Response(success=False, message=f"历史记录不存在,ID:{logid}")
|
||||||
# 强制转移
|
# 强制转移
|
||||||
force = True
|
force = True
|
||||||
# 源路径
|
if history.status and ("move" in history.mode):
|
||||||
in_path = Path(history.src)
|
# 重新整理成功的转移,则使用成功的 dest 做 in_path
|
||||||
# 目的路径
|
in_path = Path(history.dest)
|
||||||
if history.dest and str(history.dest) != "None":
|
else:
|
||||||
# 删除旧的已整理文件
|
# 源路径
|
||||||
TransferChain().delete_files(Path(history.dest))
|
in_path = Path(history.src)
|
||||||
if not target:
|
# 目的路径
|
||||||
target = history.dest
|
if history.dest and str(history.dest) != "None":
|
||||||
|
# 删除旧的已整理文件
|
||||||
|
transfer.delete_files(Path(history.dest))
|
||||||
|
if not target:
|
||||||
|
target = transfer.get_root_path(path=history.dest,
|
||||||
|
type_name=history.type,
|
||||||
|
category=history.category)
|
||||||
elif path:
|
elif path:
|
||||||
in_path = Path(path)
|
in_path = Path(path)
|
||||||
else:
|
else:
|
||||||
return schemas.Response(success=False, message=f"缺少参数:path/logid")
|
return schemas.Response(success=False, message=f"缺少参数:path/logid")
|
||||||
|
|
||||||
if target and target != "None":
|
|
||||||
target = Path(target)
|
|
||||||
else:
|
|
||||||
target = None
|
|
||||||
|
|
||||||
# 类型
|
# 类型
|
||||||
mtype = MediaType(type_name) if type_name else None
|
mtype = MediaType(type_name) if type_name else None
|
||||||
# 自定义格式
|
# 自定义格式
|
||||||
@@ -84,7 +87,7 @@ def manual_transfer(path: str = None,
|
|||||||
offset=episode_offset,
|
offset=episode_offset,
|
||||||
)
|
)
|
||||||
# 开始转移
|
# 开始转移
|
||||||
state, errormsg = TransferChain().manual_transfer(
|
state, errormsg = transfer.manual_transfer(
|
||||||
in_path=in_path,
|
in_path=in_path,
|
||||||
target=target,
|
target=target,
|
||||||
tmdbid=tmdbid,
|
tmdbid=tmdbid,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import base64
|
import base64
|
||||||
|
import re
|
||||||
from typing import Any, List
|
from typing import Any, List
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, UploadFile, File
|
from fastapi import APIRouter, Depends, HTTPException, UploadFile, File
|
||||||
@@ -59,6 +60,10 @@ def update_user(
|
|||||||
"""
|
"""
|
||||||
user_info = user_in.dict()
|
user_info = user_in.dict()
|
||||||
if user_info.get("password"):
|
if user_info.get("password"):
|
||||||
|
# 正则表达式匹配密码包含字母、数字、特殊字符中的至少两项
|
||||||
|
pattern = r'^(?![a-zA-Z]+$)(?!\d+$)(?![^\da-zA-Z\s]+$).{6,50}$'
|
||||||
|
if not re.match(pattern, user_info.get("password")):
|
||||||
|
return schemas.Response(success=False, message="密码需要同时包含字母、数字、特殊字符中的至少两项,且长度大于6位")
|
||||||
user_info["hashed_password"] = get_password_hash(user_info["password"])
|
user_info["hashed_password"] = get_password_hash(user_info["password"])
|
||||||
user_info.pop("password")
|
user_info.pop("password")
|
||||||
user = User.get_by_name(db, name=user_info["name"])
|
user = User.get_by_name(db, name=user_info["name"])
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from fastapi import APIRouter, BackgroundTasks, Request
|
from fastapi import APIRouter, BackgroundTasks, Request, Depends
|
||||||
|
|
||||||
from app import schemas
|
from app import schemas
|
||||||
from app.chain.webhook import WebhookChain
|
from app.chain.webhook import WebhookChain
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
|
from app.core.security import verify_uri_token
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@@ -18,13 +19,12 @@ def start_webhook_chain(body: Any, form: Any, args: Any):
|
|||||||
|
|
||||||
@router.post("/", summary="Webhook消息响应", response_model=schemas.Response)
|
@router.post("/", summary="Webhook消息响应", response_model=schemas.Response)
|
||||||
async def webhook_message(background_tasks: BackgroundTasks,
|
async def webhook_message(background_tasks: BackgroundTasks,
|
||||||
token: str, request: Request,
|
request: Request,
|
||||||
|
_: str = Depends(verify_uri_token)
|
||||||
) -> Any:
|
) -> Any:
|
||||||
"""
|
"""
|
||||||
Webhook响应
|
Webhook响应
|
||||||
"""
|
"""
|
||||||
if token != settings.API_TOKEN:
|
|
||||||
return schemas.Response(success=False, message="token认证不通过")
|
|
||||||
body = await request.body()
|
body = await request.body()
|
||||||
form = await request.form()
|
form = await request.form()
|
||||||
args = request.query_params
|
args = request.query_params
|
||||||
@@ -34,12 +34,10 @@ async def webhook_message(background_tasks: BackgroundTasks,
|
|||||||
|
|
||||||
@router.get("/", summary="Webhook消息响应", response_model=schemas.Response)
|
@router.get("/", summary="Webhook消息响应", response_model=schemas.Response)
|
||||||
async def webhook_message(background_tasks: BackgroundTasks,
|
async def webhook_message(background_tasks: BackgroundTasks,
|
||||||
token: str, request: Request) -> Any:
|
request: Request, _: str = Depends(verify_uri_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
Webhook响应
|
Webhook响应
|
||||||
"""
|
"""
|
||||||
if token != settings.API_TOKEN:
|
|
||||||
return schemas.Response(success=False, message="token认证不通过")
|
|
||||||
args = request.query_params
|
args = request.query_params
|
||||||
background_tasks.add_task(start_webhook_chain, None, None, args)
|
background_tasks.add_task(start_webhook_chain, None, None, args)
|
||||||
return schemas.Response(success=True)
|
return schemas.Response(success=True)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from app.chain.media import MediaChain
|
|||||||
from app.chain.subscribe import SubscribeChain
|
from app.chain.subscribe import SubscribeChain
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo
|
||||||
|
from app.core.security import verify_uri_apikey
|
||||||
from app.db import get_db
|
from app.db import get_db
|
||||||
from app.db.models.subscribe import Subscribe
|
from app.db.models.subscribe import Subscribe
|
||||||
from app.schemas import RadarrMovie, SonarrSeries
|
from app.schemas import RadarrMovie, SonarrSeries
|
||||||
@@ -18,15 +19,10 @@ arr_router = APIRouter(tags=['servarr'])
|
|||||||
|
|
||||||
|
|
||||||
@arr_router.get("/system/status", summary="系统状态")
|
@arr_router.get("/system/status", summary="系统状态")
|
||||||
def arr_system_status(apikey: str) -> Any:
|
def arr_system_status(_: str = Depends(verify_uri_apikey)) -> Any:
|
||||||
"""
|
"""
|
||||||
模拟Radarr、Sonarr系统状态
|
模拟Radarr、Sonarr系统状态
|
||||||
"""
|
"""
|
||||||
if not apikey or apikey != settings.API_TOKEN:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=403,
|
|
||||||
detail="认证失败!",
|
|
||||||
)
|
|
||||||
return {
|
return {
|
||||||
"appName": "MoviePilot",
|
"appName": "MoviePilot",
|
||||||
"instanceName": "moviepilot",
|
"instanceName": "moviepilot",
|
||||||
@@ -77,15 +73,10 @@ def arr_system_status(apikey: str) -> Any:
|
|||||||
|
|
||||||
|
|
||||||
@arr_router.get("/qualityProfile", summary="质量配置")
|
@arr_router.get("/qualityProfile", summary="质量配置")
|
||||||
def arr_qualityProfile(apikey: str) -> Any:
|
def arr_qualityProfile(_: str = Depends(verify_uri_apikey)) -> Any:
|
||||||
"""
|
"""
|
||||||
模拟Radarr、Sonarr质量配置
|
模拟Radarr、Sonarr质量配置
|
||||||
"""
|
"""
|
||||||
if not apikey or apikey != settings.API_TOKEN:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=403,
|
|
||||||
detail="认证失败!",
|
|
||||||
)
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
@@ -123,15 +114,10 @@ def arr_qualityProfile(apikey: str) -> Any:
|
|||||||
|
|
||||||
|
|
||||||
@arr_router.get("/rootfolder", summary="根目录")
|
@arr_router.get("/rootfolder", summary="根目录")
|
||||||
def arr_rootfolder(apikey: str) -> Any:
|
def arr_rootfolder(_: str = Depends(verify_uri_apikey)) -> Any:
|
||||||
"""
|
"""
|
||||||
模拟Radarr、Sonarr根目录
|
模拟Radarr、Sonarr根目录
|
||||||
"""
|
"""
|
||||||
if not apikey or apikey != settings.API_TOKEN:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=403,
|
|
||||||
detail="认证失败!",
|
|
||||||
)
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
@@ -144,15 +130,10 @@ def arr_rootfolder(apikey: str) -> Any:
|
|||||||
|
|
||||||
|
|
||||||
@arr_router.get("/tag", summary="标签")
|
@arr_router.get("/tag", summary="标签")
|
||||||
def arr_tag(apikey: str) -> Any:
|
def arr_tag(_: str = Depends(verify_uri_apikey)) -> Any:
|
||||||
"""
|
"""
|
||||||
模拟Radarr、Sonarr标签
|
模拟Radarr、Sonarr标签
|
||||||
"""
|
"""
|
||||||
if not apikey or apikey != settings.API_TOKEN:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=403,
|
|
||||||
detail="认证失败!",
|
|
||||||
)
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
@@ -162,15 +143,10 @@ def arr_tag(apikey: str) -> Any:
|
|||||||
|
|
||||||
|
|
||||||
@arr_router.get("/languageprofile", summary="语言")
|
@arr_router.get("/languageprofile", summary="语言")
|
||||||
def arr_languageprofile(apikey: str) -> Any:
|
def arr_languageprofile(_: str = Depends(verify_uri_apikey)) -> Any:
|
||||||
"""
|
"""
|
||||||
模拟Radarr、Sonarr语言
|
模拟Radarr、Sonarr语言
|
||||||
"""
|
"""
|
||||||
if not apikey or apikey != settings.API_TOKEN:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=403,
|
|
||||||
detail="认证失败!",
|
|
||||||
)
|
|
||||||
return [{
|
return [{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"name": "默认",
|
"name": "默认",
|
||||||
@@ -193,7 +169,7 @@ def arr_languageprofile(apikey: str) -> Any:
|
|||||||
|
|
||||||
|
|
||||||
@arr_router.get("/movie", summary="所有订阅电影", response_model=List[schemas.RadarrMovie])
|
@arr_router.get("/movie", summary="所有订阅电影", response_model=List[schemas.RadarrMovie])
|
||||||
def arr_movies(apikey: str, db: Session = Depends(get_db)) -> Any:
|
def arr_movies(_: str = Depends(verify_uri_apikey), db: Session = Depends(get_db)) -> Any:
|
||||||
"""
|
"""
|
||||||
查询Rardar电影
|
查询Rardar电影
|
||||||
"""
|
"""
|
||||||
@@ -262,11 +238,6 @@ def arr_movies(apikey: str, db: Session = Depends(get_db)) -> Any:
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
if not apikey or apikey != settings.API_TOKEN:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=403,
|
|
||||||
detail="认证失败!",
|
|
||||||
)
|
|
||||||
# 查询所有电影订阅
|
# 查询所有电影订阅
|
||||||
result = []
|
result = []
|
||||||
subscribes = Subscribe.list(db)
|
subscribes = Subscribe.list(db)
|
||||||
@@ -289,16 +260,11 @@ def arr_movies(apikey: str, db: Session = Depends(get_db)) -> Any:
|
|||||||
|
|
||||||
|
|
||||||
@arr_router.get("/movie/lookup", summary="查询电影", response_model=List[schemas.RadarrMovie])
|
@arr_router.get("/movie/lookup", summary="查询电影", response_model=List[schemas.RadarrMovie])
|
||||||
def arr_movie_lookup(apikey: str, term: str, db: Session = Depends(get_db)) -> Any:
|
def arr_movie_lookup(term: str, db: Session = Depends(get_db), _: str = Depends(verify_uri_apikey)) -> Any:
|
||||||
"""
|
"""
|
||||||
查询Rardar电影 term: `tmdb:${id}`
|
查询Rardar电影 term: `tmdb:${id}`
|
||||||
存在和不存在均不能返回错误
|
存在和不存在均不能返回错误
|
||||||
"""
|
"""
|
||||||
if not apikey or apikey != settings.API_TOKEN:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=403,
|
|
||||||
detail="认证失败!",
|
|
||||||
)
|
|
||||||
tmdbid = term.replace("tmdb:", "")
|
tmdbid = term.replace("tmdb:", "")
|
||||||
# 查询媒体信息
|
# 查询媒体信息
|
||||||
mediainfo = MediaChain().recognize_media(mtype=MediaType.MOVIE, tmdbid=int(tmdbid))
|
mediainfo = MediaChain().recognize_media(mtype=MediaType.MOVIE, tmdbid=int(tmdbid))
|
||||||
@@ -340,15 +306,10 @@ def arr_movie_lookup(apikey: str, term: str, db: Session = Depends(get_db)) -> A
|
|||||||
|
|
||||||
|
|
||||||
@arr_router.get("/movie/{mid}", summary="电影订阅详情", response_model=schemas.RadarrMovie)
|
@arr_router.get("/movie/{mid}", summary="电影订阅详情", response_model=schemas.RadarrMovie)
|
||||||
def arr_movie(apikey: str, mid: int, db: Session = Depends(get_db)) -> Any:
|
def arr_movie(mid: int, db: Session = Depends(get_db), _: str = Depends(verify_uri_apikey)) -> Any:
|
||||||
"""
|
"""
|
||||||
查询Rardar电影订阅
|
查询Rardar电影订阅
|
||||||
"""
|
"""
|
||||||
if not apikey or apikey != settings.API_TOKEN:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=403,
|
|
||||||
detail="认证失败!",
|
|
||||||
)
|
|
||||||
subscribe = Subscribe.get(db, mid)
|
subscribe = Subscribe.get(db, mid)
|
||||||
if subscribe:
|
if subscribe:
|
||||||
return RadarrMovie(
|
return RadarrMovie(
|
||||||
@@ -371,18 +332,13 @@ def arr_movie(apikey: str, mid: int, db: Session = Depends(get_db)) -> Any:
|
|||||||
|
|
||||||
|
|
||||||
@arr_router.post("/movie", summary="新增电影订阅")
|
@arr_router.post("/movie", summary="新增电影订阅")
|
||||||
def arr_add_movie(apikey: str,
|
def arr_add_movie(movie: RadarrMovie,
|
||||||
movie: RadarrMovie,
|
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
|
_: str = Depends(verify_uri_apikey)
|
||||||
) -> Any:
|
) -> Any:
|
||||||
"""
|
"""
|
||||||
新增Rardar电影订阅
|
新增Rardar电影订阅
|
||||||
"""
|
"""
|
||||||
if not apikey or apikey != settings.API_TOKEN:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=403,
|
|
||||||
detail="认证失败!",
|
|
||||||
)
|
|
||||||
# 检查订阅是否已存在
|
# 检查订阅是否已存在
|
||||||
subscribe = Subscribe.get_by_tmdbid(db, movie.tmdbId)
|
subscribe = Subscribe.get_by_tmdbid(db, movie.tmdbId)
|
||||||
if subscribe:
|
if subscribe:
|
||||||
@@ -394,7 +350,7 @@ def arr_add_movie(apikey: str,
|
|||||||
year=movie.year,
|
year=movie.year,
|
||||||
mtype=MediaType.MOVIE,
|
mtype=MediaType.MOVIE,
|
||||||
tmdbid=movie.tmdbId,
|
tmdbid=movie.tmdbId,
|
||||||
userid="Seerr")
|
username="Seerr")
|
||||||
if sid:
|
if sid:
|
||||||
return {
|
return {
|
||||||
"id": sid
|
"id": sid
|
||||||
@@ -407,15 +363,10 @@ def arr_add_movie(apikey: str,
|
|||||||
|
|
||||||
|
|
||||||
@arr_router.delete("/movie/{mid}", summary="删除电影订阅", response_model=schemas.Response)
|
@arr_router.delete("/movie/{mid}", summary="删除电影订阅", response_model=schemas.Response)
|
||||||
def arr_remove_movie(apikey: str, mid: int, db: Session = Depends(get_db)) -> Any:
|
def arr_remove_movie(mid: int, db: Session = Depends(get_db), _: str = Depends(verify_uri_apikey)) -> Any:
|
||||||
"""
|
"""
|
||||||
删除Rardar电影订阅
|
删除Rardar电影订阅
|
||||||
"""
|
"""
|
||||||
if not apikey or apikey != settings.API_TOKEN:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=403,
|
|
||||||
detail="认证失败!",
|
|
||||||
)
|
|
||||||
subscribe = Subscribe.get(db, mid)
|
subscribe = Subscribe.get(db, mid)
|
||||||
if subscribe:
|
if subscribe:
|
||||||
subscribe.delete(db, mid)
|
subscribe.delete(db, mid)
|
||||||
@@ -428,7 +379,7 @@ def arr_remove_movie(apikey: str, mid: int, db: Session = Depends(get_db)) -> An
|
|||||||
|
|
||||||
|
|
||||||
@arr_router.get("/series", summary="所有剧集", response_model=List[schemas.SonarrSeries])
|
@arr_router.get("/series", summary="所有剧集", response_model=List[schemas.SonarrSeries])
|
||||||
def arr_series(apikey: str, db: Session = Depends(get_db)) -> Any:
|
def arr_series(_: str = Depends(verify_uri_apikey), db: Session = Depends(get_db)) -> Any:
|
||||||
"""
|
"""
|
||||||
查询Sonarr剧集
|
查询Sonarr剧集
|
||||||
"""
|
"""
|
||||||
@@ -534,11 +485,6 @@ def arr_series(apikey: str, db: Session = Depends(get_db)) -> Any:
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
if not apikey or apikey != settings.API_TOKEN:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=403,
|
|
||||||
detail="认证失败!",
|
|
||||||
)
|
|
||||||
# 查询所有电视剧订阅
|
# 查询所有电视剧订阅
|
||||||
result = []
|
result = []
|
||||||
subscribes = Subscribe.list(db)
|
subscribes = Subscribe.list(db)
|
||||||
@@ -569,16 +515,10 @@ def arr_series(apikey: str, db: Session = Depends(get_db)) -> Any:
|
|||||||
|
|
||||||
|
|
||||||
@arr_router.get("/series/lookup", summary="查询剧集")
|
@arr_router.get("/series/lookup", summary="查询剧集")
|
||||||
def arr_series_lookup(apikey: str, term: str, db: Session = Depends(get_db)) -> Any:
|
def arr_series_lookup(term: str, db: Session = Depends(get_db), _: str = Depends(verify_uri_apikey)) -> Any:
|
||||||
"""
|
"""
|
||||||
查询Sonarr剧集 term: `tvdb:${id}` title
|
查询Sonarr剧集 term: `tvdb:${id}` title
|
||||||
"""
|
"""
|
||||||
if not apikey or apikey != settings.API_TOKEN:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=403,
|
|
||||||
detail="认证失败!",
|
|
||||||
)
|
|
||||||
|
|
||||||
# 获取TVDBID
|
# 获取TVDBID
|
||||||
if not term.startswith("tvdb:"):
|
if not term.startswith("tvdb:"):
|
||||||
mediainfo = MediaChain().recognize_media(meta=MetaInfo(term),
|
mediainfo = MediaChain().recognize_media(meta=MetaInfo(term),
|
||||||
@@ -664,15 +604,10 @@ def arr_series_lookup(apikey: str, term: str, db: Session = Depends(get_db)) ->
|
|||||||
|
|
||||||
|
|
||||||
@arr_router.get("/series/{tid}", summary="剧集详情")
|
@arr_router.get("/series/{tid}", summary="剧集详情")
|
||||||
def arr_serie(apikey: str, tid: int, db: Session = Depends(get_db)) -> Any:
|
def arr_serie(tid: int, db: Session = Depends(get_db), _: str = Depends(verify_uri_apikey)) -> Any:
|
||||||
"""
|
"""
|
||||||
查询Sonarr剧集
|
查询Sonarr剧集
|
||||||
"""
|
"""
|
||||||
if not apikey or apikey != settings.API_TOKEN:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=403,
|
|
||||||
detail="认证失败!",
|
|
||||||
)
|
|
||||||
subscribe = Subscribe.get(db, tid)
|
subscribe = Subscribe.get(db, tid)
|
||||||
if subscribe:
|
if subscribe:
|
||||||
return SonarrSeries(
|
return SonarrSeries(
|
||||||
@@ -703,16 +638,12 @@ def arr_serie(apikey: str, tid: int, db: Session = Depends(get_db)) -> Any:
|
|||||||
|
|
||||||
|
|
||||||
@arr_router.post("/series", summary="新增剧集订阅")
|
@arr_router.post("/series", summary="新增剧集订阅")
|
||||||
def arr_add_series(apikey: str, tv: schemas.SonarrSeries,
|
def arr_add_series(tv: schemas.SonarrSeries,
|
||||||
db: Session = Depends(get_db)) -> Any:
|
db: Session = Depends(get_db),
|
||||||
|
_: str = Depends(verify_uri_apikey)) -> Any:
|
||||||
"""
|
"""
|
||||||
新增Sonarr剧集订阅
|
新增Sonarr剧集订阅
|
||||||
"""
|
"""
|
||||||
if not apikey or apikey != settings.API_TOKEN:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=403,
|
|
||||||
detail="认证失败!",
|
|
||||||
)
|
|
||||||
# 检查订阅是否存在
|
# 检查订阅是否存在
|
||||||
left_seasons = []
|
left_seasons = []
|
||||||
for season in tv.seasons:
|
for season in tv.seasons:
|
||||||
@@ -737,7 +668,7 @@ def arr_add_series(apikey: str, tv: schemas.SonarrSeries,
|
|||||||
season=season.get("seasonNumber"),
|
season=season.get("seasonNumber"),
|
||||||
tmdbid=tv.tmdbId,
|
tmdbid=tv.tmdbId,
|
||||||
mtype=MediaType.TV,
|
mtype=MediaType.TV,
|
||||||
userid="Seerr")
|
username="Seerr")
|
||||||
|
|
||||||
if sid:
|
if sid:
|
||||||
return {
|
return {
|
||||||
@@ -751,15 +682,10 @@ def arr_add_series(apikey: str, tv: schemas.SonarrSeries,
|
|||||||
|
|
||||||
|
|
||||||
@arr_router.delete("/series/{tid}", summary="删除剧集订阅")
|
@arr_router.delete("/series/{tid}", summary="删除剧集订阅")
|
||||||
def arr_remove_series(apikey: str, tid: int, db: Session = Depends(get_db)) -> Any:
|
def arr_remove_series(tid: int, db: Session = Depends(get_db), _: str = Depends(verify_uri_apikey)) -> Any:
|
||||||
"""
|
"""
|
||||||
删除Sonarr剧集订阅
|
删除Sonarr剧集订阅
|
||||||
"""
|
"""
|
||||||
if not apikey or apikey != settings.API_TOKEN:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=403,
|
|
||||||
detail="认证失败!",
|
|
||||||
)
|
|
||||||
subscribe = Subscribe.get(db, tid)
|
subscribe = Subscribe.get(db, tid)
|
||||||
if subscribe:
|
if subscribe:
|
||||||
subscribe.delete(db, tid)
|
subscribe.delete(db, tid)
|
||||||
|
|||||||
@@ -107,23 +107,34 @@ class ChainBase(metaclass=ABCMeta):
|
|||||||
# 中止继续执行
|
# 中止继续执行
|
||||||
break
|
break
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.error(f"运行模块 {method} 出错:{module.__class__.__name__} - {str(err)}\n{traceback.print_exc()}")
|
logger.error(
|
||||||
|
f"运行模块 {method} 出错:{module.__class__.__name__} - {str(err)}\n{traceback.format_exc()}")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def recognize_media(self, meta: MetaBase = None,
|
def recognize_media(self, meta: MetaBase = None,
|
||||||
mtype: MediaType = None,
|
mtype: MediaType = None,
|
||||||
tmdbid: int = None) -> Optional[MediaInfo]:
|
tmdbid: int = None,
|
||||||
|
doubanid: str = None) -> Optional[MediaInfo]:
|
||||||
"""
|
"""
|
||||||
识别媒体信息
|
识别媒体信息
|
||||||
:param meta: 识别的元数据
|
:param meta: 识别的元数据
|
||||||
:param mtype: 识别的媒体类型,与tmdbid配套
|
:param mtype: 识别的媒体类型,与tmdbid配套
|
||||||
:param tmdbid: tmdbid
|
:param tmdbid: tmdbid
|
||||||
|
:param doubanid: 豆瓣ID
|
||||||
:return: 识别的媒体信息,包括剧集信息
|
:return: 识别的媒体信息,包括剧集信息
|
||||||
"""
|
"""
|
||||||
return self.run_module("recognize_media", meta=meta, mtype=mtype, tmdbid=tmdbid)
|
# 识别用名中含指定信息情形
|
||||||
|
if not mtype and meta and meta.type in [MediaType.TV, MediaType.MOVIE]:
|
||||||
|
mtype = meta.type
|
||||||
|
if not tmdbid and hasattr(meta, "tmdbid"):
|
||||||
|
tmdbid = meta.tmdbid
|
||||||
|
if not doubanid and hasattr(meta, "doubanid"):
|
||||||
|
doubanid = meta.doubanid
|
||||||
|
return self.run_module("recognize_media", meta=meta, mtype=mtype,
|
||||||
|
tmdbid=tmdbid, doubanid=doubanid)
|
||||||
|
|
||||||
def match_doubaninfo(self, name: str, imdbid: str = None,
|
def match_doubaninfo(self, name: str, imdbid: str = None,
|
||||||
mtype: str = None, year: str = None, season: int = None) -> Optional[dict]:
|
mtype: MediaType = None, year: str = None, season: int = None) -> Optional[dict]:
|
||||||
"""
|
"""
|
||||||
搜索和匹配豆瓣信息
|
搜索和匹配豆瓣信息
|
||||||
:param name: 标题
|
:param name: 标题
|
||||||
@@ -135,6 +146,18 @@ class ChainBase(metaclass=ABCMeta):
|
|||||||
return self.run_module("match_doubaninfo", name=name, imdbid=imdbid,
|
return self.run_module("match_doubaninfo", name=name, imdbid=imdbid,
|
||||||
mtype=mtype, year=year, season=season)
|
mtype=mtype, year=year, season=season)
|
||||||
|
|
||||||
|
def match_tmdbinfo(self, name: str, mtype: MediaType = None,
|
||||||
|
year: str = None, season: int = None) -> Optional[dict]:
|
||||||
|
"""
|
||||||
|
搜索和匹配TMDB信息
|
||||||
|
:param name: 标题
|
||||||
|
:param mtype: 类型
|
||||||
|
:param year: 年份
|
||||||
|
:param season: 季
|
||||||
|
"""
|
||||||
|
return self.run_module("match_tmdbinfo", name=name,
|
||||||
|
mtype=mtype, year=year, season=season)
|
||||||
|
|
||||||
def obtain_images(self, mediainfo: MediaInfo) -> Optional[MediaInfo]:
|
def obtain_images(self, mediainfo: MediaInfo) -> Optional[MediaInfo]:
|
||||||
"""
|
"""
|
||||||
补充抓取媒体信息图片
|
补充抓取媒体信息图片
|
||||||
@@ -159,13 +182,14 @@ class ChainBase(metaclass=ABCMeta):
|
|||||||
image_prefix=image_prefix, image_type=image_type,
|
image_prefix=image_prefix, image_type=image_type,
|
||||||
season=season, episode=episode)
|
season=season, episode=episode)
|
||||||
|
|
||||||
def douban_info(self, doubanid: str) -> Optional[dict]:
|
def douban_info(self, doubanid: str, mtype: MediaType = None) -> Optional[dict]:
|
||||||
"""
|
"""
|
||||||
获取豆瓣信息
|
获取豆瓣信息
|
||||||
:param doubanid: 豆瓣ID
|
:param doubanid: 豆瓣ID
|
||||||
|
:param mtype: 媒体类型
|
||||||
:return: 豆瓣信息
|
:return: 豆瓣信息
|
||||||
"""
|
"""
|
||||||
return self.run_module("douban_info", doubanid=doubanid)
|
return self.run_module("douban_info", doubanid=doubanid, mtype=mtype)
|
||||||
|
|
||||||
def tvdb_info(self, tvdbid: int) -> Optional[dict]:
|
def tvdb_info(self, tvdbid: int) -> Optional[dict]:
|
||||||
"""
|
"""
|
||||||
@@ -357,15 +381,6 @@ class ChainBase(metaclass=ABCMeta):
|
|||||||
"""
|
"""
|
||||||
return self.run_module("media_exists", mediainfo=mediainfo, itemid=itemid)
|
return self.run_module("media_exists", mediainfo=mediainfo, itemid=itemid)
|
||||||
|
|
||||||
def refresh_mediaserver(self, mediainfo: MediaInfo, file_path: Path) -> None:
|
|
||||||
"""
|
|
||||||
刷新媒体库
|
|
||||||
:param mediainfo: 识别的媒体信息
|
|
||||||
:param file_path: 文件路径
|
|
||||||
:return: 成功或失败
|
|
||||||
"""
|
|
||||||
self.run_module("refresh_mediaserver", mediainfo=mediainfo, file_path=file_path)
|
|
||||||
|
|
||||||
def post_message(self, message: Notification) -> None:
|
def post_message(self, message: Notification) -> None:
|
||||||
"""
|
"""
|
||||||
发送消息
|
发送消息
|
||||||
@@ -376,6 +391,7 @@ class ChainBase(metaclass=ABCMeta):
|
|||||||
self.eventmanager.send_event(etype=EventType.NoticeMessage,
|
self.eventmanager.send_event(etype=EventType.NoticeMessage,
|
||||||
data={
|
data={
|
||||||
"channel": message.channel,
|
"channel": message.channel,
|
||||||
|
"type": message.mtype,
|
||||||
"title": message.title,
|
"title": message.title,
|
||||||
"text": message.text,
|
"text": message.text,
|
||||||
"image": message.image,
|
"image": message.image,
|
||||||
@@ -405,15 +421,19 @@ class ChainBase(metaclass=ABCMeta):
|
|||||||
"""
|
"""
|
||||||
return self.run_module("post_torrents_message", message=message, torrents=torrents)
|
return self.run_module("post_torrents_message", message=message, torrents=torrents)
|
||||||
|
|
||||||
def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str) -> None:
|
def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str,
|
||||||
|
force_nfo: bool = False, force_img: bool = False) -> None:
|
||||||
"""
|
"""
|
||||||
刮削元数据
|
刮削元数据
|
||||||
:param path: 媒体文件路径
|
:param path: 媒体文件路径
|
||||||
:param mediainfo: 识别的媒体信息
|
:param mediainfo: 识别的媒体信息
|
||||||
:param transfer_type: 转移模式
|
:param transfer_type: 转移模式
|
||||||
|
:param force_nfo: 强制刮削nfo
|
||||||
|
:param force_img: 强制刮削图片
|
||||||
:return: 成功或失败
|
:return: 成功或失败
|
||||||
"""
|
"""
|
||||||
self.run_module("scrape_metadata", path=path, mediainfo=mediainfo, transfer_type=transfer_type)
|
self.run_module("scrape_metadata", path=path, mediainfo=mediainfo,
|
||||||
|
transfer_type=transfer_type, force_nfo=force_nfo, force_img=force_img)
|
||||||
|
|
||||||
def register_commands(self, commands: Dict[str, dict]) -> None:
|
def register_commands(self, commands: Dict[str, dict]) -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
from typing import Optional, List
|
from typing import Optional, List
|
||||||
|
|
||||||
from app.chain import ChainBase
|
from app.chain import ChainBase
|
||||||
from app.core.context import Context
|
from app.core.config import settings
|
||||||
from app.core.context import MediaInfo
|
|
||||||
from app.core.metainfo import MetaInfo
|
|
||||||
from app.log import logger
|
|
||||||
from app.schemas import MediaType
|
from app.schemas import MediaType
|
||||||
from app.utils.singleton import Singleton
|
from app.utils.singleton import Singleton
|
||||||
|
|
||||||
@@ -14,53 +11,7 @@ class DoubanChain(ChainBase, metaclass=Singleton):
|
|||||||
豆瓣处理链,单例运行
|
豆瓣处理链,单例运行
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def recognize_by_doubanid(self, doubanid: str) -> Optional[Context]:
|
def movie_top250(self, page: int = 1, count: int = 30) -> Optional[List[dict]]:
|
||||||
"""
|
|
||||||
根据豆瓣ID识别媒体信息
|
|
||||||
"""
|
|
||||||
logger.info(f'开始识别媒体信息,豆瓣ID:{doubanid} ...')
|
|
||||||
# 查询豆瓣信息
|
|
||||||
doubaninfo = self.douban_info(doubanid=doubanid)
|
|
||||||
if not doubaninfo:
|
|
||||||
logger.warn(f'未查询到豆瓣信息,豆瓣ID:{doubanid}')
|
|
||||||
return None
|
|
||||||
return self.recognize_by_doubaninfo(doubaninfo)
|
|
||||||
|
|
||||||
def recognize_by_doubaninfo(self, doubaninfo: dict) -> Optional[Context]:
|
|
||||||
"""
|
|
||||||
根据豆瓣信息识别媒体信息
|
|
||||||
"""
|
|
||||||
# 优先使用原标题匹配
|
|
||||||
season_meta = None
|
|
||||||
if doubaninfo.get("original_title"):
|
|
||||||
meta = MetaInfo(title=doubaninfo.get("original_title"))
|
|
||||||
season_meta = MetaInfo(title=doubaninfo.get("title"))
|
|
||||||
# 合并季
|
|
||||||
meta.begin_season = season_meta.begin_season
|
|
||||||
else:
|
|
||||||
meta = MetaInfo(title=doubaninfo.get("title"))
|
|
||||||
# 年份
|
|
||||||
if doubaninfo.get("year"):
|
|
||||||
meta.year = doubaninfo.get("year")
|
|
||||||
# 处理类型
|
|
||||||
if isinstance(doubaninfo.get('media_type'), MediaType):
|
|
||||||
meta.type = doubaninfo.get('media_type')
|
|
||||||
else:
|
|
||||||
meta.type = MediaType.MOVIE if doubaninfo.get("type") == "movie" else MediaType.TV
|
|
||||||
# 使用原标题识别媒体信息
|
|
||||||
mediainfo = self.recognize_media(meta=meta, mtype=meta.type)
|
|
||||||
if not mediainfo:
|
|
||||||
if season_meta and season_meta.name != meta.name:
|
|
||||||
# 使用主标题识别媒体信息
|
|
||||||
mediainfo = self.recognize_media(meta=season_meta, mtype=season_meta.type)
|
|
||||||
if not mediainfo:
|
|
||||||
logger.warn(f'{meta.name} 未识别到TMDB媒体信息')
|
|
||||||
return Context(meta_info=meta, media_info=MediaInfo(douban_info=doubaninfo))
|
|
||||||
logger.info(f'识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year} {meta.season}')
|
|
||||||
mediainfo.set_douban_info(doubaninfo)
|
|
||||||
return Context(meta_info=meta, media_info=mediainfo)
|
|
||||||
|
|
||||||
def movie_top250(self, page: int = 1, count: int = 30) -> List[dict]:
|
|
||||||
"""
|
"""
|
||||||
获取豆瓣电影TOP250
|
获取豆瓣电影TOP250
|
||||||
:param page: 页码
|
:param page: 页码
|
||||||
@@ -68,19 +19,19 @@ class DoubanChain(ChainBase, metaclass=Singleton):
|
|||||||
"""
|
"""
|
||||||
return self.run_module("movie_top250", page=page, count=count)
|
return self.run_module("movie_top250", page=page, count=count)
|
||||||
|
|
||||||
def movie_showing(self, page: int = 1, count: int = 30) -> List[dict]:
|
def movie_showing(self, page: int = 1, count: int = 30) -> Optional[List[dict]]:
|
||||||
"""
|
"""
|
||||||
获取正在上映的电影
|
获取正在上映的电影
|
||||||
"""
|
"""
|
||||||
return self.run_module("movie_showing", page=page, count=count)
|
return self.run_module("movie_showing", page=page, count=count)
|
||||||
|
|
||||||
def tv_weekly_chinese(self, page: int = 1, count: int = 30) -> List[dict]:
|
def tv_weekly_chinese(self, page: int = 1, count: int = 30) -> Optional[List[dict]]:
|
||||||
"""
|
"""
|
||||||
获取本周中国剧集榜
|
获取本周中国剧集榜
|
||||||
"""
|
"""
|
||||||
return self.run_module("tv_weekly_chinese", page=page, count=count)
|
return self.run_module("tv_weekly_chinese", page=page, count=count)
|
||||||
|
|
||||||
def tv_weekly_global(self, page: int = 1, count: int = 30) -> List[dict]:
|
def tv_weekly_global(self, page: int = 1, count: int = 30) -> Optional[List[dict]]:
|
||||||
"""
|
"""
|
||||||
获取本周全球剧集榜
|
获取本周全球剧集榜
|
||||||
"""
|
"""
|
||||||
@@ -100,8 +51,54 @@ class DoubanChain(ChainBase, metaclass=Singleton):
|
|||||||
return self.run_module("douban_discover", mtype=mtype, sort=sort, tags=tags,
|
return self.run_module("douban_discover", mtype=mtype, sort=sort, tags=tags,
|
||||||
page=page, count=count)
|
page=page, count=count)
|
||||||
|
|
||||||
def tv_animation(self, page: int = 1, count: int = 30) -> List[dict]:
|
def tv_animation(self, page: int = 1, count: int = 30) -> Optional[List[dict]]:
|
||||||
"""
|
"""
|
||||||
获取动画剧集
|
获取动画剧集
|
||||||
"""
|
"""
|
||||||
return self.run_module("tv_animation", page=page, count=count)
|
return self.run_module("tv_animation", page=page, count=count)
|
||||||
|
|
||||||
|
def movie_hot(self, page: int = 1, count: int = 30) -> Optional[List[dict]]:
|
||||||
|
"""
|
||||||
|
获取热门电影
|
||||||
|
"""
|
||||||
|
if settings.RECOGNIZE_SOURCE != "douban":
|
||||||
|
return None
|
||||||
|
return self.run_module("movie_hot", page=page, count=count)
|
||||||
|
|
||||||
|
def tv_hot(self, page: int = 1, count: int = 30) -> Optional[List[dict]]:
|
||||||
|
"""
|
||||||
|
获取热门剧集
|
||||||
|
"""
|
||||||
|
if settings.RECOGNIZE_SOURCE != "douban":
|
||||||
|
return None
|
||||||
|
return self.run_module("tv_hot", page=page, count=count)
|
||||||
|
|
||||||
|
def movie_credits(self, doubanid: str, page: int = 1) -> List[dict]:
|
||||||
|
"""
|
||||||
|
根据TMDBID查询电影演职人员
|
||||||
|
:param doubanid: 豆瓣ID
|
||||||
|
:param page: 页码
|
||||||
|
"""
|
||||||
|
return self.run_module("douban_movie_credits", doubanid=doubanid, page=page)
|
||||||
|
|
||||||
|
def tv_credits(self, doubanid: str, page: int = 1) -> List[dict]:
|
||||||
|
"""
|
||||||
|
根据TMDBID查询电视剧演职人员
|
||||||
|
:param doubanid: 豆瓣ID
|
||||||
|
:param page: 页码
|
||||||
|
"""
|
||||||
|
return self.run_module("douban_tv_credits", doubanid=doubanid, page=page)
|
||||||
|
|
||||||
|
def movie_recommend(self, doubanid: str) -> List[dict]:
|
||||||
|
"""
|
||||||
|
根据豆瓣ID查询推荐电影
|
||||||
|
:param doubanid: 豆瓣ID
|
||||||
|
"""
|
||||||
|
return self.run_module("douban_movie_recommend", doubanid=doubanid)
|
||||||
|
|
||||||
|
def tv_recommend(self, doubanid: str) -> List[dict]:
|
||||||
|
"""
|
||||||
|
根据豆瓣ID查询推荐电视剧
|
||||||
|
:param doubanid: 豆瓣ID
|
||||||
|
"""
|
||||||
|
return self.run_module("douban_tv_recommend", doubanid=doubanid)
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ class DownloadChain(ChainBase):
|
|||||||
msg_text = f"{msg_text}\n种子:{torrent.title}"
|
msg_text = f"{msg_text}\n种子:{torrent.title}"
|
||||||
if torrent.pubdate:
|
if torrent.pubdate:
|
||||||
msg_text = f"{msg_text}\n发布时间:{torrent.pubdate}"
|
msg_text = f"{msg_text}\n发布时间:{torrent.pubdate}"
|
||||||
|
if torrent.freedate:
|
||||||
|
msg_text = f"{msg_text}\n免费时间:{StringUtils.diff_time_str(torrent.freedate)}"
|
||||||
if torrent.seeders:
|
if torrent.seeders:
|
||||||
msg_text = f"{msg_text}\n做种数:{torrent.seeders}"
|
msg_text = f"{msg_text}\n做种数:{torrent.seeders}"
|
||||||
if torrent.uploadvolumefactor and torrent.downloadvolumefactor:
|
if torrent.uploadvolumefactor and torrent.downloadvolumefactor:
|
||||||
@@ -170,7 +172,8 @@ class DownloadChain(ChainBase):
|
|||||||
episodes: Set[int] = None,
|
episodes: Set[int] = None,
|
||||||
channel: MessageChannel = None,
|
channel: MessageChannel = None,
|
||||||
save_path: str = None,
|
save_path: str = None,
|
||||||
userid: Union[str, int] = None) -> Optional[str]:
|
userid: Union[str, int] = None,
|
||||||
|
username: str = None) -> Optional[str]:
|
||||||
"""
|
"""
|
||||||
下载及发送通知
|
下载及发送通知
|
||||||
:param context: 资源上下文
|
:param context: 资源上下文
|
||||||
@@ -179,6 +182,7 @@ class DownloadChain(ChainBase):
|
|||||||
:param channel: 通知渠道
|
:param channel: 通知渠道
|
||||||
:param save_path: 保存路径
|
:param save_path: 保存路径
|
||||||
:param userid: 用户ID
|
:param userid: 用户ID
|
||||||
|
:param username: 调用下载的用户名/插件名
|
||||||
"""
|
"""
|
||||||
_torrent = context.torrent_info
|
_torrent = context.torrent_info
|
||||||
_media = context.media_info
|
_media = context.media_info
|
||||||
@@ -190,7 +194,7 @@ class DownloadChain(ChainBase):
|
|||||||
channel=channel,
|
channel=channel,
|
||||||
userid=userid)
|
userid=userid)
|
||||||
if not content:
|
if not content:
|
||||||
return
|
return None
|
||||||
else:
|
else:
|
||||||
content = torrent_file
|
content = torrent_file
|
||||||
# 获取种子文件的文件夹名和文件清单
|
# 获取种子文件的文件夹名和文件清单
|
||||||
@@ -202,33 +206,31 @@ class DownloadChain(ChainBase):
|
|||||||
# 开启下载二级目录
|
# 开启下载二级目录
|
||||||
if _media.type == MediaType.MOVIE:
|
if _media.type == MediaType.MOVIE:
|
||||||
# 电影
|
# 电影
|
||||||
download_dir = Path(settings.DOWNLOAD_MOVIE_PATH or settings.DOWNLOAD_PATH) / _media.category
|
download_dir = settings.SAVE_MOVIE_PATH / _media.category
|
||||||
else:
|
else:
|
||||||
if settings.DOWNLOAD_ANIME_PATH \
|
if _media.genre_ids \
|
||||||
and _media.genre_ids \
|
|
||||||
and set(_media.genre_ids).intersection(set(settings.ANIME_GENREIDS)):
|
and set(_media.genre_ids).intersection(set(settings.ANIME_GENREIDS)):
|
||||||
# 动漫
|
# 动漫
|
||||||
download_dir = Path(settings.DOWNLOAD_ANIME_PATH)
|
download_dir = settings.SAVE_ANIME_PATH
|
||||||
else:
|
else:
|
||||||
# 电视剧
|
# 电视剧
|
||||||
download_dir = Path(settings.DOWNLOAD_TV_PATH or settings.DOWNLOAD_PATH) / _media.category
|
download_dir = settings.SAVE_TV_PATH / _media.category
|
||||||
elif _media:
|
elif _media:
|
||||||
# 未开启下载二级目录
|
# 未开启下载二级目录
|
||||||
if _media.type == MediaType.MOVIE:
|
if _media.type == MediaType.MOVIE:
|
||||||
# 电影
|
# 电影
|
||||||
download_dir = Path(settings.DOWNLOAD_MOVIE_PATH or settings.DOWNLOAD_PATH)
|
download_dir = settings.SAVE_MOVIE_PATH
|
||||||
else:
|
else:
|
||||||
if settings.DOWNLOAD_ANIME_PATH \
|
if _media.genre_ids \
|
||||||
and _media.genre_ids \
|
|
||||||
and set(_media.genre_ids).intersection(set(settings.ANIME_GENREIDS)):
|
and set(_media.genre_ids).intersection(set(settings.ANIME_GENREIDS)):
|
||||||
# 动漫
|
# 动漫
|
||||||
download_dir = Path(settings.DOWNLOAD_ANIME_PATH)
|
download_dir = settings.SAVE_ANIME_PATH
|
||||||
else:
|
else:
|
||||||
# 电视剧
|
# 电视剧
|
||||||
download_dir = Path(settings.DOWNLOAD_TV_PATH or settings.DOWNLOAD_PATH)
|
download_dir = settings.SAVE_TV_PATH
|
||||||
else:
|
else:
|
||||||
# 未识别
|
# 未识别
|
||||||
download_dir = Path(settings.DOWNLOAD_PATH)
|
download_dir = settings.SAVE_PATH
|
||||||
else:
|
else:
|
||||||
# 自定义下载目录
|
# 自定义下载目录
|
||||||
download_dir = Path(save_path)
|
download_dir = Path(save_path)
|
||||||
@@ -269,6 +271,7 @@ class DownloadChain(ChainBase):
|
|||||||
torrent_description=_torrent.description,
|
torrent_description=_torrent.description,
|
||||||
torrent_site=_torrent.site_name,
|
torrent_site=_torrent.site_name,
|
||||||
userid=userid,
|
userid=userid,
|
||||||
|
username=username,
|
||||||
channel=channel.value if channel else None,
|
channel=channel.value if channel else None,
|
||||||
date=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
date=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
||||||
)
|
)
|
||||||
@@ -282,6 +285,10 @@ class DownloadChain(ChainBase):
|
|||||||
if not file_meta.begin_episode \
|
if not file_meta.begin_episode \
|
||||||
or file_meta.begin_episode not in episodes:
|
or file_meta.begin_episode not in episodes:
|
||||||
continue
|
continue
|
||||||
|
# 只处理视频格式
|
||||||
|
if not Path(file).suffix \
|
||||||
|
or Path(file).suffix not in settings.RMT_MEDIAEXT:
|
||||||
|
continue
|
||||||
files_to_add.append({
|
files_to_add.append({
|
||||||
"download_hash": _hash,
|
"download_hash": _hash,
|
||||||
"downloader": settings.DOWNLOADER,
|
"downloader": settings.DOWNLOADER,
|
||||||
@@ -320,10 +327,12 @@ class DownloadChain(ChainBase):
|
|||||||
|
|
||||||
def batch_download(self,
|
def batch_download(self,
|
||||||
contexts: List[Context],
|
contexts: List[Context],
|
||||||
no_exists: Dict[int, Dict[int, NotExistMediaInfo]] = None,
|
no_exists: Dict[Union[int, str], Dict[int, NotExistMediaInfo]] = None,
|
||||||
save_path: str = None,
|
save_path: str = None,
|
||||||
channel: MessageChannel = None,
|
channel: MessageChannel = None,
|
||||||
userid: str = None) -> Tuple[List[Context], Dict[int, Dict[int, NotExistMediaInfo]]]:
|
userid: str = None,
|
||||||
|
username: str = None
|
||||||
|
) -> Tuple[List[Context], Dict[Union[int, str], Dict[int, NotExistMediaInfo]]]:
|
||||||
"""
|
"""
|
||||||
根据缺失数据,自动种子列表中组合择优下载
|
根据缺失数据,自动种子列表中组合择优下载
|
||||||
:param contexts: 资源上下文列表
|
:param contexts: 资源上下文列表
|
||||||
@@ -331,33 +340,36 @@ class DownloadChain(ChainBase):
|
|||||||
:param save_path: 保存路径
|
:param save_path: 保存路径
|
||||||
:param channel: 通知渠道
|
:param channel: 通知渠道
|
||||||
:param userid: 用户ID
|
:param userid: 用户ID
|
||||||
:return: 已经下载的资源列表、剩余未下载到的剧集 no_exists[tmdb_id] = {season: NotExistMediaInfo}
|
:param username: 调用下载的用户名/插件名
|
||||||
|
:return: 已经下载的资源列表、剩余未下载到的剧集 no_exists[tmdb_id/douban_id] = {season: NotExistMediaInfo}
|
||||||
"""
|
"""
|
||||||
# 已下载的项目
|
# 已下载的项目
|
||||||
downloaded_list: List[Context] = []
|
downloaded_list: List[Context] = []
|
||||||
|
|
||||||
def __update_seasons(_tmdbid: int, _need: list, _current: list) -> list:
|
def __update_seasons(_mid: Union[int, str], _need: list, _current: list) -> list:
|
||||||
"""
|
"""
|
||||||
更新need_tvs季数,返回剩余季数
|
更新need_tvs季数,返回剩余季数
|
||||||
:param _tmdbid: TMDBID
|
:param _mid: TMDBID
|
||||||
:param _need: 需要下载的季数
|
:param _need: 需要下载的季数
|
||||||
:param _current: 已经下载的季数
|
:param _current: 已经下载的季数
|
||||||
"""
|
"""
|
||||||
# 剩余季数
|
# 剩余季数
|
||||||
need = list(set(_need).difference(set(_current)))
|
need = list(set(_need).difference(set(_current)))
|
||||||
# 清除已下载的季信息
|
# 清除已下载的季信息
|
||||||
seas = copy.deepcopy(no_exists.get(_tmdbid))
|
seas = copy.deepcopy(no_exists.get(_mid))
|
||||||
for _sea in list(seas):
|
if seas:
|
||||||
if _sea not in need:
|
for _sea in list(seas):
|
||||||
no_exists[_tmdbid].pop(_sea)
|
if _sea not in need:
|
||||||
if not no_exists.get(_tmdbid) and no_exists.get(_tmdbid) is not None:
|
no_exists[_mid].pop(_sea)
|
||||||
no_exists.pop(_tmdbid)
|
if not no_exists.get(_mid) and no_exists.get(_mid) is not None:
|
||||||
|
no_exists.pop(_mid)
|
||||||
|
break
|
||||||
return need
|
return need
|
||||||
|
|
||||||
def __update_episodes(_tmdbid: int, _sea: int, _need: list, _current: set) -> list:
|
def __update_episodes(_mid: Union[int, str], _sea: int, _need: list, _current: set) -> list:
|
||||||
"""
|
"""
|
||||||
更新need_tvs集数,返回剩余集数
|
更新need_tvs集数,返回剩余集数
|
||||||
:param _tmdbid: TMDBID
|
:param _mid: TMDBID
|
||||||
:param _sea: 季数
|
:param _sea: 季数
|
||||||
:param _need: 需要下载的集数
|
:param _need: 需要下载的集数
|
||||||
:param _current: 已经下载的集数
|
:param _current: 已经下载的集数
|
||||||
@@ -365,26 +377,26 @@ class DownloadChain(ChainBase):
|
|||||||
# 剩余集数
|
# 剩余集数
|
||||||
need = list(set(_need).difference(set(_current)))
|
need = list(set(_need).difference(set(_current)))
|
||||||
if need:
|
if need:
|
||||||
not_exist = no_exists[_tmdbid][_sea]
|
not_exist = no_exists[_mid][_sea]
|
||||||
no_exists[_tmdbid][_sea] = NotExistMediaInfo(
|
no_exists[_mid][_sea] = NotExistMediaInfo(
|
||||||
season=not_exist.season,
|
season=not_exist.season,
|
||||||
episodes=need,
|
episodes=need,
|
||||||
total_episode=not_exist.total_episode,
|
total_episode=not_exist.total_episode,
|
||||||
start_episode=not_exist.start_episode
|
start_episode=not_exist.start_episode
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
no_exists[_tmdbid].pop(_sea)
|
no_exists[_mid].pop(_sea)
|
||||||
if not no_exists.get(_tmdbid) and no_exists.get(_tmdbid) is not None:
|
if not no_exists.get(_mid) and no_exists.get(_mid) is not None:
|
||||||
no_exists.pop(_tmdbid)
|
no_exists.pop(_mid)
|
||||||
return need
|
return need
|
||||||
|
|
||||||
def __get_season_episodes(tmdbid: int, season: int) -> int:
|
def __get_season_episodes(_mid: Union[int, str], season: int) -> int:
|
||||||
"""
|
"""
|
||||||
获取需要的季的集数
|
获取需要的季的集数
|
||||||
"""
|
"""
|
||||||
if not no_exists.get(tmdbid):
|
if not no_exists.get(_mid):
|
||||||
return 9999
|
return 9999
|
||||||
no_exist = no_exists.get(tmdbid)
|
no_exist = no_exists.get(_mid)
|
||||||
if not no_exist.get(season):
|
if not no_exist.get(season):
|
||||||
return 9999
|
return 9999
|
||||||
return no_exist[season].total_episode
|
return no_exist[season].total_episode
|
||||||
@@ -396,7 +408,7 @@ class DownloadChain(ChainBase):
|
|||||||
for context in contexts:
|
for context in contexts:
|
||||||
if context.media_info.type == MediaType.MOVIE:
|
if context.media_info.type == MediaType.MOVIE:
|
||||||
if self.download_single(context, save_path=save_path,
|
if self.download_single(context, save_path=save_path,
|
||||||
channel=channel, userid=userid):
|
channel=channel, userid=userid, username=username):
|
||||||
# 下载成功
|
# 下载成功
|
||||||
downloaded_list.append(context)
|
downloaded_list.append(context)
|
||||||
|
|
||||||
@@ -404,17 +416,17 @@ class DownloadChain(ChainBase):
|
|||||||
if no_exists:
|
if no_exists:
|
||||||
# 先把整季缺失的拿出来,看是否刚好有所有季都满足的种子 {tmdbid: [seasons]}
|
# 先把整季缺失的拿出来,看是否刚好有所有季都满足的种子 {tmdbid: [seasons]}
|
||||||
need_seasons: Dict[int, list] = {}
|
need_seasons: Dict[int, list] = {}
|
||||||
for need_tmdbid, need_tv in no_exists.items():
|
for need_mid, need_tv in no_exists.items():
|
||||||
for tv in need_tv.values():
|
for tv in need_tv.values():
|
||||||
if not tv:
|
if not tv:
|
||||||
continue
|
continue
|
||||||
# 季列表为空的,代表全季缺失
|
# 季列表为空的,代表全季缺失
|
||||||
if not tv.episodes:
|
if not tv.episodes:
|
||||||
if not need_seasons.get(need_tmdbid):
|
if not need_seasons.get(need_mid):
|
||||||
need_seasons[need_tmdbid] = []
|
need_seasons[need_mid] = []
|
||||||
need_seasons[need_tmdbid].append(tv.season or 1)
|
need_seasons[need_mid].append(tv.season or 1)
|
||||||
# 查找整季包含的种子,只处理整季没集的种子或者是集数超过季的种子
|
# 查找整季包含的种子,只处理整季没集的种子或者是集数超过季的种子
|
||||||
for need_tmdbid, need_season in need_seasons.items():
|
for need_mid, need_season in need_seasons.items():
|
||||||
# 循环种子
|
# 循环种子
|
||||||
for context in contexts:
|
for context in contexts:
|
||||||
# 媒体信息
|
# 媒体信息
|
||||||
@@ -432,7 +444,7 @@ class DownloadChain(ChainBase):
|
|||||||
if meta.episode_list:
|
if meta.episode_list:
|
||||||
continue
|
continue
|
||||||
# 匹配TMDBID
|
# 匹配TMDBID
|
||||||
if need_tmdbid == media.tmdb_id:
|
if need_mid == media.tmdb_id or need_mid == media.douban_id:
|
||||||
# 种子季是需要季或者子集
|
# 种子季是需要季或者子集
|
||||||
if set(torrent_season).issubset(set(need_season)):
|
if set(torrent_season).issubset(set(need_season)):
|
||||||
if len(torrent_season) == 1:
|
if len(torrent_season) == 1:
|
||||||
@@ -447,13 +459,13 @@ class DownloadChain(ChainBase):
|
|||||||
logger.info(f"{meta.org_string} 解析文件集数为 {torrent_episodes}")
|
logger.info(f"{meta.org_string} 解析文件集数为 {torrent_episodes}")
|
||||||
if not torrent_episodes:
|
if not torrent_episodes:
|
||||||
continue
|
continue
|
||||||
# 总集数
|
# 更新集数范围
|
||||||
need_total = __get_season_episodes(need_tmdbid, torrent_season[0])
|
begin_ep = min(torrent_episodes)
|
||||||
|
end_ep = max(torrent_episodes)
|
||||||
|
meta.set_episodes(begin=begin_ep, end=end_ep)
|
||||||
|
# 需要总集数
|
||||||
|
need_total = __get_season_episodes(need_mid, torrent_season[0])
|
||||||
if len(torrent_episodes) < need_total:
|
if len(torrent_episodes) < need_total:
|
||||||
# 更新集数范围
|
|
||||||
begin_ep = min(torrent_episodes)
|
|
||||||
end_ep = max(torrent_episodes)
|
|
||||||
meta.set_episodes(begin=begin_ep, end=end_ep)
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"{meta.org_string} 解析文件集数发现不是完整合集")
|
f"{meta.org_string} 解析文件集数发现不是完整合集")
|
||||||
continue
|
continue
|
||||||
@@ -464,31 +476,36 @@ class DownloadChain(ChainBase):
|
|||||||
torrent_file=content if isinstance(content, Path) else None,
|
torrent_file=content if isinstance(content, Path) else None,
|
||||||
save_path=save_path,
|
save_path=save_path,
|
||||||
channel=channel,
|
channel=channel,
|
||||||
userid=userid
|
userid=userid,
|
||||||
|
username=username
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# 下载
|
# 下载
|
||||||
download_id = self.download_single(context, save_path=save_path,
|
download_id = self.download_single(context, save_path=save_path,
|
||||||
channel=channel, userid=userid)
|
channel=channel, userid=userid, username=username)
|
||||||
|
|
||||||
if download_id:
|
if download_id:
|
||||||
# 下载成功
|
# 下载成功
|
||||||
downloaded_list.append(context)
|
downloaded_list.append(context)
|
||||||
# 更新仍需季集
|
# 更新仍需季集
|
||||||
need_season = __update_seasons(_tmdbid=need_tmdbid,
|
need_season = __update_seasons(_mid=need_mid,
|
||||||
_need=need_season,
|
_need=need_season,
|
||||||
_current=torrent_season)
|
_current=torrent_season)
|
||||||
|
if not need_season:
|
||||||
|
# 全部下载完成
|
||||||
|
break
|
||||||
# 电视剧季内的集匹配
|
# 电视剧季内的集匹配
|
||||||
if no_exists:
|
if no_exists:
|
||||||
# TMDBID列表
|
# TMDBID列表
|
||||||
need_tv_list = list(no_exists)
|
need_tv_list = list(no_exists)
|
||||||
for need_tmdbid in need_tv_list:
|
for need_mid in need_tv_list:
|
||||||
# dict[season, [NotExistMediaInfo]]
|
# dict[season, [NotExistMediaInfo]]
|
||||||
need_tv = no_exists.get(need_tmdbid)
|
need_tv = no_exists.get(need_mid)
|
||||||
if not need_tv:
|
if not need_tv:
|
||||||
continue
|
continue
|
||||||
|
need_tv_copy = copy.deepcopy(no_exists.get(need_mid))
|
||||||
# 循环每一季
|
# 循环每一季
|
||||||
for sea, tv in need_tv.items():
|
for sea, tv in need_tv_copy.items():
|
||||||
# 当前需要季
|
# 当前需要季
|
||||||
need_season = sea
|
need_season = sea
|
||||||
# 当前需要集
|
# 当前需要集
|
||||||
@@ -499,7 +516,7 @@ class DownloadChain(ChainBase):
|
|||||||
start_episode = tv.start_episode or 1
|
start_episode = tv.start_episode or 1
|
||||||
# 缺失整季的转化为缺失集进行比较
|
# 缺失整季的转化为缺失集进行比较
|
||||||
if not need_episodes:
|
if not need_episodes:
|
||||||
need_episodes = list(range(start_episode, total_episode))
|
need_episodes = list(range(start_episode, total_episode + 1))
|
||||||
# 循环种子
|
# 循环种子
|
||||||
for context in contexts:
|
for context in contexts:
|
||||||
# 媒体信息
|
# 媒体信息
|
||||||
@@ -510,7 +527,7 @@ class DownloadChain(ChainBase):
|
|||||||
if media.type != MediaType.TV:
|
if media.type != MediaType.TV:
|
||||||
continue
|
continue
|
||||||
# 匹配TMDB
|
# 匹配TMDB
|
||||||
if media.tmdb_id == need_tmdbid:
|
if media.tmdb_id == need_mid or media.douban_id == need_mid:
|
||||||
# 不重复添加
|
# 不重复添加
|
||||||
if context in downloaded_list:
|
if context in downloaded_list:
|
||||||
continue
|
continue
|
||||||
@@ -528,12 +545,12 @@ class DownloadChain(ChainBase):
|
|||||||
if torrent_episodes.issubset(set(need_episodes)):
|
if torrent_episodes.issubset(set(need_episodes)):
|
||||||
# 下载
|
# 下载
|
||||||
download_id = self.download_single(context, save_path=save_path,
|
download_id = self.download_single(context, save_path=save_path,
|
||||||
channel=channel, userid=userid)
|
channel=channel, userid=userid, username=username)
|
||||||
if download_id:
|
if download_id:
|
||||||
# 下载成功
|
# 下载成功
|
||||||
downloaded_list.append(context)
|
downloaded_list.append(context)
|
||||||
# 更新仍需集数
|
# 更新仍需集数
|
||||||
need_episodes = __update_episodes(_tmdbid=need_tmdbid,
|
need_episodes = __update_episodes(_mid=need_mid,
|
||||||
_need=need_episodes,
|
_need=need_episodes,
|
||||||
_sea=need_season,
|
_sea=need_season,
|
||||||
_current=torrent_episodes)
|
_current=torrent_episodes)
|
||||||
@@ -542,9 +559,9 @@ class DownloadChain(ChainBase):
|
|||||||
if no_exists:
|
if no_exists:
|
||||||
# TMDBID列表
|
# TMDBID列表
|
||||||
no_exists_list = list(no_exists)
|
no_exists_list = list(no_exists)
|
||||||
for need_tmdbid in no_exists_list:
|
for need_mid in no_exists_list:
|
||||||
# dict[season, [NotExistMediaInfo]]
|
# dict[season, [NotExistMediaInfo]]
|
||||||
need_tv = no_exists.get(need_tmdbid)
|
need_tv = no_exists.get(need_mid)
|
||||||
if not need_tv:
|
if not need_tv:
|
||||||
continue
|
continue
|
||||||
# 需要季列表
|
# 需要季列表
|
||||||
@@ -578,7 +595,7 @@ class DownloadChain(ChainBase):
|
|||||||
if not need_episodes:
|
if not need_episodes:
|
||||||
break
|
break
|
||||||
# 选中一个单季整季的或单季包括需要的所有集的
|
# 选中一个单季整季的或单季包括需要的所有集的
|
||||||
if media.tmdb_id == need_tmdbid \
|
if (media.tmdb_id == need_mid or media.douban_id == need_mid) \
|
||||||
and (not meta.episode_list
|
and (not meta.episode_list
|
||||||
or set(meta.episode_list).intersection(set(need_episodes))) \
|
or set(meta.episode_list).intersection(set(need_episodes))) \
|
||||||
and len(meta.season_list) == 1 \
|
and len(meta.season_list) == 1 \
|
||||||
@@ -606,17 +623,19 @@ class DownloadChain(ChainBase):
|
|||||||
episodes=selected_episodes,
|
episodes=selected_episodes,
|
||||||
save_path=save_path,
|
save_path=save_path,
|
||||||
channel=channel,
|
channel=channel,
|
||||||
userid=userid
|
userid=userid,
|
||||||
|
username=username
|
||||||
)
|
)
|
||||||
if not download_id:
|
if not download_id:
|
||||||
continue
|
continue
|
||||||
# 把识别的集更新到上下文
|
|
||||||
context.meta_info.begin_episode = min(selected_episodes)
|
|
||||||
context.meta_info.end_episode = max(selected_episodes)
|
|
||||||
# 下载成功
|
# 下载成功
|
||||||
downloaded_list.append(context)
|
downloaded_list.append(context)
|
||||||
|
# 更新种子集数范围
|
||||||
|
begin_ep = min(torrent_episodes)
|
||||||
|
end_ep = max(torrent_episodes)
|
||||||
|
meta.set_episodes(begin=begin_ep, end=end_ep)
|
||||||
# 更新仍需集数
|
# 更新仍需集数
|
||||||
need_episodes = __update_episodes(_tmdbid=need_tmdbid,
|
need_episodes = __update_episodes(_mid=need_mid,
|
||||||
_need=need_episodes,
|
_need=need_episodes,
|
||||||
_sea=need_season,
|
_sea=need_season,
|
||||||
_current=selected_episodes)
|
_current=selected_episodes)
|
||||||
@@ -628,7 +647,7 @@ class DownloadChain(ChainBase):
|
|||||||
mediainfo: MediaInfo,
|
mediainfo: MediaInfo,
|
||||||
no_exists: Dict[int, Dict[int, NotExistMediaInfo]] = None,
|
no_exists: Dict[int, Dict[int, NotExistMediaInfo]] = None,
|
||||||
totals: Dict[int, int] = None
|
totals: Dict[int, int] = None
|
||||||
) -> Tuple[bool, Dict[int, Dict[int, NotExistMediaInfo]]]:
|
) -> Tuple[bool, Dict[Union[int, str], Dict[int, NotExistMediaInfo]]]:
|
||||||
"""
|
"""
|
||||||
检查媒体库,查询是否存在,对于剧集同时返回不存在的季集信息
|
检查媒体库,查询是否存在,对于剧集同时返回不存在的季集信息
|
||||||
:param meta: 元数据
|
:param meta: 元数据
|
||||||
@@ -648,8 +667,9 @@ class DownloadChain(ChainBase):
|
|||||||
"start_episode": int
|
"start_episode": int
|
||||||
]}
|
]}
|
||||||
"""
|
"""
|
||||||
if not no_exists.get(mediainfo.tmdb_id):
|
mediakey = mediainfo.tmdb_id or mediainfo.douban_id
|
||||||
no_exists[mediainfo.tmdb_id] = {
|
if not no_exists.get(mediakey):
|
||||||
|
no_exists[mediakey] = {
|
||||||
_season: NotExistMediaInfo(
|
_season: NotExistMediaInfo(
|
||||||
season=_season,
|
season=_season,
|
||||||
episodes=_episodes,
|
episodes=_episodes,
|
||||||
@@ -658,7 +678,7 @@ class DownloadChain(ChainBase):
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
no_exists[mediainfo.tmdb_id][_season] = NotExistMediaInfo(
|
no_exists[mediakey][_season] = NotExistMediaInfo(
|
||||||
season=_season,
|
season=_season,
|
||||||
episodes=_episodes,
|
episodes=_episodes,
|
||||||
total_episode=_total,
|
total_episode=_total,
|
||||||
@@ -674,6 +694,7 @@ class DownloadChain(ChainBase):
|
|||||||
if mediainfo.type == MediaType.MOVIE:
|
if mediainfo.type == MediaType.MOVIE:
|
||||||
# 电影
|
# 电影
|
||||||
itemid = self.mediaserver.get_item_id(mtype=mediainfo.type.value,
|
itemid = self.mediaserver.get_item_id(mtype=mediainfo.type.value,
|
||||||
|
title=mediainfo.title,
|
||||||
tmdbid=mediainfo.tmdb_id)
|
tmdbid=mediainfo.tmdb_id)
|
||||||
exists_movies: Optional[ExistMediaInfo] = self.media_exists(mediainfo=mediainfo, itemid=itemid)
|
exists_movies: Optional[ExistMediaInfo] = self.media_exists(mediainfo=mediainfo, itemid=itemid)
|
||||||
if exists_movies:
|
if exists_movies:
|
||||||
@@ -684,7 +705,8 @@ class DownloadChain(ChainBase):
|
|||||||
if not mediainfo.seasons:
|
if not mediainfo.seasons:
|
||||||
# 补充媒体信息
|
# 补充媒体信息
|
||||||
mediainfo: MediaInfo = self.recognize_media(mtype=mediainfo.type,
|
mediainfo: MediaInfo = self.recognize_media(mtype=mediainfo.type,
|
||||||
tmdbid=mediainfo.tmdb_id)
|
tmdbid=mediainfo.tmdb_id,
|
||||||
|
doubanid=mediainfo.douban_id)
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
logger.error(f"媒体信息识别失败!")
|
logger.error(f"媒体信息识别失败!")
|
||||||
return False, {}
|
return False, {}
|
||||||
@@ -693,6 +715,7 @@ class DownloadChain(ChainBase):
|
|||||||
return False, {}
|
return False, {}
|
||||||
# 电视剧
|
# 电视剧
|
||||||
itemid = self.mediaserver.get_item_id(mtype=mediainfo.type.value,
|
itemid = self.mediaserver.get_item_id(mtype=mediainfo.type.value,
|
||||||
|
title=mediainfo.title,
|
||||||
tmdbid=mediainfo.tmdb_id,
|
tmdbid=mediainfo.tmdb_id,
|
||||||
season=mediainfo.season)
|
season=mediainfo.season)
|
||||||
# 媒体库已存在的剧集
|
# 媒体库已存在的剧集
|
||||||
@@ -703,7 +726,7 @@ class DownloadChain(ChainBase):
|
|||||||
if not episodes:
|
if not episodes:
|
||||||
continue
|
continue
|
||||||
# 全季不存在
|
# 全季不存在
|
||||||
if meta.season_list \
|
if meta.sea \
|
||||||
and season not in meta.season_list:
|
and season not in meta.season_list:
|
||||||
continue
|
continue
|
||||||
# 总集数
|
# 总集数
|
||||||
@@ -714,7 +737,7 @@ class DownloadChain(ChainBase):
|
|||||||
else:
|
else:
|
||||||
# 存在一些,检查每季缺失的季集
|
# 存在一些,检查每季缺失的季集
|
||||||
for season, episodes in mediainfo.seasons.items():
|
for season, episodes in mediainfo.seasons.items():
|
||||||
if meta.begin_season \
|
if meta.sea \
|
||||||
and season not in meta.season_list:
|
and season not in meta.season_list:
|
||||||
continue
|
continue
|
||||||
if not episodes:
|
if not episodes:
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ from app.schemas.types import EventType, MediaType
|
|||||||
from app.utils.singleton import Singleton
|
from app.utils.singleton import Singleton
|
||||||
from app.utils.string import StringUtils
|
from app.utils.string import StringUtils
|
||||||
|
|
||||||
|
|
||||||
recognize_lock = Lock()
|
recognize_lock = Lock()
|
||||||
|
|
||||||
|
|
||||||
@@ -27,13 +26,11 @@ class MediaChain(ChainBase, metaclass=Singleton):
|
|||||||
# 临时识别结果 {title, name, year, season, episode}
|
# 临时识别结果 {title, name, year, season, episode}
|
||||||
recognize_temp: Optional[dict] = None
|
recognize_temp: Optional[dict] = None
|
||||||
|
|
||||||
def recognize_by_title(self, title: str, subtitle: str = None) -> Optional[Context]:
|
def recognize_by_meta(self, metainfo: MetaBase) -> Optional[MediaInfo]:
|
||||||
"""
|
"""
|
||||||
根据主副标题识别媒体信息
|
根据主副标题识别媒体信息
|
||||||
"""
|
"""
|
||||||
logger.info(f'开始识别媒体信息,标题:{title},副标题:{subtitle} ...')
|
title = metainfo.title
|
||||||
# 识别元数据
|
|
||||||
metainfo = MetaInfo(title, subtitle)
|
|
||||||
# 识别媒体信息
|
# 识别媒体信息
|
||||||
mediainfo: MediaInfo = self.recognize_media(meta=metainfo)
|
mediainfo: MediaInfo = self.recognize_media(meta=metainfo)
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
@@ -43,13 +40,13 @@ class MediaChain(ChainBase, metaclass=Singleton):
|
|||||||
mediainfo = self.recognize_help(title=title, org_meta=metainfo)
|
mediainfo = self.recognize_help(title=title, org_meta=metainfo)
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
logger.warn(f'{title} 未识别到媒体信息')
|
logger.warn(f'{title} 未识别到媒体信息')
|
||||||
return Context(meta_info=metainfo)
|
return None
|
||||||
# 识别成功
|
# 识别成功
|
||||||
logger.info(f'{title} 识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year}')
|
logger.info(f'{title} 识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year}')
|
||||||
# 更新媒体图片
|
# 更新媒体图片
|
||||||
self.obtain_images(mediainfo=mediainfo)
|
self.obtain_images(mediainfo=mediainfo)
|
||||||
# 返回上下文
|
# 返回上下文
|
||||||
return Context(meta_info=metainfo, media_info=mediainfo)
|
return mediainfo
|
||||||
|
|
||||||
def recognize_help(self, title: str, org_meta: MetaBase) -> Optional[MediaInfo]:
|
def recognize_help(self, title: str, org_meta: MetaBase) -> Optional[MediaInfo]:
|
||||||
"""
|
"""
|
||||||
@@ -69,7 +66,7 @@ class MediaChain(ChainBase, metaclass=Singleton):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
# 每0.5秒循环一次,等待结果,直到10秒后超时
|
# 每0.5秒循环一次,等待结果,直到10秒后超时
|
||||||
for i in range(10):
|
for i in range(20):
|
||||||
if self.recognize_temp is not None:
|
if self.recognize_temp is not None:
|
||||||
break
|
break
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
@@ -170,8 +167,7 @@ class MediaChain(ChainBase, metaclass=Singleton):
|
|||||||
# 识别
|
# 识别
|
||||||
meta = MetaInfo(content)
|
meta = MetaInfo(content)
|
||||||
if not meta.name:
|
if not meta.name:
|
||||||
logger.warn(f'{title} 未识别到元数据!')
|
meta.cn_name = content
|
||||||
return meta, []
|
|
||||||
# 合并信息
|
# 合并信息
|
||||||
if mtype:
|
if mtype:
|
||||||
meta.type = mtype
|
meta.type = mtype
|
||||||
@@ -190,3 +186,78 @@ class MediaChain(ChainBase, metaclass=Singleton):
|
|||||||
logger.info(f"{content} 搜索到 {len(medias)} 条相关媒体信息")
|
logger.info(f"{content} 搜索到 {len(medias)} 条相关媒体信息")
|
||||||
# 识别的元数据,媒体信息列表
|
# 识别的元数据,媒体信息列表
|
||||||
return meta, medias
|
return meta, medias
|
||||||
|
|
||||||
|
def get_tmdbinfo_by_doubanid(self, doubanid: str, mtype: MediaType = None) -> Optional[dict]:
|
||||||
|
"""
|
||||||
|
根据豆瓣ID获取TMDB信息
|
||||||
|
"""
|
||||||
|
tmdbinfo = None
|
||||||
|
doubaninfo = self.douban_info(doubanid=doubanid, mtype=mtype)
|
||||||
|
if doubaninfo:
|
||||||
|
# 优先使用原标题匹配
|
||||||
|
season_meta = None
|
||||||
|
if doubaninfo.get("original_title"):
|
||||||
|
meta = MetaInfo(title=doubaninfo.get("original_title"))
|
||||||
|
season_meta = MetaInfo(title=doubaninfo.get("title"))
|
||||||
|
# 合并季
|
||||||
|
meta.begin_season = season_meta.begin_season
|
||||||
|
else:
|
||||||
|
meta = MetaInfo(title=doubaninfo.get("title"))
|
||||||
|
# 年份
|
||||||
|
if doubaninfo.get("year"):
|
||||||
|
meta.year = doubaninfo.get("year")
|
||||||
|
# 处理类型
|
||||||
|
if isinstance(doubaninfo.get('media_type'), MediaType):
|
||||||
|
meta.type = doubaninfo.get('media_type')
|
||||||
|
else:
|
||||||
|
meta.type = MediaType.MOVIE if doubaninfo.get("type") == "movie" else MediaType.TV
|
||||||
|
# 使用原标题识别TMDB媒体信息
|
||||||
|
tmdbinfo = self.match_tmdbinfo(
|
||||||
|
name=meta.name,
|
||||||
|
year=meta.year,
|
||||||
|
mtype=mtype or meta.type,
|
||||||
|
season=meta.begin_season
|
||||||
|
)
|
||||||
|
if not tmdbinfo:
|
||||||
|
if season_meta and season_meta.name != meta.name:
|
||||||
|
# 使用主标题识别媒体信息
|
||||||
|
tmdbinfo = self.match_tmdbinfo(
|
||||||
|
name=season_meta.name,
|
||||||
|
year=meta.year,
|
||||||
|
mtype=mtype or meta.type,
|
||||||
|
season=meta.begin_season
|
||||||
|
)
|
||||||
|
return tmdbinfo
|
||||||
|
|
||||||
|
def get_doubaninfo_by_tmdbid(self, tmdbid: int,
|
||||||
|
mtype: MediaType = None, season: int = None) -> Optional[dict]:
|
||||||
|
"""
|
||||||
|
根据TMDBID获取豆瓣信息
|
||||||
|
"""
|
||||||
|
tmdbinfo = self.tmdb_info(tmdbid=tmdbid, mtype=mtype)
|
||||||
|
if tmdbinfo:
|
||||||
|
# 名称
|
||||||
|
name = tmdbinfo.get("title") or tmdbinfo.get("name")
|
||||||
|
# 年份
|
||||||
|
year = None
|
||||||
|
if tmdbinfo.get('release_date'):
|
||||||
|
year = tmdbinfo['release_date'][:4]
|
||||||
|
elif tmdbinfo.get('seasons') and season:
|
||||||
|
for seainfo in tmdbinfo['seasons']:
|
||||||
|
# 季
|
||||||
|
season_number = seainfo.get("season_number")
|
||||||
|
if not season_number:
|
||||||
|
continue
|
||||||
|
air_date = seainfo.get("air_date")
|
||||||
|
if air_date and season_number == season:
|
||||||
|
year = air_date[:4]
|
||||||
|
break
|
||||||
|
# IMDBID
|
||||||
|
imdbid = tmdbinfo.get("external_ids", {}).get("imdb_id")
|
||||||
|
return self.match_doubaninfo(
|
||||||
|
name=name,
|
||||||
|
year=year,
|
||||||
|
mtype=mtype,
|
||||||
|
imdbid=imdbid
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
import threading
|
import threading
|
||||||
from typing import List, Union
|
from typing import List, Union, Optional
|
||||||
|
|
||||||
from app import schemas
|
from app import schemas
|
||||||
from app.chain import ChainBase
|
from app.chain import ChainBase
|
||||||
@@ -20,11 +20,11 @@ class MediaServerChain(ChainBase):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.dboper = MediaServerOper()
|
self.dboper = MediaServerOper()
|
||||||
|
|
||||||
def librarys(self, server: str) -> List[schemas.MediaServerLibrary]:
|
def librarys(self, server: str = None, username: str = None) -> List[schemas.MediaServerLibrary]:
|
||||||
"""
|
"""
|
||||||
获取媒体服务器所有媒体库
|
获取媒体服务器所有媒体库
|
||||||
"""
|
"""
|
||||||
return self.run_module("mediaserver_librarys", server=server)
|
return self.run_module("mediaserver_librarys", server=server, username=username)
|
||||||
|
|
||||||
def items(self, server: str, library_id: Union[str, int]) -> List[schemas.MediaServerItem]:
|
def items(self, server: str, library_id: Union[str, int]) -> List[schemas.MediaServerItem]:
|
||||||
"""
|
"""
|
||||||
@@ -44,6 +44,24 @@ class MediaServerChain(ChainBase):
|
|||||||
"""
|
"""
|
||||||
return self.run_module("mediaserver_tv_episodes", server=server, item_id=item_id)
|
return self.run_module("mediaserver_tv_episodes", server=server, item_id=item_id)
|
||||||
|
|
||||||
|
def playing(self, count: int = 20, server: str = None, username: str = None) -> List[schemas.MediaServerPlayItem]:
|
||||||
|
"""
|
||||||
|
获取媒体服务器正在播放信息
|
||||||
|
"""
|
||||||
|
return self.run_module("mediaserver_playing", count=count, server=server, username=username)
|
||||||
|
|
||||||
|
def latest(self, count: int = 20, server: str = None, username: str = None) -> List[schemas.MediaServerPlayItem]:
|
||||||
|
"""
|
||||||
|
获取媒体服务器最新入库条目
|
||||||
|
"""
|
||||||
|
return self.run_module("mediaserver_latest", count=count, server=server, username=username)
|
||||||
|
|
||||||
|
def get_play_url(self, server: str, item_id: Union[str, int]) -> Optional[str]:
|
||||||
|
"""
|
||||||
|
获取播放地址
|
||||||
|
"""
|
||||||
|
return self.run_module("mediaserver_play_url", server=server, item_id=item_id)
|
||||||
|
|
||||||
def sync(self):
|
def sync(self):
|
||||||
"""
|
"""
|
||||||
同步媒体库所有数据到本地数据库
|
同步媒体库所有数据到本地数据库
|
||||||
@@ -52,7 +70,7 @@ class MediaServerChain(ChainBase):
|
|||||||
# 汇总统计
|
# 汇总统计
|
||||||
total_count = 0
|
total_count = 0
|
||||||
# 清空登记薄
|
# 清空登记薄
|
||||||
self.dboper.empty(server=settings.MEDIASERVER)
|
self.dboper.empty()
|
||||||
# 同步黑名单
|
# 同步黑名单
|
||||||
sync_blacklist = settings.MEDIASERVER_SYNC_BLACKLIST.split(
|
sync_blacklist = settings.MEDIASERVER_SYNC_BLACKLIST.split(
|
||||||
",") if settings.MEDIASERVER_SYNC_BLACKLIST else []
|
",") if settings.MEDIASERVER_SYNC_BLACKLIST else []
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
import copy
|
import copy
|
||||||
from typing import Any
|
import json
|
||||||
|
import re
|
||||||
|
from typing import Any, Optional, Dict
|
||||||
|
|
||||||
from app.chain.download import *
|
from app.chain import ChainBase
|
||||||
|
from app.chain.download import DownloadChain
|
||||||
from app.chain.media import MediaChain
|
from app.chain.media import MediaChain
|
||||||
from app.chain.search import SearchChain
|
from app.chain.search import SearchChain
|
||||||
from app.chain.subscribe import SubscribeChain
|
from app.chain.subscribe import SubscribeChain
|
||||||
from app.core.context import MediaInfo
|
from app.core.config import settings
|
||||||
|
from app.core.context import MediaInfo, Context
|
||||||
from app.core.event import EventManager
|
from app.core.event import EventManager
|
||||||
|
from app.core.meta import MetaBase
|
||||||
|
from app.helper.torrent import TorrentHelper
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.schemas import Notification
|
from app.schemas import Notification
|
||||||
from app.schemas.types import EventType, MessageChannel
|
from app.schemas.types import EventType, MessageChannel, MediaType
|
||||||
|
from app.utils.string import StringUtils
|
||||||
|
|
||||||
# 当前页面
|
# 当前页面
|
||||||
_current_page: int = 0
|
_current_page: int = 0
|
||||||
@@ -34,7 +41,6 @@ class MessageChain(ChainBase):
|
|||||||
self.subscribechain = SubscribeChain()
|
self.subscribechain = SubscribeChain()
|
||||||
self.searchchain = SearchChain()
|
self.searchchain = SearchChain()
|
||||||
self.medtachain = MediaChain()
|
self.medtachain = MediaChain()
|
||||||
self.torrent = TorrentHelper()
|
|
||||||
self.eventmanager = EventManager()
|
self.eventmanager = EventManager()
|
||||||
self.torrenthelper = TorrentHelper()
|
self.torrenthelper = TorrentHelper()
|
||||||
|
|
||||||
@@ -87,13 +93,15 @@ class MessageChain(ChainBase):
|
|||||||
# 发送消息
|
# 发送消息
|
||||||
self.post_message(Notification(channel=channel, title="输入有误!", userid=userid))
|
self.post_message(Notification(channel=channel, title="输入有误!", userid=userid))
|
||||||
return
|
return
|
||||||
|
# 选择的序号
|
||||||
|
_choice = int(text) + _current_page * self._page_size - 1
|
||||||
# 缓存类型
|
# 缓存类型
|
||||||
cache_type: str = cache_data.get('type')
|
cache_type: str = cache_data.get('type')
|
||||||
# 缓存列表
|
# 缓存列表
|
||||||
cache_list: list = cache_data.get('items')
|
cache_list: list = copy.deepcopy(cache_data.get('items'))
|
||||||
# 选择
|
# 选择
|
||||||
if cache_type == "Search":
|
if cache_type == "Search":
|
||||||
mediainfo: MediaInfo = cache_list[int(text) + _current_page * self._page_size - 1]
|
mediainfo: MediaInfo = cache_list[_choice]
|
||||||
_current_media = mediainfo
|
_current_media = mediainfo
|
||||||
# 查询缺失的媒体信息
|
# 查询缺失的媒体信息
|
||||||
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=_current_meta,
|
exist_flag, no_exists = self.downloadchain.get_no_exists_info(meta=_current_meta,
|
||||||
@@ -108,9 +116,10 @@ class MessageChain(ChainBase):
|
|||||||
# 发送缺失的媒体信息
|
# 发送缺失的媒体信息
|
||||||
if no_exists:
|
if no_exists:
|
||||||
# 发送消息
|
# 发送消息
|
||||||
|
mediakey = mediainfo.tmdb_id or mediainfo.douban_id
|
||||||
messages = [
|
messages = [
|
||||||
f"第 {sea} 季缺失 {StringUtils.str_series(no_exist.episodes) if no_exist.episodes else no_exist.total_episode} 集"
|
f"第 {sea} 季缺失 {StringUtils.str_series(no_exist.episodes) if no_exist.episodes else no_exist.total_episode} 集"
|
||||||
for sea, no_exist in no_exists.get(mediainfo.tmdb_id).items()]
|
for sea, no_exist in no_exists.get(mediakey).items()]
|
||||||
self.post_message(Notification(channel=channel,
|
self.post_message(Notification(channel=channel,
|
||||||
title=f"{mediainfo.title_year}:\n" + "\n".join(messages),
|
title=f"{mediainfo.title_year}:\n" + "\n".join(messages),
|
||||||
userid=userid))
|
userid=userid))
|
||||||
@@ -135,7 +144,7 @@ class MessageChain(ChainBase):
|
|||||||
# 判断是否设置自动下载
|
# 判断是否设置自动下载
|
||||||
auto_download_user = settings.AUTO_DOWNLOAD_USER
|
auto_download_user = settings.AUTO_DOWNLOAD_USER
|
||||||
# 匹配到自动下载用户
|
# 匹配到自动下载用户
|
||||||
if auto_download_user and any(userid == user for user in auto_download_user.split(",")):
|
if auto_download_user and (auto_download_user == "all" or any(userid == user for user in auto_download_user.split(","))):
|
||||||
logger.info(f"用户 {userid} 在自动下载用户中,开始自动择优下载")
|
logger.info(f"用户 {userid} 在自动下载用户中,开始自动择优下载")
|
||||||
# 自动选择下载
|
# 自动选择下载
|
||||||
self.__auto_download(channel=channel,
|
self.__auto_download(channel=channel,
|
||||||
@@ -158,7 +167,7 @@ class MessageChain(ChainBase):
|
|||||||
|
|
||||||
elif cache_type == "Subscribe":
|
elif cache_type == "Subscribe":
|
||||||
# 订阅媒体
|
# 订阅媒体
|
||||||
mediainfo: MediaInfo = cache_list[int(text) - 1]
|
mediainfo: MediaInfo = cache_list[_choice]
|
||||||
# 查询缺失的媒体信息
|
# 查询缺失的媒体信息
|
||||||
exist_flag, _ = self.downloadchain.get_no_exists_info(meta=_current_meta,
|
exist_flag, _ = self.downloadchain.get_no_exists_info(meta=_current_meta,
|
||||||
mediainfo=mediainfo)
|
mediainfo=mediainfo)
|
||||||
@@ -187,9 +196,9 @@ class MessageChain(ChainBase):
|
|||||||
username=username)
|
username=username)
|
||||||
else:
|
else:
|
||||||
# 下载种子
|
# 下载种子
|
||||||
context: Context = cache_list[int(text) - 1]
|
context: Context = cache_list[_choice]
|
||||||
# 下载
|
# 下载
|
||||||
self.downloadchain.download_single(context, userid=userid, channel=channel)
|
self.downloadchain.download_single(context, userid=userid, channel=channel, username=username)
|
||||||
|
|
||||||
elif text.lower() == "p":
|
elif text.lower() == "p":
|
||||||
# 上一页
|
# 上一页
|
||||||
@@ -217,11 +226,6 @@ class MessageChain(ChainBase):
|
|||||||
start = _current_page * self._page_size
|
start = _current_page * self._page_size
|
||||||
end = start + self._page_size
|
end = start + self._page_size
|
||||||
if cache_type == "Torrent":
|
if cache_type == "Torrent":
|
||||||
# 更新缓存
|
|
||||||
user_cache[userid] = {
|
|
||||||
"type": "Torrent",
|
|
||||||
"items": cache_list[start:end]
|
|
||||||
}
|
|
||||||
# 发送种子数据
|
# 发送种子数据
|
||||||
self.__post_torrents_message(channel=channel,
|
self.__post_torrents_message(channel=channel,
|
||||||
title=_current_media.title,
|
title=_current_media.title,
|
||||||
@@ -260,11 +264,6 @@ class MessageChain(ChainBase):
|
|||||||
# 加一页
|
# 加一页
|
||||||
_current_page += 1
|
_current_page += 1
|
||||||
if cache_type == "Torrent":
|
if cache_type == "Torrent":
|
||||||
# 更新缓存
|
|
||||||
user_cache[userid] = {
|
|
||||||
"type": "Torrent",
|
|
||||||
"items": cache_list
|
|
||||||
}
|
|
||||||
# 发送种子数据
|
# 发送种子数据
|
||||||
self.__post_torrents_message(channel=channel,
|
self.__post_torrents_message(channel=channel,
|
||||||
title=_current_media.title,
|
title=_current_media.title,
|
||||||
@@ -353,13 +352,21 @@ class MessageChain(ChainBase):
|
|||||||
downloads, lefts = self.downloadchain.batch_download(contexts=cache_list,
|
downloads, lefts = self.downloadchain.batch_download(contexts=cache_list,
|
||||||
no_exists=no_exists,
|
no_exists=no_exists,
|
||||||
channel=channel,
|
channel=channel,
|
||||||
userid=userid)
|
userid=userid,
|
||||||
|
username=username)
|
||||||
if downloads and not lefts:
|
if downloads and not lefts:
|
||||||
# 全部下载完成
|
# 全部下载完成
|
||||||
logger.info(f'{_current_media.title_year} 下载完成')
|
logger.info(f'{_current_media.title_year} 下载完成')
|
||||||
else:
|
else:
|
||||||
# 未完成下载
|
# 未完成下载
|
||||||
logger.info(f'{_current_media.title_year} 未下载未完整,添加订阅 ...')
|
logger.info(f'{_current_media.title_year} 未下载未完整,添加订阅 ...')
|
||||||
|
if downloads and _current_media.type == MediaType.TV:
|
||||||
|
# 获取已下载剧集
|
||||||
|
downloaded = [download.meta_info.begin_episode for download in downloads
|
||||||
|
if download.meta_info.begin_episode]
|
||||||
|
note = json.dumps(downloaded)
|
||||||
|
else:
|
||||||
|
note = None
|
||||||
# 添加订阅,状态为R
|
# 添加订阅,状态为R
|
||||||
self.subscribechain.add(title=_current_media.title,
|
self.subscribechain.add(title=_current_media.title,
|
||||||
year=_current_media.year,
|
year=_current_media.year,
|
||||||
@@ -369,7 +376,8 @@ class MessageChain(ChainBase):
|
|||||||
channel=channel,
|
channel=channel,
|
||||||
userid=userid,
|
userid=userid,
|
||||||
username=username,
|
username=username,
|
||||||
state="R")
|
state="R",
|
||||||
|
note=note)
|
||||||
|
|
||||||
def __post_medias_message(self, channel: MessageChannel,
|
def __post_medias_message(self, channel: MessageChannel,
|
||||||
title: str, items: list, userid: str, total: int):
|
title: str, items: list, userid: str, total: int):
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import pickle
|
import pickle
|
||||||
import re
|
import re
|
||||||
|
import traceback
|
||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Dict
|
from typing import Dict, Tuple
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from app.chain import ChainBase
|
from app.chain import ChainBase
|
||||||
@@ -31,14 +32,16 @@ class SearchChain(ChainBase):
|
|||||||
self.systemconfig = SystemConfigOper()
|
self.systemconfig = SystemConfigOper()
|
||||||
self.torrenthelper = TorrentHelper()
|
self.torrenthelper = TorrentHelper()
|
||||||
|
|
||||||
def search_by_tmdbid(self, tmdbid: int, mtype: MediaType = None, area: str = "title") -> List[Context]:
|
def search_by_id(self, tmdbid: int = None, doubanid: str = None,
|
||||||
|
mtype: MediaType = None, area: str = "title") -> List[Context]:
|
||||||
"""
|
"""
|
||||||
根据TMDB ID搜索资源,精确匹配,但不不过滤本地存在的资源
|
根据TMDBID/豆瓣ID搜索资源,精确匹配,但不不过滤本地存在的资源
|
||||||
:param tmdbid: TMDB ID
|
:param tmdbid: TMDB ID
|
||||||
|
:param doubanid: 豆瓣 ID
|
||||||
:param mtype: 媒体,电影 or 电视剧
|
:param mtype: 媒体,电影 or 电视剧
|
||||||
:param area: 搜索范围,title or imdbid
|
:param area: 搜索范围,title or imdbid
|
||||||
"""
|
"""
|
||||||
mediainfo = self.recognize_media(tmdbid=tmdbid, mtype=mtype)
|
mediainfo = self.recognize_media(tmdbid=tmdbid, doubanid=doubanid, mtype=mtype)
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
logger.error(f'{tmdbid} 媒体信息识别失败!')
|
logger.error(f'{tmdbid} 媒体信息识别失败!')
|
||||||
return []
|
return []
|
||||||
@@ -72,7 +75,7 @@ class SearchChain(ChainBase):
|
|||||||
try:
|
try:
|
||||||
return pickle.loads(results)
|
return pickle.loads(results)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(str(e))
|
logger.error(f'加载搜索结果失败:{str(e)} - {traceback.format_exc()}')
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def process(self, mediainfo: MediaInfo,
|
def process(self, mediainfo: MediaInfo,
|
||||||
@@ -92,19 +95,29 @@ class SearchChain(ChainBase):
|
|||||||
:param filter_rule: 过滤规则,为空是使用默认过滤规则
|
:param filter_rule: 过滤规则,为空是使用默认过滤规则
|
||||||
:param area: 搜索范围,title or imdbid
|
:param area: 搜索范围,title or imdbid
|
||||||
"""
|
"""
|
||||||
|
# 豆瓣标题处理
|
||||||
|
if not mediainfo.tmdb_id:
|
||||||
|
meta = MetaInfo(title=mediainfo.title)
|
||||||
|
mediainfo.title = meta.name
|
||||||
|
mediainfo.season = meta.begin_season
|
||||||
logger.info(f'开始搜索资源,关键词:{keyword or mediainfo.title} ...')
|
logger.info(f'开始搜索资源,关键词:{keyword or mediainfo.title} ...')
|
||||||
# 补充媒体信息
|
# 补充媒体信息
|
||||||
if not mediainfo.names:
|
if not mediainfo.names:
|
||||||
mediainfo: MediaInfo = self.recognize_media(mtype=mediainfo.type,
|
mediainfo: MediaInfo = self.recognize_media(mtype=mediainfo.type,
|
||||||
tmdbid=mediainfo.tmdb_id)
|
tmdbid=mediainfo.tmdb_id,
|
||||||
|
doubanid=mediainfo.douban_id)
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
logger.error(f'媒体信息识别失败!')
|
logger.error(f'媒体信息识别失败!')
|
||||||
return []
|
return []
|
||||||
# 缺失的季集
|
# 缺失的季集
|
||||||
if no_exists and no_exists.get(mediainfo.tmdb_id):
|
mediakey = mediainfo.tmdb_id or mediainfo.douban_id
|
||||||
|
if no_exists and no_exists.get(mediakey):
|
||||||
# 过滤剧集
|
# 过滤剧集
|
||||||
season_episodes = {sea: info.episodes
|
season_episodes = {sea: info.episodes
|
||||||
for sea, info in no_exists[mediainfo.tmdb_id].items()}
|
for sea, info in no_exists[mediainfo.tmdb_id].items()}
|
||||||
|
elif mediainfo.season:
|
||||||
|
# 豆瓣只搜索当前季
|
||||||
|
season_episodes = {mediainfo.season: []}
|
||||||
else:
|
else:
|
||||||
season_episodes = None
|
season_episodes = None
|
||||||
# 搜索关键词
|
# 搜索关键词
|
||||||
@@ -141,6 +154,7 @@ class SearchChain(ChainBase):
|
|||||||
return []
|
return []
|
||||||
# 使用过滤规则再次过滤
|
# 使用过滤规则再次过滤
|
||||||
torrents = self.filter_torrents_by_rule(torrents=torrents,
|
torrents = self.filter_torrents_by_rule(torrents=torrents,
|
||||||
|
mediainfo=mediainfo,
|
||||||
filter_rule=filter_rule)
|
filter_rule=filter_rule)
|
||||||
if not torrents:
|
if not torrents:
|
||||||
logger.warn(f'{keyword or mediainfo.title} 没有符合过滤规则的资源')
|
logger.warn(f'{keyword or mediainfo.title} 没有符合过滤规则的资源')
|
||||||
@@ -154,6 +168,7 @@ class SearchChain(ChainBase):
|
|||||||
if mediainfo:
|
if mediainfo:
|
||||||
self.progress.start(ProgressKey.Search)
|
self.progress.start(ProgressKey.Search)
|
||||||
logger.info(f'开始匹配,总 {_total} 个资源 ...')
|
logger.info(f'开始匹配,总 {_total} 个资源 ...')
|
||||||
|
logger.info(f"标题:{mediainfo.title},原标题:{mediainfo.original_title},别名:{mediainfo.names}")
|
||||||
self.progress.update(value=0, text=f'开始匹配,总 {_total} 个资源 ...', key=ProgressKey.Search)
|
self.progress.update(value=0, text=f'开始匹配,总 {_total} 个资源 ...', key=ProgressKey.Search)
|
||||||
for torrent in torrents:
|
for torrent in torrents:
|
||||||
_count += 1
|
_count += 1
|
||||||
@@ -200,7 +215,7 @@ class SearchChain(ChainBase):
|
|||||||
continue
|
continue
|
||||||
# 在副标题中判断是否存在标题与原语种标题
|
# 在副标题中判断是否存在标题与原语种标题
|
||||||
if torrent.description:
|
if torrent.description:
|
||||||
subtitle = torrent.description.split()
|
subtitle = re.split(r'[\s/|]+', torrent.description)
|
||||||
if (StringUtils.is_chinese(mediainfo.title)
|
if (StringUtils.is_chinese(mediainfo.title)
|
||||||
and str(mediainfo.title) in subtitle) \
|
and str(mediainfo.title) in subtitle) \
|
||||||
or (StringUtils.is_chinese(mediainfo.original_title)
|
or (StringUtils.is_chinese(mediainfo.original_title)
|
||||||
@@ -323,12 +338,14 @@ class SearchChain(ChainBase):
|
|||||||
|
|
||||||
def filter_torrents_by_rule(self,
|
def filter_torrents_by_rule(self,
|
||||||
torrents: List[TorrentInfo],
|
torrents: List[TorrentInfo],
|
||||||
filter_rule: Dict[str, str] = None
|
mediainfo: MediaInfo,
|
||||||
|
filter_rule: Dict[str, str] = None,
|
||||||
) -> List[TorrentInfo]:
|
) -> List[TorrentInfo]:
|
||||||
"""
|
"""
|
||||||
使用过滤规则过滤种子
|
使用过滤规则过滤种子
|
||||||
:param torrents: 种子列表
|
:param torrents: 种子列表
|
||||||
:param filter_rule: 过滤规则
|
:param filter_rule: 过滤规则
|
||||||
|
:param mediainfo: 媒体信息
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not filter_rule:
|
if not filter_rule:
|
||||||
@@ -346,6 +363,26 @@ class SearchChain(ChainBase):
|
|||||||
resolution = filter_rule.get("resolution")
|
resolution = filter_rule.get("resolution")
|
||||||
# 特效
|
# 特效
|
||||||
effect = filter_rule.get("effect")
|
effect = filter_rule.get("effect")
|
||||||
|
# 电影大小
|
||||||
|
movie_size = filter_rule.get("movie_size")
|
||||||
|
# 剧集单集大小
|
||||||
|
tv_size = filter_rule.get("tv_size")
|
||||||
|
|
||||||
|
def __get_size_range(size_str: str) -> Tuple[float, float]:
|
||||||
|
"""
|
||||||
|
获取大小范围
|
||||||
|
"""
|
||||||
|
if not size_str:
|
||||||
|
return 0, 0
|
||||||
|
try:
|
||||||
|
size_range = size_str.split("-")
|
||||||
|
if len(size_range) == 1:
|
||||||
|
return 0, float(size_range[0])
|
||||||
|
elif len(size_range) == 2:
|
||||||
|
return float(size_range[0]), float(size_range[1])
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"解析大小范围失败:{str(e)} - {traceback.format_exc()}")
|
||||||
|
return 0, 0
|
||||||
|
|
||||||
def __filter_torrent(t: TorrentInfo) -> bool:
|
def __filter_torrent(t: TorrentInfo) -> bool:
|
||||||
"""
|
"""
|
||||||
@@ -381,6 +418,36 @@ class SearchChain(ChainBase):
|
|||||||
logger.info(f"{t.title} 不匹配特效规则 {effect}")
|
logger.info(f"{t.title} 不匹配特效规则 {effect}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# 大小
|
||||||
|
if movie_size or tv_size:
|
||||||
|
if mediainfo.type == MediaType.TV:
|
||||||
|
size = tv_size
|
||||||
|
else:
|
||||||
|
size = movie_size
|
||||||
|
# 大小范围
|
||||||
|
begin_size, end_size = __get_size_range(size)
|
||||||
|
if begin_size is not None and end_size is not None:
|
||||||
|
meta = MetaInfo(title=t.title, subtitle=t.description)
|
||||||
|
# 集数
|
||||||
|
if mediainfo.type == MediaType.TV:
|
||||||
|
# 电视剧
|
||||||
|
season = meta.begin_season or 1
|
||||||
|
if meta.total_episode:
|
||||||
|
# 识别的总集数
|
||||||
|
episodes_num = meta.total_episode
|
||||||
|
else:
|
||||||
|
# 整季集数
|
||||||
|
episodes_num = len(mediainfo.seasons.get(season) or [1])
|
||||||
|
# 比较大小
|
||||||
|
if not (begin_size * 1024 ** 3 <= (t.size / episodes_num) <= end_size * 1024 ** 3):
|
||||||
|
logger.info(f"{t.title} {StringUtils.str_filesize(t.size)} "
|
||||||
|
f"共{episodes_num}集,不匹配大小规则 {size}")
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
# 电影比较大小
|
||||||
|
if not (begin_size * 1024 ** 3 <= t.size <= end_size * 1024 ** 3):
|
||||||
|
logger.info(f"{t.title} {StringUtils.str_filesize(t.size)} 不匹配大小规则 {size}")
|
||||||
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# 使用默认过滤规则再次过滤
|
# 使用默认过滤规则再次过滤
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
import json
|
import json
|
||||||
|
import random
|
||||||
import re
|
import re
|
||||||
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Dict, List, Optional, Union, Tuple
|
from typing import Dict, List, Optional, Union, Tuple
|
||||||
|
|
||||||
from app.chain import ChainBase
|
from app.chain import ChainBase
|
||||||
from app.chain.douban import DoubanChain
|
|
||||||
from app.chain.download import DownloadChain
|
from app.chain.download import DownloadChain
|
||||||
|
from app.chain.media import MediaChain
|
||||||
from app.chain.search import SearchChain
|
from app.chain.search import SearchChain
|
||||||
from app.chain.torrents import TorrentsChain
|
from app.chain.torrents import TorrentsChain
|
||||||
|
from app.core.config import settings
|
||||||
from app.core.context import TorrentInfo, Context, MediaInfo
|
from app.core.context import TorrentInfo, Context, MediaInfo
|
||||||
from app.core.meta import MetaBase
|
from app.core.meta import MetaBase
|
||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo
|
||||||
@@ -31,6 +34,7 @@ class SubscribeChain(ChainBase):
|
|||||||
self.searchchain = SearchChain()
|
self.searchchain = SearchChain()
|
||||||
self.subscribeoper = SubscribeOper()
|
self.subscribeoper = SubscribeOper()
|
||||||
self.torrentschain = TorrentsChain()
|
self.torrentschain = TorrentsChain()
|
||||||
|
self.mediachain = MediaChain()
|
||||||
self.message = MessageHelper()
|
self.message = MessageHelper()
|
||||||
self.systemconfig = SystemConfigOper()
|
self.systemconfig = SystemConfigOper()
|
||||||
|
|
||||||
@@ -49,32 +53,39 @@ class SubscribeChain(ChainBase):
|
|||||||
识别媒体信息并添加订阅
|
识别媒体信息并添加订阅
|
||||||
"""
|
"""
|
||||||
logger.info(f'开始添加订阅,标题:{title} ...')
|
logger.info(f'开始添加订阅,标题:{title} ...')
|
||||||
metainfo = None
|
|
||||||
mediainfo = None
|
mediainfo = None
|
||||||
if not tmdbid and doubanid:
|
metainfo = MetaInfo(title)
|
||||||
# 将豆瓣信息转换为TMDB信息
|
if year:
|
||||||
context = DoubanChain().recognize_by_doubanid(doubanid)
|
metainfo.year = year
|
||||||
if context:
|
if mtype:
|
||||||
metainfo = context.meta_info
|
metainfo.type = mtype
|
||||||
mediainfo = context.media_info
|
if season:
|
||||||
|
metainfo.type = MediaType.TV
|
||||||
|
metainfo.begin_season = season
|
||||||
|
# 识别媒体信息
|
||||||
|
if settings.RECOGNIZE_SOURCE == "themoviedb":
|
||||||
|
# TMDB识别模式
|
||||||
|
if not tmdbid and doubanid:
|
||||||
|
# 将豆瓣信息转换为TMDB信息
|
||||||
|
tmdbinfo = self.mediachain.get_tmdbinfo_by_doubanid(doubanid=doubanid, mtype=mtype)
|
||||||
|
if tmdbinfo:
|
||||||
|
mediainfo = MediaInfo(tmdb_info=tmdbinfo)
|
||||||
|
else:
|
||||||
|
# 识别TMDB信息
|
||||||
|
mediainfo = self.recognize_media(meta=metainfo, mtype=mtype, tmdbid=tmdbid)
|
||||||
else:
|
else:
|
||||||
# 识别元数据
|
# 豆瓣识别模式
|
||||||
metainfo = MetaInfo(title)
|
mediainfo = self.recognize_media(meta=metainfo, mtype=mtype, doubanid=doubanid)
|
||||||
if year:
|
if mediainfo:
|
||||||
metainfo.year = year
|
# 豆瓣标题处理
|
||||||
if mtype:
|
meta = MetaInfo(mediainfo.title)
|
||||||
metainfo.type = mtype
|
mediainfo.title = meta.name
|
||||||
if season:
|
if not season:
|
||||||
metainfo.type = MediaType.TV
|
season = meta.begin_season
|
||||||
metainfo.begin_season = season
|
|
||||||
# 识别媒体信息
|
|
||||||
mediainfo = self.recognize_media(meta=metainfo, mtype=mtype, tmdbid=tmdbid)
|
|
||||||
# 识别失败
|
# 识别失败
|
||||||
if not mediainfo or not metainfo or not mediainfo.tmdb_id:
|
if not mediainfo:
|
||||||
logger.warn(f'未识别到媒体信息,标题:{title},tmdbid:{tmdbid}')
|
logger.warn(f'未识别到媒体信息,标题:{title},tmdbid:{tmdbid},doubanid:{doubanid}')
|
||||||
return None, "未识别到媒体信息"
|
return None, "未识别到媒体信息"
|
||||||
# 更新媒体图片
|
|
||||||
self.obtain_images(mediainfo=mediainfo)
|
|
||||||
# 总集数
|
# 总集数
|
||||||
if mediainfo.type == MediaType.TV:
|
if mediainfo.type == MediaType.TV:
|
||||||
if not season:
|
if not season:
|
||||||
@@ -84,16 +95,17 @@ class SubscribeChain(ChainBase):
|
|||||||
if not mediainfo.seasons:
|
if not mediainfo.seasons:
|
||||||
# 补充媒体信息
|
# 补充媒体信息
|
||||||
mediainfo = self.recognize_media(mtype=mediainfo.type,
|
mediainfo = self.recognize_media(mtype=mediainfo.type,
|
||||||
tmdbid=mediainfo.tmdb_id)
|
tmdbid=mediainfo.tmdb_id,
|
||||||
|
doubanid=mediainfo.douban_id)
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
logger.error(f"媒体信息识别失败!")
|
logger.error(f"媒体信息识别失败!")
|
||||||
return None, "媒体信息识别失败"
|
return None, "媒体信息识别失败"
|
||||||
if not mediainfo.seasons:
|
if not mediainfo.seasons:
|
||||||
logger.error(f"媒体信息中没有季集信息,标题:{title},tmdbid:{tmdbid}")
|
logger.error(f"媒体信息中没有季集信息,标题:{title},tmdbid:{tmdbid},doubanid:{doubanid}")
|
||||||
return None, "媒体信息中没有季集信息"
|
return None, "媒体信息中没有季集信息"
|
||||||
total_episode = len(mediainfo.seasons.get(season) or [])
|
total_episode = len(mediainfo.seasons.get(season) or [])
|
||||||
if not total_episode:
|
if not total_episode:
|
||||||
logger.error(f'未获取到总集数,标题:{title},tmdbid:{tmdbid}')
|
logger.error(f'未获取到总集数,标题:{title},tmdbid:{tmdbid}, doubanid:{doubanid}')
|
||||||
return None, f"未获取到第 {season} 季的总集数"
|
return None, f"未获取到第 {season} 季的总集数"
|
||||||
kwargs.update({
|
kwargs.update({
|
||||||
'total_episode': total_episode
|
'total_episode': total_episode
|
||||||
@@ -103,9 +115,13 @@ class SubscribeChain(ChainBase):
|
|||||||
kwargs.update({
|
kwargs.update({
|
||||||
'lack_episode': kwargs.get('total_episode')
|
'lack_episode': kwargs.get('total_episode')
|
||||||
})
|
})
|
||||||
|
# 更新媒体图片
|
||||||
|
self.obtain_images(mediainfo=mediainfo)
|
||||||
|
# 合并信息
|
||||||
|
if doubanid:
|
||||||
|
mediainfo.douban_id = doubanid
|
||||||
# 添加订阅
|
# 添加订阅
|
||||||
sid, err_msg = self.subscribeoper.add(mediainfo, doubanid=doubanid,
|
sid, err_msg = self.subscribeoper.add(mediainfo, season=season, username=username, **kwargs)
|
||||||
season=season, username=username, **kwargs)
|
|
||||||
if not sid:
|
if not sid:
|
||||||
logger.error(f'{mediainfo.title_year} {err_msg}')
|
logger.error(f'{mediainfo.title_year} {err_msg}')
|
||||||
if not exist_ok and message:
|
if not exist_ok and message:
|
||||||
@@ -137,6 +153,7 @@ class SubscribeChain(ChainBase):
|
|||||||
判断订阅是否已存在
|
判断订阅是否已存在
|
||||||
"""
|
"""
|
||||||
if self.subscribeoper.exists(tmdbid=mediainfo.tmdb_id,
|
if self.subscribeoper.exists(tmdbid=mediainfo.tmdb_id,
|
||||||
|
doubanid=mediainfo.douban_id,
|
||||||
season=meta.begin_season if meta else None):
|
season=meta.begin_season if meta else None):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
@@ -155,6 +172,7 @@ class SubscribeChain(ChainBase):
|
|||||||
subscribes = self.subscribeoper.list(state)
|
subscribes = self.subscribeoper.list(state)
|
||||||
# 遍历订阅
|
# 遍历订阅
|
||||||
for subscribe in subscribes:
|
for subscribe in subscribes:
|
||||||
|
mediakey = subscribe.tmdbid or subscribe.doubanid
|
||||||
# 校验当前时间减订阅创建时间是否大于1分钟,否则跳过先,留出编辑订阅的时间
|
# 校验当前时间减订阅创建时间是否大于1分钟,否则跳过先,留出编辑订阅的时间
|
||||||
if subscribe.date:
|
if subscribe.date:
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
@@ -162,6 +180,11 @@ class SubscribeChain(ChainBase):
|
|||||||
if (now - subscribe_time).total_seconds() < 60:
|
if (now - subscribe_time).total_seconds() < 60:
|
||||||
logger.debug(f"订阅标题:{subscribe.name} 新增小于1分钟,暂不搜索...")
|
logger.debug(f"订阅标题:{subscribe.name} 新增小于1分钟,暂不搜索...")
|
||||||
continue
|
continue
|
||||||
|
# 随机休眠1-5分钟
|
||||||
|
if not sid and state == 'R':
|
||||||
|
sleep_time = random.randint(60, 300)
|
||||||
|
logger.info(f'订阅搜索随机休眠 {sleep_time} 秒 ...')
|
||||||
|
time.sleep(sleep_time)
|
||||||
logger.info(f'开始搜索订阅,标题:{subscribe.name} ...')
|
logger.info(f'开始搜索订阅,标题:{subscribe.name} ...')
|
||||||
# 如果状态为N则更新为R
|
# 如果状态为N则更新为R
|
||||||
if subscribe.state == 'N':
|
if subscribe.state == 'N':
|
||||||
@@ -172,9 +195,12 @@ class SubscribeChain(ChainBase):
|
|||||||
meta.begin_season = subscribe.season or None
|
meta.begin_season = subscribe.season or None
|
||||||
meta.type = MediaType(subscribe.type)
|
meta.type = MediaType(subscribe.type)
|
||||||
# 识别媒体信息
|
# 识别媒体信息
|
||||||
mediainfo: MediaInfo = self.recognize_media(meta=meta, mtype=meta.type, tmdbid=subscribe.tmdbid)
|
mediainfo: MediaInfo = self.recognize_media(meta=meta, mtype=meta.type,
|
||||||
|
tmdbid=subscribe.tmdbid,
|
||||||
|
doubanid=subscribe.doubanid)
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
logger.warn(f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid}')
|
logger.warn(
|
||||||
|
f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid},doubanid:{subscribe.doubanid}')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 非洗版状态
|
# 非洗版状态
|
||||||
@@ -196,7 +222,7 @@ class SubscribeChain(ChainBase):
|
|||||||
exist_flag = False
|
exist_flag = False
|
||||||
if meta.type == MediaType.TV:
|
if meta.type == MediaType.TV:
|
||||||
no_exists = {
|
no_exists = {
|
||||||
subscribe.tmdbid: {
|
mediakey: {
|
||||||
subscribe.season: NotExistMediaInfo(
|
subscribe.season: NotExistMediaInfo(
|
||||||
season=subscribe.season,
|
season=subscribe.season,
|
||||||
episodes=[],
|
episodes=[],
|
||||||
@@ -210,23 +236,23 @@ class SubscribeChain(ChainBase):
|
|||||||
# 已存在
|
# 已存在
|
||||||
if exist_flag:
|
if exist_flag:
|
||||||
logger.info(f'{mediainfo.title_year} 媒体库中已存在')
|
logger.info(f'{mediainfo.title_year} 媒体库中已存在')
|
||||||
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo)
|
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo, force=True)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 电视剧订阅处理缺失集
|
# 电视剧订阅处理缺失集
|
||||||
if meta.type == MediaType.TV:
|
if meta.type == MediaType.TV:
|
||||||
# 使用订阅的总集数和开始集数替换no_exists
|
# 实际缺失集与订阅开始结束集范围进行整合
|
||||||
no_exists = self.__get_subscribe_no_exits(
|
no_exists = self.__get_subscribe_no_exits(
|
||||||
no_exists=no_exists,
|
no_exists=no_exists,
|
||||||
tmdb_id=mediainfo.tmdb_id,
|
mediakey=mediakey,
|
||||||
begin_season=meta.begin_season,
|
begin_season=meta.begin_season,
|
||||||
total_episode=subscribe.total_episode,
|
total_episode=subscribe.total_episode,
|
||||||
start_episode=subscribe.start_episode,
|
start_episode=subscribe.start_episode,
|
||||||
|
|
||||||
)
|
)
|
||||||
# 打印缺失集信息
|
# 打印汇总缺失集信息
|
||||||
if no_exists and no_exists.get(subscribe.tmdbid):
|
if no_exists and no_exists.get(mediakey):
|
||||||
no_exists_info = no_exists.get(subscribe.tmdbid).get(subscribe.season)
|
no_exists_info = no_exists.get(mediakey).get(subscribe.season)
|
||||||
if no_exists_info:
|
if no_exists_info:
|
||||||
logger.info(f'订阅 {mediainfo.title_year} {meta.season} 缺失集:{no_exists_info.episodes}')
|
logger.info(f'订阅 {mediainfo.title_year} {meta.season} 缺失集:{no_exists_info.episodes}')
|
||||||
|
|
||||||
@@ -254,13 +280,11 @@ class SubscribeChain(ChainBase):
|
|||||||
filter_rule=filter_rule)
|
filter_rule=filter_rule)
|
||||||
if not contexts:
|
if not contexts:
|
||||||
logger.warn(f'订阅 {subscribe.keyword or subscribe.name} 未搜索到资源')
|
logger.warn(f'订阅 {subscribe.keyword or subscribe.name} 未搜索到资源')
|
||||||
if meta.type == MediaType.TV:
|
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta,
|
||||||
# 未搜索到资源,但本地缺失可能有变化,更新订阅剩余集数
|
mediainfo=mediainfo, lefts=no_exists)
|
||||||
self.__update_lack_episodes(lefts=no_exists, subscribe=subscribe,
|
|
||||||
meta=meta, mediainfo=mediainfo)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 过滤
|
# 过滤搜索结果
|
||||||
matched_contexts = []
|
matched_contexts = []
|
||||||
for context in contexts:
|
for context in contexts:
|
||||||
torrent_meta = context.meta_info
|
torrent_meta = context.meta_info
|
||||||
@@ -279,41 +303,30 @@ class SubscribeChain(ChainBase):
|
|||||||
if torrent_meta.episode_list:
|
if torrent_meta.episode_list:
|
||||||
logger.info(f'{subscribe.name} 正在洗版,{torrent_info.title} 不是整季')
|
logger.info(f'{subscribe.name} 正在洗版,{torrent_info.title} 不是整季')
|
||||||
continue
|
continue
|
||||||
# 优先级小于已下载优先级的不要
|
# 洗版时,优先级小于已下载优先级的不要
|
||||||
if subscribe.current_priority \
|
if subscribe.current_priority \
|
||||||
and torrent_info.pri_order < subscribe.current_priority:
|
and torrent_info.pri_order < subscribe.current_priority:
|
||||||
logger.info(f'{subscribe.name} 正在洗版,{torrent_info.title} 优先级低于已下载优先级')
|
logger.info(f'{subscribe.name} 正在洗版,{torrent_info.title} 优先级低于已下载优先级')
|
||||||
continue
|
continue
|
||||||
matched_contexts.append(context)
|
matched_contexts.append(context)
|
||||||
|
|
||||||
if not matched_contexts:
|
if not matched_contexts:
|
||||||
logger.warn(f'订阅 {subscribe.name} 没有符合过滤条件的资源')
|
logger.warn(f'订阅 {subscribe.name} 没有符合过滤条件的资源')
|
||||||
# 非洗版未搜索到资源,但本地缺失可能有变化,更新订阅剩余集数
|
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta,
|
||||||
if meta.type == MediaType.TV and not subscribe.best_version:
|
mediainfo=mediainfo, lefts=no_exists)
|
||||||
self.__update_lack_episodes(lefts=no_exists, subscribe=subscribe,
|
|
||||||
meta=meta, mediainfo=mediainfo)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 自动下载
|
# 自动下载
|
||||||
downloads, lefts = self.downloadchain.batch_download(contexts=matched_contexts,
|
downloads, lefts = self.downloadchain.batch_download(
|
||||||
no_exists=no_exists)
|
contexts=matched_contexts,
|
||||||
# 更新已经下载的集数
|
no_exists=no_exists,
|
||||||
if downloads \
|
username=subscribe.username,
|
||||||
and meta.type == MediaType.TV \
|
save_path=subscribe.save_path
|
||||||
and not subscribe.best_version:
|
)
|
||||||
self.__update_subscribe_note(subscribe=subscribe, downloads=downloads)
|
|
||||||
|
|
||||||
if downloads and not lefts:
|
# 判断是否应完成订阅
|
||||||
# 判断是否应完成订阅
|
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo,
|
||||||
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta,
|
downloads=downloads, lefts=lefts)
|
||||||
mediainfo=mediainfo, downloads=downloads)
|
|
||||||
else:
|
|
||||||
# 未完成下载
|
|
||||||
logger.info(f'{mediainfo.title_year} 未下载完整,继续订阅 ...')
|
|
||||||
if meta.type == MediaType.TV and not subscribe.best_version:
|
|
||||||
# 更新订阅剩余集数和时间
|
|
||||||
update_date = True if downloads else False
|
|
||||||
self.__update_lack_episodes(lefts=lefts, subscribe=subscribe, meta=meta,
|
|
||||||
mediainfo=mediainfo, update_date=update_date)
|
|
||||||
|
|
||||||
# 手动触发时发送系统消息
|
# 手动触发时发送系统消息
|
||||||
if manual:
|
if manual:
|
||||||
@@ -322,35 +335,74 @@ class SubscribeChain(ChainBase):
|
|||||||
else:
|
else:
|
||||||
self.message.put('所有订阅搜索完成!')
|
self.message.put('所有订阅搜索完成!')
|
||||||
|
|
||||||
def finish_subscribe_or_not(self, subscribe: Subscribe, meta: MetaInfo,
|
def update_subscribe_priority(self, subscribe: Subscribe, meta: MetaInfo,
|
||||||
mediainfo: MediaInfo, downloads: List[Context] = None):
|
mediainfo: MediaInfo, downloads: List[Context]):
|
||||||
"""
|
"""
|
||||||
判断是否应完成订阅
|
更新订阅已下载资源的优先级
|
||||||
"""
|
"""
|
||||||
|
if not downloads:
|
||||||
|
return
|
||||||
if not subscribe.best_version:
|
if not subscribe.best_version:
|
||||||
# 全部下载完成
|
return
|
||||||
logger.info(f'{mediainfo.title_year} 完成订阅')
|
# 当前下载资源的优先级
|
||||||
|
priority = max([item.torrent_info.pri_order for item in downloads])
|
||||||
|
if priority == 100:
|
||||||
|
logger.info(f'{mediainfo.title_year} 洗版完成,删除订阅')
|
||||||
self.subscribeoper.delete(subscribe.id)
|
self.subscribeoper.delete(subscribe.id)
|
||||||
# 发送通知
|
# 发送通知
|
||||||
self.post_message(Notification(mtype=NotificationType.Subscribe,
|
self.post_message(Notification(mtype=NotificationType.Subscribe,
|
||||||
title=f'{mediainfo.title_year} {meta.season} 已完成订阅',
|
title=f'{mediainfo.title_year} {meta.season} 已洗版完成',
|
||||||
image=mediainfo.get_message_image()))
|
image=mediainfo.get_message_image()))
|
||||||
elif downloads:
|
else:
|
||||||
# 当前下载资源的优先级
|
# 正在洗版,更新资源优先级
|
||||||
priority = max([item.torrent_info.pri_order for item in downloads])
|
logger.info(f'{mediainfo.title_year} 正在洗版,更新资源优先级为 {priority}')
|
||||||
if priority == 100:
|
self.subscribeoper.update(subscribe.id, {
|
||||||
logger.info(f'{mediainfo.title_year} 洗版完成,删除订阅')
|
"current_priority": priority
|
||||||
|
})
|
||||||
|
|
||||||
|
def finish_subscribe_or_not(self, subscribe: Subscribe, meta: MetaInfo, mediainfo: MediaInfo,
|
||||||
|
downloads: List[Context] = None,
|
||||||
|
lefts: Dict[Union[int | str], Dict[int, NotExistMediaInfo]] = None,
|
||||||
|
force: bool = False):
|
||||||
|
"""
|
||||||
|
判断是否应完成订阅
|
||||||
|
"""
|
||||||
|
mediakey = subscribe.tmdbid or subscribe.doubanid
|
||||||
|
# 是否有剩余集
|
||||||
|
no_lefts = not lefts or not lefts.get(mediakey)
|
||||||
|
# 是否完成订阅
|
||||||
|
if not subscribe.best_version:
|
||||||
|
# 非洗板
|
||||||
|
if ((no_lefts and meta.type == MediaType.TV)
|
||||||
|
or (downloads and meta.type == MediaType.MOVIE)
|
||||||
|
or force):
|
||||||
|
# 全部下载完成
|
||||||
|
logger.info(f'{mediainfo.title_year} 完成订阅')
|
||||||
self.subscribeoper.delete(subscribe.id)
|
self.subscribeoper.delete(subscribe.id)
|
||||||
# 发送通知
|
# 发送通知
|
||||||
self.post_message(Notification(mtype=NotificationType.Subscribe,
|
self.post_message(Notification(mtype=NotificationType.Subscribe,
|
||||||
title=f'{mediainfo.title_year} {meta.season} 已洗版完成',
|
title=f'{mediainfo.title_year} {meta.season} 已完成订阅',
|
||||||
image=mediainfo.get_message_image()))
|
image=mediainfo.get_message_image()))
|
||||||
|
elif downloads and meta.type == MediaType.TV:
|
||||||
|
# 电视剧更新已下载集数
|
||||||
|
self.__update_subscribe_note(subscribe=subscribe, downloads=downloads)
|
||||||
|
# 更新订阅剩余集数和时间
|
||||||
|
self.__update_lack_episodes(lefts=lefts, subscribe=subscribe,
|
||||||
|
mediainfo=mediainfo, update_date=True)
|
||||||
else:
|
else:
|
||||||
# 正在洗版,更新资源优先级
|
# 未下载到内容且不完整
|
||||||
logger.info(f'{mediainfo.title_year} 正在洗版,更新资源优先级')
|
logger.info(f'{mediainfo.title_year} 未下载完整,继续订阅 ...')
|
||||||
self.subscribeoper.update(subscribe.id, {
|
if meta.type == MediaType.TV:
|
||||||
"current_priority": priority
|
# 更新订阅剩余集数
|
||||||
})
|
self.__update_lack_episodes(lefts=lefts, subscribe=subscribe,
|
||||||
|
mediainfo=mediainfo, update_date=False)
|
||||||
|
elif downloads:
|
||||||
|
# 洗板,下载到了内容,更新资源优先级
|
||||||
|
self.update_subscribe_priority(subscribe=subscribe, meta=meta,
|
||||||
|
mediainfo=mediainfo, downloads=downloads)
|
||||||
|
else:
|
||||||
|
# 洗版,未下载到内容
|
||||||
|
logger.info(f'{mediainfo.title_year} 继续洗版 ...')
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
"""
|
"""
|
||||||
@@ -408,7 +460,7 @@ class SubscribeChain(ChainBase):
|
|||||||
}
|
}
|
||||||
# 订阅默认过滤规则
|
# 订阅默认过滤规则
|
||||||
return self.systemconfig.get(SystemConfigKey.DefaultFilterRules) or {}
|
return self.systemconfig.get(SystemConfigKey.DefaultFilterRules) or {}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def check_filter_rule(torrent_info: TorrentInfo, filter_rule: Dict[str, str]) -> bool:
|
def check_filter_rule(torrent_info: TorrentInfo, filter_rule: Dict[str, str]) -> bool:
|
||||||
"""
|
"""
|
||||||
@@ -462,15 +514,19 @@ class SubscribeChain(ChainBase):
|
|||||||
# 遍历订阅
|
# 遍历订阅
|
||||||
for subscribe in subscribes:
|
for subscribe in subscribes:
|
||||||
logger.info(f'开始匹配订阅,标题:{subscribe.name} ...')
|
logger.info(f'开始匹配订阅,标题:{subscribe.name} ...')
|
||||||
|
mediakey = subscribe.tmdbid or subscribe.doubanid
|
||||||
# 生成元数据
|
# 生成元数据
|
||||||
meta = MetaInfo(subscribe.name)
|
meta = MetaInfo(subscribe.name)
|
||||||
meta.year = subscribe.year
|
meta.year = subscribe.year
|
||||||
meta.begin_season = subscribe.season or None
|
meta.begin_season = subscribe.season or None
|
||||||
meta.type = MediaType(subscribe.type)
|
meta.type = MediaType(subscribe.type)
|
||||||
# 识别媒体信息
|
# 识别媒体信息
|
||||||
mediainfo: MediaInfo = self.recognize_media(meta=meta, mtype=meta.type, tmdbid=subscribe.tmdbid)
|
mediainfo: MediaInfo = self.recognize_media(meta=meta, mtype=meta.type,
|
||||||
|
tmdbid=subscribe.tmdbid,
|
||||||
|
doubanid=subscribe.doubanid)
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
logger.warn(f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid}')
|
logger.warn(
|
||||||
|
f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid},doubanid:{subscribe.doubanid}')
|
||||||
continue
|
continue
|
||||||
# 非洗版
|
# 非洗版
|
||||||
if not subscribe.best_version:
|
if not subscribe.best_version:
|
||||||
@@ -491,7 +547,7 @@ class SubscribeChain(ChainBase):
|
|||||||
exist_flag = False
|
exist_flag = False
|
||||||
if meta.type == MediaType.TV:
|
if meta.type == MediaType.TV:
|
||||||
no_exists = {
|
no_exists = {
|
||||||
subscribe.tmdbid: {
|
mediakey: {
|
||||||
subscribe.season: NotExistMediaInfo(
|
subscribe.season: NotExistMediaInfo(
|
||||||
season=subscribe.season,
|
season=subscribe.season,
|
||||||
episodes=[],
|
episodes=[],
|
||||||
@@ -505,23 +561,23 @@ class SubscribeChain(ChainBase):
|
|||||||
# 已存在
|
# 已存在
|
||||||
if exist_flag:
|
if exist_flag:
|
||||||
logger.info(f'{mediainfo.title_year} 媒体库中已存在')
|
logger.info(f'{mediainfo.title_year} 媒体库中已存在')
|
||||||
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo)
|
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo, force=True)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 电视剧订阅
|
# 电视剧订阅
|
||||||
if meta.type == MediaType.TV:
|
if meta.type == MediaType.TV:
|
||||||
# 使用订阅的总集数和开始集数替换no_exists
|
# 整合实际缺失集与订阅开始集结束集
|
||||||
no_exists = self.__get_subscribe_no_exits(
|
no_exists = self.__get_subscribe_no_exits(
|
||||||
no_exists=no_exists,
|
no_exists=no_exists,
|
||||||
tmdb_id=mediainfo.tmdb_id,
|
mediakey=mediakey,
|
||||||
begin_season=meta.begin_season,
|
begin_season=meta.begin_season,
|
||||||
total_episode=subscribe.total_episode,
|
total_episode=subscribe.total_episode,
|
||||||
start_episode=subscribe.start_episode,
|
start_episode=subscribe.start_episode,
|
||||||
|
|
||||||
)
|
)
|
||||||
# 打印缺失集信息
|
# 打印汇总缺失集信息
|
||||||
if no_exists and no_exists.get(subscribe.tmdbid):
|
if no_exists and no_exists.get(mediakey):
|
||||||
no_exists_info = no_exists.get(subscribe.tmdbid).get(subscribe.season)
|
no_exists_info = no_exists.get(mediakey).get(subscribe.season)
|
||||||
if no_exists_info:
|
if no_exists_info:
|
||||||
logger.info(f'订阅 {mediainfo.title_year} {meta.season} 缺失集:{no_exists_info.episodes}')
|
logger.info(f'订阅 {mediainfo.title_year} {meta.season} 缺失集:{no_exists_info.episodes}')
|
||||||
|
|
||||||
@@ -576,9 +632,9 @@ class SubscribeChain(ChainBase):
|
|||||||
# 非洗版
|
# 非洗版
|
||||||
if not subscribe.best_version:
|
if not subscribe.best_version:
|
||||||
# 不是缺失的剧集不要
|
# 不是缺失的剧集不要
|
||||||
if no_exists and no_exists.get(subscribe.tmdbid):
|
if no_exists and no_exists.get(mediakey):
|
||||||
# 缺失集
|
# 缺失集
|
||||||
no_exists_info = no_exists.get(subscribe.tmdbid).get(subscribe.season)
|
no_exists_info = no_exists.get(mediakey).get(subscribe.season)
|
||||||
if no_exists_info:
|
if no_exists_info:
|
||||||
# 是否有交集
|
# 是否有交集
|
||||||
if no_exists_info.episodes and \
|
if no_exists_info.episodes and \
|
||||||
@@ -606,34 +662,33 @@ class SubscribeChain(ChainBase):
|
|||||||
filter_rule=filter_rule):
|
filter_rule=filter_rule):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# 洗版时,优先级小于已下载优先级的不要
|
||||||
|
if subscribe.best_version:
|
||||||
|
if subscribe.current_priority \
|
||||||
|
and torrent_info.pri_order < subscribe.current_priority:
|
||||||
|
logger.info(f'{subscribe.name} 正在洗版,{torrent_info.title} 优先级低于已下载优先级')
|
||||||
|
continue
|
||||||
|
|
||||||
# 匹配成功
|
# 匹配成功
|
||||||
logger.info(f'{mediainfo.title_year} 匹配成功:{torrent_info.title}')
|
logger.info(f'{mediainfo.title_year} 匹配成功:{torrent_info.title}')
|
||||||
_match_context.append(context)
|
_match_context.append(context)
|
||||||
|
|
||||||
# 开始下载
|
if not _match_context:
|
||||||
logger.info(f'{mediainfo.title_year} 匹配完成,共匹配到{len(_match_context)}个资源')
|
# 未匹配到资源
|
||||||
if _match_context:
|
logger.info(f'{mediainfo.title_year} 未匹配到符合条件的资源')
|
||||||
# 批量择优下载
|
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta,
|
||||||
downloads, lefts = self.downloadchain.batch_download(contexts=_match_context, no_exists=no_exists)
|
mediainfo=mediainfo, lefts=no_exists)
|
||||||
# 更新已经下载的集数
|
continue
|
||||||
if downloads and meta.type == MediaType.TV:
|
|
||||||
self.__update_subscribe_note(subscribe=subscribe, downloads=downloads)
|
|
||||||
|
|
||||||
if downloads and not lefts:
|
# 开始批量择优下载
|
||||||
# 判断是否要完成订阅
|
logger.info(f'{mediainfo.title_year} 匹配完成,共匹配到{len(_match_context)}个资源')
|
||||||
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta,
|
downloads, lefts = self.downloadchain.batch_download(contexts=_match_context,
|
||||||
mediainfo=mediainfo, downloads=downloads)
|
no_exists=no_exists,
|
||||||
else:
|
username=subscribe.username,
|
||||||
if meta.type == MediaType.TV and not subscribe.best_version:
|
save_path=subscribe.save_path)
|
||||||
update_date = True if downloads else False
|
# 判断是否要完成订阅
|
||||||
# 未完成下载,计算剩余集数
|
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo,
|
||||||
self.__update_lack_episodes(lefts=lefts, subscribe=subscribe, meta=meta,
|
downloads=downloads, lefts=lefts)
|
||||||
mediainfo=mediainfo, update_date=update_date)
|
|
||||||
else:
|
|
||||||
if meta.type == MediaType.TV:
|
|
||||||
# 未搜索到资源,但本地缺失可能有变化,更新订阅剩余集数
|
|
||||||
self.__update_lack_episodes(lefts=no_exists, subscribe=subscribe,
|
|
||||||
meta=meta, mediainfo=mediainfo)
|
|
||||||
|
|
||||||
def check(self):
|
def check(self):
|
||||||
"""
|
"""
|
||||||
@@ -653,9 +708,11 @@ class SubscribeChain(ChainBase):
|
|||||||
meta.begin_season = subscribe.season or None
|
meta.begin_season = subscribe.season or None
|
||||||
meta.type = MediaType(subscribe.type)
|
meta.type = MediaType(subscribe.type)
|
||||||
# 识别媒体信息
|
# 识别媒体信息
|
||||||
mediainfo: MediaInfo = self.recognize_media(meta=meta, mtype=meta.type, tmdbid=subscribe.tmdbid)
|
mediainfo: MediaInfo = self.recognize_media(meta=meta, mtype=meta.type,
|
||||||
|
tmdbid=subscribe.tmdbid, doubanid=subscribe.doubanid)
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
logger.warn(f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid}')
|
logger.warn(
|
||||||
|
f'未识别到媒体信息,标题:{subscribe.name},tmdbid:{subscribe.tmdbid},doubanid:{subscribe.doubanid}')
|
||||||
continue
|
continue
|
||||||
# 对于电视剧,获取当前季的总集数
|
# 对于电视剧,获取当前季的总集数
|
||||||
episodes = mediainfo.seasons.get(subscribe.season) or []
|
episodes = mediainfo.seasons.get(subscribe.season) or []
|
||||||
@@ -697,7 +754,11 @@ class SubscribeChain(ChainBase):
|
|||||||
mediainfo = context.media_info
|
mediainfo = context.media_info
|
||||||
if mediainfo.type != MediaType.TV:
|
if mediainfo.type != MediaType.TV:
|
||||||
continue
|
continue
|
||||||
if mediainfo.tmdb_id != subscribe.tmdbid:
|
if subscribe.tmdbid and mediainfo.tmdb_id \
|
||||||
|
and mediainfo.tmdb_id != subscribe.tmdbid:
|
||||||
|
continue
|
||||||
|
if subscribe.doubanid and mediainfo.douban_id \
|
||||||
|
and mediainfo.douban_id != subscribe.doubanid:
|
||||||
continue
|
continue
|
||||||
episodes = meta.episode_list
|
episodes = meta.episode_list
|
||||||
if not episodes:
|
if not episodes:
|
||||||
@@ -723,15 +784,17 @@ class SubscribeChain(ChainBase):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def __update_lack_episodes(self, lefts: Dict[int, Dict[int, NotExistMediaInfo]],
|
def __update_lack_episodes(self, lefts: Dict[Union[int, str], Dict[int, NotExistMediaInfo]],
|
||||||
subscribe: Subscribe,
|
subscribe: Subscribe,
|
||||||
meta: MetaBase,
|
|
||||||
mediainfo: MediaInfo,
|
mediainfo: MediaInfo,
|
||||||
update_date: bool = False):
|
update_date: bool = False):
|
||||||
"""
|
"""
|
||||||
更新订阅剩余集数
|
更新订阅剩余集数
|
||||||
"""
|
"""
|
||||||
left_seasons = lefts.get(mediainfo.tmdb_id)
|
if not lefts:
|
||||||
|
return
|
||||||
|
mediakey = subscribe.tmdbid or subscribe.doubanid
|
||||||
|
left_seasons = lefts.get(mediakey)
|
||||||
if left_seasons:
|
if left_seasons:
|
||||||
for season_info in left_seasons.values():
|
for season_info in left_seasons.values():
|
||||||
season = season_info.season
|
season = season_info.season
|
||||||
@@ -752,9 +815,6 @@ class SubscribeChain(ChainBase):
|
|||||||
self.subscribeoper.update(subscribe.id, {
|
self.subscribeoper.update(subscribe.id, {
|
||||||
"lack_episode": lack_episode
|
"lack_episode": lack_episode
|
||||||
})
|
})
|
||||||
else:
|
|
||||||
# 判断是否应完成订阅
|
|
||||||
self.finish_subscribe_or_not(subscribe=subscribe, meta=meta, mediainfo=mediainfo)
|
|
||||||
|
|
||||||
def remote_list(self, channel: MessageChannel, userid: Union[str, int] = None):
|
def remote_list(self, channel: MessageChannel, userid: Union[str, int] = None):
|
||||||
"""
|
"""
|
||||||
@@ -772,11 +832,17 @@ class SubscribeChain(ChainBase):
|
|||||||
messages = []
|
messages = []
|
||||||
for subscribe in subscribes:
|
for subscribe in subscribes:
|
||||||
if subscribe.type == MediaType.MOVIE.value:
|
if subscribe.type == MediaType.MOVIE.value:
|
||||||
tmdb_link = f"https://www.themoviedb.org/movie/{subscribe.tmdbid}"
|
if subscribe.tmdbid:
|
||||||
messages.append(f"{subscribe.id}. [{subscribe.name}({subscribe.year})]({tmdb_link})")
|
link = f"https://www.themoviedb.org/movie/{subscribe.tmdbid}"
|
||||||
|
else:
|
||||||
|
link = f"https://movie.douban.com/subject/{subscribe.doubanid}"
|
||||||
|
messages.append(f"{subscribe.id}. [{subscribe.name}({subscribe.year})]({link})")
|
||||||
else:
|
else:
|
||||||
tmdb_link = f"https://www.themoviedb.org/tv/{subscribe.tmdbid}"
|
if subscribe.tmdbid:
|
||||||
messages.append(f"{subscribe.id}. [{subscribe.name}({subscribe.year})]({tmdb_link}) "
|
link = f"https://www.themoviedb.org/tv/{subscribe.tmdbid}"
|
||||||
|
else:
|
||||||
|
link = f"https://movie.douban.com/subject/{subscribe.doubanid}"
|
||||||
|
messages.append(f"{subscribe.id}. [{subscribe.name}({subscribe.year})]({link}) "
|
||||||
f"第{subscribe.season}季 "
|
f"第{subscribe.season}季 "
|
||||||
f"_{subscribe.total_episode - (subscribe.lack_episode or subscribe.total_episode)}"
|
f"_{subscribe.total_episode - (subscribe.lack_episode or subscribe.total_episode)}"
|
||||||
f"/{subscribe.total_episode}_")
|
f"/{subscribe.total_episode}_")
|
||||||
@@ -810,25 +876,25 @@ class SubscribeChain(ChainBase):
|
|||||||
self.remote_list(channel, userid)
|
self.remote_list(channel, userid)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __get_subscribe_no_exits(no_exists: Dict[int, Dict[int, NotExistMediaInfo]],
|
def __get_subscribe_no_exits(no_exists: Dict[Union[int, str], Dict[int, NotExistMediaInfo]],
|
||||||
tmdb_id: int,
|
mediakey: Union[str, int],
|
||||||
begin_season: int,
|
begin_season: int,
|
||||||
total_episode: int,
|
total_episode: int,
|
||||||
start_episode: int):
|
start_episode: int):
|
||||||
"""
|
"""
|
||||||
根据订阅开始集数和总集数,结合TMDB信息计算当前订阅的缺失集数
|
根据订阅开始集数和总集数,结合TMDB信息计算当前订阅的缺失集数
|
||||||
:param no_exists: 缺失季集列表
|
:param no_exists: 缺失季集列表
|
||||||
:param tmdb_id: TMDB ID
|
:param mediakey: TMDB ID或豆瓣ID
|
||||||
:param begin_season: 开始季
|
:param begin_season: 开始季
|
||||||
:param total_episode: 订阅设定总集数
|
:param total_episode: 订阅设定总集数
|
||||||
:param start_episode: 订阅设定开始集数
|
:param start_episode: 订阅设定开始集数
|
||||||
"""
|
"""
|
||||||
# 使用订阅的总集数和开始集数替换no_exists
|
# 使用订阅的总集数和开始集数替换no_exists
|
||||||
if no_exists \
|
if no_exists \
|
||||||
and no_exists.get(tmdb_id) \
|
and no_exists.get(mediakey) \
|
||||||
and (total_episode or start_episode):
|
and (total_episode or start_episode):
|
||||||
# 该季原缺失信息
|
# 该季原缺失信息
|
||||||
no_exist_season = no_exists.get(tmdb_id).get(begin_season)
|
no_exist_season = no_exists.get(mediakey).get(begin_season)
|
||||||
if no_exist_season:
|
if no_exist_season:
|
||||||
# 原集列表
|
# 原集列表
|
||||||
episode_list = no_exist_season.episodes
|
episode_list = no_exist_season.episodes
|
||||||
@@ -860,7 +926,7 @@ class SubscribeChain(ChainBase):
|
|||||||
# 与原集列表取交集
|
# 与原集列表取交集
|
||||||
episodes = list(set(episode_list).intersection(set(new_episodes)))
|
episodes = list(set(episode_list).intersection(set(new_episodes)))
|
||||||
# 更新集合
|
# 更新集合
|
||||||
no_exists[tmdb_id][begin_season] = NotExistMediaInfo(
|
no_exists[mediakey][begin_season] = NotExistMediaInfo(
|
||||||
season=begin_season,
|
season=begin_season,
|
||||||
episodes=episodes,
|
episodes=episodes,
|
||||||
total_episode=total_episode,
|
total_episode=total_episode,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
@@ -18,7 +17,6 @@ class SystemChain(ChainBase, metaclass=Singleton):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
_restart_file = "__system_restart__"
|
_restart_file = "__system_restart__"
|
||||||
_update_file = "__system_update__"
|
|
||||||
|
|
||||||
def remote_clear_cache(self, channel: MessageChannel, userid: Union[int, str]):
|
def remote_clear_cache(self, channel: MessageChannel, userid: Union[int, str]):
|
||||||
"""
|
"""
|
||||||
@@ -42,31 +40,6 @@ class SystemChain(ChainBase, metaclass=Singleton):
|
|||||||
}, self._restart_file)
|
}, self._restart_file)
|
||||||
SystemUtils.restart()
|
SystemUtils.restart()
|
||||||
|
|
||||||
def update(self, channel: MessageChannel = None, userid: Union[int, str] = None):
|
|
||||||
"""
|
|
||||||
重启系统
|
|
||||||
"""
|
|
||||||
if not SystemUtils.is_docker():
|
|
||||||
logger.error("非Docker版本不支持自动更新!")
|
|
||||||
return
|
|
||||||
|
|
||||||
if channel and userid:
|
|
||||||
self.post_message(Notification(channel=channel,
|
|
||||||
title="系统正在更新,请耐心等候!", userid=userid))
|
|
||||||
# 保存重启信息
|
|
||||||
self.save_cache({
|
|
||||||
"channel": channel.value,
|
|
||||||
"userid": userid
|
|
||||||
}, self._update_file)
|
|
||||||
|
|
||||||
# 重启系统
|
|
||||||
os.system("bash /usr/local/bin/mp_update")
|
|
||||||
|
|
||||||
if channel and userid:
|
|
||||||
self.post_message(Notification(channel=channel,
|
|
||||||
title="暂无新版本!", userid=userid))
|
|
||||||
self.remove_cache(self._update_file)
|
|
||||||
|
|
||||||
def version(self, channel: MessageChannel, userid: Union[int, str]):
|
def version(self, channel: MessageChannel, userid: Union[int, str]):
|
||||||
"""
|
"""
|
||||||
查看当前版本、远程版本
|
查看当前版本、远程版本
|
||||||
@@ -86,12 +59,9 @@ class SystemChain(ChainBase, metaclass=Singleton):
|
|||||||
如通过交互命令重启,
|
如通过交互命令重启,
|
||||||
重启完发送msg
|
重启完发送msg
|
||||||
"""
|
"""
|
||||||
cache_file, action, channel, userid = None, None, None, None
|
|
||||||
# 重启消息
|
# 重启消息
|
||||||
restart_channel = self.load_cache(self._restart_file)
|
restart_channel = self.load_cache(self._restart_file)
|
||||||
if restart_channel:
|
if restart_channel:
|
||||||
cache_file = self._restart_file
|
|
||||||
action = "重启"
|
|
||||||
# 发送重启完成msg
|
# 发送重启完成msg
|
||||||
if not isinstance(restart_channel, dict):
|
if not isinstance(restart_channel, dict):
|
||||||
restart_channel = json.loads(restart_channel)
|
restart_channel = json.loads(restart_channel)
|
||||||
@@ -100,21 +70,6 @@ class SystemChain(ChainBase, metaclass=Singleton):
|
|||||||
channel.value == restart_channel.get('channel')), None)
|
channel.value == restart_channel.get('channel')), None)
|
||||||
userid = restart_channel.get('userid')
|
userid = restart_channel.get('userid')
|
||||||
|
|
||||||
# 更新消息
|
|
||||||
update_channel = self.load_cache(self._update_file)
|
|
||||||
if update_channel:
|
|
||||||
cache_file = self._update_file
|
|
||||||
action = "更新"
|
|
||||||
# 发送重启完成msg
|
|
||||||
if not isinstance(update_channel, dict):
|
|
||||||
update_channel = json.loads(update_channel)
|
|
||||||
channel = next(
|
|
||||||
(channel for channel in MessageChannel.__members__.values() if
|
|
||||||
channel.value == update_channel.get('channel')), None)
|
|
||||||
userid = update_channel.get('userid')
|
|
||||||
|
|
||||||
# 发送消息
|
|
||||||
if channel and userid:
|
|
||||||
# 版本号
|
# 版本号
|
||||||
release_version = self.__get_release_version()
|
release_version = self.__get_release_version()
|
||||||
local_version = self.get_local_version()
|
local_version = self.get_local_version()
|
||||||
@@ -123,16 +78,16 @@ class SystemChain(ChainBase, metaclass=Singleton):
|
|||||||
else:
|
else:
|
||||||
title = f"当前版本:{local_version},远程版本:{release_version}"
|
title = f"当前版本:{local_version},远程版本:{release_version}"
|
||||||
self.post_message(Notification(channel=channel,
|
self.post_message(Notification(channel=channel,
|
||||||
title=f"系统已{action}完成!{title}",
|
title=f"系统已重启完成!{title}",
|
||||||
userid=userid))
|
userid=userid))
|
||||||
self.remove_cache(cache_file)
|
self.remove_cache(self._restart_file)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __get_release_version():
|
def __get_release_version():
|
||||||
"""
|
"""
|
||||||
获取最新版本
|
获取最新版本
|
||||||
"""
|
"""
|
||||||
version_res = RequestUtils(proxies=settings.PROXY).get_res(
|
version_res = RequestUtils(proxies=settings.PROXY, headers=settings.GITHUB_HEADERS).get_res(
|
||||||
"https://api.github.com/repos/jxxghp/MoviePilot/releases/latest")
|
"https://api.github.com/repos/jxxghp/MoviePilot/releases/latest")
|
||||||
if version_res:
|
if version_res:
|
||||||
ver_json = version_res.json()
|
ver_json = version_res.json()
|
||||||
@@ -151,12 +106,12 @@ class SystemChain(ChainBase, metaclass=Singleton):
|
|||||||
try:
|
try:
|
||||||
with open(version_file, 'rb') as f:
|
with open(version_file, 'rb') as f:
|
||||||
version = f.read()
|
version = f.read()
|
||||||
pattern = r"v(\d+\.\d+\.\d+)"
|
pattern = r"'([^']*)'"
|
||||||
match = re.search(pattern, str(version))
|
match = re.search(pattern, str(version))
|
||||||
|
|
||||||
if match:
|
if match:
|
||||||
version = match.group(1)
|
version = match.group(1)
|
||||||
return f"v{version}"
|
return version
|
||||||
else:
|
else:
|
||||||
logger.warn("未找到版本号")
|
logger.warn("未找到版本号")
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -25,17 +25,21 @@ class TmdbChain(ChainBase, metaclass=Singleton):
|
|||||||
:param page: 页码
|
:param page: 页码
|
||||||
:return: 媒体信息列表
|
:return: 媒体信息列表
|
||||||
"""
|
"""
|
||||||
|
if settings.RECOGNIZE_SOURCE != "themoviedb":
|
||||||
|
return None
|
||||||
return self.run_module("tmdb_discover", mtype=mtype,
|
return self.run_module("tmdb_discover", mtype=mtype,
|
||||||
sort_by=sort_by, with_genres=with_genres,
|
sort_by=sort_by, with_genres=with_genres,
|
||||||
with_original_language=with_original_language,
|
with_original_language=with_original_language,
|
||||||
page=page)
|
page=page)
|
||||||
|
|
||||||
def tmdb_trending(self, page: int = 1) -> List[dict]:
|
def tmdb_trending(self, page: int = 1) -> Optional[List[dict]]:
|
||||||
"""
|
"""
|
||||||
TMDB流行趋势
|
TMDB流行趋势
|
||||||
:param page: 第几页
|
:param page: 第几页
|
||||||
:return: TMDB信息列表
|
:return: TMDB信息列表
|
||||||
"""
|
"""
|
||||||
|
if settings.RECOGNIZE_SOURCE != "themoviedb":
|
||||||
|
return None
|
||||||
return self.run_module("tmdb_trending", page=page)
|
return self.run_module("tmdb_trending", page=page)
|
||||||
|
|
||||||
def tmdb_seasons(self, tmdbid: int) -> List[schemas.TmdbSeason]:
|
def tmdb_seasons(self, tmdbid: int) -> List[schemas.TmdbSeason]:
|
||||||
@@ -58,28 +62,28 @@ class TmdbChain(ChainBase, metaclass=Singleton):
|
|||||||
根据TMDBID查询类似电影
|
根据TMDBID查询类似电影
|
||||||
:param tmdbid: TMDBID
|
:param tmdbid: TMDBID
|
||||||
"""
|
"""
|
||||||
return self.run_module("movie_similar", tmdbid=tmdbid)
|
return self.run_module("tmdb_movie_similar", tmdbid=tmdbid)
|
||||||
|
|
||||||
def tv_similar(self, tmdbid: int) -> List[dict]:
|
def tv_similar(self, tmdbid: int) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
根据TMDBID查询类似电视剧
|
根据TMDBID查询类似电视剧
|
||||||
:param tmdbid: TMDBID
|
:param tmdbid: TMDBID
|
||||||
"""
|
"""
|
||||||
return self.run_module("tv_similar", tmdbid=tmdbid)
|
return self.run_module("tmdb_tv_similar", tmdbid=tmdbid)
|
||||||
|
|
||||||
def movie_recommend(self, tmdbid: int) -> List[dict]:
|
def movie_recommend(self, tmdbid: int) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
根据TMDBID查询推荐电影
|
根据TMDBID查询推荐电影
|
||||||
:param tmdbid: TMDBID
|
:param tmdbid: TMDBID
|
||||||
"""
|
"""
|
||||||
return self.run_module("movie_recommend", tmdbid=tmdbid)
|
return self.run_module("tmdb_movie_recommend", tmdbid=tmdbid)
|
||||||
|
|
||||||
def tv_recommend(self, tmdbid: int) -> List[dict]:
|
def tv_recommend(self, tmdbid: int) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
根据TMDBID查询推荐电视剧
|
根据TMDBID查询推荐电视剧
|
||||||
:param tmdbid: TMDBID
|
:param tmdbid: TMDBID
|
||||||
"""
|
"""
|
||||||
return self.run_module("tv_recommend", tmdbid=tmdbid)
|
return self.run_module("tmdb_tv_recommend", tmdbid=tmdbid)
|
||||||
|
|
||||||
def movie_credits(self, tmdbid: int, page: int = 1) -> List[dict]:
|
def movie_credits(self, tmdbid: int, page: int = 1) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
@@ -87,7 +91,7 @@ class TmdbChain(ChainBase, metaclass=Singleton):
|
|||||||
:param tmdbid: TMDBID
|
:param tmdbid: TMDBID
|
||||||
:param page: 页码
|
:param page: 页码
|
||||||
"""
|
"""
|
||||||
return self.run_module("movie_credits", tmdbid=tmdbid, page=page)
|
return self.run_module("tmdb_movie_credits", tmdbid=tmdbid, page=page)
|
||||||
|
|
||||||
def tv_credits(self, tmdbid: int, page: int = 1) -> List[dict]:
|
def tv_credits(self, tmdbid: int, page: int = 1) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
@@ -95,14 +99,14 @@ class TmdbChain(ChainBase, metaclass=Singleton):
|
|||||||
:param tmdbid: TMDBID
|
:param tmdbid: TMDBID
|
||||||
:param page: 页码
|
:param page: 页码
|
||||||
"""
|
"""
|
||||||
return self.run_module("tv_credits", tmdbid=tmdbid, page=page)
|
return self.run_module("tmdb_tv_credits", tmdbid=tmdbid, page=page)
|
||||||
|
|
||||||
def person_detail(self, person_id: int) -> dict:
|
def person_detail(self, person_id: int) -> dict:
|
||||||
"""
|
"""
|
||||||
根据TMDBID查询演职员详情
|
根据TMDBID查询演职员详情
|
||||||
:param person_id: 人物ID
|
:param person_id: 人物ID
|
||||||
"""
|
"""
|
||||||
return self.run_module("person_detail", person_id=person_id)
|
return self.run_module("tmdb_person_detail", person_id=person_id)
|
||||||
|
|
||||||
def person_credits(self, person_id: int, page: int = 1) -> List[dict]:
|
def person_credits(self, person_id: int, page: int = 1) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
@@ -110,7 +114,7 @@ class TmdbChain(ChainBase, metaclass=Singleton):
|
|||||||
:param person_id: 人物ID
|
:param person_id: 人物ID
|
||||||
:param page: 页码
|
:param page: 页码
|
||||||
"""
|
"""
|
||||||
return self.run_module("person_credits", person_id=person_id, page=page)
|
return self.run_module("tmdb_person_credits", person_id=person_id, page=page)
|
||||||
|
|
||||||
@cached(cache=TTLCache(maxsize=1, ttl=3600))
|
@cached(cache=TTLCache(maxsize=1, ttl=3600))
|
||||||
def get_random_wallpager(self):
|
def get_random_wallpager(self):
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import re
|
import re
|
||||||
|
import traceback
|
||||||
from typing import Dict, List, Union
|
from typing import Dict, List, Union
|
||||||
|
|
||||||
from cachetools import cached, TTLCache
|
from cachetools import cached, TTLCache
|
||||||
|
|
||||||
from app.chain import ChainBase
|
from app.chain import ChainBase
|
||||||
|
from app.chain.media import MediaChain
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.core.context import TorrentInfo, Context, MediaInfo
|
from app.core.context import TorrentInfo, Context, MediaInfo
|
||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo
|
||||||
@@ -11,6 +13,7 @@ from app.db.site_oper import SiteOper
|
|||||||
from app.db.systemconfig_oper import SystemConfigOper
|
from app.db.systemconfig_oper import SystemConfigOper
|
||||||
from app.helper.rss import RssHelper
|
from app.helper.rss import RssHelper
|
||||||
from app.helper.sites import SitesHelper
|
from app.helper.sites import SitesHelper
|
||||||
|
from app.helper.torrent import TorrentHelper
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.schemas import Notification
|
from app.schemas import Notification
|
||||||
from app.schemas.types import SystemConfigKey, MessageChannel, NotificationType
|
from app.schemas.types import SystemConfigKey, MessageChannel, NotificationType
|
||||||
@@ -32,6 +35,8 @@ class TorrentsChain(ChainBase, metaclass=Singleton):
|
|||||||
self.siteoper = SiteOper()
|
self.siteoper = SiteOper()
|
||||||
self.rsshelper = RssHelper()
|
self.rsshelper = RssHelper()
|
||||||
self.systemconfig = SystemConfigOper()
|
self.systemconfig = SystemConfigOper()
|
||||||
|
self.mediachain = MediaChain()
|
||||||
|
self.torrenthelper = TorrentHelper()
|
||||||
|
|
||||||
def remote_refresh(self, channel: MessageChannel, userid: Union[str, int] = None):
|
def remote_refresh(self, channel: MessageChannel, userid: Union[str, int] = None):
|
||||||
"""
|
"""
|
||||||
@@ -58,7 +63,16 @@ class TorrentsChain(ChainBase, metaclass=Singleton):
|
|||||||
else:
|
else:
|
||||||
return self.load_cache(self._rss_file) or {}
|
return self.load_cache(self._rss_file) or {}
|
||||||
|
|
||||||
@cached(cache=TTLCache(maxsize=128 if settings.BIG_MEMORY_MODE else 1, ttl=600))
|
def clear_torrents(self):
|
||||||
|
"""
|
||||||
|
清理种子缓存数据
|
||||||
|
"""
|
||||||
|
logger.info(f'开始清理种子缓存数据 ...')
|
||||||
|
self.remove_cache(self._spider_file)
|
||||||
|
self.remove_cache(self._rss_file)
|
||||||
|
logger.info(f'种子缓存数据清理完成')
|
||||||
|
|
||||||
|
@cached(cache=TTLCache(maxsize=128, ttl=595))
|
||||||
def browse(self, domain: str) -> List[TorrentInfo]:
|
def browse(self, domain: str) -> List[TorrentInfo]:
|
||||||
"""
|
"""
|
||||||
浏览站点首页内容,返回种子清单,TTL缓存10分钟
|
浏览站点首页内容,返回种子清单,TTL缓存10分钟
|
||||||
@@ -71,7 +85,7 @@ class TorrentsChain(ChainBase, metaclass=Singleton):
|
|||||||
return []
|
return []
|
||||||
return self.refresh_torrents(site=site)
|
return self.refresh_torrents(site=site)
|
||||||
|
|
||||||
@cached(cache=TTLCache(maxsize=128 if settings.BIG_MEMORY_MODE else 1, ttl=300))
|
@cached(cache=TTLCache(maxsize=128, ttl=295))
|
||||||
def rss(self, domain: str) -> List[TorrentInfo]:
|
def rss(self, domain: str) -> List[TorrentInfo]:
|
||||||
"""
|
"""
|
||||||
获取站点RSS内容,返回种子清单,TTL缓存5分钟
|
获取站点RSS内容,返回种子清单,TTL缓存5分钟
|
||||||
@@ -132,6 +146,11 @@ class TorrentsChain(ChainBase, metaclass=Singleton):
|
|||||||
# 读取缓存
|
# 读取缓存
|
||||||
torrents_cache = self.get_torrents()
|
torrents_cache = self.get_torrents()
|
||||||
|
|
||||||
|
# 缓存过滤掉无效种子
|
||||||
|
for _domain, _torrents in torrents_cache.items():
|
||||||
|
torrents_cache[_domain] = [_torrent for _torrent in _torrents
|
||||||
|
if not self.torrenthelper.is_invalid(_torrent.torrent_info.enclosure)]
|
||||||
|
|
||||||
# 所有站点索引
|
# 所有站点索引
|
||||||
indexers = self.siteshelper.get_indexers()
|
indexers = self.siteshelper.get_indexers()
|
||||||
# 遍历站点缓存资源
|
# 遍历站点缓存资源
|
||||||
@@ -166,7 +185,7 @@ class TorrentsChain(ChainBase, metaclass=Singleton):
|
|||||||
# 识别
|
# 识别
|
||||||
meta = MetaInfo(title=torrent.title, subtitle=torrent.description)
|
meta = MetaInfo(title=torrent.title, subtitle=torrent.description)
|
||||||
# 识别媒体信息
|
# 识别媒体信息
|
||||||
mediainfo: MediaInfo = self.recognize_media(meta=meta)
|
mediainfo: MediaInfo = self.mediachain.recognize_by_meta(meta)
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
logger.warn(f'未识别到媒体信息,标题:{torrent.title}')
|
logger.warn(f'未识别到媒体信息,标题:{torrent.title}')
|
||||||
# 存储空的媒体信息
|
# 存储空的媒体信息
|
||||||
@@ -228,5 +247,5 @@ class TorrentsChain(ChainBase, metaclass=Singleton):
|
|||||||
self.post_message(
|
self.post_message(
|
||||||
Notification(mtype=NotificationType.SiteMessage, title=f"站点 {domain} RSS链接已过期"))
|
Notification(mtype=NotificationType.SiteMessage, title=f"站点 {domain} RSS链接已过期"))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(str(e))
|
logger.error(f"站点 {domain} RSS链接自动获取失败:{str(e)} - {traceback.format_exc()}")
|
||||||
self.post_message(Notification(mtype=NotificationType.SiteMessage, title=f"站点 {domain} RSS链接已过期"))
|
self.post_message(Notification(mtype=NotificationType.SiteMessage, title=f"站点 {domain} RSS链接已过期"))
|
||||||
|
|||||||
@@ -66,7 +66,8 @@ class TransferChain(ChainBase):
|
|||||||
mtype = MediaType(downloadhis.type)
|
mtype = MediaType(downloadhis.type)
|
||||||
# 按TMDBID识别
|
# 按TMDBID识别
|
||||||
mediainfo = self.recognize_media(mtype=mtype,
|
mediainfo = self.recognize_media(mtype=mtype,
|
||||||
tmdbid=downloadhis.tmdbid)
|
tmdbid=downloadhis.tmdbid,
|
||||||
|
doubanid=downloadhis.doubanid)
|
||||||
else:
|
else:
|
||||||
# 非MoviePilot下载的任务,按文件识别
|
# 非MoviePilot下载的任务,按文件识别
|
||||||
mediainfo = None
|
mediainfo = None
|
||||||
@@ -243,7 +244,7 @@ class TransferChain(ChainBase):
|
|||||||
|
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
# 识别媒体信息
|
# 识别媒体信息
|
||||||
file_mediainfo = self.recognize_media(meta=file_meta)
|
file_mediainfo = self.mediachain.recognize_by_meta(file_meta)
|
||||||
else:
|
else:
|
||||||
file_mediainfo = mediainfo
|
file_mediainfo = mediainfo
|
||||||
|
|
||||||
@@ -258,8 +259,8 @@ class TransferChain(ChainBase):
|
|||||||
)
|
)
|
||||||
self.post_message(Notification(
|
self.post_message(Notification(
|
||||||
mtype=NotificationType.Manual,
|
mtype=NotificationType.Manual,
|
||||||
title=f"{file_path.name} 未识别到媒体信息,无法入库!\n"
|
title=f"{file_path.name} 未识别到媒体信息,无法入库!",
|
||||||
f"回复:```\n/redo {his.id} [tmdbid]|[类型]\n``` 手动识别转移。"
|
text=f"回复:```\n/redo {his.id} [tmdbid]|[类型]\n``` 手动识别转移。"
|
||||||
))
|
))
|
||||||
# 计数
|
# 计数
|
||||||
processed_num += 1
|
processed_num += 1
|
||||||
@@ -275,9 +276,6 @@ class TransferChain(ChainBase):
|
|||||||
|
|
||||||
logger.info(f"{file_path.name} 识别为:{file_mediainfo.type.value} {file_mediainfo.title_year}")
|
logger.info(f"{file_path.name} 识别为:{file_mediainfo.type.value} {file_mediainfo.title_year}")
|
||||||
|
|
||||||
# 更新媒体图片
|
|
||||||
self.obtain_images(mediainfo=file_mediainfo)
|
|
||||||
|
|
||||||
# 获取集数据
|
# 获取集数据
|
||||||
if file_mediainfo.type == MediaType.TV:
|
if file_mediainfo.type == MediaType.TV:
|
||||||
episodes_info = self.tmdbchain.tmdb_episodes(tmdbid=file_mediainfo.tmdb_id,
|
episodes_info = self.tmdbchain.tmdb_episodes(tmdbid=file_mediainfo.tmdb_id,
|
||||||
@@ -375,9 +373,6 @@ class TransferChain(ChainBase):
|
|||||||
# 媒体目录
|
# 媒体目录
|
||||||
if transfer_info.target_path.is_file():
|
if transfer_info.target_path.is_file():
|
||||||
transfer_info.target_path = transfer_info.target_path.parent
|
transfer_info.target_path = transfer_info.target_path.parent
|
||||||
# 刷新媒体库,根目录或季目录
|
|
||||||
if settings.REFRESH_MEDIASERVER:
|
|
||||||
self.refresh_mediaserver(mediainfo=media, file_path=transfer_info.target_path)
|
|
||||||
# 发送通知
|
# 发送通知
|
||||||
se_str = None
|
se_str = None
|
||||||
if media.type == MediaType.TV:
|
if media.type == MediaType.TV:
|
||||||
@@ -452,7 +447,7 @@ class TransferChain(ChainBase):
|
|||||||
|
|
||||||
def args_error():
|
def args_error():
|
||||||
self.post_message(Notification(channel=channel,
|
self.post_message(Notification(channel=channel,
|
||||||
title="请输入正确的命令格式:/redo [id] [tmdbid]|[类型],"
|
title="请输入正确的命令格式:/redo [id] [tmdbid/豆瓣id]|[类型],"
|
||||||
"[id]历史记录编号", userid=userid))
|
"[id]历史记录编号", userid=userid))
|
||||||
|
|
||||||
if not arg_str:
|
if not arg_str:
|
||||||
@@ -467,31 +462,50 @@ class TransferChain(ChainBase):
|
|||||||
if not logid.isdigit():
|
if not logid.isdigit():
|
||||||
args_error()
|
args_error()
|
||||||
return
|
return
|
||||||
# TMDB ID
|
# TMDBID/豆瓣ID
|
||||||
tmdb_strs = arg_strs[1].split('|')
|
id_strs = arg_strs[1].split('|')
|
||||||
tmdbid = tmdb_strs[0]
|
media_id = id_strs[0]
|
||||||
if not logid.isdigit():
|
if not logid.isdigit():
|
||||||
args_error()
|
args_error()
|
||||||
return
|
return
|
||||||
# 类型
|
# 类型
|
||||||
type_str = tmdb_strs[1] if len(tmdb_strs) > 1 else None
|
type_str = id_strs[1] if len(id_strs) > 1 else None
|
||||||
if not type_str or type_str not in [MediaType.MOVIE.value, MediaType.TV.value]:
|
if not type_str or type_str not in [MediaType.MOVIE.value, MediaType.TV.value]:
|
||||||
args_error()
|
args_error()
|
||||||
return
|
return
|
||||||
state, errmsg = self.re_transfer(logid=int(logid),
|
state, errmsg = self.re_transfer(logid=int(logid),
|
||||||
mtype=MediaType(type_str), tmdbid=int(tmdbid))
|
mtype=MediaType(type_str),
|
||||||
|
mediaid=media_id)
|
||||||
if not state:
|
if not state:
|
||||||
self.post_message(Notification(channel=channel, title="手动整理失败",
|
self.post_message(Notification(channel=channel, title="手动整理失败",
|
||||||
text=errmsg, userid=userid))
|
text=errmsg, userid=userid))
|
||||||
return
|
return
|
||||||
|
|
||||||
def re_transfer(self, logid: int,
|
@staticmethod
|
||||||
mtype: MediaType = None, tmdbid: int = None) -> Tuple[bool, str]:
|
def get_root_path(path: str, type_name: str, category: str) -> Path:
|
||||||
|
"""
|
||||||
|
计算媒体库目录的根路径
|
||||||
|
"""
|
||||||
|
if not path or path == "None":
|
||||||
|
return None
|
||||||
|
index = -2
|
||||||
|
if type_name != '电影':
|
||||||
|
index = -3
|
||||||
|
if category:
|
||||||
|
index -= 1
|
||||||
|
if '/' in path:
|
||||||
|
retpath = '/'.join(path.split('/')[:index])
|
||||||
|
else:
|
||||||
|
retpath = '\\'.join(path.split('\\')[:index])
|
||||||
|
return Path(retpath)
|
||||||
|
|
||||||
|
def re_transfer(self, logid: int, mtype: MediaType = None,
|
||||||
|
mediaid: str = None) -> Tuple[bool, str]:
|
||||||
"""
|
"""
|
||||||
根据历史记录,重新识别转移,只支持简单条件
|
根据历史记录,重新识别转移,只支持简单条件
|
||||||
:param logid: 历史记录ID
|
:param logid: 历史记录ID
|
||||||
:param mtype: 媒体类型
|
:param mtype: 媒体类型
|
||||||
:param tmdbid: TMDB ID
|
:param mediaid: TMDB ID/豆瓣ID
|
||||||
"""
|
"""
|
||||||
# 查询历史记录
|
# 查询历史记录
|
||||||
history: TransferHistory = self.transferhis.get(logid)
|
history: TransferHistory = self.transferhis.get(logid)
|
||||||
@@ -502,19 +516,20 @@ class TransferChain(ChainBase):
|
|||||||
src_path = Path(history.src)
|
src_path = Path(history.src)
|
||||||
if not src_path.exists():
|
if not src_path.exists():
|
||||||
return False, f"源目录不存在:{src_path}"
|
return False, f"源目录不存在:{src_path}"
|
||||||
dest_path = Path(history.dest) if history.dest else None
|
dest_path = self.get_root_path(path=history.dest, type_name=history.type, category=history.category)
|
||||||
# 查询媒体信息
|
# 查询媒体信息
|
||||||
if mtype and tmdbid:
|
if mtype and mediaid:
|
||||||
mediainfo = self.recognize_media(mtype=mtype, tmdbid=tmdbid)
|
mediainfo = self.recognize_media(mtype=mtype, tmdbid=int(mediaid) if str(mediaid).isdigit() else None,
|
||||||
|
doubanid=mediaid)
|
||||||
|
if mediainfo:
|
||||||
|
# 更新媒体图片
|
||||||
|
self.obtain_images(mediainfo=mediainfo)
|
||||||
else:
|
else:
|
||||||
meta = MetaInfoPath(src_path)
|
mediainfo = self.mediachain.recognize_by_path(str(src_path))
|
||||||
mediainfo = self.recognize_media(meta=meta)
|
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
return False, f"未识别到媒体信息,类型:{mtype.value},tmdbid:{tmdbid}"
|
return False, f"未识别到媒体信息,类型:{mtype.value},id:{mediaid}"
|
||||||
# 重新执行转移
|
# 重新执行转移
|
||||||
logger.info(f"{src_path.name} 识别为:{mediainfo.title_year}")
|
logger.info(f"{src_path.name} 识别为:{mediainfo.title_year}")
|
||||||
# 更新媒体图片
|
|
||||||
self.obtain_images(mediainfo=mediainfo)
|
|
||||||
|
|
||||||
# 删除旧的已整理文件
|
# 删除旧的已整理文件
|
||||||
if history.dest:
|
if history.dest:
|
||||||
@@ -617,14 +632,15 @@ class TransferChain(ChainBase):
|
|||||||
title=msg_title, text=msg_str, image=mediainfo.get_message_image()))
|
title=msg_title, text=msg_str, image=mediainfo.get_message_image()))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def delete_files(path: Path):
|
def delete_files(path: Path) -> Tuple[bool, str]:
|
||||||
"""
|
"""
|
||||||
删除转移后的文件以及空目录
|
删除转移后的文件以及空目录
|
||||||
:param path: 文件路径
|
:param path: 文件路径
|
||||||
|
:return: 成功标识,错误信息
|
||||||
"""
|
"""
|
||||||
logger.info(f"开始删除文件以及空目录:{path} ...")
|
logger.info(f"开始删除文件以及空目录:{path} ...")
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
return
|
return True, f"文件或目录不存在:{path}"
|
||||||
if path.is_file():
|
if path.is_file():
|
||||||
# 删除文件、nfo、jpg等同名文件
|
# 删除文件、nfo、jpg等同名文件
|
||||||
pattern = path.stem.replace('[', '?').replace(']', '?')
|
pattern = path.stem.replace('[', '?').replace(']', '?')
|
||||||
@@ -636,7 +652,7 @@ class TransferChain(ChainBase):
|
|||||||
elif str(path.parent) == str(path.root):
|
elif str(path.parent) == str(path.root):
|
||||||
# 根目录,不删除
|
# 根目录,不删除
|
||||||
logger.warn(f"根目录 {path} 不能删除!")
|
logger.warn(f"根目录 {path} 不能删除!")
|
||||||
return
|
return False, f"根目录 {path} 不能删除!"
|
||||||
else:
|
else:
|
||||||
# 非根目录,才删除目录
|
# 非根目录,才删除目录
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
@@ -662,5 +678,10 @@ class TransferChain(ChainBase):
|
|||||||
# 父目录非根目录,才删除父目录
|
# 父目录非根目录,才删除父目录
|
||||||
if not SystemUtils.exits_files(parent_path, settings.RMT_MEDIAEXT):
|
if not SystemUtils.exits_files(parent_path, settings.RMT_MEDIAEXT):
|
||||||
# 当前路径下没有媒体文件则删除
|
# 当前路径下没有媒体文件则删除
|
||||||
shutil.rmtree(parent_path)
|
try:
|
||||||
|
shutil.rmtree(parent_path)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"删除目录 {parent_path} 失败:{str(e)}")
|
||||||
|
return False, f"删除目录 {parent_path} 失败:{str(e)}"
|
||||||
logger.warn(f"目录 {parent_path} 已删除")
|
logger.warn(f"目录 {parent_path} 已删除")
|
||||||
|
return True, ""
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
import time
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from app.chain import ChainBase
|
from app.chain import ChainBase
|
||||||
from app.schemas import Notification
|
from app.schemas.types import EventType
|
||||||
from app.schemas.types import EventType, MediaImageType, MediaType, NotificationType
|
|
||||||
from app.utils.singleton import Singleton
|
from app.utils.singleton import Singleton
|
||||||
from app.utils.web import WebUtils
|
|
||||||
|
|
||||||
|
|
||||||
class WebhookChain(ChainBase, metaclass=Singleton):
|
class WebhookChain(ChainBase, metaclass=Singleton):
|
||||||
@@ -15,7 +12,7 @@ class WebhookChain(ChainBase, metaclass=Singleton):
|
|||||||
|
|
||||||
def message(self, body: Any, form: Any, args: Any) -> None:
|
def message(self, body: Any, form: Any, args: Any) -> None:
|
||||||
"""
|
"""
|
||||||
处理Webhook报文并发送消息
|
处理Webhook报文并发送事件
|
||||||
"""
|
"""
|
||||||
# 获取主体内容
|
# 获取主体内容
|
||||||
event_info = self.webhook_parser(body=body, form=form, args=args)
|
event_info = self.webhook_parser(body=body, form=form, args=args)
|
||||||
@@ -23,76 +20,3 @@ class WebhookChain(ChainBase, metaclass=Singleton):
|
|||||||
return
|
return
|
||||||
# 广播事件
|
# 广播事件
|
||||||
self.eventmanager.send_event(EventType.WebhookMessage, event_info)
|
self.eventmanager.send_event(EventType.WebhookMessage, event_info)
|
||||||
# 拼装消息内容
|
|
||||||
_webhook_actions = {
|
|
||||||
"library.new": "新入库",
|
|
||||||
"system.webhooktest": "测试",
|
|
||||||
"playback.start": "开始播放",
|
|
||||||
"playback.stop": "停止播放",
|
|
||||||
"user.authenticated": "登录成功",
|
|
||||||
"user.authenticationfailed": "登录失败",
|
|
||||||
"media.play": "开始播放",
|
|
||||||
"media.stop": "停止播放",
|
|
||||||
"PlaybackStart": "开始播放",
|
|
||||||
"PlaybackStop": "停止播放",
|
|
||||||
"item.rate": "标记了"
|
|
||||||
}
|
|
||||||
_webhook_images = {
|
|
||||||
"emby": "https://emby.media/notificationicon.png",
|
|
||||||
"plex": "https://www.plex.tv/wp-content/uploads/2022/04/new-logo-process-lines-gray.png",
|
|
||||||
"jellyfin": "https://play-lh.googleusercontent.com/SCsUK3hCCRqkJbmLDctNYCfehLxsS4ggD1ZPHIFrrAN1Tn9yhjmGMPep2D9lMaaa9eQi"
|
|
||||||
}
|
|
||||||
|
|
||||||
if not _webhook_actions.get(event_info.event):
|
|
||||||
return
|
|
||||||
|
|
||||||
# 消息标题
|
|
||||||
if event_info.item_type in ["TV", "SHOW"]:
|
|
||||||
message_title = f"{_webhook_actions.get(event_info.event)}剧集 {event_info.item_name}"
|
|
||||||
elif event_info.item_type == "MOV":
|
|
||||||
message_title = f"{_webhook_actions.get(event_info.event)}电影 {event_info.item_name}"
|
|
||||||
elif event_info.item_type == "AUD":
|
|
||||||
message_title = f"{_webhook_actions.get(event_info.event)}有声书 {event_info.item_name}"
|
|
||||||
else:
|
|
||||||
message_title = f"{_webhook_actions.get(event_info.event)}"
|
|
||||||
|
|
||||||
# 消息内容
|
|
||||||
message_texts = []
|
|
||||||
if event_info.user_name:
|
|
||||||
message_texts.append(f"用户:{event_info.user_name}")
|
|
||||||
if event_info.device_name:
|
|
||||||
message_texts.append(f"设备:{event_info.client} {event_info.device_name}")
|
|
||||||
if event_info.ip:
|
|
||||||
message_texts.append(f"IP地址:{event_info.ip} {WebUtils.get_location(event_info.ip)}")
|
|
||||||
if event_info.percentage:
|
|
||||||
percentage = round(float(event_info.percentage), 2)
|
|
||||||
message_texts.append(f"进度:{percentage}%")
|
|
||||||
if event_info.overview:
|
|
||||||
message_texts.append(f"剧情:{event_info.overview}")
|
|
||||||
message_texts.append(f"时间:{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))}")
|
|
||||||
|
|
||||||
# 消息内容
|
|
||||||
message_content = "\n".join(message_texts)
|
|
||||||
|
|
||||||
# 消息图片
|
|
||||||
image_url = event_info.image_url
|
|
||||||
# 查询剧集图片
|
|
||||||
if (event_info.tmdb_id
|
|
||||||
and event_info.season_id
|
|
||||||
and event_info.episode_id):
|
|
||||||
specific_image = self.obtain_specific_image(
|
|
||||||
mediaid=event_info.tmdb_id,
|
|
||||||
mtype=MediaType.TV,
|
|
||||||
image_type=MediaImageType.Backdrop,
|
|
||||||
season=event_info.season_id,
|
|
||||||
episode=event_info.episode_id
|
|
||||||
)
|
|
||||||
if specific_image:
|
|
||||||
image_url = specific_image
|
|
||||||
# 使用默认图片
|
|
||||||
if not image_url:
|
|
||||||
image_url = _webhook_images.get(event_info.channel)
|
|
||||||
|
|
||||||
# 发送消息
|
|
||||||
self.post_message(Notification(mtype=NotificationType.MediaServer,
|
|
||||||
title=message_title, text=message_content, image=image_url))
|
|
||||||
|
|||||||
@@ -149,12 +149,6 @@ class Command(metaclass=Singleton):
|
|||||||
"description": "当前版本",
|
"description": "当前版本",
|
||||||
"category": "管理",
|
"category": "管理",
|
||||||
"data": {}
|
"data": {}
|
||||||
},
|
|
||||||
"/update": {
|
|
||||||
"func": SystemChain().update,
|
|
||||||
"description": "更新系统",
|
|
||||||
"category": "管理",
|
|
||||||
"data": {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# 汇总插件命令
|
# 汇总插件命令
|
||||||
@@ -321,8 +315,7 @@ class Command(metaclass=Singleton):
|
|||||||
else:
|
else:
|
||||||
logger.info(f"{command.get('description')} 执行完成")
|
logger.info(f"{command.get('description')} 执行完成")
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.error(f"执行命令 {cmd} 出错:{str(err)}")
|
logger.error(f"执行命令 {cmd} 出错:{str(err)} - {traceback.format_exc()}")
|
||||||
traceback.print_exc()
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def send_plugin_event(etype: EventType, data: dict) -> None:
|
def send_plugin_event(etype: EventType, data: dict) -> None:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import secrets
|
import secrets
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List
|
from typing import List, Optional
|
||||||
|
|
||||||
from pydantic import BaseSettings
|
from pydantic import BaseSettings
|
||||||
|
|
||||||
@@ -35,20 +35,20 @@ class Settings(BaseSettings):
|
|||||||
CONFIG_DIR: str = None
|
CONFIG_DIR: str = None
|
||||||
# 超级管理员
|
# 超级管理员
|
||||||
SUPERUSER: str = "admin"
|
SUPERUSER: str = "admin"
|
||||||
# 超级管理员初始密码
|
|
||||||
SUPERUSER_PASSWORD: str = "password"
|
|
||||||
# API密钥,需要更换
|
# API密钥,需要更换
|
||||||
API_TOKEN: str = "moviepilot"
|
API_TOKEN: str = "moviepilot"
|
||||||
|
# 登录页面电影海报,tmdb/bing
|
||||||
|
WALLPAPER: str = "tmdb"
|
||||||
# 网络代理 IP:PORT
|
# 网络代理 IP:PORT
|
||||||
PROXY_HOST: str = None
|
PROXY_HOST: str = None
|
||||||
# 媒体信息搜索来源
|
# 媒体识别来源 themoviedb/douban
|
||||||
SEARCH_SOURCE: str = "themoviedb"
|
RECOGNIZE_SOURCE: str = "themoviedb"
|
||||||
|
# 刮削来源 themoviedb/douban
|
||||||
|
SCRAP_SOURCE: str = "themoviedb"
|
||||||
# 刮削入库的媒体文件
|
# 刮削入库的媒体文件
|
||||||
SCRAP_METADATA: bool = True
|
SCRAP_METADATA: bool = True
|
||||||
# 新增已入库媒体是否跟随TMDB信息变化
|
# 新增已入库媒体是否跟随TMDB信息变化
|
||||||
SCRAP_FOLLOW_TMDB: bool = True
|
SCRAP_FOLLOW_TMDB: bool = True
|
||||||
# 刮削来源
|
|
||||||
SCRAP_SOURCE: str = "themoviedb"
|
|
||||||
# TMDB图片地址
|
# TMDB图片地址
|
||||||
TMDB_IMAGE_DOMAIN: str = "image.tmdb.org"
|
TMDB_IMAGE_DOMAIN: str = "image.tmdb.org"
|
||||||
# TMDB API地址
|
# TMDB API地址
|
||||||
@@ -57,6 +57,8 @@ class Settings(BaseSettings):
|
|||||||
TMDB_API_KEY: str = "db55323b8d3e4154498498a75642b381"
|
TMDB_API_KEY: str = "db55323b8d3e4154498498a75642b381"
|
||||||
# TVDB API Key
|
# TVDB API Key
|
||||||
TVDB_API_KEY: str = "6b481081-10aa-440c-99f2-21d17717ee02"
|
TVDB_API_KEY: str = "6b481081-10aa-440c-99f2-21d17717ee02"
|
||||||
|
# Fanart开关
|
||||||
|
FANART_ENABLE: bool = True
|
||||||
# Fanart API Key
|
# Fanart API Key
|
||||||
FANART_API_KEY: str = "d2d31f9ecabea050fc7d68aa3146015f"
|
FANART_API_KEY: str = "d2d31f9ecabea050fc7d68aa3146015f"
|
||||||
# 支持的后缀格式
|
# 支持的后缀格式
|
||||||
@@ -127,6 +129,10 @@ class Settings(BaseSettings):
|
|||||||
QB_PASSWORD: str = None
|
QB_PASSWORD: str = None
|
||||||
# Qbittorrent分类自动管理
|
# Qbittorrent分类自动管理
|
||||||
QB_CATEGORY: bool = False
|
QB_CATEGORY: bool = False
|
||||||
|
# Qbittorrent按顺序下载
|
||||||
|
QB_SEQUENTIAL: bool = True
|
||||||
|
# Qbittorrent忽略队列限制,强制继续
|
||||||
|
QB_FORCE_RESUME: bool = False
|
||||||
# Transmission地址,IP:PORT
|
# Transmission地址,IP:PORT
|
||||||
TR_HOST: str = None
|
TR_HOST: str = None
|
||||||
# Transmission用户名
|
# Transmission用户名
|
||||||
@@ -136,7 +142,7 @@ class Settings(BaseSettings):
|
|||||||
# 种子标签
|
# 种子标签
|
||||||
TORRENT_TAG: str = "MOVIEPILOT"
|
TORRENT_TAG: str = "MOVIEPILOT"
|
||||||
# 下载保存目录,容器内映射路径需要一致
|
# 下载保存目录,容器内映射路径需要一致
|
||||||
DOWNLOAD_PATH: str = "/downloads"
|
DOWNLOAD_PATH: str = None
|
||||||
# 电影下载保存目录,容器内映射路径需要一致
|
# 电影下载保存目录,容器内映射路径需要一致
|
||||||
DOWNLOAD_MOVIE_PATH: str = None
|
DOWNLOAD_MOVIE_PATH: str = None
|
||||||
# 电视剧下载保存目录,容器内映射路径需要一致
|
# 电视剧下载保存目录,容器内映射路径需要一致
|
||||||
@@ -149,22 +155,26 @@ class Settings(BaseSettings):
|
|||||||
DOWNLOAD_SUBTITLE: bool = True
|
DOWNLOAD_SUBTITLE: bool = True
|
||||||
# 媒体服务器 emby/jellyfin/plex,多个媒体服务器,分割
|
# 媒体服务器 emby/jellyfin/plex,多个媒体服务器,分割
|
||||||
MEDIASERVER: str = "emby"
|
MEDIASERVER: str = "emby"
|
||||||
# 入库刷新媒体库
|
|
||||||
REFRESH_MEDIASERVER: bool = True
|
|
||||||
# 媒体服务器同步间隔(小时)
|
# 媒体服务器同步间隔(小时)
|
||||||
MEDIASERVER_SYNC_INTERVAL: int = 6
|
MEDIASERVER_SYNC_INTERVAL: Optional[int] = 6
|
||||||
# 媒体服务器同步黑名单,多个媒体库名称,分割
|
# 媒体服务器同步黑名单,多个媒体库名称,分割
|
||||||
MEDIASERVER_SYNC_BLACKLIST: str = None
|
MEDIASERVER_SYNC_BLACKLIST: str = None
|
||||||
# EMBY服务器地址,IP:PORT
|
# EMBY服务器地址,IP:PORT
|
||||||
EMBY_HOST: str = None
|
EMBY_HOST: str = None
|
||||||
|
# EMBY外网地址,http(s)://DOMAIN:PORT,未设置时使用EMBY_HOST
|
||||||
|
EMBY_PLAY_HOST: str = None
|
||||||
# EMBY Api Key
|
# EMBY Api Key
|
||||||
EMBY_API_KEY: str = None
|
EMBY_API_KEY: str = None
|
||||||
# Jellyfin服务器地址,IP:PORT
|
# Jellyfin服务器地址,IP:PORT
|
||||||
JELLYFIN_HOST: str = None
|
JELLYFIN_HOST: str = None
|
||||||
|
# Jellyfin外网地址,http(s)://DOMAIN:PORT,未设置时使用JELLYFIN_HOST
|
||||||
|
JELLYFIN_PLAY_HOST: str = None
|
||||||
# Jellyfin Api Key
|
# Jellyfin Api Key
|
||||||
JELLYFIN_API_KEY: str = None
|
JELLYFIN_API_KEY: str = None
|
||||||
# Plex服务器地址,IP:PORT
|
# Plex服务器地址,IP:PORT
|
||||||
PLEX_HOST: str = None
|
PLEX_HOST: str = None
|
||||||
|
# Plex外网地址,http(s)://DOMAIN:PORT,未设置时使用PLEX_HOST
|
||||||
|
PLEX_PLAY_HOST: str = None
|
||||||
# Plex Token
|
# Plex Token
|
||||||
PLEX_TOKEN: str = None
|
PLEX_TOKEN: str = None
|
||||||
# 转移方式 link/copy/move/softlink
|
# 转移方式 link/copy/move/softlink
|
||||||
@@ -176,18 +186,18 @@ class Settings(BaseSettings):
|
|||||||
# CookieCloud端对端加密密码
|
# CookieCloud端对端加密密码
|
||||||
COOKIECLOUD_PASSWORD: str = None
|
COOKIECLOUD_PASSWORD: str = None
|
||||||
# CookieCloud同步间隔(分钟)
|
# CookieCloud同步间隔(分钟)
|
||||||
COOKIECLOUD_INTERVAL: int = 60 * 24
|
COOKIECLOUD_INTERVAL: Optional[int] = 60 * 24
|
||||||
# OCR服务器地址
|
# OCR服务器地址
|
||||||
OCR_HOST: str = "https://movie-pilot.org"
|
OCR_HOST: str = "https://movie-pilot.org"
|
||||||
# CookieCloud对应的浏览器UA
|
# CookieCloud对应的浏览器UA
|
||||||
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.57"
|
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.57"
|
||||||
# 媒体库目录,多个目录使用,分隔
|
# 媒体库目录,多个目录使用,分隔
|
||||||
LIBRARY_PATH: str = None
|
LIBRARY_PATH: str = None
|
||||||
# 电影媒体库目录名,默认"电影"
|
# 电影媒体库目录名
|
||||||
LIBRARY_MOVIE_NAME: str = None
|
LIBRARY_MOVIE_NAME: str = "电影"
|
||||||
# 电视剧媒体库目录名,默认"电视剧"
|
# 电视剧媒体库目录名
|
||||||
LIBRARY_TV_NAME: str = None
|
LIBRARY_TV_NAME: str = "电视剧"
|
||||||
# 动漫媒体库目录名,默认"电视剧/动漫"
|
# 动漫媒体库目录名,不设置时使用电视剧目录
|
||||||
LIBRARY_ANIME_NAME: str = None
|
LIBRARY_ANIME_NAME: str = None
|
||||||
# 二级分类
|
# 二级分类
|
||||||
LIBRARY_CATEGORY: bool = True
|
LIBRARY_CATEGORY: bool = True
|
||||||
@@ -202,8 +212,16 @@ class Settings(BaseSettings):
|
|||||||
"/Season {{season}}" \
|
"/Season {{season}}" \
|
||||||
"/{{title}} - {{season_episode}}{% if part %}-{{part}}{% endif %}{% if episode %} - 第 {{episode}} 集{% endif %}" \
|
"/{{title}} - {{season_episode}}{% if part %}-{{part}}{% endif %}{% if episode %} - 第 {{episode}} 集{% endif %}" \
|
||||||
"{{fileExt}}"
|
"{{fileExt}}"
|
||||||
|
# 转移时覆盖模式
|
||||||
|
OVERWRITE_MODE: str = "size"
|
||||||
# 大内存模式
|
# 大内存模式
|
||||||
BIG_MEMORY_MODE: bool = False
|
BIG_MEMORY_MODE: bool = False
|
||||||
|
# 插件市场仓库地址,多个地址使用,分隔,地址以/结尾
|
||||||
|
PLUGIN_MARKET: str = "https://github.com/jxxghp/MoviePilot-Plugins"
|
||||||
|
# Github token,提高请求api限流阈值 ghp_****
|
||||||
|
GITHUB_TOKEN: str = None
|
||||||
|
# 自动检查和更新站点资源包(站点索引、认证等)
|
||||||
|
AUTO_UPDATE_RESOURCE: bool = True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def INNER_CONFIG_PATH(self):
|
def INNER_CONFIG_PATH(self):
|
||||||
@@ -275,7 +293,54 @@ class Settings(BaseSettings):
|
|||||||
def LIBRARY_PATHS(self) -> List[Path]:
|
def LIBRARY_PATHS(self) -> List[Path]:
|
||||||
if self.LIBRARY_PATH:
|
if self.LIBRARY_PATH:
|
||||||
return [Path(path) for path in self.LIBRARY_PATH.split(",")]
|
return [Path(path) for path in self.LIBRARY_PATH.split(",")]
|
||||||
return []
|
return [self.CONFIG_PATH / "library"]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def SAVE_PATH(self) -> Path:
|
||||||
|
"""
|
||||||
|
获取下载保存目录
|
||||||
|
"""
|
||||||
|
if self.DOWNLOAD_PATH:
|
||||||
|
return Path(self.DOWNLOAD_PATH)
|
||||||
|
return self.CONFIG_PATH / "downloads"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def SAVE_MOVIE_PATH(self) -> Path:
|
||||||
|
"""
|
||||||
|
获取电影下载保存目录
|
||||||
|
"""
|
||||||
|
if self.DOWNLOAD_MOVIE_PATH:
|
||||||
|
return Path(self.DOWNLOAD_MOVIE_PATH)
|
||||||
|
return self.SAVE_PATH
|
||||||
|
|
||||||
|
@property
|
||||||
|
def SAVE_TV_PATH(self) -> Path:
|
||||||
|
"""
|
||||||
|
获取电视剧下载保存目录
|
||||||
|
"""
|
||||||
|
if self.DOWNLOAD_TV_PATH:
|
||||||
|
return Path(self.DOWNLOAD_TV_PATH)
|
||||||
|
return self.SAVE_PATH
|
||||||
|
|
||||||
|
@property
|
||||||
|
def SAVE_ANIME_PATH(self) -> Path:
|
||||||
|
"""
|
||||||
|
获取动漫下载保存目录
|
||||||
|
"""
|
||||||
|
if self.DOWNLOAD_ANIME_PATH:
|
||||||
|
return Path(self.DOWNLOAD_ANIME_PATH)
|
||||||
|
return self.SAVE_TV_PATH
|
||||||
|
|
||||||
|
@property
|
||||||
|
def GITHUB_HEADERS(self):
|
||||||
|
"""
|
||||||
|
Github请求头
|
||||||
|
"""
|
||||||
|
if self.GITHUB_TOKEN:
|
||||||
|
return {
|
||||||
|
"Authorization": f"Bearer {self.GITHUB_TOKEN}"
|
||||||
|
}
|
||||||
|
return {}
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from app.core.config import settings
|
|||||||
from app.core.meta import MetaBase
|
from app.core.meta import MetaBase
|
||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo
|
||||||
from app.schemas.types import MediaType
|
from app.schemas.types import MediaType
|
||||||
|
from app.utils.string import StringUtils
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -44,6 +45,8 @@ class TorrentInfo:
|
|||||||
pubdate: str = None
|
pubdate: str = None
|
||||||
# 已过时间
|
# 已过时间
|
||||||
date_elapsed: str = None
|
date_elapsed: str = None
|
||||||
|
# 免费截止时间
|
||||||
|
freedate: str = None
|
||||||
# 上传因子
|
# 上传因子
|
||||||
uploadvolumefactor: float = None
|
uploadvolumefactor: float = None
|
||||||
# 下载因子
|
# 下载因子
|
||||||
@@ -90,7 +93,9 @@ class TorrentInfo:
|
|||||||
"1.0 1.0": "普通",
|
"1.0 1.0": "普通",
|
||||||
"1.0 0.0": "免费",
|
"1.0 0.0": "免费",
|
||||||
"2.0 1.0": "2X",
|
"2.0 1.0": "2X",
|
||||||
|
"4.0 1.0": "4X",
|
||||||
"2.0 0.0": "2X免费",
|
"2.0 0.0": "2X免费",
|
||||||
|
"4.0 0.0": "4X免费",
|
||||||
"1.0 0.5": "50%",
|
"1.0 0.5": "50%",
|
||||||
"2.0 0.5": "2X 50%",
|
"2.0 0.5": "2X 50%",
|
||||||
"1.0 0.7": "70%",
|
"1.0 0.7": "70%",
|
||||||
@@ -105,12 +110,22 @@ class TorrentInfo:
|
|||||||
"""
|
"""
|
||||||
return self.get_free_string(self.uploadvolumefactor, self.downloadvolumefactor)
|
return self.get_free_string(self.uploadvolumefactor, self.downloadvolumefactor)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def freedate_diff(self):
|
||||||
|
"""
|
||||||
|
返回免费剩余时间
|
||||||
|
"""
|
||||||
|
if not self.freedate:
|
||||||
|
return ""
|
||||||
|
return StringUtils.diff_time_str(self.freedate)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
"""
|
"""
|
||||||
返回字典
|
返回字典
|
||||||
"""
|
"""
|
||||||
dicts = asdict(self)
|
dicts = asdict(self)
|
||||||
dicts["volume_factor"] = self.volume_factor
|
dicts["volume_factor"] = self.volume_factor
|
||||||
|
dicts["freedate_diff"] = self.freedate_diff
|
||||||
return dicts
|
return dicts
|
||||||
|
|
||||||
|
|
||||||
@@ -414,24 +429,31 @@ class MediaInfo:
|
|||||||
# 豆瓣ID
|
# 豆瓣ID
|
||||||
self.douban_id = str(info.get("id"))
|
self.douban_id = str(info.get("id"))
|
||||||
# 类型
|
# 类型
|
||||||
|
|
||||||
if not self.type:
|
if not self.type:
|
||||||
if isinstance(info.get('media_type'), MediaType):
|
if isinstance(info.get('media_type'), MediaType):
|
||||||
self.type = info.get('media_type')
|
self.type = info.get('media_type')
|
||||||
else:
|
elif info.get("type"):
|
||||||
self.type = MediaType.MOVIE if info.get("type") == "movie" else MediaType.TV
|
self.type = MediaType.MOVIE if info.get("type") == "movie" else MediaType.TV
|
||||||
|
elif info.get("type_name"):
|
||||||
|
self.type = MediaType(info.get("type_name"))
|
||||||
# 标题
|
# 标题
|
||||||
if not self.title:
|
if not self.title:
|
||||||
self.title = info.get("title")
|
self.title = info.get("title")
|
||||||
# 识别标题中的季
|
|
||||||
meta = MetaInfo(self.title)
|
|
||||||
self.season = meta.begin_season
|
|
||||||
# 原语种标题
|
# 原语种标题
|
||||||
if not self.original_title:
|
if not self.original_title:
|
||||||
self.original_title = info.get("original_title")
|
self.original_title = info.get("original_title")
|
||||||
# 年份
|
# 年份
|
||||||
if not self.year:
|
if not self.year:
|
||||||
self.year = info.get("year")[:4] if info.get("year") else None
|
self.year = info.get("year")[:4] if info.get("year") else None
|
||||||
|
# 识别标题中的季
|
||||||
|
meta = MetaInfo(info.get("title"))
|
||||||
|
# 季
|
||||||
|
if not self.season:
|
||||||
|
self.season = meta.begin_season
|
||||||
|
if self.season:
|
||||||
|
self.type = MediaType.TV
|
||||||
|
elif not self.type:
|
||||||
|
self.type = MediaType.MOVIE
|
||||||
# 评分
|
# 评分
|
||||||
if not self.vote_average:
|
if not self.vote_average:
|
||||||
rating = info.get("rating")
|
rating = info.get("rating")
|
||||||
@@ -472,14 +494,34 @@ class MediaInfo:
|
|||||||
self.actors = info.get("actors") or []
|
self.actors = info.get("actors") or []
|
||||||
# 别名
|
# 别名
|
||||||
if not self.names:
|
if not self.names:
|
||||||
self.names = info.get("aka") or []
|
akas = info.get("aka")
|
||||||
|
if akas:
|
||||||
|
self.names = [re.sub(r'\([港台豆友译名]+\)', "", aka) for aka in akas]
|
||||||
# 剧集
|
# 剧集
|
||||||
if self.type == MediaType.TV and not self.seasons:
|
if self.type == MediaType.TV and not self.seasons:
|
||||||
meta = MetaInfo(info.get("title"))
|
meta = MetaInfo(info.get("title"))
|
||||||
if meta.begin_season:
|
season = meta.begin_season or 1
|
||||||
episodes_count = info.get("episodes_count")
|
episodes_count = info.get("episodes_count")
|
||||||
if episodes_count:
|
if episodes_count:
|
||||||
self.seasons[meta.begin_season] = list(range(1, episodes_count + 1))
|
self.seasons[season] = list(range(1, episodes_count + 1))
|
||||||
|
# 季年份
|
||||||
|
if self.type == MediaType.TV and not self.season_years:
|
||||||
|
season = self.season or 1
|
||||||
|
self.season_years = {
|
||||||
|
season: self.year
|
||||||
|
}
|
||||||
|
# 风格
|
||||||
|
if not self.genres:
|
||||||
|
self.genres = [{"id": genre, "name": genre} for genre in info.get("genres") or []]
|
||||||
|
# 时长
|
||||||
|
if not self.runtime and info.get("durations"):
|
||||||
|
# 查找数字
|
||||||
|
match = re.search(r'\d+', info.get("durations")[0])
|
||||||
|
if match:
|
||||||
|
self.runtime = int(match.group())
|
||||||
|
# 国家
|
||||||
|
if not self.production_countries:
|
||||||
|
self.production_countries = [{"id": country, "name": country} for country in info.get("countries") or []]
|
||||||
# 剩余属性赋值
|
# 剩余属性赋值
|
||||||
for key, value in info.items():
|
for key, value in info.items():
|
||||||
if not hasattr(self, key):
|
if not hasattr(self, key):
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from queue import Queue, Empty
|
from queue import Queue, Empty
|
||||||
|
from typing import Dict, Any
|
||||||
|
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.utils.singleton import Singleton
|
from app.utils.singleton import Singleton
|
||||||
@@ -14,7 +15,7 @@ class EventManager(metaclass=Singleton):
|
|||||||
# 事件队列
|
# 事件队列
|
||||||
self._eventQueue = Queue()
|
self._eventQueue = Queue()
|
||||||
# 事件响应函数字典
|
# 事件响应函数字典
|
||||||
self._handlers = {}
|
self._handlers: Dict[str, Dict[str, Any]] = {}
|
||||||
# 已禁用的事件响应
|
# 已禁用的事件响应
|
||||||
self._disabled_handlers = []
|
self._disabled_handlers = []
|
||||||
|
|
||||||
@@ -24,12 +25,13 @@ class EventManager(metaclass=Singleton):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
event = self._eventQueue.get(block=True, timeout=1)
|
event = self._eventQueue.get(block=True, timeout=1)
|
||||||
handlerList = self._handlers.get(event.event_type) or []
|
handlers = self._handlers.get(event.event_type) or {}
|
||||||
if handlerList:
|
if handlers:
|
||||||
# 去除掉被禁用的事件响应
|
# 去除掉被禁用的事件响应
|
||||||
handlerList = [handler for handler in handlerList
|
handlerList = [handler for handler in handlers.values()
|
||||||
if handler.__qualname__.split(".")[0] not in self._disabled_handlers]
|
if handler.__qualname__.split(".")[0] not in self._disabled_handlers]
|
||||||
return event, handlerList
|
return event, handlerList
|
||||||
|
return event, []
|
||||||
except Empty:
|
except Empty:
|
||||||
return None, []
|
return None, []
|
||||||
|
|
||||||
@@ -44,13 +46,15 @@ class EventManager(metaclass=Singleton):
|
|||||||
注册事件处理
|
注册事件处理
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
handlerList = self._handlers[etype.value]
|
handlers = self._handlers[etype.value]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
handlerList = []
|
handlers = {}
|
||||||
self._handlers[etype.value] = handlerList
|
self._handlers[etype.value] = handlers
|
||||||
if handler not in handlerList:
|
if handler.__qualname__ in handlers:
|
||||||
handlerList.append(handler)
|
handlers.pop(handler.__qualname__)
|
||||||
logger.debug(f"Event Registed:{etype.value} - {handler}")
|
else:
|
||||||
|
logger.debug(f"Event Registed:{etype.value} - {handler.__qualname__}")
|
||||||
|
handlers[handler.__qualname__] = handler
|
||||||
|
|
||||||
def disable_events_hander(self, class_name: str):
|
def disable_events_hander(self, class_name: str):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import re
|
import re
|
||||||
|
import traceback
|
||||||
|
|
||||||
import zhconv
|
import zhconv
|
||||||
import anitopy
|
import anitopy
|
||||||
from app.core.meta.customization import CustomizationMatcher
|
from app.core.meta.customization import CustomizationMatcher
|
||||||
from app.core.meta.metabase import MetaBase
|
from app.core.meta.metabase import MetaBase
|
||||||
from app.core.meta.releasegroup import ReleaseGroupsMatcher
|
from app.core.meta.releasegroup import ReleaseGroupsMatcher
|
||||||
|
from app.log import logger
|
||||||
from app.utils.string import StringUtils
|
from app.utils.string import StringUtils
|
||||||
from app.schemas.types import MediaType
|
from app.schemas.types import MediaType
|
||||||
|
|
||||||
@@ -117,7 +120,7 @@ class MetaAnime(MetaBase):
|
|||||||
else:
|
else:
|
||||||
self.total_episode = 1
|
self.total_episode = 1
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(str(err))
|
logger.debug(f"解析集数失败:{str(err)} - {traceback.format_exc()}")
|
||||||
self.begin_episode = None
|
self.begin_episode = None
|
||||||
self.end_episode = None
|
self.end_episode = None
|
||||||
self.type = MediaType.TV
|
self.type = MediaType.TV
|
||||||
@@ -162,7 +165,7 @@ class MetaAnime(MetaBase):
|
|||||||
if not self.type:
|
if not self.type:
|
||||||
self.type = MediaType.TV
|
self.type = MediaType.TV
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(str(e))
|
logger.error(f"解析动漫信息失败:{str(e)} - {traceback.format_exc()}")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __prepare_title(title: str):
|
def __prepare_title(title: str):
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
|
import traceback
|
||||||
from dataclasses import dataclass, asdict
|
from dataclasses import dataclass, asdict
|
||||||
from typing import Union, Optional, List, Self
|
from typing import Union, Optional, List, Self
|
||||||
|
|
||||||
import cn2an
|
import cn2an
|
||||||
import regex as re
|
import regex as re
|
||||||
|
|
||||||
|
from app.log import logger
|
||||||
from app.utils.string import StringUtils
|
from app.utils.string import StringUtils
|
||||||
from app.schemas.types import MediaType
|
from app.schemas.types import MediaType
|
||||||
|
|
||||||
@@ -59,6 +61,9 @@ class MetaBase(object):
|
|||||||
audio_encode: Optional[str] = None
|
audio_encode: Optional[str] = None
|
||||||
# 应用的识别词信息
|
# 应用的识别词信息
|
||||||
apply_words: Optional[List[str]] = None
|
apply_words: Optional[List[str]] = None
|
||||||
|
# 附加信息
|
||||||
|
tmdbid: int = None
|
||||||
|
doubanid: str = None
|
||||||
|
|
||||||
# 副标题解析
|
# 副标题解析
|
||||||
_subtitle_flag = False
|
_subtitle_flag = False
|
||||||
@@ -124,7 +129,7 @@ class MetaBase(object):
|
|||||||
else:
|
else:
|
||||||
begin_season = int(cn2an.cn2an(seasons, mode='smart'))
|
begin_season = int(cn2an.cn2an(seasons, mode='smart'))
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(str(err))
|
logger.debug(f'识别季失败:{str(err)} - {traceback.format_exc()}')
|
||||||
return
|
return
|
||||||
if self.begin_season is None and isinstance(begin_season, int):
|
if self.begin_season is None and isinstance(begin_season, int):
|
||||||
self.begin_season = begin_season
|
self.begin_season = begin_season
|
||||||
@@ -155,7 +160,7 @@ class MetaBase(object):
|
|||||||
else:
|
else:
|
||||||
begin_episode = int(cn2an.cn2an(episodes, mode='smart'))
|
begin_episode = int(cn2an.cn2an(episodes, mode='smart'))
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(str(err))
|
logger.debug(f'识别集失败:{str(err)} - {traceback.format_exc()}')
|
||||||
return
|
return
|
||||||
if self.begin_episode is None and isinstance(begin_episode, int):
|
if self.begin_episode is None and isinstance(begin_episode, int):
|
||||||
self.begin_episode = begin_episode
|
self.begin_episode = begin_episode
|
||||||
@@ -178,7 +183,7 @@ class MetaBase(object):
|
|||||||
try:
|
try:
|
||||||
self.total_episode = int(cn2an.cn2an(episode_all.strip(), mode='smart'))
|
self.total_episode = int(cn2an.cn2an(episode_all.strip(), mode='smart'))
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(str(err))
|
logger.debug(f'识别集失败:{str(err)} - {traceback.format_exc()}')
|
||||||
return
|
return
|
||||||
self.begin_episode = None
|
self.begin_episode = None
|
||||||
self.end_episode = None
|
self.end_episode = None
|
||||||
@@ -194,7 +199,7 @@ class MetaBase(object):
|
|||||||
try:
|
try:
|
||||||
self.total_season = int(cn2an.cn2an(season_all.strip(), mode='smart'))
|
self.total_season = int(cn2an.cn2an(season_all.strip(), mode='smart'))
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(str(err))
|
logger.debug(f'识别季失败:{str(err)} - {traceback.format_exc()}')
|
||||||
return
|
return
|
||||||
self.begin_season = 1
|
self.begin_season = 1
|
||||||
self.end_season = self.total_season
|
self.end_season = self.total_season
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class MetaVideo(MetaBase):
|
|||||||
_name_no_begin_re = r"^\[.+?]"
|
_name_no_begin_re = r"^\[.+?]"
|
||||||
_name_no_chinese_re = r".*版|.*字幕"
|
_name_no_chinese_re = r".*版|.*字幕"
|
||||||
_name_se_words = ['共', '第', '季', '集', '话', '話', '期']
|
_name_se_words = ['共', '第', '季', '集', '话', '話', '期']
|
||||||
|
_name_movie_words = ['剧场版', '劇場版', '电影版', '電影版']
|
||||||
_name_nostring_re = r"^PTS|^JADE|^AOD|^CHC|^[A-Z]{1,4}TV[\-0-9UVHDK]*" \
|
_name_nostring_re = r"^PTS|^JADE|^AOD|^CHC|^[A-Z]{1,4}TV[\-0-9UVHDK]*" \
|
||||||
r"|HBO$|\s+HBO|\d{1,2}th|\d{1,2}bit|NETFLIX|AMAZON|IMAX|^3D|\s+3D|^BBC\s+|\s+BBC|BBC$|DISNEY\+?|XXX|\s+DC$" \
|
r"|HBO$|\s+HBO|\d{1,2}th|\d{1,2}bit|NETFLIX|AMAZON|IMAX|^3D|\s+3D|^BBC\s+|\s+BBC|BBC$|DISNEY\+?|XXX|\s+DC$" \
|
||||||
r"|[第\s共]+[0-9一二三四五六七八九十\-\s]+季" \
|
r"|[第\s共]+[0-9一二三四五六七八九十\-\s]+季" \
|
||||||
@@ -182,8 +183,9 @@ class MetaVideo(MetaBase):
|
|||||||
if not self.cn_name:
|
if not self.cn_name:
|
||||||
self.cn_name = token
|
self.cn_name = token
|
||||||
elif not self._stop_cnname_flag:
|
elif not self._stop_cnname_flag:
|
||||||
if not re.search("%s" % self._name_no_chinese_re, token, flags=re.IGNORECASE) \
|
if re.search("%s" % self._name_movie_words, token, flags=re.IGNORECASE) \
|
||||||
and not re.search("%s" % self._name_se_words, token, flags=re.IGNORECASE):
|
or (not re.search("%s" % self._name_no_chinese_re, token, flags=re.IGNORECASE)
|
||||||
|
and not re.search("%s" % self._name_se_words, token, flags=re.IGNORECASE)):
|
||||||
self.cn_name = "%s %s" % (self.cn_name, token)
|
self.cn_name = "%s %s" % (self.cn_name, token)
|
||||||
self._stop_cnname_flag = True
|
self._stop_cnname_flag = True
|
||||||
else:
|
else:
|
||||||
@@ -268,7 +270,7 @@ class MetaVideo(MetaBase):
|
|||||||
self.tokens.get_next()
|
self.tokens.get_next()
|
||||||
self._last_token_type = "part"
|
self._last_token_type = "part"
|
||||||
self._continue_flag = False
|
self._continue_flag = False
|
||||||
self._stop_name_flag = False
|
# self._stop_name_flag = False
|
||||||
|
|
||||||
def __init_year(self, token: str):
|
def __init_year(self, token: str):
|
||||||
if not self.name:
|
if not self.name:
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
|
import traceback
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
|
||||||
import cn2an
|
import cn2an
|
||||||
import regex as re
|
import regex as re
|
||||||
|
|
||||||
from app.db.systemconfig_oper import SystemConfigOper
|
from app.db.systemconfig_oper import SystemConfigOper
|
||||||
|
from app.log import logger
|
||||||
from app.schemas.types import SystemConfigKey
|
from app.schemas.types import SystemConfigKey
|
||||||
from app.utils.singleton import Singleton
|
from app.utils.singleton import Singleton
|
||||||
|
|
||||||
@@ -62,7 +64,7 @@ class WordsMatcher(metaclass=Singleton):
|
|||||||
appley_words.append(word)
|
appley_words.append(word)
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(str(err))
|
logger.error(f"自定义识别词预处理标题失败:{str(err)} - {traceback.format_exc()}")
|
||||||
|
|
||||||
return title, appley_words
|
return title, appley_words
|
||||||
|
|
||||||
@@ -77,7 +79,7 @@ class WordsMatcher(metaclass=Singleton):
|
|||||||
else:
|
else:
|
||||||
return re.sub(r'%s' % replaced, r'%s' % replace, title), "", True
|
return re.sub(r'%s' % replaced, r'%s' % replace, title), "", True
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(str(err))
|
logger.error(f"自定义识别词正则替换失败:{str(err)} - {traceback.format_exc()}")
|
||||||
return title, str(err), False
|
return title, str(err), False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -129,5 +131,5 @@ class WordsMatcher(metaclass=Singleton):
|
|||||||
title = re.sub(episode_offset_re, r'%s' % episode_num[1], title)
|
title = re.sub(episode_offset_re, r'%s' % episode_num[1], title)
|
||||||
return title, "", True
|
return title, "", True
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(str(err))
|
logger.error(f"自定义识别词集数偏移失败:{str(err)} - {traceback.format_exc()}")
|
||||||
return title, str(err), False
|
return title, str(err), False
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Tuple
|
||||||
|
|
||||||
import regex as re
|
import regex as re
|
||||||
|
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.core.meta import MetaAnime, MetaVideo, MetaBase
|
from app.core.meta import MetaAnime, MetaVideo, MetaBase
|
||||||
from app.core.meta.words import WordsMatcher
|
from app.core.meta.words import WordsMatcher
|
||||||
|
from app.schemas.types import MediaType
|
||||||
|
|
||||||
|
|
||||||
def MetaInfo(title: str, subtitle: str = None) -> MetaBase:
|
def MetaInfo(title: str, subtitle: str = None) -> MetaBase:
|
||||||
@@ -18,6 +20,8 @@ def MetaInfo(title: str, subtitle: str = None) -> MetaBase:
|
|||||||
org_title = title
|
org_title = title
|
||||||
# 预处理标题
|
# 预处理标题
|
||||||
title, apply_words = WordsMatcher().prepare(title)
|
title, apply_words = WordsMatcher().prepare(title)
|
||||||
|
# 获取标题中媒体信息
|
||||||
|
title, metainfo = find_metainfo(title)
|
||||||
# 判断是否处理文件
|
# 判断是否处理文件
|
||||||
if title and Path(title).suffix.lower() in settings.RMT_MEDIAEXT:
|
if title and Path(title).suffix.lower() in settings.RMT_MEDIAEXT:
|
||||||
isfile = True
|
isfile = True
|
||||||
@@ -29,7 +33,25 @@ def MetaInfo(title: str, subtitle: str = None) -> MetaBase:
|
|||||||
meta.title = org_title
|
meta.title = org_title
|
||||||
# 记录使用的识别词
|
# 记录使用的识别词
|
||||||
meta.apply_words = apply_words or []
|
meta.apply_words = apply_words or []
|
||||||
|
# 修正媒体信息
|
||||||
|
if metainfo.get('tmdbid'):
|
||||||
|
meta.tmdbid = metainfo['tmdbid']
|
||||||
|
if metainfo.get('doubanid'):
|
||||||
|
meta.tmdbid = metainfo['doubanid']
|
||||||
|
if metainfo.get('type'):
|
||||||
|
meta.type = metainfo['type']
|
||||||
|
if metainfo.get('begin_season'):
|
||||||
|
meta.begin_season = metainfo['begin_season']
|
||||||
|
if metainfo.get('end_season'):
|
||||||
|
meta.end_season = metainfo['end_season']
|
||||||
|
if metainfo.get('total_season'):
|
||||||
|
meta.total_season = metainfo['total_season']
|
||||||
|
if metainfo.get('begin_episode'):
|
||||||
|
meta.begin_episode = metainfo['begin_episode']
|
||||||
|
if metainfo.get('end_episode'):
|
||||||
|
meta.end_episode = metainfo['end_episode']
|
||||||
|
if metainfo.get('total_episode'):
|
||||||
|
meta.total_episode = metainfo['total_episode']
|
||||||
return meta
|
return meta
|
||||||
|
|
||||||
|
|
||||||
@@ -38,12 +60,16 @@ def MetaInfoPath(path: Path) -> MetaBase:
|
|||||||
根据路径识别元数据
|
根据路径识别元数据
|
||||||
:param path: 路径
|
:param path: 路径
|
||||||
"""
|
"""
|
||||||
# 上级目录元数据
|
|
||||||
dir_meta = MetaInfo(title=path.parent.name)
|
|
||||||
# 文件元数据,不包含后缀
|
# 文件元数据,不包含后缀
|
||||||
file_meta = MetaInfo(title=path.stem)
|
file_meta = MetaInfo(title=path.stem)
|
||||||
|
# 上级目录元数据
|
||||||
|
dir_meta = MetaInfo(title=path.parent.name)
|
||||||
# 合并元数据
|
# 合并元数据
|
||||||
file_meta.merge(dir_meta)
|
file_meta.merge(dir_meta)
|
||||||
|
# 上上级目录元数据
|
||||||
|
root_meta = MetaInfo(title=path.parent.parent.name)
|
||||||
|
# 合并元数据
|
||||||
|
file_meta.merge(root_meta)
|
||||||
return file_meta
|
return file_meta
|
||||||
|
|
||||||
|
|
||||||
@@ -65,3 +91,76 @@ def is_anime(name: str) -> bool:
|
|||||||
if re.search(r'\[[+0-9XVPI-]+]\s*\[', name, re.IGNORECASE):
|
if re.search(r'\[[+0-9XVPI-]+]\s*\[', name, re.IGNORECASE):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def find_metainfo(title: str) -> Tuple[str, dict]:
|
||||||
|
"""
|
||||||
|
从标题中提取媒体信息
|
||||||
|
"""
|
||||||
|
metainfo = {
|
||||||
|
'tmdbid': None,
|
||||||
|
'doubanid': None,
|
||||||
|
'type': None,
|
||||||
|
'begin_season': None,
|
||||||
|
'end_season': None,
|
||||||
|
'total_season': None,
|
||||||
|
'begin_episode': None,
|
||||||
|
'end_episode': None,
|
||||||
|
'total_episode': None,
|
||||||
|
}
|
||||||
|
if not title:
|
||||||
|
return title, metainfo
|
||||||
|
# 从标题中提取媒体信息 格式为{[tmdbid=xxx;type=xxx;s=xxx;e=xxx]}
|
||||||
|
results = re.findall(r'(?<={\[)[\W\w]+(?=]})', title)
|
||||||
|
if not results:
|
||||||
|
return title, metainfo
|
||||||
|
for result in results:
|
||||||
|
# 查找tmdbid信息
|
||||||
|
tmdbid = re.findall(r'(?<=tmdbid=)\d+', result)
|
||||||
|
if tmdbid and tmdbid[0].isdigit():
|
||||||
|
metainfo['tmdbid'] = tmdbid[0]
|
||||||
|
# 查找豆瓣id信息
|
||||||
|
doubanid = re.findall(r'(?<=doubanid=)\d+', result)
|
||||||
|
if doubanid and doubanid[0].isdigit():
|
||||||
|
metainfo['doubanid'] = doubanid[0]
|
||||||
|
# 查找媒体类型
|
||||||
|
mtype = re.findall(r'(?<=type=)\w+', result)
|
||||||
|
if mtype:
|
||||||
|
match mtype[0]:
|
||||||
|
case "movie":
|
||||||
|
metainfo['type'] = MediaType.MOVIE
|
||||||
|
case "tv":
|
||||||
|
metainfo['type'] = MediaType.TV
|
||||||
|
case _:
|
||||||
|
pass
|
||||||
|
# 查找季信息
|
||||||
|
begin_season = re.findall(r'(?<=s=)\d+', result)
|
||||||
|
if begin_season and begin_season[0].isdigit():
|
||||||
|
metainfo['begin_season'] = int(begin_season[0])
|
||||||
|
end_season = re.findall(r'(?<=s=\d+-)\d+', result)
|
||||||
|
if end_season and end_season[0].isdigit():
|
||||||
|
metainfo['end_season'] = int(end_season[0])
|
||||||
|
# 查找集信息
|
||||||
|
begin_episode = re.findall(r'(?<=e=)\d+', result)
|
||||||
|
if begin_episode and begin_episode[0].isdigit():
|
||||||
|
metainfo['begin_episode'] = int(begin_episode[0])
|
||||||
|
end_episode = re.findall(r'(?<=e=\d+-)\d+', result)
|
||||||
|
if end_episode and end_episode[0].isdigit():
|
||||||
|
metainfo['end_episode'] = int(end_episode[0])
|
||||||
|
# 去除title中该部分
|
||||||
|
if tmdbid or mtype or begin_season or end_season or begin_episode or end_episode:
|
||||||
|
title = title.replace(f"{{[{result}]}}", '')
|
||||||
|
# 计算季集总数
|
||||||
|
if metainfo.get('begin_season') and metainfo.get('end_season'):
|
||||||
|
if metainfo['begin_season'] > metainfo['end_season']:
|
||||||
|
metainfo['begin_season'], metainfo['end_season'] = metainfo['end_season'], metainfo['begin_season']
|
||||||
|
metainfo['total_season'] = metainfo['end_season'] - metainfo['begin_season'] + 1
|
||||||
|
elif metainfo.get('begin_season') and not metainfo.get('end_season'):
|
||||||
|
metainfo['total_season'] = 1
|
||||||
|
if metainfo.get('begin_episode') and metainfo.get('end_episode'):
|
||||||
|
if metainfo['begin_episode'] > metainfo['end_episode']:
|
||||||
|
metainfo['begin_episode'], metainfo['end_episode'] = metainfo['end_episode'], metainfo['begin_episode']
|
||||||
|
metainfo['total_episode'] = metainfo['end_episode'] - metainfo['begin_episode'] + 1
|
||||||
|
elif metainfo.get('begin_episode') and not metainfo.get('end_episode'):
|
||||||
|
metainfo['total_episode'] = 1
|
||||||
|
return title, metainfo
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
import traceback
|
import traceback
|
||||||
from typing import List, Any, Dict, Tuple
|
from typing import List, Any, Dict, Tuple
|
||||||
|
|
||||||
|
from app.core.config import settings
|
||||||
from app.core.event import eventmanager
|
from app.core.event import eventmanager
|
||||||
from app.db.systemconfig_oper import SystemConfigOper
|
from app.db.systemconfig_oper import SystemConfigOper
|
||||||
from app.helper.module import ModuleHelper
|
from app.helper.module import ModuleHelper
|
||||||
|
from app.helper.plugin import PluginHelper
|
||||||
from app.helper.sites import SitesHelper
|
from app.helper.sites import SitesHelper
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.schemas.types import SystemConfigKey
|
from app.schemas.types import SystemConfigKey
|
||||||
from app.utils.object import ObjectUtils
|
from app.utils.object import ObjectUtils
|
||||||
from app.utils.singleton import Singleton
|
from app.utils.singleton import Singleton
|
||||||
|
from app.utils.string import StringUtils
|
||||||
|
from app.utils.system import SystemUtils
|
||||||
|
|
||||||
|
|
||||||
class PluginManager(metaclass=Singleton):
|
class PluginManager(metaclass=Singleton):
|
||||||
@@ -26,11 +30,12 @@ class PluginManager(metaclass=Singleton):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.siteshelper = SitesHelper()
|
self.siteshelper = SitesHelper()
|
||||||
|
self.pluginhelper = PluginHelper()
|
||||||
|
self.systemconfig = SystemConfigOper()
|
||||||
|
self.install_online_plugin()
|
||||||
self.init_config()
|
self.init_config()
|
||||||
|
|
||||||
def init_config(self):
|
def init_config(self):
|
||||||
# 配置管理
|
|
||||||
self.systemconfig = SystemConfigOper()
|
|
||||||
# 停止已有插件
|
# 停止已有插件
|
||||||
self.stop()
|
self.stop()
|
||||||
# 启动插件
|
# 启动插件
|
||||||
@@ -40,7 +45,6 @@ class PluginManager(metaclass=Singleton):
|
|||||||
"""
|
"""
|
||||||
启动加载插件
|
启动加载插件
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# 扫描插件目录
|
# 扫描插件目录
|
||||||
plugins = ModuleHelper.load(
|
plugins = ModuleHelper.load(
|
||||||
"app.plugins",
|
"app.plugins",
|
||||||
@@ -98,13 +102,46 @@ class PluginManager(metaclass=Singleton):
|
|||||||
self._plugins = {}
|
self._plugins = {}
|
||||||
self._running_plugins = {}
|
self._running_plugins = {}
|
||||||
|
|
||||||
|
def install_online_plugin(self):
|
||||||
|
"""
|
||||||
|
安装本地不存在的在线插件
|
||||||
|
"""
|
||||||
|
if SystemUtils.is_frozen():
|
||||||
|
return
|
||||||
|
logger.info("开始安装在线插件...")
|
||||||
|
# 已安装插件
|
||||||
|
install_plugins = self.systemconfig.get(SystemConfigKey.UserInstalledPlugins) or []
|
||||||
|
# 在线插件
|
||||||
|
online_plugins = self.get_online_plugins()
|
||||||
|
if not online_plugins:
|
||||||
|
logger.error("未获取到在线插件")
|
||||||
|
return
|
||||||
|
# 支持更新的插件自动更新
|
||||||
|
for plugin in online_plugins:
|
||||||
|
# 只处理已安装的插件
|
||||||
|
if plugin.get("id") in install_plugins and not self.is_plugin_exists(plugin.get("id")):
|
||||||
|
# 下载安装
|
||||||
|
state, msg = self.pluginhelper.install(pid=plugin.get("id"),
|
||||||
|
repo_url=plugin.get("repo_url"))
|
||||||
|
# 安装失败
|
||||||
|
if not state:
|
||||||
|
logger.error(
|
||||||
|
f"插件 {plugin.get('plugin_name')} v{plugin.get('plugin_version')} 安装失败:{msg}")
|
||||||
|
continue
|
||||||
|
logger.info(f"插件 {plugin.get('plugin_name')} 安装成功,版本:{plugin.get('plugin_version')}")
|
||||||
|
logger.info("在线插件安装完成")
|
||||||
|
|
||||||
def get_plugin_config(self, pid: str) -> dict:
|
def get_plugin_config(self, pid: str) -> dict:
|
||||||
"""
|
"""
|
||||||
获取插件配置
|
获取插件配置
|
||||||
"""
|
"""
|
||||||
if not self._plugins.get(pid):
|
if not self._plugins.get(pid):
|
||||||
return {}
|
return {}
|
||||||
return self.systemconfig.get(self._config_key % pid) or {}
|
conf = self.systemconfig.get(self._config_key % pid)
|
||||||
|
if conf:
|
||||||
|
# 去掉空Key
|
||||||
|
return {k: v for k, v in conf.items() if k}
|
||||||
|
return {}
|
||||||
|
|
||||||
def save_plugin_config(self, pid: str, conf: dict) -> bool:
|
def save_plugin_config(self, pid: str, conf: dict) -> bool:
|
||||||
"""
|
"""
|
||||||
@@ -114,6 +151,14 @@ class PluginManager(metaclass=Singleton):
|
|||||||
return False
|
return False
|
||||||
return self.systemconfig.set(self._config_key % pid, conf)
|
return self.systemconfig.set(self._config_key % pid, conf)
|
||||||
|
|
||||||
|
def delete_plugin_config(self, pid: str) -> bool:
|
||||||
|
"""
|
||||||
|
删除插件配置
|
||||||
|
"""
|
||||||
|
if not self._plugins.get(pid):
|
||||||
|
return False
|
||||||
|
return self.systemconfig.delete(self._config_key % pid)
|
||||||
|
|
||||||
def get_plugin_form(self, pid: str) -> Tuple[List[dict], Dict[str, Any]]:
|
def get_plugin_form(self, pid: str) -> Tuple[List[dict], Dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
获取插件表单
|
获取插件表单
|
||||||
@@ -172,6 +217,26 @@ class PluginManager(metaclass=Singleton):
|
|||||||
ret_apis.extend(apis)
|
ret_apis.extend(apis)
|
||||||
return ret_apis
|
return ret_apis
|
||||||
|
|
||||||
|
def get_plugin_services(self) -> List[Dict[str, Any]]:
|
||||||
|
"""
|
||||||
|
获取插件服务
|
||||||
|
[{
|
||||||
|
"id": "服务ID",
|
||||||
|
"name": "服务名称",
|
||||||
|
"trigger": "触发器:cron、interval、date、CronTrigger.from_crontab()",
|
||||||
|
"func": self.xxx,
|
||||||
|
"kwagrs": {} # 定时器参数
|
||||||
|
}]
|
||||||
|
"""
|
||||||
|
ret_services = []
|
||||||
|
for pid, plugin in self._running_plugins.items():
|
||||||
|
if hasattr(plugin, "get_service") \
|
||||||
|
and ObjectUtils.check_method(plugin.get_service):
|
||||||
|
services = plugin.get_service()
|
||||||
|
if services:
|
||||||
|
ret_services.extend(services)
|
||||||
|
return ret_services
|
||||||
|
|
||||||
def run_plugin_method(self, pid: str, method: str, *args, **kwargs) -> Any:
|
def run_plugin_method(self, pid: str, method: str, *args, **kwargs) -> Any:
|
||||||
"""
|
"""
|
||||||
运行插件方法
|
运行插件方法
|
||||||
@@ -188,9 +253,92 @@ class PluginManager(metaclass=Singleton):
|
|||||||
"""
|
"""
|
||||||
return list(self._plugins.keys())
|
return list(self._plugins.keys())
|
||||||
|
|
||||||
def get_plugin_apps(self) -> List[dict]:
|
def get_online_plugins(self) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
获取所有插件信息
|
获取所有在线插件信息
|
||||||
|
"""
|
||||||
|
# 返回值
|
||||||
|
all_confs = []
|
||||||
|
if not settings.PLUGIN_MARKET:
|
||||||
|
return all_confs
|
||||||
|
# 已安装插件
|
||||||
|
installed_apps = self.systemconfig.get(SystemConfigKey.UserInstalledPlugins) or []
|
||||||
|
# 线上插件列表
|
||||||
|
markets = settings.PLUGIN_MARKET.split(",")
|
||||||
|
for market in markets:
|
||||||
|
online_plugins = self.pluginhelper.get_plugins(market) or {}
|
||||||
|
if not online_plugins:
|
||||||
|
logger.warn(f"获取插件库失败 {market}")
|
||||||
|
for pid, plugin in online_plugins.items():
|
||||||
|
# 运行状插件
|
||||||
|
plugin_obj = self._running_plugins.get(pid)
|
||||||
|
# 非运行态插件
|
||||||
|
plugin_static = self._plugins.get(pid)
|
||||||
|
# 基本属性
|
||||||
|
conf = {}
|
||||||
|
# ID
|
||||||
|
conf.update({"id": pid})
|
||||||
|
# 安装状态
|
||||||
|
if pid in installed_apps and plugin_static:
|
||||||
|
conf.update({"installed": True})
|
||||||
|
else:
|
||||||
|
conf.update({"installed": False})
|
||||||
|
# 是否有新版本
|
||||||
|
conf.update({"has_update": False})
|
||||||
|
if plugin_static:
|
||||||
|
installed_version = getattr(plugin_static, "plugin_version")
|
||||||
|
if StringUtils.compare_version(installed_version, plugin.get("version")) < 0:
|
||||||
|
# 需要更新
|
||||||
|
conf.update({"has_update": True})
|
||||||
|
# 运行状态
|
||||||
|
if plugin_obj and hasattr(plugin_obj, "get_state"):
|
||||||
|
try:
|
||||||
|
state = plugin_obj.get_state()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"获取插件 {pid} 状态出错:{str(e)}")
|
||||||
|
state = False
|
||||||
|
conf.update({"state": state})
|
||||||
|
else:
|
||||||
|
conf.update({"state": False})
|
||||||
|
# 是否有详情页面
|
||||||
|
conf.update({"has_page": False})
|
||||||
|
if plugin_obj and hasattr(plugin_obj, "get_page"):
|
||||||
|
if ObjectUtils.check_method(plugin_obj.get_page):
|
||||||
|
conf.update({"has_page": True})
|
||||||
|
# 权限
|
||||||
|
if plugin.get("level"):
|
||||||
|
conf.update({"auth_level": plugin.get("level")})
|
||||||
|
if self.siteshelper.auth_level < plugin.get("level"):
|
||||||
|
continue
|
||||||
|
# 名称
|
||||||
|
if plugin.get("name"):
|
||||||
|
conf.update({"plugin_name": plugin.get("name")})
|
||||||
|
# 描述
|
||||||
|
if plugin.get("description"):
|
||||||
|
conf.update({"plugin_desc": plugin.get("description")})
|
||||||
|
# 版本
|
||||||
|
if plugin.get("version"):
|
||||||
|
conf.update({"plugin_version": plugin.get("version")})
|
||||||
|
# 图标
|
||||||
|
if plugin.get("icon"):
|
||||||
|
conf.update({"plugin_icon": plugin.get("icon")})
|
||||||
|
# 作者
|
||||||
|
if plugin.get("author"):
|
||||||
|
conf.update({"plugin_author": plugin.get("author")})
|
||||||
|
# 仓库链接
|
||||||
|
conf.update({"repo_url": market})
|
||||||
|
# 本地标志
|
||||||
|
conf.update({"is_local": False})
|
||||||
|
# 汇总
|
||||||
|
all_confs.append(conf)
|
||||||
|
# 按插件ID去重
|
||||||
|
if all_confs:
|
||||||
|
all_confs = list({v["id"]: v for v in all_confs}.values())
|
||||||
|
return all_confs
|
||||||
|
|
||||||
|
def get_local_plugins(self) -> List[dict]:
|
||||||
|
"""
|
||||||
|
获取所有本地已下载的插件信息
|
||||||
"""
|
"""
|
||||||
# 返回值
|
# 返回值
|
||||||
all_confs = []
|
all_confs = []
|
||||||
@@ -209,8 +357,13 @@ class PluginManager(metaclass=Singleton):
|
|||||||
else:
|
else:
|
||||||
conf.update({"installed": False})
|
conf.update({"installed": False})
|
||||||
# 运行状态
|
# 运行状态
|
||||||
if plugin_obj and hasattr(plugin, "get_state"):
|
if plugin_obj and hasattr(plugin_obj, "get_state"):
|
||||||
conf.update({"state": plugin_obj.get_state()})
|
try:
|
||||||
|
state = plugin_obj.get_state()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"获取插件 {pid} 状态出错:{str(e)}")
|
||||||
|
state = False
|
||||||
|
conf.update({"state": state})
|
||||||
else:
|
else:
|
||||||
conf.update({"state": False})
|
conf.update({"state": False})
|
||||||
# 是否有详情页面
|
# 是否有详情页面
|
||||||
@@ -221,6 +374,7 @@ class PluginManager(metaclass=Singleton):
|
|||||||
conf.update({"has_page": False})
|
conf.update({"has_page": False})
|
||||||
# 权限
|
# 权限
|
||||||
if hasattr(plugin, "auth_level"):
|
if hasattr(plugin, "auth_level"):
|
||||||
|
conf.update({"auth_level": plugin.auth_level})
|
||||||
if self.siteshelper.auth_level < plugin.auth_level:
|
if self.siteshelper.auth_level < plugin.auth_level:
|
||||||
continue
|
continue
|
||||||
# 名称
|
# 名称
|
||||||
@@ -235,15 +389,26 @@ class PluginManager(metaclass=Singleton):
|
|||||||
# 图标
|
# 图标
|
||||||
if hasattr(plugin, "plugin_icon"):
|
if hasattr(plugin, "plugin_icon"):
|
||||||
conf.update({"plugin_icon": plugin.plugin_icon})
|
conf.update({"plugin_icon": plugin.plugin_icon})
|
||||||
# 主题色
|
|
||||||
if hasattr(plugin, "plugin_color"):
|
|
||||||
conf.update({"plugin_color": plugin.plugin_color})
|
|
||||||
# 作者
|
# 作者
|
||||||
if hasattr(plugin, "plugin_author"):
|
if hasattr(plugin, "plugin_author"):
|
||||||
conf.update({"plugin_author": plugin.plugin_author})
|
conf.update({"plugin_author": plugin.plugin_author})
|
||||||
# 作者链接
|
# 作者链接
|
||||||
if hasattr(plugin, "author_url"):
|
if hasattr(plugin, "author_url"):
|
||||||
conf.update({"author_url": plugin.author_url})
|
conf.update({"author_url": plugin.author_url})
|
||||||
|
# 是否需要更新
|
||||||
|
conf.update({"has_update": False})
|
||||||
|
# 本地标志
|
||||||
|
conf.update({"is_local": True})
|
||||||
# 汇总
|
# 汇总
|
||||||
all_confs.append(conf)
|
all_confs.append(conf)
|
||||||
return all_confs
|
return all_confs
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def is_plugin_exists(pid: str) -> bool:
|
||||||
|
"""
|
||||||
|
判断插件是否存在
|
||||||
|
"""
|
||||||
|
if not pid:
|
||||||
|
return False
|
||||||
|
plugin_dir = settings.ROOT_PATH / "app" / "plugins" / pid.lower()
|
||||||
|
return plugin_dir.exists()
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import hashlib
|
|||||||
import hmac
|
import hmac
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import traceback
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Any, Union, Optional
|
from typing import Any, Union, Optional
|
||||||
import jwt
|
import jwt
|
||||||
@@ -16,6 +17,8 @@ from app import schemas
|
|||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from cryptography.fernet import Fernet
|
from cryptography.fernet import Fernet
|
||||||
|
|
||||||
|
from app.log import logger
|
||||||
|
|
||||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||||
ALGORITHM = "HS256"
|
ALGORITHM = "HS256"
|
||||||
|
|
||||||
@@ -26,7 +29,8 @@ reusable_oauth2 = OAuth2PasswordBearer(
|
|||||||
|
|
||||||
|
|
||||||
def create_access_token(
|
def create_access_token(
|
||||||
subject: Union[str, Any], expires_delta: timedelta = None
|
userid: Union[str, Any], username: str, super_user: bool = False,
|
||||||
|
expires_delta: timedelta = None
|
||||||
) -> str:
|
) -> str:
|
||||||
if expires_delta:
|
if expires_delta:
|
||||||
expire = datetime.utcnow() + expires_delta
|
expire = datetime.utcnow() + expires_delta
|
||||||
@@ -34,7 +38,12 @@ def create_access_token(
|
|||||||
expire = datetime.utcnow() + timedelta(
|
expire = datetime.utcnow() + timedelta(
|
||||||
minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES
|
minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES
|
||||||
)
|
)
|
||||||
to_encode = {"exp": expire, "sub": str(subject)}
|
to_encode = {
|
||||||
|
"exp": expire,
|
||||||
|
"sub": str(userid),
|
||||||
|
"username": username,
|
||||||
|
"super_user": super_user
|
||||||
|
}
|
||||||
encoded_jwt = jwt.encode(to_encode, settings.SECRET_KEY, algorithm=ALGORITHM)
|
encoded_jwt = jwt.encode(to_encode, settings.SECRET_KEY, algorithm=ALGORITHM)
|
||||||
return encoded_jwt
|
return encoded_jwt
|
||||||
|
|
||||||
@@ -52,6 +61,44 @@ def verify_token(token: str = Depends(reusable_oauth2)) -> schemas.TokenPayload:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_token(token: str = None) -> str:
|
||||||
|
"""
|
||||||
|
从请求URL中获取token
|
||||||
|
"""
|
||||||
|
return token
|
||||||
|
|
||||||
|
|
||||||
|
def get_apikey(apikey: str = None) -> str:
|
||||||
|
"""
|
||||||
|
从请求URL中获取apikey
|
||||||
|
"""
|
||||||
|
return apikey
|
||||||
|
|
||||||
|
|
||||||
|
def verify_uri_token(token: str = Depends(get_token)) -> str:
|
||||||
|
"""
|
||||||
|
通过依赖项使用token进行身份认证
|
||||||
|
"""
|
||||||
|
if token != settings.API_TOKEN:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
|
detail="token校验不通过"
|
||||||
|
)
|
||||||
|
return token
|
||||||
|
|
||||||
|
|
||||||
|
def verify_uri_apikey(apikey: str = Depends(get_apikey)) -> str:
|
||||||
|
"""
|
||||||
|
通过依赖项使用apikey进行身份认证
|
||||||
|
"""
|
||||||
|
if apikey != settings.API_TOKEN:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
|
detail="apikey校验不通过"
|
||||||
|
)
|
||||||
|
return apikey
|
||||||
|
|
||||||
|
|
||||||
def verify_password(plain_password: str, hashed_password: str) -> bool:
|
def verify_password(plain_password: str, hashed_password: str) -> bool:
|
||||||
return pwd_context.verify(plain_password, hashed_password)
|
return pwd_context.verify(plain_password, hashed_password)
|
||||||
|
|
||||||
@@ -68,7 +115,7 @@ def decrypt(data: bytes, key: bytes) -> Optional[bytes]:
|
|||||||
try:
|
try:
|
||||||
return fernet.decrypt(data)
|
return fernet.decrypt(data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(str(e))
|
logger.error(f"解密失败:{str(e)} - {traceback.format_exc()}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
|
from typing import Any, Self, List
|
||||||
from typing import Tuple, Optional, Generator
|
from typing import Tuple, Optional, Generator
|
||||||
|
|
||||||
from sqlalchemy import create_engine, QueuePool
|
from sqlalchemy import create_engine, QueuePool
|
||||||
from sqlalchemy.orm import sessionmaker, Session, scoped_session
|
from sqlalchemy import inspect
|
||||||
|
from sqlalchemy.orm import declared_attr
|
||||||
|
from sqlalchemy.orm import sessionmaker, Session, scoped_session, as_declarative
|
||||||
|
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
|
|
||||||
@@ -135,6 +138,52 @@ def db_query(func):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
@as_declarative()
|
||||||
|
class Base:
|
||||||
|
id: Any
|
||||||
|
__name__: str
|
||||||
|
|
||||||
|
@db_update
|
||||||
|
def create(self, db: Session):
|
||||||
|
db.add(self)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
@db_query
|
||||||
|
def get(cls, db: Session, rid: int) -> Self:
|
||||||
|
return db.query(cls).filter(cls.id == rid).first()
|
||||||
|
|
||||||
|
@db_update
|
||||||
|
def update(self, db: Session, payload: dict):
|
||||||
|
payload = {k: v for k, v in payload.items() if v is not None}
|
||||||
|
for key, value in payload.items():
|
||||||
|
setattr(self, key, value)
|
||||||
|
if inspect(self).detached:
|
||||||
|
db.add(self)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
@db_update
|
||||||
|
def delete(cls, db: Session, rid):
|
||||||
|
db.query(cls).filter(cls.id == rid).delete()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
@db_update
|
||||||
|
def truncate(cls, db: Session):
|
||||||
|
db.query(cls).delete()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
@db_query
|
||||||
|
def list(cls, db: Session) -> List[Self]:
|
||||||
|
result = db.query(cls).all()
|
||||||
|
return list(result)
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return {c.name: getattr(self, c.name, None) for c in self.__table__.columns}
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def __tablename__(self) -> str:
|
||||||
|
return self.__name__.lower()
|
||||||
|
|
||||||
|
|
||||||
class DbOper:
|
class DbOper:
|
||||||
"""
|
"""
|
||||||
数据库操作基类
|
数据库操作基类
|
||||||
|
|||||||
@@ -24,12 +24,11 @@ class DownloadHistoryOper(DbOper):
|
|||||||
"""
|
"""
|
||||||
return DownloadHistory.get_by_hash(self._db, download_hash)
|
return DownloadHistory.get_by_hash(self._db, download_hash)
|
||||||
|
|
||||||
def add(self, **kwargs) -> DownloadHistory:
|
def add(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
新增下载历史
|
新增下载历史
|
||||||
"""
|
"""
|
||||||
downloadhistory = DownloadHistory(**kwargs)
|
DownloadHistory(**kwargs).create(self._db)
|
||||||
return downloadhistory.create(self._db)
|
|
||||||
|
|
||||||
def add_files(self, file_items: List[dict]):
|
def add_files(self, file_items: List[dict]):
|
||||||
"""
|
"""
|
||||||
@@ -58,7 +57,14 @@ class DownloadHistoryOper(DbOper):
|
|||||||
按fullpath查询下载文件记录
|
按fullpath查询下载文件记录
|
||||||
:param fullpath: 数据key
|
:param fullpath: 数据key
|
||||||
"""
|
"""
|
||||||
return DownloadFiles.get_by_fullpath(self._db, fullpath)
|
return DownloadFiles.get_by_fullpath(self._db, fullpath=fullpath, all_files=False)
|
||||||
|
|
||||||
|
def get_files_by_fullpath(self, fullpath: str) -> List[DownloadFiles]:
|
||||||
|
"""
|
||||||
|
按fullpath查询下载文件记录
|
||||||
|
:param fullpath: 数据key
|
||||||
|
"""
|
||||||
|
return DownloadFiles.get_by_fullpath(self._db, fullpath=fullpath, all_files=True)
|
||||||
|
|
||||||
def get_files_by_savepath(self, fullpath: str) -> List[DownloadFiles]:
|
def get_files_by_savepath(self, fullpath: str) -> List[DownloadFiles]:
|
||||||
"""
|
"""
|
||||||
@@ -79,7 +85,7 @@ class DownloadHistoryOper(DbOper):
|
|||||||
按fullpath查询下载文件记录hash
|
按fullpath查询下载文件记录hash
|
||||||
:param fullpath: 数据key
|
:param fullpath: 数据key
|
||||||
"""
|
"""
|
||||||
fileinfo: DownloadFiles = DownloadFiles.get_by_fullpath(self._db, fullpath)
|
fileinfo: DownloadFiles = DownloadFiles.get_by_fullpath(self._db, fullpath=fullpath, all_files=False)
|
||||||
if fileinfo:
|
if fileinfo:
|
||||||
return fileinfo.download_hash
|
return fileinfo.download_hash
|
||||||
return ""
|
return ""
|
||||||
@@ -109,10 +115,20 @@ class DownloadHistoryOper(DbOper):
|
|||||||
episode=episode,
|
episode=episode,
|
||||||
tmdbid=tmdbid)
|
tmdbid=tmdbid)
|
||||||
|
|
||||||
def list_by_user_date(self, date: str, userid: str = None) -> List[DownloadHistory]:
|
def list_by_user_date(self, date: str, username: str = None) -> List[DownloadHistory]:
|
||||||
"""
|
"""
|
||||||
查询某用户某时间之后的下载历史
|
查询某用户某时间之前的下载历史
|
||||||
"""
|
"""
|
||||||
return DownloadHistory.list_by_user_date(db=self._db,
|
return DownloadHistory.list_by_user_date(db=self._db,
|
||||||
date=date,
|
date=date,
|
||||||
userid=userid)
|
username=username)
|
||||||
|
|
||||||
|
def list_by_date(self, date: str, type: str, tmdbid: str, seasons: str = None) -> List[DownloadHistory]:
|
||||||
|
"""
|
||||||
|
查询某时间之后的下载历史
|
||||||
|
"""
|
||||||
|
return DownloadHistory.list_by_date(db=self._db,
|
||||||
|
date=date,
|
||||||
|
type=type,
|
||||||
|
tmdbid=tmdbid,
|
||||||
|
seasons=seasons)
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
import importlib
|
import random
|
||||||
from pathlib import Path
|
import string
|
||||||
|
|
||||||
from alembic.command import upgrade
|
from alembic.command import upgrade
|
||||||
from alembic.config import Config
|
from alembic.config import Config
|
||||||
|
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.core.security import get_password_hash
|
from app.core.security import get_password_hash
|
||||||
from app.db import Engine, SessionFactory
|
from app.db import Engine, SessionFactory, Base
|
||||||
from app.db.models import Base
|
from app.db.models import *
|
||||||
from app.db.models.user import User
|
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
|
|
||||||
|
|
||||||
@@ -16,21 +15,29 @@ def init_db():
|
|||||||
"""
|
"""
|
||||||
初始化数据库
|
初始化数据库
|
||||||
"""
|
"""
|
||||||
# 导入模块,避免建表缺失
|
|
||||||
for module in Path(__file__).with_name("models").glob("*.py"):
|
|
||||||
importlib.import_module(f"app.db.models.{module.stem}")
|
|
||||||
# 全量建表
|
# 全量建表
|
||||||
Base.metadata.create_all(bind=Engine)
|
Base.metadata.create_all(bind=Engine)
|
||||||
|
|
||||||
|
|
||||||
|
def init_super_user():
|
||||||
|
"""
|
||||||
|
初始化超级管理员
|
||||||
|
"""
|
||||||
# 初始化超级管理员
|
# 初始化超级管理员
|
||||||
with SessionFactory() as db:
|
with SessionFactory() as db:
|
||||||
user = User.get_by_name(db=db, name=settings.SUPERUSER)
|
_user = User.get_by_name(db=db, name=settings.SUPERUSER)
|
||||||
if not user:
|
if not _user:
|
||||||
user = User(
|
# 定义包含数字、大小写字母的字符集合
|
||||||
|
characters = string.ascii_letters + string.digits
|
||||||
|
# 生成随机密码
|
||||||
|
random_password = ''.join(random.choice(characters) for _ in range(16))
|
||||||
|
logger.info(f"【超级管理员初始密码】{random_password} 请登录系统后在设定中修改。 注:该密码只会显示一次,请注意保存。")
|
||||||
|
_user = User(
|
||||||
name=settings.SUPERUSER,
|
name=settings.SUPERUSER,
|
||||||
hashed_password=get_password_hash(settings.SUPERUSER_PASSWORD),
|
hashed_password=get_password_hash(random_password),
|
||||||
is_superuser=True,
|
is_superuser=True,
|
||||||
)
|
)
|
||||||
user.create(db)
|
_user.create(db)
|
||||||
|
|
||||||
|
|
||||||
def update_db():
|
def update_db():
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class MediaServerOper(DbOper):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def empty(self, server: str):
|
def empty(self, server: Optional[str] = None):
|
||||||
"""
|
"""
|
||||||
清空媒体服务器数据
|
清空媒体服务器数据
|
||||||
"""
|
"""
|
||||||
@@ -39,10 +39,12 @@ class MediaServerOper(DbOper):
|
|||||||
# 优先按TMDBID查
|
# 优先按TMDBID查
|
||||||
item = MediaServerItem.exist_by_tmdbid(self._db, tmdbid=kwargs.get("tmdbid"),
|
item = MediaServerItem.exist_by_tmdbid(self._db, tmdbid=kwargs.get("tmdbid"),
|
||||||
mtype=kwargs.get("mtype"))
|
mtype=kwargs.get("mtype"))
|
||||||
else:
|
elif kwargs.get("title"):
|
||||||
# 按标题、类型、年份查
|
# 按标题、类型、年份查
|
||||||
item = MediaServerItem.exists_by_title(self._db, title=kwargs.get("title"),
|
item = MediaServerItem.exists_by_title(self._db, title=kwargs.get("title"),
|
||||||
mtype=kwargs.get("mtype"), year=kwargs.get("year"))
|
mtype=kwargs.get("mtype"), year=kwargs.get("year"))
|
||||||
|
else:
|
||||||
|
return None
|
||||||
if not item:
|
if not item:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -1,50 +1,9 @@
|
|||||||
from typing import Any, Self, List
|
from .downloadhistory import DownloadHistory, DownloadFiles
|
||||||
|
from .mediaserver import MediaServerItem
|
||||||
from sqlalchemy.orm import as_declarative, declared_attr, Session
|
from .plugindata import PluginData
|
||||||
|
from .site import Site
|
||||||
from app.db import db_update, db_query
|
from .siteicon import SiteIcon
|
||||||
|
from .subscribe import Subscribe
|
||||||
|
from .systemconfig import SystemConfig
|
||||||
@as_declarative()
|
from .transferhistory import TransferHistory
|
||||||
class Base:
|
from .user import User
|
||||||
id: Any
|
|
||||||
__name__: str
|
|
||||||
|
|
||||||
@db_update
|
|
||||||
def create(self, db: Session) -> Self:
|
|
||||||
db.add(self)
|
|
||||||
return self
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@db_query
|
|
||||||
def get(cls, db: Session, rid: int) -> Self:
|
|
||||||
return db.query(cls).filter(cls.id == rid).first()
|
|
||||||
|
|
||||||
@db_update
|
|
||||||
def update(self, db: Session, payload: dict):
|
|
||||||
payload = {k: v for k, v in payload.items() if v is not None}
|
|
||||||
for key, value in payload.items():
|
|
||||||
setattr(self, key, value)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@db_update
|
|
||||||
def delete(cls, db: Session, rid):
|
|
||||||
db.query(cls).filter(cls.id == rid).delete()
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@db_update
|
|
||||||
def truncate(cls, db: Session):
|
|
||||||
db.query(cls).delete()
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@db_query
|
|
||||||
def list(cls, db: Session) -> List[Self]:
|
|
||||||
result = db.query(cls).all()
|
|
||||||
return list(result)
|
|
||||||
|
|
||||||
def to_dict(self):
|
|
||||||
return {c.name: getattr(self, c.name, None) for c in self.__table__.columns}
|
|
||||||
|
|
||||||
@declared_attr
|
|
||||||
def __tablename__(self) -> str:
|
|
||||||
return self.__name__.lower()
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
from sqlalchemy import Column, Integer, String, Sequence
|
from sqlalchemy import Column, Integer, String, Sequence
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from app.db import db_query
|
from app.db import db_query, db_update, Base
|
||||||
from app.db.models import Base, db_update
|
|
||||||
|
|
||||||
|
|
||||||
class DownloadHistory(Base):
|
class DownloadHistory(Base):
|
||||||
@@ -38,6 +37,8 @@ class DownloadHistory(Base):
|
|||||||
torrent_site = Column(String)
|
torrent_site = Column(String)
|
||||||
# 下载用户
|
# 下载用户
|
||||||
userid = Column(String)
|
userid = Column(String)
|
||||||
|
# 下载用户名/插件名
|
||||||
|
username = Column(String)
|
||||||
# 下载渠道
|
# 下载渠道
|
||||||
channel = Column(String)
|
channel = Column(String)
|
||||||
# 创建时间
|
# 创建时间
|
||||||
@@ -108,19 +109,37 @@ class DownloadHistory(Base):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_query
|
@db_query
|
||||||
def list_by_user_date(db: Session, date: str, userid: str = None):
|
def list_by_user_date(db: Session, date: str, username: str = None):
|
||||||
"""
|
"""
|
||||||
查询某用户某时间之后的下载历史
|
查询某用户某时间之后的下载历史
|
||||||
"""
|
"""
|
||||||
if userid:
|
if username:
|
||||||
result = db.query(DownloadHistory).filter(DownloadHistory.date < date,
|
result = db.query(DownloadHistory).filter(DownloadHistory.date < date,
|
||||||
DownloadHistory.userid == userid).order_by(
|
DownloadHistory.username == username).order_by(
|
||||||
DownloadHistory.id.desc()).all()
|
DownloadHistory.id.desc()).all()
|
||||||
else:
|
else:
|
||||||
result = db.query(DownloadHistory).filter(DownloadHistory.date < date).order_by(
|
result = db.query(DownloadHistory).filter(DownloadHistory.date < date).order_by(
|
||||||
DownloadHistory.id.desc()).all()
|
DownloadHistory.id.desc()).all()
|
||||||
return list(result)
|
return list(result)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@db_query
|
||||||
|
def list_by_date(db: Session, date: str, type: str, tmdbid: str, seasons: str = None):
|
||||||
|
"""
|
||||||
|
查询某时间之后的下载历史
|
||||||
|
"""
|
||||||
|
if seasons:
|
||||||
|
return db.query(DownloadHistory).filter(DownloadHistory.date > date,
|
||||||
|
DownloadHistory.type == type,
|
||||||
|
DownloadHistory.tmdbid == tmdbid,
|
||||||
|
DownloadHistory.seasons == seasons).order_by(
|
||||||
|
DownloadHistory.id.desc()).all()
|
||||||
|
else:
|
||||||
|
return db.query(DownloadHistory).filter(DownloadHistory.date > date,
|
||||||
|
DownloadHistory.type == type,
|
||||||
|
DownloadHistory.tmdbid == tmdbid).order_by(
|
||||||
|
DownloadHistory.id.desc()).all()
|
||||||
|
|
||||||
|
|
||||||
class DownloadFiles(Base):
|
class DownloadFiles(Base):
|
||||||
"""
|
"""
|
||||||
@@ -155,9 +174,13 @@ class DownloadFiles(Base):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_query
|
@db_query
|
||||||
def get_by_fullpath(db: Session, fullpath: str):
|
def get_by_fullpath(db: Session, fullpath: str, all_files: bool = False):
|
||||||
return db.query(DownloadFiles).filter(DownloadFiles.fullpath == fullpath).order_by(
|
if not all_files:
|
||||||
DownloadFiles.id.desc()).first()
|
return db.query(DownloadFiles).filter(DownloadFiles.fullpath == fullpath).order_by(
|
||||||
|
DownloadFiles.id.desc()).first()
|
||||||
|
else:
|
||||||
|
return db.query(DownloadFiles).filter(DownloadFiles.fullpath == fullpath).order_by(
|
||||||
|
DownloadFiles.id.desc()).all()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_query
|
@db_query
|
||||||
@@ -165,7 +188,6 @@ class DownloadFiles(Base):
|
|||||||
result = db.query(DownloadFiles).filter(DownloadFiles.savepath == savepath).all()
|
result = db.query(DownloadFiles).filter(DownloadFiles.savepath == savepath).all()
|
||||||
return list(result)
|
return list(result)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
@db_update
|
@db_update
|
||||||
def delete_by_fullpath(db: Session, fullpath: str):
|
def delete_by_fullpath(db: Session, fullpath: str):
|
||||||
db.query(DownloadFiles).filter(DownloadFiles.fullpath == fullpath,
|
db.query(DownloadFiles).filter(DownloadFiles.fullpath == fullpath,
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from sqlalchemy import Column, Integer, String, Sequence
|
from sqlalchemy import Column, Integer, String, Sequence
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from app.db import db_query
|
from app.db import db_query, db_update, Base
|
||||||
from app.db.models import Base, db_update
|
|
||||||
|
|
||||||
|
|
||||||
class MediaServerItem(Base):
|
class MediaServerItem(Base):
|
||||||
"""
|
"""
|
||||||
站点表
|
媒体服务器媒体条目表
|
||||||
"""
|
"""
|
||||||
id = Column(Integer, Sequence('id'), primary_key=True, index=True)
|
id = Column(Integer, Sequence('id'), primary_key=True, index=True)
|
||||||
# 服务器类型
|
# 服务器类型
|
||||||
@@ -48,8 +48,11 @@ class MediaServerItem(Base):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_update
|
@db_update
|
||||||
def empty(db: Session, server: str):
|
def empty(db: Session, server: Optional[str] = None):
|
||||||
db.query(MediaServerItem).filter(MediaServerItem.server == server).delete()
|
if server is None:
|
||||||
|
db.query(MediaServerItem).delete()
|
||||||
|
else:
|
||||||
|
db.query(MediaServerItem).filter(MediaServerItem.server == server).delete()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_query
|
@db_query
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
from sqlalchemy import Column, Integer, String, Sequence
|
from sqlalchemy import Column, Integer, String, Sequence
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from app.db import db_query
|
from app.db import db_query, db_update, Base
|
||||||
from app.db.models import Base, db_update
|
|
||||||
|
|
||||||
|
|
||||||
class PluginData(Base):
|
class PluginData(Base):
|
||||||
@@ -3,8 +3,7 @@ from datetime import datetime
|
|||||||
from sqlalchemy import Boolean, Column, Integer, String, Sequence
|
from sqlalchemy import Boolean, Column, Integer, String, Sequence
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from app.db import db_query
|
from app.db import db_query, db_update, Base
|
||||||
from app.db.models import Base, db_update
|
|
||||||
|
|
||||||
|
|
||||||
class Site(Base):
|
class Site(Base):
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
from sqlalchemy import Column, Integer, String, Sequence
|
from sqlalchemy import Column, Integer, String, Sequence
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from app.db import db_query
|
from app.db import db_query, Base
|
||||||
from app.db.models import Base
|
|
||||||
|
|
||||||
|
|
||||||
class SiteIcon(Base):
|
class SiteIcon(Base):
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
from sqlalchemy import Column, Integer, String, Sequence
|
from sqlalchemy import Column, Integer, String, Sequence
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from app.db import db_update, db_query
|
from app.db import db_query, db_update, Base
|
||||||
from app.db.models import Base
|
|
||||||
|
|
||||||
|
|
||||||
class Subscribe(Base):
|
class Subscribe(Base):
|
||||||
@@ -66,14 +65,20 @@ class Subscribe(Base):
|
|||||||
best_version = Column(Integer, default=0)
|
best_version = Column(Integer, default=0)
|
||||||
# 当前优先级
|
# 当前优先级
|
||||||
current_priority = Column(Integer)
|
current_priority = Column(Integer)
|
||||||
|
# 保存路径
|
||||||
|
save_path = Column(String)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_query
|
@db_query
|
||||||
def exists(db: Session, tmdbid: int, season: int = None):
|
def exists(db: Session, tmdbid: int = None, doubanid: str = None, season: int = None):
|
||||||
if season:
|
if tmdbid:
|
||||||
return db.query(Subscribe).filter(Subscribe.tmdbid == tmdbid,
|
if season:
|
||||||
Subscribe.season == season).first()
|
return db.query(Subscribe).filter(Subscribe.tmdbid == tmdbid,
|
||||||
return db.query(Subscribe).filter(Subscribe.tmdbid == tmdbid).first()
|
Subscribe.season == season).first()
|
||||||
|
return db.query(Subscribe).filter(Subscribe.tmdbid == tmdbid).first()
|
||||||
|
elif doubanid:
|
||||||
|
return db.query(Subscribe).filter(Subscribe.doubanid == doubanid).first()
|
||||||
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_query
|
@db_query
|
||||||
@@ -93,7 +98,10 @@ class Subscribe(Base):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_query
|
@db_query
|
||||||
def get_by_title(db: Session, title: str):
|
def get_by_title(db: Session, title: str, season: int = None):
|
||||||
|
if season:
|
||||||
|
return db.query(Subscribe).filter(Subscribe.name == title,
|
||||||
|
Subscribe.season == season).first()
|
||||||
return db.query(Subscribe).filter(Subscribe.name == title).first()
|
return db.query(Subscribe).filter(Subscribe.name == title).first()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
from sqlalchemy import Column, Integer, String, Sequence
|
from sqlalchemy import Column, Integer, String, Sequence
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from app.db import db_update, db_query
|
from app.db import db_query, db_update, Base
|
||||||
from app.db.models import Base
|
|
||||||
|
|
||||||
|
|
||||||
class SystemConfig(Base):
|
class SystemConfig(Base):
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ import time
|
|||||||
from sqlalchemy import Column, Integer, String, Sequence, Boolean, func
|
from sqlalchemy import Column, Integer, String, Sequence, Boolean, func
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from app.db import db_query
|
from app.db import db_query, db_update, Base
|
||||||
from app.db.models import Base, db_update
|
|
||||||
|
|
||||||
|
|
||||||
class TransferHistory(Base):
|
class TransferHistory(Base):
|
||||||
@@ -49,17 +48,28 @@ class TransferHistory(Base):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_query
|
@db_query
|
||||||
def list_by_title(db: Session, title: str, page: int = 1, count: int = 30):
|
def list_by_title(db: Session, title: str, page: int = 1, count: int = 30, status: bool = None):
|
||||||
result = db.query(TransferHistory).filter(TransferHistory.title.like(f'%{title}%')).order_by(
|
if status is not None:
|
||||||
TransferHistory.date.desc()).offset((page - 1) * count).limit(
|
result = db.query(TransferHistory).filter(TransferHistory.title.like(f'%{title}%'),
|
||||||
count).all()
|
TransferHistory.status == status).order_by(
|
||||||
|
TransferHistory.date.desc()).offset((page - 1) * count).limit(
|
||||||
|
count).all()
|
||||||
|
else:
|
||||||
|
result = db.query(TransferHistory).filter(TransferHistory.title.like(f'%{title}%')).order_by(
|
||||||
|
TransferHistory.date.desc()).offset((page - 1) * count).limit(
|
||||||
|
count).all()
|
||||||
return list(result)
|
return list(result)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_query
|
@db_query
|
||||||
def list_by_page(db: Session, page: int = 1, count: int = 30):
|
def list_by_page(db: Session, page: int = 1, count: int = 30, status: bool = None):
|
||||||
result = db.query(TransferHistory).order_by(TransferHistory.date.desc()).offset((page - 1) * count).limit(
|
if status is not None:
|
||||||
count).all()
|
result = db.query(TransferHistory).filter(TransferHistory.status == status).order_by(
|
||||||
|
TransferHistory.date.desc()).offset((page - 1) * count).limit(
|
||||||
|
count).all()
|
||||||
|
else:
|
||||||
|
result = db.query(TransferHistory).order_by(TransferHistory.date.desc()).offset((page - 1) * count).limit(
|
||||||
|
count).all()
|
||||||
return list(result)
|
return list(result)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -93,13 +103,20 @@ class TransferHistory(Base):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_query
|
@db_query
|
||||||
def count(db: Session):
|
def count(db: Session, status: bool = None):
|
||||||
return db.query(func.count(TransferHistory.id)).first()[0]
|
if status is not None:
|
||||||
|
return db.query(func.count(TransferHistory.id)).filter(TransferHistory.status == status).first()[0]
|
||||||
|
else:
|
||||||
|
return db.query(func.count(TransferHistory.id)).first()[0]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_query
|
@db_query
|
||||||
def count_by_title(db: Session, title: str):
|
def count_by_title(db: Session, title: str, status: bool = None):
|
||||||
return db.query(func.count(TransferHistory.id)).filter(TransferHistory.title.like(f'%{title}%')).first()[0]
|
if status is not None:
|
||||||
|
return db.query(func.count(TransferHistory.id)).filter(TransferHistory.title.like(f'%{title}%'),
|
||||||
|
TransferHistory.status == status).first()[0]
|
||||||
|
else:
|
||||||
|
return db.query(func.count(TransferHistory.id)).filter(TransferHistory.title.like(f'%{title}%')).first()[0]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_query
|
@db_query
|
||||||
@@ -158,6 +175,13 @@ class TransferHistory(Base):
|
|||||||
# 电视剧所有季集
|
# 电视剧所有季集
|
||||||
result = db.query(TransferHistory).filter(TransferHistory.title == title,
|
result = db.query(TransferHistory).filter(TransferHistory.title == title,
|
||||||
TransferHistory.year == year).all()
|
TransferHistory.year == year).all()
|
||||||
|
# 类型 + 转移路径(emby webhook season无tmdbid场景)
|
||||||
|
elif mtype and season and dest:
|
||||||
|
# 电视剧某季
|
||||||
|
result = db.query(TransferHistory).filter(TransferHistory.type == mtype,
|
||||||
|
TransferHistory.seasons == season,
|
||||||
|
TransferHistory.dest.like(f"{dest}%")).all()
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
return list(result)
|
return list(result)
|
||||||
return []
|
return []
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ from sqlalchemy import Boolean, Column, Integer, String, Sequence
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from app.core.security import verify_password
|
from app.core.security import verify_password
|
||||||
from app.db import db_update, db_query
|
from app.db import db_query, db_update, Base
|
||||||
from app.db.models import Base
|
|
||||||
|
|
||||||
|
|
||||||
class User(Base):
|
class User(Base):
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import json
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from app.db import DbOper
|
from app.db import DbOper
|
||||||
from app.db.models.plugin import PluginData
|
from app.db.models.plugindata import PluginData
|
||||||
from app.utils.object import ObjectUtils
|
from app.utils.object import ObjectUtils
|
||||||
|
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ class PluginDataOper(DbOper):
|
|||||||
插件数据管理
|
插件数据管理
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def save(self, plugin_id: str, key: str, value: Any) -> PluginData:
|
def save(self, plugin_id: str, key: str, value: Any):
|
||||||
"""
|
"""
|
||||||
保存插件数据
|
保存插件数据
|
||||||
:param plugin_id: 插件id
|
:param plugin_id: 插件id
|
||||||
@@ -25,10 +25,8 @@ class PluginDataOper(DbOper):
|
|||||||
plugin.update(self._db, {
|
plugin.update(self._db, {
|
||||||
"value": value
|
"value": value
|
||||||
})
|
})
|
||||||
return plugin
|
|
||||||
else:
|
else:
|
||||||
plugin = PluginData(plugin_id=plugin_id, key=key, value=value)
|
PluginData(plugin_id=plugin_id, key=key, value=value).create(self._db)
|
||||||
return plugin.create(self._db)
|
|
||||||
|
|
||||||
def get_data(self, plugin_id: str, key: str) -> Any:
|
def get_data(self, plugin_id: str, key: str) -> Any:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ class SubscribeOper(DbOper):
|
|||||||
"""
|
"""
|
||||||
新增订阅
|
新增订阅
|
||||||
"""
|
"""
|
||||||
subscribe = Subscribe.exists(self._db, tmdbid=mediainfo.tmdb_id, season=kwargs.get('season'))
|
subscribe = Subscribe.exists(self._db,
|
||||||
|
tmdbid=mediainfo.tmdb_id,
|
||||||
|
doubanid=mediainfo.douban_id,
|
||||||
|
season=kwargs.get('season'))
|
||||||
if not subscribe:
|
if not subscribe:
|
||||||
subscribe = Subscribe(name=mediainfo.title,
|
subscribe = Subscribe(name=mediainfo.title,
|
||||||
year=mediainfo.year,
|
year=mediainfo.year,
|
||||||
@@ -23,6 +26,7 @@ class SubscribeOper(DbOper):
|
|||||||
tmdbid=mediainfo.tmdb_id,
|
tmdbid=mediainfo.tmdb_id,
|
||||||
imdbid=mediainfo.imdb_id,
|
imdbid=mediainfo.imdb_id,
|
||||||
tvdbid=mediainfo.tvdb_id,
|
tvdbid=mediainfo.tvdb_id,
|
||||||
|
doubanid=mediainfo.douban_id,
|
||||||
poster=mediainfo.get_poster_image(),
|
poster=mediainfo.get_poster_image(),
|
||||||
backdrop=mediainfo.get_backdrop_image(),
|
backdrop=mediainfo.get_backdrop_image(),
|
||||||
vote=mediainfo.vote_average,
|
vote=mediainfo.vote_average,
|
||||||
@@ -30,18 +34,27 @@ class SubscribeOper(DbOper):
|
|||||||
date=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
|
date=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
|
||||||
**kwargs)
|
**kwargs)
|
||||||
subscribe.create(self._db)
|
subscribe.create(self._db)
|
||||||
|
# 查询订阅
|
||||||
|
subscribe = Subscribe.exists(self._db,
|
||||||
|
tmdbid=mediainfo.tmdb_id,
|
||||||
|
doubanid=mediainfo.douban_id,
|
||||||
|
season=kwargs.get('season'))
|
||||||
return subscribe.id, "新增订阅成功"
|
return subscribe.id, "新增订阅成功"
|
||||||
else:
|
else:
|
||||||
return subscribe.id, "订阅已存在"
|
return subscribe.id, "订阅已存在"
|
||||||
|
|
||||||
def exists(self, tmdbid: int, season: int) -> bool:
|
def exists(self, tmdbid: int = None, doubanid: str = None, season: int = None) -> bool:
|
||||||
"""
|
"""
|
||||||
判断是否存在
|
判断是否存在
|
||||||
"""
|
"""
|
||||||
if season:
|
if tmdbid:
|
||||||
return True if Subscribe.exists(self._db, tmdbid=tmdbid, season=season) else False
|
if season:
|
||||||
else:
|
return True if Subscribe.exists(self._db, tmdbid=tmdbid, season=season) else False
|
||||||
return True if Subscribe.exists(self._db, tmdbid=tmdbid) else False
|
else:
|
||||||
|
return True if Subscribe.exists(self._db, tmdbid=tmdbid) else False
|
||||||
|
elif doubanid:
|
||||||
|
return True if Subscribe.exists(self._db, doubanid=doubanid) else False
|
||||||
|
return False
|
||||||
|
|
||||||
def get(self, sid: int) -> Subscribe:
|
def get(self, sid: int) -> Subscribe:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -56,6 +56,20 @@ class SystemConfigOper(DbOper, metaclass=Singleton):
|
|||||||
return self.__SYSTEMCONF
|
return self.__SYSTEMCONF
|
||||||
return self.__SYSTEMCONF.get(key)
|
return self.__SYSTEMCONF.get(key)
|
||||||
|
|
||||||
|
def delete(self, key: Union[str, SystemConfigKey]):
|
||||||
|
"""
|
||||||
|
删除系统设置
|
||||||
|
"""
|
||||||
|
if isinstance(key, SystemConfigKey):
|
||||||
|
key = key.value
|
||||||
|
# 更新内存
|
||||||
|
self.__SYSTEMCONF.pop(key, None)
|
||||||
|
# 写入数据库
|
||||||
|
conf = SystemConfig.get_by_key(self._db, key)
|
||||||
|
if conf:
|
||||||
|
conf.delete(self._db, conf.id)
|
||||||
|
return True
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if self._db:
|
if self._db:
|
||||||
self._db.close()
|
self._db.close()
|
||||||
|
|||||||
@@ -43,14 +43,14 @@ class TransferHistoryOper(DbOper):
|
|||||||
"""
|
"""
|
||||||
return TransferHistory.list_by_hash(self._db, download_hash)
|
return TransferHistory.list_by_hash(self._db, download_hash)
|
||||||
|
|
||||||
def add(self, **kwargs) -> TransferHistory:
|
def add(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
新增转移历史
|
新增转移历史
|
||||||
"""
|
"""
|
||||||
kwargs.update({
|
kwargs.update({
|
||||||
"date": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
"date": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
||||||
})
|
})
|
||||||
return TransferHistory(**kwargs).create(self._db)
|
TransferHistory(**kwargs).create(self._db)
|
||||||
|
|
||||||
def statistic(self, days: int = 7) -> List[Any]:
|
def statistic(self, days: int = 7) -> List[Any]:
|
||||||
"""
|
"""
|
||||||
@@ -103,7 +103,8 @@ class TransferHistoryOper(DbOper):
|
|||||||
kwargs.update({
|
kwargs.update({
|
||||||
"date": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
"date": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
||||||
})
|
})
|
||||||
return TransferHistory(**kwargs).create(self._db)
|
TransferHistory(**kwargs).create(self._db)
|
||||||
|
return TransferHistory.get_by_src(self._db, kwargs.get("src"))
|
||||||
|
|
||||||
def update_download_hash(self, historyid, download_hash):
|
def update_download_hash(self, historyid, download_hash):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import importlib
|
import importlib
|
||||||
import pkgutil
|
import pkgutil
|
||||||
|
import traceback
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from app.log import logger
|
||||||
|
|
||||||
|
|
||||||
class ModuleHelper:
|
class ModuleHelper:
|
||||||
@@ -20,14 +24,32 @@ class ModuleHelper:
|
|||||||
submodules: list = []
|
submodules: list = []
|
||||||
packages = importlib.import_module(package_path)
|
packages = importlib.import_module(package_path)
|
||||||
for importer, package_name, _ in pkgutil.iter_modules(packages.__path__):
|
for importer, package_name, _ in pkgutil.iter_modules(packages.__path__):
|
||||||
if package_name.startswith('_'):
|
try:
|
||||||
continue
|
if package_name.startswith('_'):
|
||||||
full_package_name = f'{package_path}.{package_name}'
|
|
||||||
module = importlib.import_module(full_package_name)
|
|
||||||
for name, obj in module.__dict__.items():
|
|
||||||
if name.startswith('_'):
|
|
||||||
continue
|
continue
|
||||||
if isinstance(obj, type) and filter_func(name, obj):
|
full_package_name = f'{package_path}.{package_name}'
|
||||||
submodules.append(obj)
|
module = importlib.import_module(full_package_name)
|
||||||
|
importlib.reload(module)
|
||||||
|
for name, obj in module.__dict__.items():
|
||||||
|
if name.startswith('_'):
|
||||||
|
continue
|
||||||
|
if isinstance(obj, type) and filter_func(name, obj):
|
||||||
|
submodules.append(obj)
|
||||||
|
except Exception as err:
|
||||||
|
logger.error(f'加载模块 {package_name} 失败:{str(err)} - {traceback.format_exc()}')
|
||||||
|
|
||||||
return submodules
|
return submodules
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def dynamic_import_all_modules(base_path: Path, package_name: str):
|
||||||
|
"""
|
||||||
|
动态导入目录下所有模块
|
||||||
|
"""
|
||||||
|
modules = []
|
||||||
|
# 遍历文件夹,找到所有模块文件
|
||||||
|
for file in base_path.glob("*.py"):
|
||||||
|
file_name = file.stem
|
||||||
|
if file_name != "__init__":
|
||||||
|
modules.append(file_name)
|
||||||
|
full_module_name = f"{package_name}.{file_name}"
|
||||||
|
importlib.import_module(full_module_name)
|
||||||
|
|||||||
153
app/helper/plugin.py
Normal file
153
app/helper/plugin.py
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
import json
|
||||||
|
import shutil
|
||||||
|
import traceback
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Dict, Tuple, Optional, List
|
||||||
|
|
||||||
|
from cachetools import TTLCache, cached
|
||||||
|
|
||||||
|
from app.core.config import settings
|
||||||
|
from app.log import logger
|
||||||
|
from app.utils.http import RequestUtils
|
||||||
|
from app.utils.singleton import Singleton
|
||||||
|
from app.utils.system import SystemUtils
|
||||||
|
|
||||||
|
|
||||||
|
class PluginHelper(metaclass=Singleton):
|
||||||
|
"""
|
||||||
|
插件市场管理,下载安装插件到本地
|
||||||
|
"""
|
||||||
|
|
||||||
|
_base_url = "https://raw.githubusercontent.com/%s/%s/main/"
|
||||||
|
|
||||||
|
@cached(cache=TTLCache(maxsize=10, ttl=1800))
|
||||||
|
def get_plugins(self, repo_url: str) -> Dict[str, dict]:
|
||||||
|
"""
|
||||||
|
获取Github所有最新插件列表
|
||||||
|
:param repo_url: Github仓库地址
|
||||||
|
"""
|
||||||
|
if not repo_url:
|
||||||
|
return {}
|
||||||
|
user, repo = self.get_repo_info(repo_url)
|
||||||
|
if not user or not repo:
|
||||||
|
return {}
|
||||||
|
raw_url = self._base_url % (user, repo)
|
||||||
|
res = RequestUtils(proxies=settings.PROXY, headers=settings.GITHUB_HEADERS,
|
||||||
|
timeout=10).get_res(f"{raw_url}package.json")
|
||||||
|
if res:
|
||||||
|
return json.loads(res.text)
|
||||||
|
return {}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_repo_info(repo_url: str) -> Tuple[Optional[str], Optional[str]]:
|
||||||
|
"""
|
||||||
|
获取Github仓库信息
|
||||||
|
:param repo_url: Github仓库地址
|
||||||
|
"""
|
||||||
|
if not repo_url:
|
||||||
|
return None, None
|
||||||
|
if not repo_url.endswith("/"):
|
||||||
|
repo_url += "/"
|
||||||
|
if repo_url.count("/") < 6:
|
||||||
|
repo_url = f"{repo_url}main/"
|
||||||
|
try:
|
||||||
|
user, repo = repo_url.split("/")[-4:-2]
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"解析Github仓库地址失败:{str(e)} - {traceback.format_exc()}")
|
||||||
|
return None, None
|
||||||
|
return user, repo
|
||||||
|
|
||||||
|
def install(self, pid: str, repo_url: str) -> Tuple[bool, str]:
|
||||||
|
"""
|
||||||
|
安装插件
|
||||||
|
"""
|
||||||
|
if SystemUtils.is_frozen():
|
||||||
|
return False, "可执行文件模式下,只能安装本地插件"
|
||||||
|
|
||||||
|
# 从Github的repo_url获取用户和项目名
|
||||||
|
user, repo = self.get_repo_info(repo_url)
|
||||||
|
if not user or not repo:
|
||||||
|
return False, "不支持的插件仓库地址格式"
|
||||||
|
|
||||||
|
def __get_filelist(_p: str) -> Tuple[Optional[list], Optional[str]]:
|
||||||
|
"""
|
||||||
|
获取插件的文件列表
|
||||||
|
"""
|
||||||
|
file_api = f"https://api.github.com/repos/{user}/{repo}/contents/plugins/{_p.lower()}"
|
||||||
|
r = RequestUtils(proxies=settings.PROXY, headers=settings.GITHUB_HEADERS, timeout=30).get_res(file_api)
|
||||||
|
if not r or r.status_code != 200:
|
||||||
|
return None, f"连接仓库失败:{r.status_code} - {r.reason}"
|
||||||
|
ret = r.json()
|
||||||
|
if ret and ret[0].get("message") == "Not Found":
|
||||||
|
return None, "插件在仓库中不存在"
|
||||||
|
return ret, ""
|
||||||
|
|
||||||
|
def __download_files(_p: str, _l: List[dict]) -> Tuple[bool, str]:
|
||||||
|
"""
|
||||||
|
下载插件文件
|
||||||
|
"""
|
||||||
|
if not _l:
|
||||||
|
return False, "文件列表为空"
|
||||||
|
for item in _l:
|
||||||
|
if item.get("download_url"):
|
||||||
|
# 下载插件文件
|
||||||
|
res = RequestUtils(proxies=settings.PROXY,
|
||||||
|
headers=settings.GITHUB_HEADERS, timeout=60).get_res(item["download_url"])
|
||||||
|
if not res:
|
||||||
|
return False, f"文件 {item.get('name')} 下载失败!"
|
||||||
|
elif res.status_code != 200:
|
||||||
|
return False, f"下载文件 {item.get('name')} 失败:{res.status_code} - {res.reason}"
|
||||||
|
# 创建插件文件夹
|
||||||
|
file_path = Path(settings.ROOT_PATH) / "app" / item.get("path")
|
||||||
|
if not file_path.parent.exists():
|
||||||
|
file_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
with open(file_path, "w", encoding="utf-8") as f:
|
||||||
|
f.write(res.text)
|
||||||
|
else:
|
||||||
|
# 递归下载子目录
|
||||||
|
p = f"{_p}/{item.get('name')}"
|
||||||
|
l, m = __get_filelist(p)
|
||||||
|
if not l:
|
||||||
|
return False, m
|
||||||
|
__download_files(p, l)
|
||||||
|
return True, ""
|
||||||
|
|
||||||
|
if not pid or not repo_url:
|
||||||
|
return False, "参数错误"
|
||||||
|
|
||||||
|
# 获取插件的文件列表
|
||||||
|
"""
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "__init__.py",
|
||||||
|
"path": "plugins/autobackup/__init__.py",
|
||||||
|
"sha": "cd10eba3f0355d61adeb35561cb26a0a36c15a6c",
|
||||||
|
"size": 12385,
|
||||||
|
"url": "https://api.github.com/repos/jxxghp/MoviePilot-Plugins/contents/plugins/autobackup/__init__.py?ref=main",
|
||||||
|
"html_url": "https://github.com/jxxghp/MoviePilot-Plugins/blob/main/plugins/autobackup/__init__.py",
|
||||||
|
"git_url": "https://api.github.com/repos/jxxghp/MoviePilot-Plugins/git/blobs/cd10eba3f0355d61adeb35561cb26a0a36c15a6c",
|
||||||
|
"download_url": "https://raw.githubusercontent.com/jxxghp/MoviePilot-Plugins/main/plugins/autobackup/__init__.py",
|
||||||
|
"type": "file",
|
||||||
|
"_links": {
|
||||||
|
"self": "https://api.github.com/repos/jxxghp/MoviePilot-Plugins/contents/plugins/autobackup/__init__.py?ref=main",
|
||||||
|
"git": "https://api.github.com/repos/jxxghp/MoviePilot-Plugins/git/blobs/cd10eba3f0355d61adeb35561cb26a0a36c15a6c",
|
||||||
|
"html": "https://github.com/jxxghp/MoviePilot-Plugins/blob/main/plugins/autobackup/__init__.py"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
"""
|
||||||
|
# 获取第一级文件列表
|
||||||
|
file_list, msg = __get_filelist(pid.lower())
|
||||||
|
if not file_list:
|
||||||
|
return False, msg
|
||||||
|
# 本地存在时先删除
|
||||||
|
plugin_dir = Path(settings.ROOT_PATH) / "app" / "plugins" / pid.lower()
|
||||||
|
if plugin_dir.exists():
|
||||||
|
shutil.rmtree(plugin_dir, ignore_errors=True)
|
||||||
|
# 下载所有文件
|
||||||
|
__download_files(pid.lower(), file_list)
|
||||||
|
# 插件目录下如有requirements.txt则安装依赖
|
||||||
|
requirements_file = plugin_dir / "requirements.txt"
|
||||||
|
if requirements_file.exists():
|
||||||
|
SystemUtils.execute(f"pip install -r {requirements_file} > /dev/null 2>&1")
|
||||||
|
return True, ""
|
||||||
103
app/helper/resource.py
Normal file
103
app/helper/resource.py
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from app.core.config import settings
|
||||||
|
from app.helper.sites import SitesHelper
|
||||||
|
from app.log import logger
|
||||||
|
from app.utils.http import RequestUtils
|
||||||
|
from app.utils.singleton import Singleton
|
||||||
|
from app.utils.string import StringUtils
|
||||||
|
from app.utils.system import SystemUtils
|
||||||
|
|
||||||
|
|
||||||
|
class ResourceHelper(metaclass=Singleton):
|
||||||
|
"""
|
||||||
|
检测和更新资源包
|
||||||
|
"""
|
||||||
|
# 资源包的git仓库地址
|
||||||
|
_repo = "https://raw.githubusercontent.com/jxxghp/MoviePilot-Resources/main/package.json"
|
||||||
|
_files_api = f"https://api.github.com/repos/jxxghp/MoviePilot-Resources/contents/resources"
|
||||||
|
_base_dir: Path = settings.ROOT_PATH
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.siteshelper = SitesHelper()
|
||||||
|
self.check()
|
||||||
|
|
||||||
|
def check(self):
|
||||||
|
"""
|
||||||
|
检测是否有更新,如有则下载安装
|
||||||
|
"""
|
||||||
|
if not settings.AUTO_UPDATE_RESOURCE:
|
||||||
|
return
|
||||||
|
if SystemUtils.is_frozen():
|
||||||
|
return
|
||||||
|
logger.info("开始检测资源包版本...")
|
||||||
|
res = RequestUtils(proxies=settings.PROXY, headers=settings.GITHUB_HEADERS, timeout=10).get_res(self._repo)
|
||||||
|
if res:
|
||||||
|
resource_info = json.loads(res.text)
|
||||||
|
else:
|
||||||
|
logger.warn("无法连接资源包仓库!")
|
||||||
|
return
|
||||||
|
online_version = resource_info.get("version")
|
||||||
|
if online_version:
|
||||||
|
logger.info(f"最新资源包版本:v{online_version}")
|
||||||
|
# 需要更新的资源包
|
||||||
|
need_updates = {}
|
||||||
|
# 资源明细
|
||||||
|
resources: dict = resource_info.get("resources") or {}
|
||||||
|
for rname, resource in resources.items():
|
||||||
|
rtype = resource.get("type")
|
||||||
|
platform = resource.get("platform")
|
||||||
|
target = resource.get("target")
|
||||||
|
version = resource.get("version")
|
||||||
|
# 判断平台
|
||||||
|
if platform and platform != SystemUtils.platform:
|
||||||
|
continue
|
||||||
|
# 判断本地是否存在
|
||||||
|
local_path = self._base_dir / target / rname
|
||||||
|
if not local_path.exists():
|
||||||
|
continue
|
||||||
|
# 判断版本号
|
||||||
|
if rtype == "auth":
|
||||||
|
# 站点认证资源
|
||||||
|
local_version = self.siteshelper.auth_version
|
||||||
|
elif rtype == "sites":
|
||||||
|
# 站点索引资源
|
||||||
|
local_version = self.siteshelper.indexer_version
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
if StringUtils.compare_version(version, local_version) > 0:
|
||||||
|
logger.info(f"{rname} 资源包有更新,最新版本:v{version}")
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
# 需要安装
|
||||||
|
need_updates[rname] = target
|
||||||
|
if need_updates:
|
||||||
|
# 下载文件信息列表
|
||||||
|
r = RequestUtils(proxies=settings.PROXY, headers=settings.GITHUB_HEADERS,
|
||||||
|
timeout=30).get_res(self._files_api)
|
||||||
|
if not r or r.status_code != 200:
|
||||||
|
return None, f"连接仓库失败:{r.status_code} - {r.reason}"
|
||||||
|
files_info = r.json()
|
||||||
|
for item in files_info:
|
||||||
|
save_path = need_updates.get(item.get("name"))
|
||||||
|
if not save_path:
|
||||||
|
continue
|
||||||
|
if item.get("download_url"):
|
||||||
|
# 下载资源文件
|
||||||
|
res = RequestUtils(proxies=settings.PROXY, headers=settings.GITHUB_HEADERS,
|
||||||
|
timeout=180).get_res(item["download_url"])
|
||||||
|
if not res:
|
||||||
|
logger.error(f"文件 {item.get('name')} 下载失败!")
|
||||||
|
elif res.status_code != 200:
|
||||||
|
logger.error(f"下载文件 {item.get('name')} 失败:{res.status_code} - {res.reason}")
|
||||||
|
# 创建插件文件夹
|
||||||
|
file_path = self._base_dir / save_path / item.get("name")
|
||||||
|
if not file_path.parent.exists():
|
||||||
|
file_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
# 写入文件
|
||||||
|
file_path.write_bytes(res.content)
|
||||||
|
logger.info("资源包更新完成,开始重启服务...")
|
||||||
|
SystemUtils.restart()
|
||||||
|
else:
|
||||||
|
logger.info("所有资源已最新,无需更新")
|
||||||
@@ -1,11 +1,15 @@
|
|||||||
|
import re
|
||||||
|
import traceback
|
||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
from typing import List, Tuple, Union
|
from typing import List, Tuple, Union
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
|
import chardet
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.helper.browser import PlaywrightHelper
|
from app.helper.browser import PlaywrightHelper
|
||||||
|
from app.log import logger
|
||||||
from app.utils.dom import DomUtils
|
from app.utils.dom import DomUtils
|
||||||
from app.utils.http import RequestUtils
|
from app.utils.http import RequestUtils
|
||||||
from app.utils.string import StringUtils
|
from app.utils.string import StringUtils
|
||||||
@@ -236,13 +240,32 @@ class RssHelper:
|
|||||||
ret = RequestUtils(proxies=settings.PROXY if proxy else None).get_res(url)
|
ret = RequestUtils(proxies=settings.PROXY if proxy else None).get_res(url)
|
||||||
if not ret:
|
if not ret:
|
||||||
return []
|
return []
|
||||||
ret.encoding = ret.apparent_encoding
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(str(err))
|
logger.error(f"获取RSS失败:{str(err)} - {traceback.format_exc()}")
|
||||||
return []
|
return []
|
||||||
if ret:
|
if ret:
|
||||||
ret_xml = ret.text
|
ret_xml = ""
|
||||||
try:
|
try:
|
||||||
|
# 使用chardet检测字符编码
|
||||||
|
raw_data = ret.content
|
||||||
|
if raw_data:
|
||||||
|
try:
|
||||||
|
result = chardet.detect(raw_data)
|
||||||
|
encoding = result['encoding']
|
||||||
|
# 解码为字符串
|
||||||
|
ret_xml = raw_data.decode(encoding)
|
||||||
|
except Exception as e:
|
||||||
|
logger.debug(f"chardet解码失败:{str(e)}")
|
||||||
|
# 探测utf-8解码
|
||||||
|
match = re.search(r'encoding\s*=\s*["\']([^"\']+)["\']', ret.text)
|
||||||
|
if match:
|
||||||
|
encoding = match.group(1)
|
||||||
|
if encoding:
|
||||||
|
ret_xml = raw_data.decode(encoding)
|
||||||
|
else:
|
||||||
|
ret.encoding = ret.apparent_encoding
|
||||||
|
if not ret_xml:
|
||||||
|
ret_xml = ret.text
|
||||||
# 解析XML
|
# 解析XML
|
||||||
dom_tree = xml.dom.minidom.parseString(ret_xml)
|
dom_tree = xml.dom.minidom.parseString(ret_xml)
|
||||||
rootNode = dom_tree.documentElement
|
rootNode = dom_tree.documentElement
|
||||||
@@ -284,10 +307,10 @@ class RssHelper:
|
|||||||
'pubdate': pubdate}
|
'pubdate': pubdate}
|
||||||
ret_array.append(tmp_dict)
|
ret_array.append(tmp_dict)
|
||||||
except Exception as e1:
|
except Exception as e1:
|
||||||
print(str(e1))
|
logger.debug(f"解析RSS失败:{str(e1)} - {traceback.format_exc()}")
|
||||||
continue
|
continue
|
||||||
except Exception as e2:
|
except Exception as e2:
|
||||||
print(str(e2))
|
logger.error(f"解析RSS失败:{str(e2)} - {traceback.format_exc()}")
|
||||||
# RSS过期 观众RSS 链接已过期,您需要获得一个新的! pthome RSS Link has expired, You need to get a new one!
|
# RSS过期 观众RSS 链接已过期,您需要获得一个新的! pthome RSS Link has expired, You need to get a new one!
|
||||||
_rss_expired_msg = [
|
_rss_expired_msg = [
|
||||||
"RSS 链接已过期, 您需要获得一个新的!",
|
"RSS 链接已过期, 您需要获得一个新的!",
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -14,13 +14,17 @@ from app.db.systemconfig_oper import SystemConfigOper
|
|||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.utils.http import RequestUtils
|
from app.utils.http import RequestUtils
|
||||||
from app.schemas.types import MediaType, SystemConfigKey
|
from app.schemas.types import MediaType, SystemConfigKey
|
||||||
|
from app.utils.singleton import Singleton
|
||||||
|
|
||||||
|
|
||||||
class TorrentHelper:
|
class TorrentHelper(metaclass=Singleton):
|
||||||
"""
|
"""
|
||||||
种子帮助类
|
种子帮助类
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# 失败的种子:站点链接
|
||||||
|
_invalid_torrents = []
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.system_config = SystemConfigOper()
|
self.system_config = SystemConfigOper()
|
||||||
|
|
||||||
@@ -123,6 +127,8 @@ class TorrentHelper:
|
|||||||
elif req.status_code == 429:
|
elif req.status_code == 429:
|
||||||
return None, None, "", [], "触发站点流控,请稍后重试"
|
return None, None, "", [], "触发站点流控,请稍后重试"
|
||||||
else:
|
else:
|
||||||
|
# 把错误的种子记下来,避免重复使用
|
||||||
|
self.add_invalid(url)
|
||||||
return None, None, "", [], f"下载种子出错,状态码:{req.status_code}"
|
return None, None, "", [], f"下载种子出错,状态码:{req.status_code}"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -276,3 +282,16 @@ class TorrentHelper:
|
|||||||
continue
|
continue
|
||||||
episodes = list(set(episodes).union(set(meta.episode_list)))
|
episodes = list(set(episodes).union(set(meta.episode_list)))
|
||||||
return episodes
|
return episodes
|
||||||
|
|
||||||
|
def is_invalid(self, url: str) -> bool:
|
||||||
|
"""
|
||||||
|
判断种子是否是无效种子
|
||||||
|
"""
|
||||||
|
return url in self._invalid_torrents
|
||||||
|
|
||||||
|
def add_invalid(self, url: str):
|
||||||
|
"""
|
||||||
|
添加无效种子
|
||||||
|
"""
|
||||||
|
if url not in self._invalid_torrents:
|
||||||
|
self._invalid_torrents.append(url)
|
||||||
|
|||||||
62
app/main.py
62
app/main.py
@@ -19,12 +19,15 @@ if SystemUtils.is_frozen():
|
|||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.core.module import ModuleManager
|
from app.core.module import ModuleManager
|
||||||
from app.core.plugin import PluginManager
|
from app.core.plugin import PluginManager
|
||||||
from app.db.init import init_db, update_db
|
from app.db.init import init_db, update_db, init_super_user
|
||||||
from app.helper.thread import ThreadHelper
|
from app.helper.thread import ThreadHelper
|
||||||
from app.helper.display import DisplayHelper
|
from app.helper.display import DisplayHelper
|
||||||
|
from app.helper.resource import ResourceHelper
|
||||||
from app.helper.sites import SitesHelper
|
from app.helper.sites import SitesHelper
|
||||||
|
from app.helper.message import MessageHelper
|
||||||
from app.scheduler import Scheduler
|
from app.scheduler import Scheduler
|
||||||
from app.command import Command
|
from app.command import Command, CommandChian
|
||||||
|
from app.schemas import Notification, NotificationType
|
||||||
|
|
||||||
# App
|
# App
|
||||||
App = FastAPI(title=settings.PROJECT_NAME,
|
App = FastAPI(title=settings.PROJECT_NAME,
|
||||||
@@ -60,33 +63,35 @@ def start_frontend():
|
|||||||
"""
|
"""
|
||||||
启动前端服务
|
启动前端服务
|
||||||
"""
|
"""
|
||||||
if not SystemUtils.is_frozen():
|
# 仅Windows可执行文件支持内嵌nginx
|
||||||
|
if not SystemUtils.is_frozen() \
|
||||||
|
or not SystemUtils.is_windows():
|
||||||
return
|
return
|
||||||
|
# 临时Nginx目录
|
||||||
nginx_path = settings.ROOT_PATH / 'nginx'
|
nginx_path = settings.ROOT_PATH / 'nginx'
|
||||||
if not nginx_path.exists():
|
if not nginx_path.exists():
|
||||||
return
|
return
|
||||||
|
# 配置目录下的Nginx目录
|
||||||
|
run_nginx_dir = settings.CONFIG_PATH.with_name('nginx')
|
||||||
|
if not run_nginx_dir.exists():
|
||||||
|
# 移动到配置目录
|
||||||
|
SystemUtils.move(nginx_path, run_nginx_dir)
|
||||||
|
# 启动Nginx
|
||||||
import subprocess
|
import subprocess
|
||||||
if SystemUtils.is_windows():
|
subprocess.Popen("start nginx.exe",
|
||||||
subprocess.Popen("start nginx.exe",
|
cwd=run_nginx_dir,
|
||||||
cwd=nginx_path,
|
shell=True)
|
||||||
shell=True)
|
|
||||||
else:
|
|
||||||
subprocess.Popen("nohup ./nginx &",
|
|
||||||
cwd=nginx_path,
|
|
||||||
shell=True)
|
|
||||||
|
|
||||||
|
|
||||||
def stop_frontend():
|
def stop_frontend():
|
||||||
"""
|
"""
|
||||||
停止前端服务
|
停止前端服务
|
||||||
"""
|
"""
|
||||||
if not SystemUtils.is_frozen():
|
if not SystemUtils.is_frozen() \
|
||||||
|
or not SystemUtils.is_windows():
|
||||||
return
|
return
|
||||||
import subprocess
|
import subprocess
|
||||||
if SystemUtils.is_windows():
|
subprocess.Popen(f"taskkill /f /im nginx.exe", shell=True)
|
||||||
subprocess.Popen(f"taskkill /f /im nginx.exe", shell=True)
|
|
||||||
else:
|
|
||||||
subprocess.Popen(f"killall nginx", shell=True)
|
|
||||||
|
|
||||||
|
|
||||||
def start_tray():
|
def start_tray():
|
||||||
@@ -97,6 +102,9 @@ def start_tray():
|
|||||||
if not SystemUtils.is_frozen():
|
if not SystemUtils.is_frozen():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not SystemUtils.is_windows():
|
||||||
|
return
|
||||||
|
|
||||||
def open_web():
|
def open_web():
|
||||||
"""
|
"""
|
||||||
调用浏览器打开前端页面
|
调用浏览器打开前端页面
|
||||||
@@ -132,6 +140,22 @@ def start_tray():
|
|||||||
threading.Thread(target=TrayIcon.run, daemon=True).start()
|
threading.Thread(target=TrayIcon.run, daemon=True).start()
|
||||||
|
|
||||||
|
|
||||||
|
def check_auth():
|
||||||
|
"""
|
||||||
|
检查认证状态
|
||||||
|
"""
|
||||||
|
if SitesHelper().auth_level < 2:
|
||||||
|
err_msg = "用户认证失败,站点相关功能将无法使用!"
|
||||||
|
MessageHelper().put(f"注意:{err_msg}")
|
||||||
|
CommandChian().post_message(
|
||||||
|
Notification(
|
||||||
|
mtype=NotificationType.Manual,
|
||||||
|
title="MoviePilot用户认证",
|
||||||
|
text=err_msg
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@App.on_event("shutdown")
|
@App.on_event("shutdown")
|
||||||
def shutdown_server():
|
def shutdown_server():
|
||||||
"""
|
"""
|
||||||
@@ -158,10 +182,14 @@ def start_module():
|
|||||||
"""
|
"""
|
||||||
启动模块
|
启动模块
|
||||||
"""
|
"""
|
||||||
|
# 初始化超级管理员
|
||||||
|
init_super_user()
|
||||||
# 虚拟显示
|
# 虚拟显示
|
||||||
DisplayHelper()
|
DisplayHelper()
|
||||||
# 站点管理
|
# 站点管理
|
||||||
SitesHelper()
|
SitesHelper()
|
||||||
|
# 资源包检测
|
||||||
|
ResourceHelper()
|
||||||
# 加载模块
|
# 加载模块
|
||||||
ModuleManager()
|
ModuleManager()
|
||||||
# 加载插件
|
# 加载插件
|
||||||
@@ -174,6 +202,8 @@ def start_module():
|
|||||||
init_routers()
|
init_routers()
|
||||||
# 启动前端服务
|
# 启动前端服务
|
||||||
start_frontend()
|
start_frontend()
|
||||||
|
# 检查认证状态
|
||||||
|
check_auth()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from app.core.metainfo import MetaInfo
|
|||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.modules import _ModuleBase
|
from app.modules import _ModuleBase
|
||||||
from app.modules.douban.apiv2 import DoubanApi
|
from app.modules.douban.apiv2 import DoubanApi
|
||||||
|
from app.modules.douban.douban_cache import DoubanCache
|
||||||
from app.modules.douban.scraper import DoubanScraper
|
from app.modules.douban.scraper import DoubanScraper
|
||||||
from app.schemas.types import MediaType
|
from app.schemas.types import MediaType
|
||||||
from app.utils.common import retry
|
from app.utils.common import retry
|
||||||
@@ -18,10 +19,12 @@ from app.utils.system import SystemUtils
|
|||||||
class DoubanModule(_ModuleBase):
|
class DoubanModule(_ModuleBase):
|
||||||
doubanapi: DoubanApi = None
|
doubanapi: DoubanApi = None
|
||||||
scraper: DoubanScraper = None
|
scraper: DoubanScraper = None
|
||||||
|
cache: DoubanCache = None
|
||||||
|
|
||||||
def init_module(self) -> None:
|
def init_module(self) -> None:
|
||||||
self.doubanapi = DoubanApi()
|
self.doubanapi = DoubanApi()
|
||||||
self.scraper = DoubanScraper()
|
self.scraper = DoubanScraper()
|
||||||
|
self.cache = DoubanCache()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
pass
|
pass
|
||||||
@@ -29,10 +32,87 @@ class DoubanModule(_ModuleBase):
|
|||||||
def init_setting(self) -> Tuple[str, Union[str, bool]]:
|
def init_setting(self) -> Tuple[str, Union[str, bool]]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def douban_info(self, doubanid: str) -> Optional[dict]:
|
def recognize_media(self, meta: MetaBase = None,
|
||||||
|
mtype: MediaType = None,
|
||||||
|
doubanid: str = None,
|
||||||
|
**kwargs) -> Optional[MediaInfo]:
|
||||||
|
"""
|
||||||
|
识别媒体信息
|
||||||
|
:param meta: 识别的元数据
|
||||||
|
:param mtype: 识别的媒体类型,与doubanid配套
|
||||||
|
:param doubanid: 豆瓣ID
|
||||||
|
:return: 识别的媒体信息,包括剧集信息
|
||||||
|
"""
|
||||||
|
if settings.RECOGNIZE_SOURCE != "douban":
|
||||||
|
return None
|
||||||
|
|
||||||
|
if not meta:
|
||||||
|
cache_info = {}
|
||||||
|
else:
|
||||||
|
if mtype:
|
||||||
|
meta.type = mtype
|
||||||
|
cache_info = self.cache.get(meta)
|
||||||
|
if not cache_info:
|
||||||
|
# 缓存没有或者强制不使用缓存
|
||||||
|
if doubanid:
|
||||||
|
# 直接查询详情
|
||||||
|
info = self.douban_info(doubanid=doubanid, mtype=mtype or meta.type)
|
||||||
|
elif meta:
|
||||||
|
if meta.begin_season:
|
||||||
|
logger.info(f"正在识别 {meta.name} 第{meta.begin_season}季 ...")
|
||||||
|
else:
|
||||||
|
logger.info(f"正在识别 {meta.name} ...")
|
||||||
|
# 匹配豆瓣信息
|
||||||
|
match_info = self.match_doubaninfo(name=meta.name,
|
||||||
|
mtype=mtype or meta.type,
|
||||||
|
year=meta.year,
|
||||||
|
season=meta.begin_season)
|
||||||
|
if match_info:
|
||||||
|
# 匹配到豆瓣信息
|
||||||
|
info = self.douban_info(
|
||||||
|
doubanid=match_info.get("id"),
|
||||||
|
mtype=mtype or meta.type
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
logger.info(f"{meta.name if meta else doubanid} 未匹配到豆瓣媒体信息")
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
logger.error("识别媒体信息时未提供元数据或豆瓣ID")
|
||||||
|
return None
|
||||||
|
# 保存到缓存
|
||||||
|
if meta:
|
||||||
|
self.cache.update(meta, info)
|
||||||
|
else:
|
||||||
|
# 使用缓存信息
|
||||||
|
if cache_info.get("title"):
|
||||||
|
logger.info(f"{meta.name} 使用豆瓣识别缓存:{cache_info.get('title')}")
|
||||||
|
info = self.douban_info(mtype=cache_info.get("type"),
|
||||||
|
doubanid=cache_info.get("id"))
|
||||||
|
else:
|
||||||
|
logger.info(f"{meta.name} 使用豆瓣识别缓存:无法识别")
|
||||||
|
info = None
|
||||||
|
|
||||||
|
if info:
|
||||||
|
# 赋值TMDB信息并返回
|
||||||
|
mediainfo = MediaInfo(douban_info=info)
|
||||||
|
if meta:
|
||||||
|
logger.info(f"{meta.name} 豆瓣识别结果:{mediainfo.type.value} "
|
||||||
|
f"{mediainfo.title_year} "
|
||||||
|
f"{mediainfo.douban_id}")
|
||||||
|
else:
|
||||||
|
logger.info(f"{doubanid} 豆瓣识别结果:{mediainfo.type.value} "
|
||||||
|
f"{mediainfo.title_year}")
|
||||||
|
return mediainfo
|
||||||
|
else:
|
||||||
|
logger.info(f"{meta.name if meta else doubanid} 未匹配到豆瓣媒体信息")
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def douban_info(self, doubanid: str, mtype: MediaType = None) -> Optional[dict]:
|
||||||
"""
|
"""
|
||||||
获取豆瓣信息
|
获取豆瓣信息
|
||||||
:param doubanid: 豆瓣ID
|
:param doubanid: 豆瓣ID
|
||||||
|
:param mtype: 媒体类型
|
||||||
:return: 豆瓣信息
|
:return: 豆瓣信息
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
@@ -300,22 +380,40 @@ class DoubanModule(_ModuleBase):
|
|||||||
"interest_cmt_earlier_tip_desc": "该短评的发布时间早于公开上映时间,作者可能通过其他渠道提前观看,请谨慎参考。其评分将不计入总评分。"
|
"interest_cmt_earlier_tip_desc": "该短评的发布时间早于公开上映时间,作者可能通过其他渠道提前观看,请谨慎参考。其评分将不计入总评分。"
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def __douban_tv():
|
||||||
|
"""
|
||||||
|
获取豆瓣剧集信息
|
||||||
|
"""
|
||||||
|
info = self.doubanapi.tv_detail(doubanid)
|
||||||
|
if info:
|
||||||
|
celebrities = self.doubanapi.tv_celebrities(doubanid)
|
||||||
|
if celebrities:
|
||||||
|
info["directors"] = celebrities.get("directors")
|
||||||
|
info["actors"] = celebrities.get("actors")
|
||||||
|
return info
|
||||||
|
|
||||||
|
def __douban_movie():
|
||||||
|
"""
|
||||||
|
获取豆瓣电影信息
|
||||||
|
"""
|
||||||
|
info = self.doubanapi.movie_detail(doubanid)
|
||||||
|
if info:
|
||||||
|
celebrities = self.doubanapi.movie_celebrities(doubanid)
|
||||||
|
if celebrities:
|
||||||
|
info["directors"] = celebrities.get("directors")
|
||||||
|
info["actors"] = celebrities.get("actors")
|
||||||
|
return info
|
||||||
|
|
||||||
if not doubanid:
|
if not doubanid:
|
||||||
return None
|
return None
|
||||||
logger.info(f"开始获取豆瓣信息:{doubanid} ...")
|
logger.info(f"开始获取豆瓣信息:{doubanid} ...")
|
||||||
douban_info = self.doubanapi.movie_detail(doubanid)
|
if mtype == MediaType.TV:
|
||||||
if douban_info:
|
return __douban_tv()
|
||||||
celebrities = self.doubanapi.movie_celebrities(doubanid)
|
elif mtype == MediaType.MOVIE:
|
||||||
if celebrities:
|
return __douban_movie()
|
||||||
douban_info["directors"] = celebrities.get("directors")
|
|
||||||
douban_info["actors"] = celebrities.get("actors")
|
|
||||||
else:
|
else:
|
||||||
douban_info = self.doubanapi.tv_detail(doubanid)
|
return __douban_movie() or __douban_tv()
|
||||||
celebrities = self.doubanapi.tv_celebrities(doubanid)
|
|
||||||
if douban_info and celebrities:
|
|
||||||
douban_info["directors"] = celebrities.get("directors")
|
|
||||||
douban_info["actors"] = celebrities.get("actors")
|
|
||||||
return douban_info
|
|
||||||
|
|
||||||
def douban_discover(self, mtype: MediaType, sort: str, tags: str,
|
def douban_discover(self, mtype: MediaType, sort: str, tags: str,
|
||||||
page: int = 1, count: int = 30) -> Optional[List[dict]]:
|
page: int = 1, count: int = 30) -> Optional[List[dict]]:
|
||||||
@@ -379,6 +477,26 @@ class DoubanModule(_ModuleBase):
|
|||||||
return []
|
return []
|
||||||
return infos.get("subject_collection_items")
|
return infos.get("subject_collection_items")
|
||||||
|
|
||||||
|
def movie_hot(self, page: int = 1, count: int = 30) -> List[dict]:
|
||||||
|
"""
|
||||||
|
获取豆瓣热门电影
|
||||||
|
"""
|
||||||
|
infos = self.doubanapi.movie_hot_gaia(start=(page - 1) * count,
|
||||||
|
count=count)
|
||||||
|
if not infos:
|
||||||
|
return []
|
||||||
|
return infos.get("subject_collection_items")
|
||||||
|
|
||||||
|
def tv_hot(self, page: int = 1, count: int = 30) -> List[dict]:
|
||||||
|
"""
|
||||||
|
获取豆瓣热门剧集
|
||||||
|
"""
|
||||||
|
infos = self.doubanapi.tv_hot(start=(page - 1) * count,
|
||||||
|
count=count)
|
||||||
|
if not infos:
|
||||||
|
return []
|
||||||
|
return infos.get("subject_collection_items")
|
||||||
|
|
||||||
def search_medias(self, meta: MetaBase) -> Optional[List[MediaInfo]]:
|
def search_medias(self, meta: MetaBase) -> Optional[List[MediaInfo]]:
|
||||||
"""
|
"""
|
||||||
搜索媒体信息
|
搜索媒体信息
|
||||||
@@ -386,7 +504,7 @@ class DoubanModule(_ModuleBase):
|
|||||||
:reutrn: 媒体信息
|
:reutrn: 媒体信息
|
||||||
"""
|
"""
|
||||||
# 未启用豆瓣搜索时返回None
|
# 未启用豆瓣搜索时返回None
|
||||||
if settings.SEARCH_SOURCE != "douban":
|
if settings.RECOGNIZE_SOURCE != "douban":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not meta.name:
|
if not meta.name:
|
||||||
@@ -397,7 +515,7 @@ class DoubanModule(_ModuleBase):
|
|||||||
# 返回数据
|
# 返回数据
|
||||||
ret_medias = []
|
ret_medias = []
|
||||||
for item_obj in result.get("items"):
|
for item_obj in result.get("items"):
|
||||||
if meta.type and meta.type.value != item_obj.get("type_name"):
|
if meta.type and meta.type != MediaType.UNKNOWN and meta.type.value != item_obj.get("type_name"):
|
||||||
continue
|
continue
|
||||||
if item_obj.get("type_name") not in (MediaType.TV.value, MediaType.MOVIE.value):
|
if item_obj.get("type_name") not in (MediaType.TV.value, MediaType.MOVIE.value):
|
||||||
continue
|
continue
|
||||||
@@ -407,12 +525,12 @@ class DoubanModule(_ModuleBase):
|
|||||||
|
|
||||||
@retry(Exception, 5, 3, 3, logger=logger)
|
@retry(Exception, 5, 3, 3, logger=logger)
|
||||||
def match_doubaninfo(self, name: str, imdbid: str = None,
|
def match_doubaninfo(self, name: str, imdbid: str = None,
|
||||||
mtype: str = None, year: str = None, season: int = None) -> dict:
|
mtype: MediaType = None, year: str = None, season: int = None) -> dict:
|
||||||
"""
|
"""
|
||||||
搜索和匹配豆瓣信息
|
搜索和匹配豆瓣信息
|
||||||
:param name: 名称
|
:param name: 名称
|
||||||
:param imdbid: IMDB ID
|
:param imdbid: IMDB ID
|
||||||
:param mtype: 类型 电影/电视剧
|
:param mtype: 类型
|
||||||
:param year: 年份
|
:param year: 年份
|
||||||
:param season: 季号
|
:param season: 季号
|
||||||
"""
|
"""
|
||||||
@@ -441,9 +559,9 @@ class DoubanModule(_ModuleBase):
|
|||||||
type_name = item_obj.get("type_name")
|
type_name = item_obj.get("type_name")
|
||||||
if type_name not in [MediaType.TV.value, MediaType.MOVIE.value]:
|
if type_name not in [MediaType.TV.value, MediaType.MOVIE.value]:
|
||||||
continue
|
continue
|
||||||
if mtype and mtype != type_name:
|
if mtype and mtype.value != type_name:
|
||||||
continue
|
continue
|
||||||
if mtype == MediaType.TV and not season:
|
if mtype and mtype == MediaType.TV and not season:
|
||||||
season = 1
|
season = 1
|
||||||
item = item_obj.get("target")
|
item = item_obj.get("target")
|
||||||
title = item.get("title")
|
title = item.get("title")
|
||||||
@@ -470,12 +588,15 @@ class DoubanModule(_ModuleBase):
|
|||||||
return []
|
return []
|
||||||
return infos.get("subject_collection_items")
|
return infos.get("subject_collection_items")
|
||||||
|
|
||||||
def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str) -> None:
|
def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str,
|
||||||
|
force_nfo: bool = False, force_img: bool = False) -> None:
|
||||||
"""
|
"""
|
||||||
刮削元数据
|
刮削元数据
|
||||||
:param path: 媒体文件路径
|
:param path: 媒体文件路径
|
||||||
:param mediainfo: 识别的媒体信息
|
:param mediainfo: 识别的媒体信息
|
||||||
:param transfer_type: 传输类型
|
:param transfer_type: 传输类型
|
||||||
|
:param force_nfo: 是否强制刮削nfo
|
||||||
|
:param force_img: 是否强制刮削图片
|
||||||
:return: 成功或失败
|
:return: 成功或失败
|
||||||
"""
|
"""
|
||||||
if settings.SCRAP_SOURCE != "douban":
|
if settings.SCRAP_SOURCE != "douban":
|
||||||
@@ -486,23 +607,35 @@ class DoubanModule(_ModuleBase):
|
|||||||
meta = MetaInfo(path.stem)
|
meta = MetaInfo(path.stem)
|
||||||
if not meta.name:
|
if not meta.name:
|
||||||
return
|
return
|
||||||
# 根据名称查询豆瓣数据
|
|
||||||
doubaninfo = self.match_doubaninfo(name=mediainfo.title,
|
|
||||||
imdbid=mediainfo.imdb_id,
|
|
||||||
mtype=mediainfo.type.value,
|
|
||||||
year=mediainfo.year,
|
|
||||||
season=meta.begin_season)
|
|
||||||
if not doubaninfo:
|
|
||||||
logger.warn(f"未找到 {mediainfo.title} 的豆瓣信息")
|
|
||||||
return
|
|
||||||
# 查询豆瓣详情
|
# 查询豆瓣详情
|
||||||
doubaninfo = self.douban_info(doubaninfo.get("id"))
|
if not mediainfo.douban_id:
|
||||||
|
# 根据名称查询豆瓣数据
|
||||||
|
doubaninfo = self.match_doubaninfo(name=mediainfo.title,
|
||||||
|
imdbid=mediainfo.imdb_id,
|
||||||
|
mtype=mediainfo.type,
|
||||||
|
year=mediainfo.year)
|
||||||
|
if not doubaninfo:
|
||||||
|
logger.warn(f"未找到 {mediainfo.title} 的豆瓣信息")
|
||||||
|
return
|
||||||
|
doubaninfo = self.douban_info(doubanid=doubaninfo.get("id"), mtype=mediainfo.type)
|
||||||
|
else:
|
||||||
|
doubaninfo = self.douban_info(doubanid=mediainfo.douban_id,
|
||||||
|
mtype=mediainfo.type)
|
||||||
|
if not doubaninfo:
|
||||||
|
logger(f"未获取到 {mediainfo.douban_id} 的豆瓣媒体信息,无法刮削!")
|
||||||
|
return
|
||||||
|
# 豆瓣媒体信息
|
||||||
|
mediainfo = MediaInfo(douban_info=doubaninfo)
|
||||||
|
# 补充图片
|
||||||
|
self.obtain_images(mediainfo)
|
||||||
# 刮削路径
|
# 刮削路径
|
||||||
scrape_path = path / path.name
|
scrape_path = path / path.name
|
||||||
self.scraper.gen_scraper_files(meta=meta,
|
self.scraper.gen_scraper_files(meta=meta,
|
||||||
mediainfo=MediaInfo(douban_info=doubaninfo),
|
mediainfo=mediainfo,
|
||||||
file_path=scrape_path,
|
file_path=scrape_path,
|
||||||
transfer_type=transfer_type)
|
transfer_type=transfer_type,
|
||||||
|
force_nfo=force_nfo,
|
||||||
|
force_img=force_img)
|
||||||
else:
|
else:
|
||||||
# 目录下的所有文件
|
# 目录下的所有文件
|
||||||
for file in SystemUtils.list_files(path, settings.RMT_MEDIAEXT):
|
for file in SystemUtils.list_files(path, settings.RMT_MEDIAEXT):
|
||||||
@@ -513,22 +646,119 @@ class DoubanModule(_ModuleBase):
|
|||||||
meta = MetaInfo(file.stem)
|
meta = MetaInfo(file.stem)
|
||||||
if not meta.name:
|
if not meta.name:
|
||||||
continue
|
continue
|
||||||
# 根据名称查询豆瓣数据
|
if not mediainfo.douban_id:
|
||||||
doubaninfo = self.match_doubaninfo(name=mediainfo.title,
|
# 根据名称查询豆瓣数据
|
||||||
imdbid=mediainfo.imdb_id,
|
doubaninfo = self.match_doubaninfo(name=mediainfo.title,
|
||||||
mtype=mediainfo.type.value,
|
imdbid=mediainfo.imdb_id,
|
||||||
year=mediainfo.year,
|
mtype=mediainfo.type,
|
||||||
season=meta.begin_season)
|
year=mediainfo.year,
|
||||||
|
season=meta.begin_season)
|
||||||
|
if not doubaninfo:
|
||||||
|
logger.warn(f"未找到 {mediainfo.title} 的豆瓣信息")
|
||||||
|
break
|
||||||
|
# 查询豆瓣详情
|
||||||
|
doubaninfo = self.douban_info(doubanid=doubaninfo.get("id"), mtype=mediainfo.type)
|
||||||
|
else:
|
||||||
|
doubaninfo = self.douban_info(doubanid=mediainfo.douban_id,
|
||||||
|
mtype=mediainfo.type)
|
||||||
if not doubaninfo:
|
if not doubaninfo:
|
||||||
logger.warn(f"未找到 {mediainfo.title} 的豆瓣信息")
|
logger(f"未获取到 {mediainfo.douban_id} 的豆瓣媒体信息,无法刮削!")
|
||||||
break
|
continue
|
||||||
# 查询豆瓣详情
|
# 豆瓣媒体信息
|
||||||
doubaninfo = self.douban_info(doubaninfo.get("id"))
|
mediainfo = MediaInfo(douban_info=doubaninfo)
|
||||||
|
# 补充图片
|
||||||
|
self.obtain_images(mediainfo)
|
||||||
# 刮削
|
# 刮削
|
||||||
self.scraper.gen_scraper_files(meta=meta,
|
self.scraper.gen_scraper_files(meta=meta,
|
||||||
mediainfo=MediaInfo(douban_info=doubaninfo),
|
mediainfo=mediainfo,
|
||||||
file_path=file,
|
file_path=file,
|
||||||
transfer_type=transfer_type)
|
transfer_type=transfer_type,
|
||||||
|
force_nfo=force_nfo,
|
||||||
|
force_img=force_img)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"刮削文件 {file} 失败,原因:{str(e)}")
|
logger.error(f"刮削文件 {file} 失败,原因:{str(e)}")
|
||||||
logger.info(f"{path} 刮削完成")
|
logger.info(f"{path} 刮削完成")
|
||||||
|
|
||||||
|
def obtain_images(self, mediainfo: MediaInfo) -> Optional[MediaInfo]:
|
||||||
|
"""
|
||||||
|
补充抓取媒体信息图片
|
||||||
|
:param mediainfo: 识别的媒体信息
|
||||||
|
:return: 更新后的媒体信息
|
||||||
|
"""
|
||||||
|
if settings.RECOGNIZE_SOURCE != "douban":
|
||||||
|
return None
|
||||||
|
if not mediainfo.douban_id:
|
||||||
|
return None
|
||||||
|
if mediainfo.backdrop_path:
|
||||||
|
# 没有图片缺失
|
||||||
|
return mediainfo
|
||||||
|
# 调用图片接口
|
||||||
|
if not mediainfo.backdrop_path:
|
||||||
|
if mediainfo.type == MediaType.MOVIE:
|
||||||
|
info = self.doubanapi.movie_photos(mediainfo.douban_id)
|
||||||
|
else:
|
||||||
|
info = self.doubanapi.tv_photos(mediainfo.douban_id)
|
||||||
|
if not info:
|
||||||
|
return mediainfo
|
||||||
|
images = info.get("photos")
|
||||||
|
# 背景图
|
||||||
|
if images:
|
||||||
|
backdrop = images[0].get("image", {}).get("large") or {}
|
||||||
|
if backdrop:
|
||||||
|
mediainfo.backdrop_path = backdrop.get("url")
|
||||||
|
return mediainfo
|
||||||
|
|
||||||
|
def clear_cache(self):
|
||||||
|
"""
|
||||||
|
清除缓存
|
||||||
|
"""
|
||||||
|
logger.info("开始清除豆瓣缓存 ...")
|
||||||
|
self.doubanapi.clear_cache()
|
||||||
|
self.cache.clear()
|
||||||
|
logger.info("豆瓣缓存清除完成")
|
||||||
|
|
||||||
|
def douban_movie_credits(self, doubanid: str, page: int = 1, count: int = 20) -> List[dict]:
|
||||||
|
"""
|
||||||
|
根据TMDBID查询电影演职员表
|
||||||
|
:param doubanid: 豆瓣ID
|
||||||
|
:param page: 页码
|
||||||
|
:param count: 数量
|
||||||
|
"""
|
||||||
|
result = self.doubanapi.movie_celebrities(subject_id=doubanid)
|
||||||
|
if not result:
|
||||||
|
return []
|
||||||
|
ret_list = result.get("actors") or []
|
||||||
|
if ret_list:
|
||||||
|
return ret_list[(page - 1) * count: page * count]
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
|
||||||
|
def douban_tv_credits(self, doubanid: str, page: int = 1, count: int = 20) -> List[dict]:
|
||||||
|
"""
|
||||||
|
根据TMDBID查询电视剧演职员表
|
||||||
|
:param doubanid: 豆瓣ID
|
||||||
|
:param page: 页码
|
||||||
|
:param count: 数量
|
||||||
|
"""
|
||||||
|
result = self.doubanapi.tv_celebrities(subject_id=doubanid)
|
||||||
|
if not result:
|
||||||
|
return []
|
||||||
|
ret_list = result.get("actors") or []
|
||||||
|
if ret_list:
|
||||||
|
return ret_list[(page - 1) * count: page * count]
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
|
||||||
|
def douban_movie_recommend(self, doubanid: str) -> List[dict]:
|
||||||
|
"""
|
||||||
|
根据豆瓣ID查询推荐电影
|
||||||
|
:param doubanid: 豆瓣ID
|
||||||
|
"""
|
||||||
|
return self.doubanapi.movie_recommendations(subject_id=doubanid) or []
|
||||||
|
|
||||||
|
def douban_tv_recommend(self, doubanid: str) -> List[dict]:
|
||||||
|
"""
|
||||||
|
根据豆瓣ID查询推荐电视剧
|
||||||
|
:param doubanid: 豆瓣ID
|
||||||
|
"""
|
||||||
|
return self.doubanapi.tv_recommendations(subject_id=doubanid) or []
|
||||||
|
|||||||
@@ -427,6 +427,60 @@ class DoubanApi(metaclass=Singleton):
|
|||||||
return self.__invoke(self._urls["doulist_items"] % subject_id,
|
return self.__invoke(self._urls["doulist_items"] % subject_id,
|
||||||
start=start, count=count, _ts=ts)
|
start=start, count=count, _ts=ts)
|
||||||
|
|
||||||
|
def movie_recommendations(self, subject_id: str, start: int = 0, count: int = 20,
|
||||||
|
ts=datetime.strftime(datetime.now(), '%Y%m%d')):
|
||||||
|
"""
|
||||||
|
电影推荐
|
||||||
|
:param subject_id: 电影id
|
||||||
|
:param start: 开始
|
||||||
|
:param count: 数量
|
||||||
|
:param ts: 时间戳
|
||||||
|
"""
|
||||||
|
return self.__invoke(self._urls["movie_recommendations"] % subject_id,
|
||||||
|
start=start, count=count, _ts=ts)
|
||||||
|
|
||||||
|
def tv_recommendations(self, subject_id: str, start: int = 0, count: int = 20,
|
||||||
|
ts=datetime.strftime(datetime.now(), '%Y%m%d')):
|
||||||
|
"""
|
||||||
|
电视剧推荐
|
||||||
|
:param subject_id: 电视剧id
|
||||||
|
:param start: 开始
|
||||||
|
:param count: 数量
|
||||||
|
:param ts: 时间戳
|
||||||
|
"""
|
||||||
|
return self.__invoke(self._urls["tv_recommendations"] % subject_id,
|
||||||
|
start=start, count=count, _ts=ts)
|
||||||
|
|
||||||
|
def movie_photos(self, subject_id: str, start: int = 0, count: int = 20,
|
||||||
|
ts=datetime.strftime(datetime.now(), '%Y%m%d')):
|
||||||
|
"""
|
||||||
|
电影剧照
|
||||||
|
:param subject_id: 电影id
|
||||||
|
:param start: 开始
|
||||||
|
:param count: 数量
|
||||||
|
:param ts: 时间戳
|
||||||
|
"""
|
||||||
|
return self.__invoke(self._urls["movie_photos"] % subject_id,
|
||||||
|
start=start, count=count, _ts=ts)
|
||||||
|
|
||||||
|
def tv_photos(self, subject_id: str, start: int = 0, count: int = 20,
|
||||||
|
ts=datetime.strftime(datetime.now(), '%Y%m%d')):
|
||||||
|
"""
|
||||||
|
电视剧剧照
|
||||||
|
:param subject_id: 电视剧id
|
||||||
|
:param start: 开始
|
||||||
|
:param count: 数量
|
||||||
|
:param ts: 时间戳
|
||||||
|
"""
|
||||||
|
return self.__invoke(self._urls["tv_photos"] % subject_id,
|
||||||
|
start=start, count=count, _ts=ts)
|
||||||
|
|
||||||
|
def clear_cache(self):
|
||||||
|
"""
|
||||||
|
清空LRU缓存
|
||||||
|
"""
|
||||||
|
self.__invoke.cache_clear()
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if self._session:
|
if self._session:
|
||||||
self._session.close()
|
self._session.close()
|
||||||
|
|||||||
234
app/modules/douban/douban_cache.py
Normal file
234
app/modules/douban/douban_cache.py
Normal file
@@ -0,0 +1,234 @@
|
|||||||
|
import pickle
|
||||||
|
import random
|
||||||
|
import time
|
||||||
|
import traceback
|
||||||
|
from pathlib import Path
|
||||||
|
from threading import RLock
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from app.core.config import settings
|
||||||
|
from app.core.meta import MetaBase
|
||||||
|
from app.core.metainfo import MetaInfo
|
||||||
|
from app.log import logger
|
||||||
|
from app.utils.singleton import Singleton
|
||||||
|
from app.schemas.types import MediaType
|
||||||
|
|
||||||
|
lock = RLock()
|
||||||
|
|
||||||
|
CACHE_EXPIRE_TIMESTAMP_STR = "cache_expire_timestamp"
|
||||||
|
EXPIRE_TIMESTAMP = settings.CACHE_CONF.get('meta')
|
||||||
|
|
||||||
|
|
||||||
|
class DoubanCache(metaclass=Singleton):
|
||||||
|
"""
|
||||||
|
豆瓣缓存数据
|
||||||
|
{
|
||||||
|
"id": '',
|
||||||
|
"title": '',
|
||||||
|
"year": '',
|
||||||
|
"type": MediaType
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
_meta_data: dict = {}
|
||||||
|
# 缓存文件路径
|
||||||
|
_meta_path: Path = None
|
||||||
|
# TMDB缓存过期
|
||||||
|
_tmdb_cache_expire: bool = True
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._meta_path = settings.TEMP_PATH / "__douban_cache__"
|
||||||
|
self._meta_data = self.__load(self._meta_path)
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
"""
|
||||||
|
清空所有TMDB缓存
|
||||||
|
"""
|
||||||
|
with lock:
|
||||||
|
self._meta_data = {}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __get_key(meta: MetaBase) -> str:
|
||||||
|
"""
|
||||||
|
获取缓存KEY
|
||||||
|
"""
|
||||||
|
return f"[{meta.type.value if meta.type else '未知'}]{meta.name}-{meta.year}-{meta.begin_season}"
|
||||||
|
|
||||||
|
def get(self, meta: MetaBase):
|
||||||
|
"""
|
||||||
|
根据KEY值获取缓存值
|
||||||
|
"""
|
||||||
|
key = self.__get_key(meta)
|
||||||
|
with lock:
|
||||||
|
info: dict = self._meta_data.get(key)
|
||||||
|
if info:
|
||||||
|
expire = info.get(CACHE_EXPIRE_TIMESTAMP_STR)
|
||||||
|
if not expire or int(time.time()) < expire:
|
||||||
|
info[CACHE_EXPIRE_TIMESTAMP_STR] = int(time.time()) + EXPIRE_TIMESTAMP
|
||||||
|
self._meta_data[key] = info
|
||||||
|
elif expire and self._tmdb_cache_expire:
|
||||||
|
self.delete(key)
|
||||||
|
return info or {}
|
||||||
|
|
||||||
|
def delete(self, key: str) -> dict:
|
||||||
|
"""
|
||||||
|
删除缓存信息
|
||||||
|
@param key: 缓存key
|
||||||
|
@return: 被删除的缓存内容
|
||||||
|
"""
|
||||||
|
with lock:
|
||||||
|
return self._meta_data.pop(key, None)
|
||||||
|
|
||||||
|
def delete_by_doubanid(self, doubanid: str) -> None:
|
||||||
|
"""
|
||||||
|
清空对应豆瓣ID的所有缓存记录,以强制更新TMDB中最新的数据
|
||||||
|
"""
|
||||||
|
for key in list(self._meta_data):
|
||||||
|
if self._meta_data.get(key, {}).get("id") == doubanid:
|
||||||
|
with lock:
|
||||||
|
self._meta_data.pop(key)
|
||||||
|
|
||||||
|
def delete_unknown(self) -> None:
|
||||||
|
"""
|
||||||
|
清除未识别的缓存记录,以便重新搜索TMDB
|
||||||
|
"""
|
||||||
|
for key in list(self._meta_data):
|
||||||
|
if self._meta_data.get(key, {}).get("id") == "0":
|
||||||
|
with lock:
|
||||||
|
self._meta_data.pop(key)
|
||||||
|
|
||||||
|
def modify(self, key: str, title: str) -> dict:
|
||||||
|
"""
|
||||||
|
删除缓存信息
|
||||||
|
@param key: 缓存key
|
||||||
|
@param title: 标题
|
||||||
|
@return: 被修改后缓存内容
|
||||||
|
"""
|
||||||
|
with lock:
|
||||||
|
if self._meta_data.get(key):
|
||||||
|
self._meta_data[key]['title'] = title
|
||||||
|
self._meta_data[key][CACHE_EXPIRE_TIMESTAMP_STR] = int(time.time()) + EXPIRE_TIMESTAMP
|
||||||
|
return self._meta_data.get(key)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __load(path: Path) -> dict:
|
||||||
|
"""
|
||||||
|
从文件中加载缓存
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
if path.exists():
|
||||||
|
with open(path, 'rb') as f:
|
||||||
|
data = pickle.load(f)
|
||||||
|
return data
|
||||||
|
return {}
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"加载缓存失败: {str(e)} - {traceback.format_exc()}")
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def update(self, meta: MetaBase, info: dict) -> None:
|
||||||
|
"""
|
||||||
|
新增或更新缓存条目
|
||||||
|
"""
|
||||||
|
with lock:
|
||||||
|
if info:
|
||||||
|
# 缓存标题
|
||||||
|
cache_title = info.get("title")
|
||||||
|
# 缓存年份
|
||||||
|
cache_year = info.get('year')
|
||||||
|
# 类型
|
||||||
|
if isinstance(info.get('media_type'), MediaType):
|
||||||
|
mtype = info.get('media_type')
|
||||||
|
elif info.get("type"):
|
||||||
|
mtype = MediaType.MOVIE if info.get("type") == "movie" else MediaType.TV
|
||||||
|
else:
|
||||||
|
meta = MetaInfo(cache_title)
|
||||||
|
if meta.begin_season:
|
||||||
|
mtype = MediaType.TV
|
||||||
|
else:
|
||||||
|
mtype = MediaType.MOVIE
|
||||||
|
# 海报
|
||||||
|
poster_path = info.get("pic", {}).get("large")
|
||||||
|
if not poster_path and info.get("cover_url"):
|
||||||
|
poster_path = info.get("cover_url")
|
||||||
|
if not poster_path and info.get("cover"):
|
||||||
|
poster_path = info.get("cover").get("url")
|
||||||
|
|
||||||
|
self._meta_data[self.__get_key(meta)] = {
|
||||||
|
"id": info.get("id"),
|
||||||
|
"type": mtype,
|
||||||
|
"year": cache_year,
|
||||||
|
"title": cache_title,
|
||||||
|
"poster_path": poster_path,
|
||||||
|
CACHE_EXPIRE_TIMESTAMP_STR: int(time.time()) + EXPIRE_TIMESTAMP
|
||||||
|
}
|
||||||
|
elif info is not None:
|
||||||
|
# None时不缓存,此时代表网络错误,允许重复请求
|
||||||
|
self._meta_data[self.__get_key(meta)] = {'id': "0"}
|
||||||
|
|
||||||
|
def save(self, force: bool = False) -> None:
|
||||||
|
"""
|
||||||
|
保存缓存数据到文件
|
||||||
|
"""
|
||||||
|
|
||||||
|
meta_data = self.__load(self._meta_path)
|
||||||
|
new_meta_data = {k: v for k, v in self._meta_data.items() if v.get("id")}
|
||||||
|
|
||||||
|
if not force \
|
||||||
|
and not self._random_sample(new_meta_data) \
|
||||||
|
and meta_data.keys() == new_meta_data.keys():
|
||||||
|
return
|
||||||
|
|
||||||
|
with open(self._meta_path, 'wb') as f:
|
||||||
|
pickle.dump(new_meta_data, f, pickle.HIGHEST_PROTOCOL)
|
||||||
|
|
||||||
|
def _random_sample(self, new_meta_data: dict) -> bool:
|
||||||
|
"""
|
||||||
|
采样分析是否需要保存
|
||||||
|
"""
|
||||||
|
ret = False
|
||||||
|
if len(new_meta_data) < 25:
|
||||||
|
keys = list(new_meta_data.keys())
|
||||||
|
for k in keys:
|
||||||
|
info = new_meta_data.get(k)
|
||||||
|
expire = info.get(CACHE_EXPIRE_TIMESTAMP_STR)
|
||||||
|
if not expire:
|
||||||
|
ret = True
|
||||||
|
info[CACHE_EXPIRE_TIMESTAMP_STR] = int(time.time()) + EXPIRE_TIMESTAMP
|
||||||
|
elif int(time.time()) >= expire:
|
||||||
|
ret = True
|
||||||
|
if self._tmdb_cache_expire:
|
||||||
|
new_meta_data.pop(k)
|
||||||
|
else:
|
||||||
|
count = 0
|
||||||
|
keys = random.sample(sorted(new_meta_data.keys()), 25)
|
||||||
|
for k in keys:
|
||||||
|
info = new_meta_data.get(k)
|
||||||
|
expire = info.get(CACHE_EXPIRE_TIMESTAMP_STR)
|
||||||
|
if not expire:
|
||||||
|
ret = True
|
||||||
|
info[CACHE_EXPIRE_TIMESTAMP_STR] = int(time.time()) + EXPIRE_TIMESTAMP
|
||||||
|
elif int(time.time()) >= expire:
|
||||||
|
ret = True
|
||||||
|
if self._tmdb_cache_expire:
|
||||||
|
new_meta_data.pop(k)
|
||||||
|
count += 1
|
||||||
|
if count >= 5:
|
||||||
|
ret |= self._random_sample(new_meta_data)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def get_title(self, key: str) -> Optional[str]:
|
||||||
|
"""
|
||||||
|
获取缓存的标题
|
||||||
|
"""
|
||||||
|
cache_media_info = self._meta_data.get(key)
|
||||||
|
if not cache_media_info or not cache_media_info.get("id"):
|
||||||
|
return None
|
||||||
|
return cache_media_info.get("title")
|
||||||
|
|
||||||
|
def set_title(self, key: str, cn_title: str) -> None:
|
||||||
|
"""
|
||||||
|
重新设置缓存标题
|
||||||
|
"""
|
||||||
|
cache_media_info = self._meta_data.get(key)
|
||||||
|
if not cache_media_info:
|
||||||
|
return
|
||||||
|
self._meta_data[key]['title'] = cn_title
|
||||||
@@ -14,45 +14,67 @@ from app.utils.system import SystemUtils
|
|||||||
|
|
||||||
|
|
||||||
class DoubanScraper:
|
class DoubanScraper:
|
||||||
|
|
||||||
_transfer_type = settings.TRANSFER_TYPE
|
_transfer_type = settings.TRANSFER_TYPE
|
||||||
|
_force_nfo = False
|
||||||
|
_force_img = False
|
||||||
|
|
||||||
def gen_scraper_files(self, meta: MetaBase, mediainfo: MediaInfo,
|
def gen_scraper_files(self, meta: MetaBase, mediainfo: MediaInfo,
|
||||||
file_path: Path, transfer_type: str):
|
file_path: Path, transfer_type: str,
|
||||||
|
force_nfo: bool = False, force_img: bool = False):
|
||||||
"""
|
"""
|
||||||
生成刮削文件
|
生成刮削文件
|
||||||
:param meta: 元数据
|
:param meta: 元数据
|
||||||
:param mediainfo: 媒体信息
|
:param mediainfo: 媒体信息
|
||||||
:param file_path: 文件路径或者目录路径
|
:param file_path: 文件路径或者目录路径
|
||||||
:param transfer_type: 转输类型
|
:param transfer_type: 转输类型
|
||||||
|
:param force_nfo: 强制生成NFO
|
||||||
|
:param force_img: 强制生成图片
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self._transfer_type = transfer_type
|
self._transfer_type = transfer_type
|
||||||
|
self._force_nfo = force_nfo
|
||||||
|
self._force_img = force_img
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 电影
|
# 电影
|
||||||
if mediainfo.type == MediaType.MOVIE:
|
if mediainfo.type == MediaType.MOVIE:
|
||||||
# 强制或者不已存在时才处理
|
# 强制或者不已存在时才处理
|
||||||
if not file_path.with_name("movie.nfo").exists() \
|
if self._force_nfo or (not file_path.with_name("movie.nfo").exists()
|
||||||
and not file_path.with_suffix(".nfo").exists():
|
and not file_path.with_suffix(".nfo").exists()):
|
||||||
# 生成电影描述文件
|
# 生成电影描述文件
|
||||||
self.__gen_movie_nfo_file(mediainfo=mediainfo,
|
self.__gen_movie_nfo_file(mediainfo=mediainfo,
|
||||||
file_path=file_path)
|
file_path=file_path)
|
||||||
# 生成电影图片
|
# 生成电影图片
|
||||||
self.__save_image(url=mediainfo.poster_path,
|
image_path = file_path.with_name(f"poster{Path(mediainfo.poster_path).suffix}")
|
||||||
file_path=file_path.with_name(f"poster{Path(mediainfo.poster_path).suffix}"))
|
if self._force_img or not image_path.exists():
|
||||||
|
self.__save_image(url=mediainfo.poster_path,
|
||||||
|
file_path=image_path)
|
||||||
|
# 背景图
|
||||||
|
if mediainfo.backdrop_path:
|
||||||
|
image_path = file_path.with_name(f"backdrop{Path(mediainfo.backdrop_path).suffix}")
|
||||||
|
if self._force_img or not image_path.exists():
|
||||||
|
self.__save_image(url=mediainfo.backdrop_path,
|
||||||
|
file_path=image_path)
|
||||||
# 电视剧
|
# 电视剧
|
||||||
else:
|
else:
|
||||||
# 不存在时才处理
|
# 不存在时才处理
|
||||||
if not file_path.parent.with_name("tvshow.nfo").exists():
|
if self._force_nfo or not file_path.parent.with_name("tvshow.nfo").exists():
|
||||||
# 根目录描述文件
|
# 根目录描述文件
|
||||||
self.__gen_tv_nfo_file(mediainfo=mediainfo,
|
self.__gen_tv_nfo_file(mediainfo=mediainfo,
|
||||||
dir_path=file_path.parents[1])
|
dir_path=file_path.parents[1])
|
||||||
# 生成根目录图片
|
# 生成根目录图片
|
||||||
self.__save_image(url=mediainfo.poster_path,
|
image_path = file_path.with_name(f"poster{Path(mediainfo.poster_path).suffix}")
|
||||||
file_path=file_path.with_name(f"poster{Path(mediainfo.poster_path).suffix}"))
|
if self._force_img or not image_path.exists():
|
||||||
|
self.__save_image(url=mediainfo.poster_path,
|
||||||
|
file_path=image_path)
|
||||||
|
# 背景图
|
||||||
|
if mediainfo.backdrop_path:
|
||||||
|
image_path = file_path.with_name(f"backdrop{Path(mediainfo.backdrop_path).suffix}")
|
||||||
|
if self._force_img or not image_path.exists():
|
||||||
|
self.__save_image(url=mediainfo.backdrop_path,
|
||||||
|
file_path=image_path)
|
||||||
# 季目录NFO
|
# 季目录NFO
|
||||||
if not file_path.with_name("season.nfo").exists():
|
if self._force_nfo or not file_path.with_name("season.nfo").exists():
|
||||||
self.__gen_tv_season_nfo_file(mediainfo=mediainfo,
|
self.__gen_tv_season_nfo_file(mediainfo=mediainfo,
|
||||||
season=meta.begin_season,
|
season=meta.begin_season,
|
||||||
season_path=file_path.parent)
|
season_path=file_path.parent)
|
||||||
@@ -167,8 +189,6 @@ class DoubanScraper:
|
|||||||
"""
|
"""
|
||||||
下载图片并保存
|
下载图片并保存
|
||||||
"""
|
"""
|
||||||
if file_path.exists():
|
|
||||||
return
|
|
||||||
if not url:
|
if not url:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
@@ -193,8 +213,6 @@ class DoubanScraper:
|
|||||||
"""
|
"""
|
||||||
保存NFO
|
保存NFO
|
||||||
"""
|
"""
|
||||||
if file_path.exists():
|
|
||||||
return
|
|
||||||
xml_str = doc.toprettyxml(indent=" ", encoding="utf-8")
|
xml_str = doc.toprettyxml(indent=" ", encoding="utf-8")
|
||||||
if self._transfer_type in ['rclone_move', 'rclone_copy']:
|
if self._transfer_type in ['rclone_move', 'rclone_copy']:
|
||||||
self.__save_remove_file(file_path, xml_str)
|
self.__save_remove_file(file_path, xml_str)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
from pathlib import Path
|
|
||||||
from typing import Optional, Tuple, Union, Any, List, Generator
|
from typing import Optional, Tuple, Union, Any, List, Generator
|
||||||
|
|
||||||
from app import schemas
|
from app import schemas
|
||||||
@@ -26,7 +25,7 @@ class EmbyModule(_ModuleBase):
|
|||||||
定时任务,每10分钟调用一次
|
定时任务,每10分钟调用一次
|
||||||
"""
|
"""
|
||||||
# 定时重连
|
# 定时重连
|
||||||
if not self.emby.is_inactive():
|
if self.emby.is_inactive():
|
||||||
self.emby.reconnect()
|
self.emby.reconnect()
|
||||||
|
|
||||||
def user_authenticate(self, name: str, password: str) -> Optional[str]:
|
def user_authenticate(self, name: str, password: str) -> Optional[str]:
|
||||||
@@ -96,24 +95,6 @@ class EmbyModule(_ModuleBase):
|
|||||||
itemid=itemid
|
itemid=itemid
|
||||||
)
|
)
|
||||||
|
|
||||||
def refresh_mediaserver(self, mediainfo: MediaInfo, file_path: Path) -> None:
|
|
||||||
"""
|
|
||||||
刷新媒体库
|
|
||||||
:param mediainfo: 识别的媒体信息
|
|
||||||
:param file_path: 文件路径
|
|
||||||
:return: 成功或失败
|
|
||||||
"""
|
|
||||||
items = [
|
|
||||||
schemas.RefreshMediaItem(
|
|
||||||
title=mediainfo.title,
|
|
||||||
year=mediainfo.year,
|
|
||||||
type=mediainfo.type,
|
|
||||||
category=mediainfo.category,
|
|
||||||
target_path=file_path
|
|
||||||
)
|
|
||||||
]
|
|
||||||
self.emby.refresh_library_by_items(items)
|
|
||||||
|
|
||||||
def media_statistic(self) -> List[schemas.Statistic]:
|
def media_statistic(self) -> List[schemas.Statistic]:
|
||||||
"""
|
"""
|
||||||
媒体数量统计
|
媒体数量统计
|
||||||
@@ -122,13 +103,13 @@ class EmbyModule(_ModuleBase):
|
|||||||
media_statistic.user_count = self.emby.get_user_count()
|
media_statistic.user_count = self.emby.get_user_count()
|
||||||
return [media_statistic]
|
return [media_statistic]
|
||||||
|
|
||||||
def mediaserver_librarys(self, server: str) -> Optional[List[schemas.MediaServerLibrary]]:
|
def mediaserver_librarys(self, server: str = None, username: str = None) -> Optional[List[schemas.MediaServerLibrary]]:
|
||||||
"""
|
"""
|
||||||
媒体库列表
|
媒体库列表
|
||||||
"""
|
"""
|
||||||
if server != "emby":
|
if server and server != "emby":
|
||||||
return None
|
return None
|
||||||
return self.emby.get_librarys()
|
return self.emby.get_librarys(username)
|
||||||
|
|
||||||
def mediaserver_items(self, server: str, library_id: str) -> Optional[Generator]:
|
def mediaserver_items(self, server: str, library_id: str) -> Optional[Generator]:
|
||||||
"""
|
"""
|
||||||
@@ -160,3 +141,29 @@ class EmbyModule(_ModuleBase):
|
|||||||
season=season,
|
season=season,
|
||||||
episodes=episodes
|
episodes=episodes
|
||||||
) for season, episodes in seasoninfo.items()]
|
) for season, episodes in seasoninfo.items()]
|
||||||
|
|
||||||
|
def mediaserver_playing(self, count: int = 20,
|
||||||
|
server: str = None, username: str = None) -> List[schemas.MediaServerPlayItem]:
|
||||||
|
"""
|
||||||
|
获取媒体服务器正在播放信息
|
||||||
|
"""
|
||||||
|
if server and server != "emby":
|
||||||
|
return []
|
||||||
|
return self.emby.get_resume(num=count, username=username)
|
||||||
|
|
||||||
|
def mediaserver_play_url(self, server: str, item_id: Union[str, int]) -> Optional[str]:
|
||||||
|
"""
|
||||||
|
获取媒体库播放地址
|
||||||
|
"""
|
||||||
|
if server != "emby":
|
||||||
|
return None
|
||||||
|
return self.emby.get_play_url(item_id)
|
||||||
|
|
||||||
|
def mediaserver_latest(self, count: int = 20,
|
||||||
|
server: str = None, username: str = None) -> List[schemas.MediaServerPlayItem]:
|
||||||
|
"""
|
||||||
|
获取媒体服务器最新入库条目
|
||||||
|
"""
|
||||||
|
if server and server != "emby":
|
||||||
|
return []
|
||||||
|
return self.emby.get_latest(num=count, username=username)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
import traceback
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Optional, Union, Dict, Generator, Tuple
|
from typing import List, Optional, Union, Dict, Generator, Tuple
|
||||||
|
|
||||||
@@ -22,9 +23,16 @@ class Emby(metaclass=Singleton):
|
|||||||
self._host += "/"
|
self._host += "/"
|
||||||
if not self._host.startswith("http"):
|
if not self._host.startswith("http"):
|
||||||
self._host = "http://" + self._host
|
self._host = "http://" + self._host
|
||||||
|
self._playhost = settings.EMBY_PLAY_HOST
|
||||||
|
if self._playhost:
|
||||||
|
if not self._playhost.endswith("/"):
|
||||||
|
self._playhost += "/"
|
||||||
|
if not self._playhost.startswith("http"):
|
||||||
|
self._playhost = "http://" + self._playhost
|
||||||
self._apikey = settings.EMBY_API_KEY
|
self._apikey = settings.EMBY_API_KEY
|
||||||
self.user = self.get_user(settings.SUPERUSER)
|
self.user = self.get_user(settings.SUPERUSER)
|
||||||
self.folders = self.get_emby_folders()
|
self.folders = self.get_emby_folders()
|
||||||
|
self.serverid = self.get_server_id()
|
||||||
|
|
||||||
def is_inactive(self) -> bool:
|
def is_inactive(self) -> bool:
|
||||||
"""
|
"""
|
||||||
@@ -59,13 +67,52 @@ class Emby(metaclass=Singleton):
|
|||||||
logger.error(f"连接Library/SelectableMediaFolders 出错:" + str(e))
|
logger.error(f"连接Library/SelectableMediaFolders 出错:" + str(e))
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def __get_emby_librarys(self) -> List[dict]:
|
def get_emby_virtual_folders(self) -> List[dict]:
|
||||||
|
"""
|
||||||
|
获取Emby媒体库所有路径列表(包含共享路径)
|
||||||
|
"""
|
||||||
|
if not self._host or not self._apikey:
|
||||||
|
return []
|
||||||
|
req_url = "%semby/Library/VirtualFolders/Query?api_key=%s" % (self._host, self._apikey)
|
||||||
|
try:
|
||||||
|
res = RequestUtils().get_res(req_url)
|
||||||
|
if res:
|
||||||
|
library_items = res.json().get("Items")
|
||||||
|
librarys = []
|
||||||
|
for library_item in library_items:
|
||||||
|
library_name = library_item.get('Name')
|
||||||
|
pathInfos = library_item.get('LibraryOptions', {}).get('PathInfos')
|
||||||
|
library_paths = []
|
||||||
|
for path in pathInfos:
|
||||||
|
if path.get('NetworkPath'):
|
||||||
|
library_paths.append(path.get('NetworkPath'))
|
||||||
|
else:
|
||||||
|
library_paths.append(path.get('Path'))
|
||||||
|
|
||||||
|
if library_name and library_paths:
|
||||||
|
librarys.append({
|
||||||
|
'Name': library_name,
|
||||||
|
'Path': library_paths
|
||||||
|
})
|
||||||
|
return librarys
|
||||||
|
else:
|
||||||
|
logger.error(f"Library/VirtualFolders/Query 未获取到返回数据")
|
||||||
|
return []
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"连接Library/VirtualFolders/Query 出错:" + str(e))
|
||||||
|
return []
|
||||||
|
|
||||||
|
def __get_emby_librarys(self, username: str = None) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
获取Emby媒体库列表
|
获取Emby媒体库列表
|
||||||
"""
|
"""
|
||||||
if not self._host or not self._apikey:
|
if not self._host or not self._apikey:
|
||||||
return []
|
return []
|
||||||
req_url = f"{self._host}emby/Users/{self.user}/Views?api_key={self._apikey}"
|
if username:
|
||||||
|
user = self.get_user(username)
|
||||||
|
else:
|
||||||
|
user = self.user
|
||||||
|
req_url = f"{self._host}emby/Users/{user}/Views?api_key={self._apikey}"
|
||||||
try:
|
try:
|
||||||
res = RequestUtils().get_res(req_url)
|
res = RequestUtils().get_res(req_url)
|
||||||
if res:
|
if res:
|
||||||
@@ -77,14 +124,17 @@ class Emby(metaclass=Singleton):
|
|||||||
logger.error(f"连接User/Views 出错:" + str(e))
|
logger.error(f"连接User/Views 出错:" + str(e))
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def get_librarys(self) -> List[schemas.MediaServerLibrary]:
|
def get_librarys(self, username: str = None) -> List[schemas.MediaServerLibrary]:
|
||||||
"""
|
"""
|
||||||
获取媒体服务器所有媒体库列表
|
获取媒体服务器所有媒体库列表
|
||||||
"""
|
"""
|
||||||
if not self._host or not self._apikey:
|
if not self._host or not self._apikey:
|
||||||
return []
|
return []
|
||||||
libraries = []
|
libraries = []
|
||||||
for library in self.__get_emby_librarys() or []:
|
black_list = (settings.MEDIASERVER_SYNC_BLACKLIST or '').split(",")
|
||||||
|
for library in self.__get_emby_librarys(username) or []:
|
||||||
|
if library.get("Name") in black_list:
|
||||||
|
continue
|
||||||
match library.get("CollectionType"):
|
match library.get("CollectionType"):
|
||||||
case "movies":
|
case "movies":
|
||||||
library_type = MediaType.MOVIE.value
|
library_type = MediaType.MOVIE.value
|
||||||
@@ -92,13 +142,17 @@ class Emby(metaclass=Singleton):
|
|||||||
library_type = MediaType.TV.value
|
library_type = MediaType.TV.value
|
||||||
case _:
|
case _:
|
||||||
continue
|
continue
|
||||||
|
image = self.__get_local_image_by_id(library.get("Id"))
|
||||||
libraries.append(
|
libraries.append(
|
||||||
schemas.MediaServerLibrary(
|
schemas.MediaServerLibrary(
|
||||||
server="emby",
|
server="emby",
|
||||||
id=library.get("Id"),
|
id=library.get("Id"),
|
||||||
name=library.get("Name"),
|
name=library.get("Name"),
|
||||||
path=library.get("Path"),
|
path=library.get("Path"),
|
||||||
type=library_type
|
type=library_type,
|
||||||
|
image=image,
|
||||||
|
link=f'{self._playhost or self._host}web/index.html'
|
||||||
|
f'#!/videos?serverId={self.serverid}&parentId={library.get("Id")}'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return libraries
|
return libraries
|
||||||
@@ -244,7 +298,7 @@ class Emby(metaclass=Singleton):
|
|||||||
"&Limit=10"
|
"&Limit=10"
|
||||||
"&IncludeSearchTypes=false"
|
"&IncludeSearchTypes=false"
|
||||||
"&api_key=%s") % (
|
"&api_key=%s") % (
|
||||||
self._host, name, self._apikey)
|
self._host, name, self._apikey)
|
||||||
try:
|
try:
|
||||||
res = RequestUtils().get_res(req_url)
|
res = RequestUtils().get_res(req_url)
|
||||||
if res:
|
if res:
|
||||||
@@ -366,7 +420,7 @@ class Emby(metaclass=Singleton):
|
|||||||
season_episodes[season_index] = []
|
season_episodes[season_index] = []
|
||||||
season_episodes[season_index].append(episode_index)
|
season_episodes[season_index].append(episode_index)
|
||||||
# 返回
|
# 返回
|
||||||
return tv_item.get("Id"), season_episodes
|
return item_id, season_episodes
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"连接Shows/Id/Episodes出错:" + str(e))
|
logger.error(f"连接Shows/Id/Episodes出错:" + str(e))
|
||||||
return None, None
|
return None, None
|
||||||
@@ -482,7 +536,7 @@ class Emby(metaclass=Singleton):
|
|||||||
if item_path.is_relative_to(subfolder_path):
|
if item_path.is_relative_to(subfolder_path):
|
||||||
return folder.get("Id")
|
return folder.get("Id")
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(str(err))
|
logger.debug(f"匹配子目录出错:{err} - {traceback.format_exc()}")
|
||||||
# 如果找不到,只要路径中有分类目录名就命中
|
# 如果找不到,只要路径中有分类目录名就命中
|
||||||
for folder in self.folders:
|
for folder in self.folders:
|
||||||
for subfolder in folder.get("SubFolders"):
|
for subfolder in folder.get("SubFolders"):
|
||||||
@@ -803,7 +857,10 @@ class Emby(metaclass=Singleton):
|
|||||||
logger.debug(f"接收到emby webhook:{message}")
|
logger.debug(f"接收到emby webhook:{message}")
|
||||||
eventItem = schemas.WebhookEventInfo(event=eventType, channel="emby")
|
eventItem = schemas.WebhookEventInfo(event=eventType, channel="emby")
|
||||||
if message.get('Item'):
|
if message.get('Item'):
|
||||||
if message.get('Item', {}).get('Type') == 'Episode':
|
eventItem.media_type = message.get('Item', {}).get('Type')
|
||||||
|
if message.get('Item', {}).get('Type') == 'Episode' \
|
||||||
|
or message.get('Item', {}).get('Type') == 'Series' \
|
||||||
|
or message.get('Item', {}).get('Type') == 'Season':
|
||||||
eventItem.item_type = "TV"
|
eventItem.item_type = "TV"
|
||||||
if message.get('Item', {}).get('SeriesName') \
|
if message.get('Item', {}).get('SeriesName') \
|
||||||
and message.get('Item', {}).get('ParentIndexNumber') \
|
and message.get('Item', {}).get('ParentIndexNumber') \
|
||||||
@@ -813,6 +870,10 @@ class Emby(metaclass=Singleton):
|
|||||||
"S" + str(message.get('Item', {}).get('ParentIndexNumber')),
|
"S" + str(message.get('Item', {}).get('ParentIndexNumber')),
|
||||||
"E" + str(message.get('Item', {}).get('IndexNumber')),
|
"E" + str(message.get('Item', {}).get('IndexNumber')),
|
||||||
message.get('Item', {}).get('Name'))
|
message.get('Item', {}).get('Name'))
|
||||||
|
elif message.get('Item', {}).get('SeriesName'):
|
||||||
|
eventItem.item_name = "%s %s" % (
|
||||||
|
message.get('Item', {}).get('SeriesName'),
|
||||||
|
message.get('Item', {}).get('Name'))
|
||||||
else:
|
else:
|
||||||
eventItem.item_name = message.get('Item', {}).get('Name')
|
eventItem.item_name = message.get('Item', {}).get('Name')
|
||||||
eventItem.item_id = message.get('Item', {}).get('SeriesId')
|
eventItem.item_id = message.get('Item', {}).get('SeriesId')
|
||||||
@@ -839,7 +900,7 @@ class Emby(metaclass=Singleton):
|
|||||||
eventItem.overview = message.get('Item', {}).get('Overview')
|
eventItem.overview = message.get('Item', {}).get('Overview')
|
||||||
eventItem.percentage = message.get('TranscodingInfo', {}).get('CompletionPercentage')
|
eventItem.percentage = message.get('TranscodingInfo', {}).get('CompletionPercentage')
|
||||||
if not eventItem.percentage:
|
if not eventItem.percentage:
|
||||||
if message.get('PlaybackInfo', {}).get('PositionTicks'):
|
if message.get('PlaybackInfo', {}).get('PositionTicks') and message.get('Item', {}).get('RunTimeTicks'):
|
||||||
eventItem.percentage = message.get('PlaybackInfo', {}).get('PositionTicks') / \
|
eventItem.percentage = message.get('PlaybackInfo', {}).get('PositionTicks') / \
|
||||||
message.get('Item', {}).get('RunTimeTicks') * 100
|
message.get('Item', {}).get('RunTimeTicks') * 100
|
||||||
if message.get('Session'):
|
if message.get('Session'):
|
||||||
@@ -900,3 +961,160 @@ class Emby(metaclass=Singleton):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"连接Emby出错:" + str(e))
|
logger.error(f"连接Emby出错:" + str(e))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_play_url(self, item_id: str) -> str:
|
||||||
|
"""
|
||||||
|
拼装媒体播放链接
|
||||||
|
:param item_id: 媒体的的ID
|
||||||
|
"""
|
||||||
|
return f"{self._playhost or self._host}web/index.html#!" \
|
||||||
|
f"/item?id={item_id}&context=home&serverId={self.serverid}"
|
||||||
|
|
||||||
|
def __get_backdrop_url(self, item_id: str, image_tag: str) -> str:
|
||||||
|
"""
|
||||||
|
获取Emby的Backdrop图片地址
|
||||||
|
:param: item_id: 在Emby中的ID
|
||||||
|
:param: image_tag: 图片的tag
|
||||||
|
:param: remote 是否远程使用,TG微信等客户端调用应为True
|
||||||
|
:param: inner 是否NT内部调用,为True是会使用NT中转
|
||||||
|
"""
|
||||||
|
if not self._host or not self._apikey:
|
||||||
|
return ""
|
||||||
|
if not image_tag or not item_id:
|
||||||
|
return ""
|
||||||
|
return f"{self._host}Items/{item_id}/" \
|
||||||
|
f"Images/Backdrop?tag={image_tag}&fillWidth=666&api_key={self._apikey}"
|
||||||
|
|
||||||
|
def __get_local_image_by_id(self, item_id: str) -> str:
|
||||||
|
"""
|
||||||
|
根据ItemId从媒体服务器查询本地图片地址
|
||||||
|
:param: item_id: 在Emby中的ID
|
||||||
|
:param: remote 是否远程使用,TG微信等客户端调用应为True
|
||||||
|
:param: inner 是否NT内部调用,为True是会使用NT中转
|
||||||
|
"""
|
||||||
|
if not self._host or not self._apikey:
|
||||||
|
return ""
|
||||||
|
return "%sItems/%s/Images/Primary" % (self._host, item_id)
|
||||||
|
|
||||||
|
def get_resume(self, num: int = 12, username: str = None) -> Optional[List[schemas.MediaServerPlayItem]]:
|
||||||
|
"""
|
||||||
|
获得继续观看
|
||||||
|
"""
|
||||||
|
if not self._host or not self._apikey:
|
||||||
|
return None
|
||||||
|
if username:
|
||||||
|
user = self.get_user(username)
|
||||||
|
else:
|
||||||
|
user = self.user
|
||||||
|
req_url = (f"{self._host}Users/{user}/Items/Resume?"
|
||||||
|
f"Limit=100&MediaTypes=Video&api_key={self._apikey}&Fields=ProductionYear,Path")
|
||||||
|
try:
|
||||||
|
res = RequestUtils().get_res(req_url)
|
||||||
|
if res:
|
||||||
|
result = res.json().get("Items") or []
|
||||||
|
ret_resume = []
|
||||||
|
# 用户媒体库文件夹列表(排除黑名单)
|
||||||
|
library_folders = self.get_user_library_folders()
|
||||||
|
for item in result:
|
||||||
|
if len(ret_resume) == num:
|
||||||
|
break
|
||||||
|
if item.get("Type") not in ["Movie", "Episode"]:
|
||||||
|
continue
|
||||||
|
item_path = item.get("Path")
|
||||||
|
if item_path and library_folders and not any(
|
||||||
|
str(item_path).startswith(folder) for folder in library_folders):
|
||||||
|
continue
|
||||||
|
item_type = MediaType.MOVIE.value if item.get("Type") == "Movie" else MediaType.TV.value
|
||||||
|
link = self.get_play_url(item.get("Id"))
|
||||||
|
if item_type == MediaType.MOVIE.value:
|
||||||
|
title = item.get("Name")
|
||||||
|
subtitle = item.get("ProductionYear")
|
||||||
|
else:
|
||||||
|
title = f'{item.get("SeriesName")}'
|
||||||
|
subtitle = f'S{item.get("ParentIndexNumber")}:{item.get("IndexNumber")} - {item.get("Name")}'
|
||||||
|
if item_type == MediaType.MOVIE.value:
|
||||||
|
if item.get("BackdropImageTags"):
|
||||||
|
image = self.__get_backdrop_url(item_id=item.get("Id"),
|
||||||
|
image_tag=item.get("BackdropImageTags")[0])
|
||||||
|
else:
|
||||||
|
image = self.__get_local_image_by_id(item.get("Id"))
|
||||||
|
else:
|
||||||
|
image = self.__get_backdrop_url(item_id=item.get("SeriesId"),
|
||||||
|
image_tag=item.get("SeriesPrimaryImageTag"))
|
||||||
|
if not image:
|
||||||
|
image = self.__get_local_image_by_id(item.get("SeriesId"))
|
||||||
|
ret_resume.append(schemas.MediaServerPlayItem(
|
||||||
|
id=item.get("Id"),
|
||||||
|
title=title,
|
||||||
|
subtitle=subtitle,
|
||||||
|
type=item_type,
|
||||||
|
image=image,
|
||||||
|
link=link,
|
||||||
|
percent=item.get("UserData", {}).get("PlayedPercentage")
|
||||||
|
))
|
||||||
|
return ret_resume
|
||||||
|
else:
|
||||||
|
logger.error(f"Users/Items/Resume 未获取到返回数据")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"连接Users/Items/Resume出错:" + str(e))
|
||||||
|
return []
|
||||||
|
|
||||||
|
def get_latest(self, num: int = 20, username: str = None) -> Optional[List[schemas.MediaServerPlayItem]]:
|
||||||
|
"""
|
||||||
|
获得最近更新
|
||||||
|
"""
|
||||||
|
if not self._host or not self._apikey:
|
||||||
|
return None
|
||||||
|
if username:
|
||||||
|
user = self.get_user(username)
|
||||||
|
else:
|
||||||
|
user = self.user
|
||||||
|
req_url = (f"{self._host}Users/{user}/Items/Latest?"
|
||||||
|
f"Limit=100&MediaTypes=Video&api_key={self._apikey}&Fields=ProductionYear,Path")
|
||||||
|
try:
|
||||||
|
res = RequestUtils().get_res(req_url)
|
||||||
|
if res:
|
||||||
|
result = res.json() or []
|
||||||
|
ret_latest = []
|
||||||
|
# 用户媒体库文件夹列表(排除黑名单)
|
||||||
|
library_folders = self.get_user_library_folders()
|
||||||
|
for item in result:
|
||||||
|
if len(ret_latest) == num:
|
||||||
|
break
|
||||||
|
if item.get("Type") not in ["Movie", "Series"]:
|
||||||
|
continue
|
||||||
|
item_path = item.get("Path")
|
||||||
|
if item_path and library_folders and not any(
|
||||||
|
str(item_path).startswith(folder) for folder in library_folders):
|
||||||
|
continue
|
||||||
|
item_type = MediaType.MOVIE.value if item.get("Type") == "Movie" else MediaType.TV.value
|
||||||
|
link = self.get_play_url(item.get("Id"))
|
||||||
|
image = self.__get_local_image_by_id(item_id=item.get("Id"))
|
||||||
|
ret_latest.append(schemas.MediaServerPlayItem(
|
||||||
|
id=item.get("Id"),
|
||||||
|
title=item.get("Name"),
|
||||||
|
subtitle=item.get("ProductionYear"),
|
||||||
|
type=item_type,
|
||||||
|
image=image,
|
||||||
|
link=link
|
||||||
|
))
|
||||||
|
return ret_latest
|
||||||
|
else:
|
||||||
|
logger.error(f"Users/Items/Latest 未获取到返回数据")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"连接Users/Items/Latest出错:" + str(e))
|
||||||
|
return []
|
||||||
|
|
||||||
|
def get_user_library_folders(self):
|
||||||
|
"""
|
||||||
|
获取Emby媒体库文件夹列表(排除黑名单)
|
||||||
|
"""
|
||||||
|
if not self._host or not self._apikey:
|
||||||
|
return []
|
||||||
|
library_folders = []
|
||||||
|
black_list = (settings.MEDIASERVER_SYNC_BLACKLIST or '').split(",")
|
||||||
|
for library in self.get_emby_virtual_folders() or []:
|
||||||
|
if library.get("Name") in black_list:
|
||||||
|
continue
|
||||||
|
library_folders += [folder for folder in library.get("Path")]
|
||||||
|
return library_folders
|
||||||
|
|||||||
@@ -326,17 +326,21 @@ class FanartModule(_ModuleBase):
|
|||||||
:param mediainfo: 识别的媒体信息
|
:param mediainfo: 识别的媒体信息
|
||||||
:return: 更新后的媒体信息
|
:return: 更新后的媒体信息
|
||||||
"""
|
"""
|
||||||
|
if not settings.FANART_ENABLE:
|
||||||
|
return None
|
||||||
|
if not mediainfo.tmdb_id and not mediainfo.tvdb_id:
|
||||||
|
return None
|
||||||
if mediainfo.type == MediaType.MOVIE:
|
if mediainfo.type == MediaType.MOVIE:
|
||||||
result = self.__request_fanart(mediainfo.type, mediainfo.tmdb_id)
|
result = self.__request_fanart(mediainfo.type, mediainfo.tmdb_id)
|
||||||
else:
|
else:
|
||||||
if mediainfo.tvdb_id:
|
if mediainfo.tvdb_id:
|
||||||
result = self.__request_fanart(mediainfo.type, mediainfo.tvdb_id)
|
result = self.__request_fanart(mediainfo.type, mediainfo.tvdb_id)
|
||||||
else:
|
else:
|
||||||
logger.info(f"{mediainfo.title_year} 没有tvdbid,无法获取Fanart图片")
|
logger.info(f"{mediainfo.title_year} 没有tvdbid,无法获取fanart图片")
|
||||||
return
|
return None
|
||||||
if not result or result.get('status') == 'error':
|
if not result or result.get('status') == 'error':
|
||||||
logger.warn(f"没有获取到 {mediainfo.title_year} 的Fanart图片数据")
|
logger.warn(f"没有获取到 {mediainfo.title_year} 的fanart图片数据")
|
||||||
return
|
return None
|
||||||
# 获取所有图片
|
# 获取所有图片
|
||||||
for name, images in result.items():
|
for name, images in result.items():
|
||||||
if not images:
|
if not images:
|
||||||
|
|||||||
@@ -8,11 +8,12 @@ from jinja2 import Template
|
|||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.core.context import MediaInfo
|
from app.core.context import MediaInfo
|
||||||
from app.core.meta import MetaBase
|
from app.core.meta import MetaBase
|
||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo, MetaInfoPath
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.modules import _ModuleBase
|
from app.modules import _ModuleBase
|
||||||
from app.schemas import TransferInfo, ExistMediaInfo, TmdbEpisode
|
from app.schemas import TransferInfo, ExistMediaInfo, TmdbEpisode
|
||||||
from app.schemas.types import MediaType
|
from app.schemas.types import MediaType
|
||||||
|
from app.utils.string import StringUtils
|
||||||
from app.utils.system import SystemUtils
|
from app.utils.system import SystemUtils
|
||||||
|
|
||||||
lock = Lock()
|
lock = Lock()
|
||||||
@@ -44,15 +45,28 @@ class FileTransferModule(_ModuleBase):
|
|||||||
"""
|
"""
|
||||||
# 获取目标路径
|
# 获取目标路径
|
||||||
if not target:
|
if not target:
|
||||||
|
# 未指定目的目录,根据源目录选择一个媒体库
|
||||||
target = self.get_target_path(in_path=path)
|
target = self.get_target_path(in_path=path)
|
||||||
elif not target.exists() or target.is_file():
|
# 拼装媒体库一、二级子目录
|
||||||
# 目的路径不存在或者是文件时,找对应的媒体库目录
|
target = self.__get_dest_dir(mediainfo=mediainfo, target_dir=target)
|
||||||
target = self.get_library_path(target)
|
else:
|
||||||
|
# 指定了目的目录
|
||||||
|
if target.is_file():
|
||||||
|
logger.error(f"转移目标路径是一个文件 {target} 是一个文件")
|
||||||
|
return TransferInfo(success=False,
|
||||||
|
path=path,
|
||||||
|
message=f"{target} 不是有效目录")
|
||||||
|
# 只拼装二级子目录(不要一级目录)
|
||||||
|
target = self.__get_dest_dir(mediainfo=mediainfo, target_dir=target, typename_dir=False)
|
||||||
|
|
||||||
if not target:
|
if not target:
|
||||||
logger.error("未找到媒体库目录,无法转移文件")
|
logger.error("未找到媒体库目录,无法转移文件")
|
||||||
return TransferInfo(success=False,
|
return TransferInfo(success=False,
|
||||||
path=path,
|
path=path,
|
||||||
message="未找到媒体库目录")
|
message="未找到媒体库目录")
|
||||||
|
else:
|
||||||
|
logger.info(f"获取转移目标路径:{target}")
|
||||||
|
|
||||||
# 转移
|
# 转移
|
||||||
return self.transfer_media(in_path=path,
|
return self.transfer_media(in_path=path,
|
||||||
in_meta=meta,
|
in_meta=meta,
|
||||||
@@ -330,33 +344,42 @@ class FileTransferModule(_ModuleBase):
|
|||||||
over_flag=over_flag)
|
over_flag=over_flag)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __get_dest_dir(mediainfo: MediaInfo, target_dir: Path) -> Path:
|
def __get_dest_dir(mediainfo: MediaInfo, target_dir: Path, typename_dir: bool = True) -> Path:
|
||||||
"""
|
"""
|
||||||
根据设置并装媒体库目录
|
根据设置并装媒体库目录
|
||||||
:param mediainfo: 媒体信息
|
:param mediainfo: 媒体信息
|
||||||
:target_dir: 媒体库根目录
|
:target_dir: 媒体库根目录
|
||||||
|
:typename_dir: 是否加上类型目录
|
||||||
"""
|
"""
|
||||||
|
if not target_dir:
|
||||||
|
return target_dir
|
||||||
|
|
||||||
if mediainfo.type == MediaType.MOVIE:
|
if mediainfo.type == MediaType.MOVIE:
|
||||||
# 电影
|
# 电影
|
||||||
if settings.LIBRARY_MOVIE_NAME:
|
if typename_dir:
|
||||||
|
# 目的目录加上类型和二级分类
|
||||||
target_dir = target_dir / settings.LIBRARY_MOVIE_NAME / mediainfo.category
|
target_dir = target_dir / settings.LIBRARY_MOVIE_NAME / mediainfo.category
|
||||||
else:
|
else:
|
||||||
# 目的目录加上类型和二级分类
|
# 目的目录加上二级分类
|
||||||
target_dir = target_dir / mediainfo.type.value / mediainfo.category
|
target_dir = target_dir / mediainfo.category
|
||||||
|
|
||||||
if mediainfo.type == MediaType.TV:
|
if mediainfo.type == MediaType.TV:
|
||||||
# 电视剧
|
# 电视剧
|
||||||
if settings.LIBRARY_ANIME_NAME \
|
if mediainfo.genre_ids \
|
||||||
and mediainfo.genre_ids \
|
|
||||||
and set(mediainfo.genre_ids).intersection(set(settings.ANIME_GENREIDS)):
|
and set(mediainfo.genre_ids).intersection(set(settings.ANIME_GENREIDS)):
|
||||||
# 动漫
|
# 动漫
|
||||||
target_dir = target_dir / settings.LIBRARY_ANIME_NAME / mediainfo.category
|
if typename_dir:
|
||||||
elif settings.LIBRARY_TV_NAME:
|
target_dir = target_dir / (settings.LIBRARY_ANIME_NAME
|
||||||
# 电视剧
|
or settings.LIBRARY_TV_NAME) / mediainfo.category
|
||||||
target_dir = target_dir / settings.LIBRARY_TV_NAME / mediainfo.category
|
else:
|
||||||
|
target_dir = target_dir / mediainfo.category
|
||||||
else:
|
else:
|
||||||
# 目的目录加上类型和二级分类
|
# 电视剧
|
||||||
target_dir = target_dir / mediainfo.type.value / mediainfo.category
|
if typename_dir:
|
||||||
|
target_dir = target_dir / settings.LIBRARY_TV_NAME / mediainfo.category
|
||||||
|
else:
|
||||||
|
target_dir = target_dir / mediainfo.category
|
||||||
|
|
||||||
return target_dir
|
return target_dir
|
||||||
|
|
||||||
def transfer_media(self,
|
def transfer_media(self,
|
||||||
@@ -386,12 +409,8 @@ class FileTransferModule(_ModuleBase):
|
|||||||
if transfer_type not in ['rclone_copy', 'rclone_move']:
|
if transfer_type not in ['rclone_copy', 'rclone_move']:
|
||||||
# 检查目标路径
|
# 检查目标路径
|
||||||
if not target_dir.exists():
|
if not target_dir.exists():
|
||||||
return TransferInfo(success=False,
|
logger.info(f"目标路径不存在,正在创建:{target_dir} ...")
|
||||||
path=in_path,
|
target_dir.mkdir(parents=True, exist_ok=True)
|
||||||
message=f"{target_dir} 目标路径不存在")
|
|
||||||
|
|
||||||
# 媒体库目的目录
|
|
||||||
target_dir = self.__get_dest_dir(mediainfo=mediainfo, target_dir=target_dir)
|
|
||||||
|
|
||||||
# 重命名格式
|
# 重命名格式
|
||||||
rename_format = settings.TV_RENAME_FORMAT \
|
rename_format = settings.TV_RENAME_FORMAT \
|
||||||
@@ -468,9 +487,36 @@ class FileTransferModule(_ModuleBase):
|
|||||||
# 判断是否要覆盖
|
# 判断是否要覆盖
|
||||||
overflag = False
|
overflag = False
|
||||||
if new_file.exists():
|
if new_file.exists():
|
||||||
if new_file.stat().st_size < in_path.stat().st_size:
|
# 目标文件已存在
|
||||||
logger.info(f"目标文件已存在,但文件大小更小,将覆盖:{new_file}")
|
logger.info(f"目标文件已存在,转移覆盖模式:{settings.OVERWRITE_MODE}")
|
||||||
overflag = True
|
match settings.OVERWRITE_MODE:
|
||||||
|
case 'always':
|
||||||
|
# 总是覆盖同名文件
|
||||||
|
overflag = True
|
||||||
|
case 'size':
|
||||||
|
# 存在时大覆盖小
|
||||||
|
if new_file.stat().st_size < in_path.stat().st_size:
|
||||||
|
logger.info(f"目标文件文件大小更小,将被覆盖:{new_file}")
|
||||||
|
overflag = True
|
||||||
|
else:
|
||||||
|
return TransferInfo(success=False,
|
||||||
|
message=f"媒体库中已存在,且质量更好",
|
||||||
|
path=in_path,
|
||||||
|
target_path=new_file,
|
||||||
|
fail_list=[str(in_path)])
|
||||||
|
case 'never':
|
||||||
|
# 存在不覆盖
|
||||||
|
return TransferInfo(success=False,
|
||||||
|
message=f"媒体库中已存在,当前设置为不覆盖",
|
||||||
|
path=in_path,
|
||||||
|
target_path=new_file,
|
||||||
|
fail_list=[str(in_path)])
|
||||||
|
case 'latest':
|
||||||
|
# 仅保留最新版本
|
||||||
|
self.delete_all_version_files(new_file)
|
||||||
|
overflag = True
|
||||||
|
case _:
|
||||||
|
pass
|
||||||
# 原文件大小
|
# 原文件大小
|
||||||
file_size = in_path.stat().st_size
|
file_size = in_path.stat().st_size
|
||||||
# 转移文件
|
# 转移文件
|
||||||
@@ -517,12 +563,14 @@ class FileTransferModule(_ModuleBase):
|
|||||||
return {
|
return {
|
||||||
# 标题
|
# 标题
|
||||||
"title": mediainfo.title,
|
"title": mediainfo.title,
|
||||||
# 原文件名
|
|
||||||
"original_name": f"{meta.org_string}{file_ext}",
|
|
||||||
# 原语种标题
|
# 原语种标题
|
||||||
"original_title": mediainfo.original_title,
|
"original_title": mediainfo.original_title,
|
||||||
# 识别名称
|
# 原文件名
|
||||||
|
"original_name": f"{meta.org_string}{file_ext}",
|
||||||
|
# 识别名称(优先使用中文)
|
||||||
"name": meta.name,
|
"name": meta.name,
|
||||||
|
# 识别的英文名称(可能为空)
|
||||||
|
"en_name": meta.en_name,
|
||||||
# 年份
|
# 年份
|
||||||
"year": mediainfo.year or meta.year,
|
"year": mediainfo.year or meta.year,
|
||||||
# 资源类型
|
# 资源类型
|
||||||
@@ -543,6 +591,8 @@ class FileTransferModule(_ModuleBase):
|
|||||||
"tmdbid": mediainfo.tmdb_id,
|
"tmdbid": mediainfo.tmdb_id,
|
||||||
# IMDBID
|
# IMDBID
|
||||||
"imdbid": mediainfo.imdb_id,
|
"imdbid": mediainfo.imdb_id,
|
||||||
|
# 豆瓣ID
|
||||||
|
"doubanid": mediainfo.douban_id,
|
||||||
# 季号
|
# 季号
|
||||||
"season": meta.season_seq,
|
"season": meta.season_seq,
|
||||||
# 集号
|
# 集号
|
||||||
@@ -613,7 +663,8 @@ class FileTransferModule(_ModuleBase):
|
|||||||
if in_path:
|
if in_path:
|
||||||
for path in dest_paths:
|
for path in dest_paths:
|
||||||
try:
|
try:
|
||||||
relative = in_path.relative_to(path).as_posix()
|
# 计算in_path和path的公共字符串长度
|
||||||
|
relative = StringUtils.find_common_prefix(str(in_path), str(path))
|
||||||
if len(relative) > max_length:
|
if len(relative) > max_length:
|
||||||
max_length = len(relative)
|
max_length = len(relative)
|
||||||
target_path = path
|
target_path = path
|
||||||
@@ -622,20 +673,19 @@ class FileTransferModule(_ModuleBase):
|
|||||||
continue
|
continue
|
||||||
if target_path:
|
if target_path:
|
||||||
return target_path
|
return target_path
|
||||||
# 顺序匹配第1个满足空间存储要求的目录
|
# 顺序匹配第1个满足空间存储要求的目录
|
||||||
if in_path.exists():
|
if in_path.exists():
|
||||||
file_size = in_path.stat().st_size
|
file_size = in_path.stat().st_size
|
||||||
for path in dest_paths:
|
for path in dest_paths:
|
||||||
if SystemUtils.free_space(path) > file_size:
|
if SystemUtils.free_space(path) > file_size:
|
||||||
return path
|
return path
|
||||||
# 默认返回第1个
|
# 默认返回第1个
|
||||||
return dest_paths[0]
|
return dest_paths[0]
|
||||||
|
|
||||||
def media_exists(self, mediainfo: MediaInfo, itemid: str = None) -> Optional[ExistMediaInfo]:
|
def media_exists(self, mediainfo: MediaInfo, **kwargs) -> Optional[ExistMediaInfo]:
|
||||||
"""
|
"""
|
||||||
判断媒体文件是否存在于本地文件系统
|
判断媒体文件是否存在于本地文件系统,只支持标准媒体库结构
|
||||||
:param mediainfo: 识别的媒体信息
|
:param mediainfo: 识别的媒体信息
|
||||||
:param itemid: 媒体服务器ItemID
|
|
||||||
:return: 如不存在返回None,存在时返回信息,包括每季已存在所有集{type: movie/tv, seasons: {season: [episodes]}}
|
:return: 如不存在返回None,存在时返回信息,包括每季已存在所有集{type: movie/tv, seasons: {season: [episodes]}}
|
||||||
"""
|
"""
|
||||||
if not settings.LIBRARY_PATHS:
|
if not settings.LIBRARY_PATHS:
|
||||||
@@ -696,3 +746,34 @@ class FileTransferModule(_ModuleBase):
|
|||||||
return ExistMediaInfo(type=MediaType.TV, seasons=seasons)
|
return ExistMediaInfo(type=MediaType.TV, seasons=seasons)
|
||||||
# 不存在
|
# 不存在
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def delete_all_version_files(path: Path) -> bool:
|
||||||
|
"""
|
||||||
|
删除目录下的所有版本文件
|
||||||
|
:param path: 目录路径
|
||||||
|
"""
|
||||||
|
if not path.exists():
|
||||||
|
return False
|
||||||
|
# 识别文件中的季集信息
|
||||||
|
meta = MetaInfoPath(path)
|
||||||
|
season = meta.season
|
||||||
|
episode = meta.episode
|
||||||
|
# 检索媒体文件
|
||||||
|
logger.warn(f"正在删除目标目录中其它版本的文件:{path.parent}")
|
||||||
|
media_files = SystemUtils.list_files(directory=path.parent, extensions=settings.RMT_MEDIAEXT)
|
||||||
|
if not media_files:
|
||||||
|
logger.info(f"目录中没有媒体文件:{path.parent}")
|
||||||
|
return False
|
||||||
|
# 删除文件
|
||||||
|
for media_file in media_files:
|
||||||
|
if media_file == path:
|
||||||
|
continue
|
||||||
|
# 识别文件中的季集信息
|
||||||
|
filemeta = MetaInfoPath(media_file)
|
||||||
|
# 相同季集的文件才删除
|
||||||
|
if filemeta.season != season or filemeta.episode != episode:
|
||||||
|
continue
|
||||||
|
logger.info(f"正在删除文件:{media_file}")
|
||||||
|
media_file.unlink()
|
||||||
|
return True
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class IndexerModule(_ModuleBase):
|
|||||||
# 确认搜索的名字
|
# 确认搜索的名字
|
||||||
if not keywords:
|
if not keywords:
|
||||||
# 浏览种子页
|
# 浏览种子页
|
||||||
keywords = [None]
|
keywords = ['']
|
||||||
|
|
||||||
# 开始索引
|
# 开始索引
|
||||||
result_array = []
|
result_array = []
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import copy
|
import copy
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
import re
|
||||||
|
import traceback
|
||||||
from typing import List
|
from typing import List
|
||||||
from urllib.parse import quote, urlencode
|
from urllib.parse import quote, urlencode
|
||||||
|
|
||||||
@@ -12,9 +13,9 @@ from ruamel.yaml import CommentedMap
|
|||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.helper.browser import PlaywrightHelper
|
from app.helper.browser import PlaywrightHelper
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
|
from app.schemas.types import MediaType
|
||||||
from app.utils.http import RequestUtils
|
from app.utils.http import RequestUtils
|
||||||
from app.utils.string import StringUtils
|
from app.utils.string import StringUtils
|
||||||
from app.schemas.types import MediaType
|
|
||||||
|
|
||||||
|
|
||||||
class TorrentSpider:
|
class TorrentSpider:
|
||||||
@@ -547,6 +548,29 @@ class TorrentSpider:
|
|||||||
else:
|
else:
|
||||||
self.torrents_info['labels'] = []
|
self.torrents_info['labels'] = []
|
||||||
|
|
||||||
|
def __get_free_date(self, torrent):
|
||||||
|
# free date
|
||||||
|
if 'freedate' not in self.fields:
|
||||||
|
return
|
||||||
|
selector = self.fields.get('freedate', {})
|
||||||
|
freedate = torrent(selector.get('selector', '')).clone()
|
||||||
|
self.__remove(freedate, selector)
|
||||||
|
items = self.__attribute_or_text(freedate, selector)
|
||||||
|
self.torrents_info['freedate'] = self.__index(items, selector)
|
||||||
|
self.torrents_info['freedate'] = self.__filter_text(self.torrents_info.get('freedate'),
|
||||||
|
selector.get('filters'))
|
||||||
|
|
||||||
|
def __get_hit_and_run(self, torrent):
|
||||||
|
# hitandrun
|
||||||
|
if 'hr' not in self.fields:
|
||||||
|
return
|
||||||
|
selector = self.fields.get('hr', {})
|
||||||
|
hit_and_run = torrent(selector.get('selector', ''))
|
||||||
|
if hit_and_run:
|
||||||
|
self.torrents_info['hit_and_run'] = True
|
||||||
|
else:
|
||||||
|
self.torrents_info['hit_and_run'] = False
|
||||||
|
|
||||||
def get_info(self, torrent) -> dict:
|
def get_info(self, torrent) -> dict:
|
||||||
"""
|
"""
|
||||||
解析单条种子数据
|
解析单条种子数据
|
||||||
@@ -566,13 +590,15 @@ class TorrentSpider:
|
|||||||
self.__get_uploadvolumefactor(torrent)
|
self.__get_uploadvolumefactor(torrent)
|
||||||
self.__get_pubdate(torrent)
|
self.__get_pubdate(torrent)
|
||||||
self.__get_date_elapsed(torrent)
|
self.__get_date_elapsed(torrent)
|
||||||
|
self.__get_free_date(torrent)
|
||||||
self.__get_labels(torrent)
|
self.__get_labels(torrent)
|
||||||
|
self.__get_hit_and_run(torrent)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.error("%s 搜索出现错误:%s" % (self.indexername, str(err)))
|
logger.error("%s 搜索出现错误:%s" % (self.indexername, str(err)))
|
||||||
return self.torrents_info
|
return self.torrents_info
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __filter_text(text, filters):
|
def __filter_text(text: str, filters: list):
|
||||||
"""
|
"""
|
||||||
对文件进行处理
|
对文件进行处理
|
||||||
"""
|
"""
|
||||||
@@ -583,8 +609,8 @@ class TorrentSpider:
|
|||||||
for filter_item in filters:
|
for filter_item in filters:
|
||||||
if not text:
|
if not text:
|
||||||
break
|
break
|
||||||
|
method_name = filter_item.get("name")
|
||||||
try:
|
try:
|
||||||
method_name = filter_item.get("name")
|
|
||||||
args = filter_item.get("args")
|
args = filter_item.get("args")
|
||||||
if method_name == "re_search" and isinstance(args, list):
|
if method_name == "re_search" and isinstance(args, list):
|
||||||
text = re.search(r"%s" % args[0], text).group(args[-1])
|
text = re.search(r"%s" % args[0], text).group(args[-1])
|
||||||
@@ -599,7 +625,7 @@ class TorrentSpider:
|
|||||||
elif method_name == "appendleft":
|
elif method_name == "appendleft":
|
||||||
text = f"{args}{text}"
|
text = f"{args}{text}"
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(str(err))
|
logger.debug(f'过滤器 {method_name} 处理失败:{str(err)} - {traceback.format_exc()}')
|
||||||
return text.strip()
|
return text.strip()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -613,7 +639,7 @@ class TorrentSpider:
|
|||||||
item.remove(v)
|
item.remove(v)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __attribute_or_text(item, selector):
|
def __attribute_or_text(item, selector: dict):
|
||||||
if not selector:
|
if not selector:
|
||||||
return item
|
return item
|
||||||
if not item:
|
if not item:
|
||||||
@@ -625,7 +651,7 @@ class TorrentSpider:
|
|||||||
return items
|
return items
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __index(items, selector):
|
def __index(items: list, selector: dict):
|
||||||
if not items:
|
if not items:
|
||||||
return None
|
return None
|
||||||
if selector:
|
if selector:
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
from pathlib import Path
|
|
||||||
from typing import Optional, Tuple, Union, Any, List, Generator
|
from typing import Optional, Tuple, Union, Any, List, Generator
|
||||||
|
|
||||||
from app import schemas
|
from app import schemas
|
||||||
@@ -23,7 +22,7 @@ class JellyfinModule(_ModuleBase):
|
|||||||
定时任务,每10分钟调用一次
|
定时任务,每10分钟调用一次
|
||||||
"""
|
"""
|
||||||
# 定时重连
|
# 定时重连
|
||||||
if not self.jellyfin.is_inactive():
|
if self.jellyfin.is_inactive():
|
||||||
self.jellyfin.reconnect()
|
self.jellyfin.reconnect()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
@@ -94,15 +93,6 @@ class JellyfinModule(_ModuleBase):
|
|||||||
itemid=itemid
|
itemid=itemid
|
||||||
)
|
)
|
||||||
|
|
||||||
def refresh_mediaserver(self, mediainfo: MediaInfo, file_path: Path) -> None:
|
|
||||||
"""
|
|
||||||
刷新媒体库
|
|
||||||
:param mediainfo: 识别的媒体信息
|
|
||||||
:param file_path: 文件路径
|
|
||||||
:return: 成功或失败
|
|
||||||
"""
|
|
||||||
self.jellyfin.refresh_root_library()
|
|
||||||
|
|
||||||
def media_statistic(self) -> List[schemas.Statistic]:
|
def media_statistic(self) -> List[schemas.Statistic]:
|
||||||
"""
|
"""
|
||||||
媒体数量统计
|
媒体数量统计
|
||||||
@@ -111,13 +101,13 @@ class JellyfinModule(_ModuleBase):
|
|||||||
media_statistic.user_count = self.jellyfin.get_user_count()
|
media_statistic.user_count = self.jellyfin.get_user_count()
|
||||||
return [media_statistic]
|
return [media_statistic]
|
||||||
|
|
||||||
def mediaserver_librarys(self, server: str) -> Optional[List[schemas.MediaServerLibrary]]:
|
def mediaserver_librarys(self, server: str = None, username: str = None) -> Optional[List[schemas.MediaServerLibrary]]:
|
||||||
"""
|
"""
|
||||||
媒体库列表
|
媒体库列表
|
||||||
"""
|
"""
|
||||||
if server != "jellyfin":
|
if server and server != "jellyfin":
|
||||||
return None
|
return None
|
||||||
return self.jellyfin.get_librarys()
|
return self.jellyfin.get_librarys(username)
|
||||||
|
|
||||||
def mediaserver_items(self, server: str, library_id: str) -> Optional[Generator]:
|
def mediaserver_items(self, server: str, library_id: str) -> Optional[Generator]:
|
||||||
"""
|
"""
|
||||||
@@ -149,3 +139,29 @@ class JellyfinModule(_ModuleBase):
|
|||||||
season=season,
|
season=season,
|
||||||
episodes=episodes
|
episodes=episodes
|
||||||
) for season, episodes in seasoninfo.items()]
|
) for season, episodes in seasoninfo.items()]
|
||||||
|
|
||||||
|
def mediaserver_playing(self, count: int = 20,
|
||||||
|
server: str = None, username: str = None) -> List[schemas.MediaServerPlayItem]:
|
||||||
|
"""
|
||||||
|
获取媒体服务器正在播放信息
|
||||||
|
"""
|
||||||
|
if server and server != "jellyfin":
|
||||||
|
return []
|
||||||
|
return self.jellyfin.get_resume(num=count, username=username)
|
||||||
|
|
||||||
|
def mediaserver_play_url(self, server: str, item_id: Union[str, int]) -> Optional[str]:
|
||||||
|
"""
|
||||||
|
获取媒体库播放地址
|
||||||
|
"""
|
||||||
|
if server != "jellyfin":
|
||||||
|
return None
|
||||||
|
return self.jellyfin.get_play_url(item_id)
|
||||||
|
|
||||||
|
def mediaserver_latest(self, count: int = 20,
|
||||||
|
server: str = None, username: str = None) -> List[schemas.MediaServerPlayItem]:
|
||||||
|
"""
|
||||||
|
获取媒体服务器最新入库条目
|
||||||
|
"""
|
||||||
|
if server and server != "jellyfin":
|
||||||
|
return []
|
||||||
|
return self.jellyfin.get_latest(num=count, username=username)
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ class Jellyfin(metaclass=Singleton):
|
|||||||
self._host += "/"
|
self._host += "/"
|
||||||
if not self._host.startswith("http"):
|
if not self._host.startswith("http"):
|
||||||
self._host = "http://" + self._host
|
self._host = "http://" + self._host
|
||||||
|
self._playhost = settings.JELLYFIN_PLAY_HOST
|
||||||
|
if self._playhost:
|
||||||
|
if not self._playhost.endswith("/"):
|
||||||
|
self._playhost += "/"
|
||||||
|
if not self._playhost.startswith("http"):
|
||||||
|
self._playhost = "http://" + self._playhost
|
||||||
self._apikey = settings.JELLYFIN_API_KEY
|
self._apikey = settings.JELLYFIN_API_KEY
|
||||||
self.user = self.get_user(settings.SUPERUSER)
|
self.user = self.get_user(settings.SUPERUSER)
|
||||||
self.serverid = self.get_server_id()
|
self.serverid = self.get_server_id()
|
||||||
@@ -39,13 +45,70 @@ class Jellyfin(metaclass=Singleton):
|
|||||||
self.user = self.get_user()
|
self.user = self.get_user()
|
||||||
self.serverid = self.get_server_id()
|
self.serverid = self.get_server_id()
|
||||||
|
|
||||||
def __get_jellyfin_librarys(self) -> List[dict]:
|
def get_jellyfin_folders(self) -> List[dict]:
|
||||||
|
"""
|
||||||
|
获取Jellyfin媒体库路径列表
|
||||||
|
"""
|
||||||
|
if not self._host or not self._apikey:
|
||||||
|
return []
|
||||||
|
req_url = "%Library/SelectableMediaFolders?api_key=%s" % (self._host, self._apikey)
|
||||||
|
try:
|
||||||
|
res = RequestUtils().get_res(req_url)
|
||||||
|
if res:
|
||||||
|
return res.json()
|
||||||
|
else:
|
||||||
|
logger.error(f"Library/SelectableMediaFolders 未获取到返回数据")
|
||||||
|
return []
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"连接Library/SelectableMediaFolders 出错:" + str(e))
|
||||||
|
return []
|
||||||
|
|
||||||
|
def get_jellyfin_virtual_folders(self) -> List[dict]:
|
||||||
|
"""
|
||||||
|
获取Jellyfin媒体库所有路径列表(包含共享路径)
|
||||||
|
"""
|
||||||
|
if not self._host or not self._apikey:
|
||||||
|
return []
|
||||||
|
req_url = "%sLibrary/VirtualFolders/Query?api_key=%s" % (self._host, self._apikey)
|
||||||
|
try:
|
||||||
|
res = RequestUtils().get_res(req_url)
|
||||||
|
if res:
|
||||||
|
library_items = res.json().get("Items")
|
||||||
|
librarys = []
|
||||||
|
for library_item in library_items:
|
||||||
|
library_name = library_item.get('Name')
|
||||||
|
pathInfos = library_item.get('LibraryOptions', {}).get('PathInfos')
|
||||||
|
library_paths = []
|
||||||
|
for path in pathInfos:
|
||||||
|
if path.get('NetworkPath'):
|
||||||
|
library_paths.append(path.get('NetworkPath'))
|
||||||
|
else:
|
||||||
|
library_paths.append(path.get('Path'))
|
||||||
|
|
||||||
|
if library_name and library_paths:
|
||||||
|
librarys.append({
|
||||||
|
'Name': library_name,
|
||||||
|
'Path': library_paths
|
||||||
|
})
|
||||||
|
return librarys
|
||||||
|
else:
|
||||||
|
logger.error(f"Library/VirtualFolders/Query 未获取到返回数据")
|
||||||
|
return []
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"连接Library/VirtualFolders/Query 出错:" + str(e))
|
||||||
|
return []
|
||||||
|
|
||||||
|
def __get_jellyfin_librarys(self, username: str = None) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
获取Jellyfin媒体库的信息
|
获取Jellyfin媒体库的信息
|
||||||
"""
|
"""
|
||||||
if not self._host or not self._apikey:
|
if not self._host or not self._apikey:
|
||||||
return []
|
return []
|
||||||
req_url = f"{self._host}Users/{self.user}/Views?api_key={self._apikey}"
|
if username:
|
||||||
|
user = self.get_user(username)
|
||||||
|
else:
|
||||||
|
user = self.user
|
||||||
|
req_url = f"{self._host}Users/{user}/Views?api_key={self._apikey}"
|
||||||
try:
|
try:
|
||||||
res = RequestUtils().get_res(req_url)
|
res = RequestUtils().get_res(req_url)
|
||||||
if res:
|
if res:
|
||||||
@@ -57,14 +120,17 @@ class Jellyfin(metaclass=Singleton):
|
|||||||
logger.error(f"连接Users/Views 出错:" + str(e))
|
logger.error(f"连接Users/Views 出错:" + str(e))
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def get_librarys(self):
|
def get_librarys(self, username: str = None) -> List[schemas.MediaServerLibrary]:
|
||||||
"""
|
"""
|
||||||
获取媒体服务器所有媒体库列表
|
获取媒体服务器所有媒体库列表
|
||||||
"""
|
"""
|
||||||
if not self._host or not self._apikey:
|
if not self._host or not self._apikey:
|
||||||
return []
|
return []
|
||||||
libraries = []
|
libraries = []
|
||||||
for library in self.__get_jellyfin_librarys() or []:
|
black_list = (settings.MEDIASERVER_SYNC_BLACKLIST or '').split(",")
|
||||||
|
for library in self.__get_jellyfin_librarys(username) or []:
|
||||||
|
if library.get("Name") in black_list:
|
||||||
|
continue
|
||||||
match library.get("CollectionType"):
|
match library.get("CollectionType"):
|
||||||
case "movies":
|
case "movies":
|
||||||
library_type = MediaType.MOVIE.value
|
library_type = MediaType.MOVIE.value
|
||||||
@@ -72,13 +138,21 @@ class Jellyfin(metaclass=Singleton):
|
|||||||
library_type = MediaType.TV.value
|
library_type = MediaType.TV.value
|
||||||
case _:
|
case _:
|
||||||
continue
|
continue
|
||||||
|
image = self.__get_local_image_by_id(library.get("Id"))
|
||||||
|
link = f"{self._playhost or self._host}web/index.html#!" \
|
||||||
|
f"/movies.html?topParentId={library.get('Id')}" \
|
||||||
|
if library_type == MediaType.MOVIE.value \
|
||||||
|
else f"{self._playhost or self._host}web/index.html#!" \
|
||||||
|
f"/tv.html?topParentId={library.get('Id')}"
|
||||||
libraries.append(
|
libraries.append(
|
||||||
schemas.MediaServerLibrary(
|
schemas.MediaServerLibrary(
|
||||||
server="jellyfin",
|
server="jellyfin",
|
||||||
id=library.get("Id"),
|
id=library.get("Id"),
|
||||||
name=library.get("Name"),
|
name=library.get("Name"),
|
||||||
path=library.get("Path"),
|
path=library.get("Path"),
|
||||||
type=library_type
|
type=library_type,
|
||||||
|
image=image,
|
||||||
|
link=link
|
||||||
))
|
))
|
||||||
return libraries
|
return libraries
|
||||||
|
|
||||||
@@ -212,7 +286,7 @@ class Jellyfin(metaclass=Singleton):
|
|||||||
return None
|
return None
|
||||||
req_url = ("%sUsers/%s/Items?"
|
req_url = ("%sUsers/%s/Items?"
|
||||||
"api_key=%s&searchTerm=%s&IncludeItemTypes=Series&Limit=10&Recursive=true") % (
|
"api_key=%s&searchTerm=%s&IncludeItemTypes=Series&Limit=10&Recursive=true") % (
|
||||||
self._host, self.user, self._apikey, name)
|
self._host, self.user, self._apikey, name)
|
||||||
try:
|
try:
|
||||||
res = RequestUtils().get_res(req_url)
|
res = RequestUtils().get_res(req_url)
|
||||||
if res:
|
if res:
|
||||||
@@ -227,8 +301,8 @@ class Jellyfin(metaclass=Singleton):
|
|||||||
return None
|
return None
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def get_movies(self,
|
def get_movies(self,
|
||||||
title: str,
|
title: str,
|
||||||
year: str = None,
|
year: str = None,
|
||||||
tmdb_id: int = None) -> Optional[List[schemas.MediaServerItem]]:
|
tmdb_id: int = None) -> Optional[List[schemas.MediaServerItem]]:
|
||||||
"""
|
"""
|
||||||
@@ -242,7 +316,7 @@ class Jellyfin(metaclass=Singleton):
|
|||||||
return None
|
return None
|
||||||
req_url = ("%sUsers/%s/Items?"
|
req_url = ("%sUsers/%s/Items?"
|
||||||
"api_key=%s&searchTerm=%s&IncludeItemTypes=Movie&Limit=10&Recursive=true") % (
|
"api_key=%s&searchTerm=%s&IncludeItemTypes=Movie&Limit=10&Recursive=true") % (
|
||||||
self._host, self.user, self._apikey, title)
|
self._host, self.user, self._apikey, title)
|
||||||
try:
|
try:
|
||||||
res = RequestUtils().get_res(req_url)
|
res = RequestUtils().get_res(req_url)
|
||||||
if res:
|
if res:
|
||||||
@@ -332,7 +406,7 @@ class Jellyfin(metaclass=Singleton):
|
|||||||
if not season_episodes.get(season_index):
|
if not season_episodes.get(season_index):
|
||||||
season_episodes[season_index] = []
|
season_episodes[season_index] = []
|
||||||
season_episodes[season_index].append(episode_index)
|
season_episodes[season_index].append(episode_index)
|
||||||
return tv_info.get('Id'), season_episodes
|
return item_id, season_episodes
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"连接Shows/Id/Episodes出错:" + str(e))
|
logger.error(f"连接Shows/Id/Episodes出错:" + str(e))
|
||||||
return None, None
|
return None, None
|
||||||
@@ -466,7 +540,10 @@ class Jellyfin(metaclass=Singleton):
|
|||||||
eventItem.device_name = message.get('DeviceName')
|
eventItem.device_name = message.get('DeviceName')
|
||||||
eventItem.user_name = message.get('NotificationUsername')
|
eventItem.user_name = message.get('NotificationUsername')
|
||||||
eventItem.client = message.get('ClientName')
|
eventItem.client = message.get('ClientName')
|
||||||
if message.get("ItemType") == "Episode":
|
eventItem.media_type = message.get('ItemType')
|
||||||
|
if message.get("ItemType") == "Episode" \
|
||||||
|
or message.get("ItemType") == "Series" \
|
||||||
|
or message.get("ItemType") == "Season":
|
||||||
# 剧集
|
# 剧集
|
||||||
eventItem.item_type = "TV"
|
eventItem.item_type = "TV"
|
||||||
eventItem.season_id = message.get('SeasonNumber')
|
eventItem.season_id = message.get('SeasonNumber')
|
||||||
@@ -584,3 +661,154 @@ class Jellyfin(metaclass=Singleton):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"连接Jellyfin出错:" + str(e))
|
logger.error(f"连接Jellyfin出错:" + str(e))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_play_url(self, item_id: str) -> str:
|
||||||
|
"""
|
||||||
|
拼装媒体播放链接
|
||||||
|
:param item_id: 媒体的的ID
|
||||||
|
"""
|
||||||
|
return f"{self._playhost or self._host}web/index.html#!" \
|
||||||
|
f"/details?id={item_id}&serverId={self.serverid}"
|
||||||
|
|
||||||
|
def __get_local_image_by_id(self, item_id: str) -> str:
|
||||||
|
"""
|
||||||
|
根据ItemId从媒体服务器查询有声书图片地址
|
||||||
|
:param: item_id: 在Emby中的ID
|
||||||
|
:param: remote 是否远程使用,TG微信等客户端调用应为True
|
||||||
|
:param: inner 是否NT内部调用,为True是会使用NT中转
|
||||||
|
"""
|
||||||
|
if not self._host or not self._apikey:
|
||||||
|
return ""
|
||||||
|
return "%sItems/%s/Images/Primary" % (self._host, item_id)
|
||||||
|
|
||||||
|
def __get_backdrop_url(self, item_id: str, image_tag: str) -> str:
|
||||||
|
"""
|
||||||
|
获取Backdrop图片地址
|
||||||
|
:param: item_id: 在Emby中的ID
|
||||||
|
:param: image_tag: 图片的tag
|
||||||
|
:param: remote 是否远程使用,TG微信等客户端调用应为True
|
||||||
|
:param: inner 是否NT内部调用,为True是会使用NT中转
|
||||||
|
"""
|
||||||
|
if not self._host or not self._apikey:
|
||||||
|
return ""
|
||||||
|
if not image_tag or not item_id:
|
||||||
|
return ""
|
||||||
|
return f"{self._host}Items/{item_id}/" \
|
||||||
|
f"Images/Backdrop?tag={image_tag}&fillWidth=666&api_key={self._apikey}"
|
||||||
|
|
||||||
|
def get_resume(self, num: int = 12, username: str = None) -> Optional[List[schemas.MediaServerPlayItem]]:
|
||||||
|
"""
|
||||||
|
获得继续观看
|
||||||
|
"""
|
||||||
|
if not self._host or not self._apikey:
|
||||||
|
return None
|
||||||
|
if username:
|
||||||
|
user = self.get_user(username)
|
||||||
|
else:
|
||||||
|
user = self.user
|
||||||
|
req_url = (f"{self._host}Users/{user}/Items/Resume?"
|
||||||
|
f"Limit=100&MediaTypes=Video&api_key={self._apikey}&Fields=ProductionYear,Path")
|
||||||
|
try:
|
||||||
|
res = RequestUtils().get_res(req_url)
|
||||||
|
if res:
|
||||||
|
result = res.json().get("Items") or []
|
||||||
|
ret_resume = []
|
||||||
|
# 用户媒体库文件夹列表(排除黑名单)
|
||||||
|
library_folders = self.get_user_library_folders()
|
||||||
|
for item in result:
|
||||||
|
if len(ret_resume) == num:
|
||||||
|
break
|
||||||
|
if item.get("Type") not in ["Movie", "Episode"]:
|
||||||
|
continue
|
||||||
|
item_path = item.get("Path")
|
||||||
|
if item_path and library_folders and not any(
|
||||||
|
str(item_path).startswith(folder) for folder in library_folders):
|
||||||
|
continue
|
||||||
|
item_type = MediaType.MOVIE.value if item.get("Type") == "Movie" else MediaType.TV.value
|
||||||
|
link = self.get_play_url(item.get("Id"))
|
||||||
|
if item.get("BackdropImageTags"):
|
||||||
|
image = self.__get_backdrop_url(item_id=item.get("Id"),
|
||||||
|
image_tag=item.get("BackdropImageTags")[0])
|
||||||
|
else:
|
||||||
|
image = self.__get_local_image_by_id(item.get("Id"))
|
||||||
|
if item_type == MediaType.MOVIE.value:
|
||||||
|
title = item.get("Name")
|
||||||
|
subtitle = item.get("ProductionYear")
|
||||||
|
else:
|
||||||
|
title = f'{item.get("SeriesName")}'
|
||||||
|
subtitle = f'S{item.get("ParentIndexNumber")}:{item.get("IndexNumber")} - {item.get("Name")}'
|
||||||
|
ret_resume.append(schemas.MediaServerPlayItem(
|
||||||
|
id=item.get("Id"),
|
||||||
|
title=title,
|
||||||
|
subtitle=subtitle,
|
||||||
|
type=item_type,
|
||||||
|
image=image,
|
||||||
|
link=link,
|
||||||
|
percent=item.get("UserData", {}).get("PlayedPercentage")
|
||||||
|
))
|
||||||
|
return ret_resume
|
||||||
|
else:
|
||||||
|
logger.error(f"Users/Items/Resume 未获取到返回数据")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"连接Users/Items/Resume出错:" + str(e))
|
||||||
|
return []
|
||||||
|
|
||||||
|
def get_latest(self, num=20, username: str = None) -> Optional[List[schemas.MediaServerPlayItem]]:
|
||||||
|
"""
|
||||||
|
获得最近更新
|
||||||
|
"""
|
||||||
|
if not self._host or not self._apikey:
|
||||||
|
return None
|
||||||
|
if username:
|
||||||
|
user = self.get_user(username)
|
||||||
|
else:
|
||||||
|
user = self.user
|
||||||
|
req_url = (f"{self._host}Users/{user}/Items/Latest?"
|
||||||
|
f"Limit=100&MediaTypes=Video&api_key={self._apikey}&Fields=ProductionYear,Path")
|
||||||
|
try:
|
||||||
|
res = RequestUtils().get_res(req_url)
|
||||||
|
if res:
|
||||||
|
result = res.json() or []
|
||||||
|
ret_latest = []
|
||||||
|
# 用户媒体库文件夹列表(排除黑名单)
|
||||||
|
library_folders = self.get_user_library_folders()
|
||||||
|
for item in result:
|
||||||
|
if len(ret_latest) == num:
|
||||||
|
break
|
||||||
|
if item.get("Type") not in ["Movie", "Series"]:
|
||||||
|
continue
|
||||||
|
item_path = item.get("Path")
|
||||||
|
if item_path and library_folders and not any(
|
||||||
|
str(item_path).startswith(folder) for folder in library_folders):
|
||||||
|
continue
|
||||||
|
item_type = MediaType.MOVIE.value if item.get("Type") == "Movie" else MediaType.TV.value
|
||||||
|
link = self.get_play_url(item.get("Id"))
|
||||||
|
image = self.__get_local_image_by_id(item_id=item.get("Id"))
|
||||||
|
ret_latest.append(schemas.MediaServerPlayItem(
|
||||||
|
id=item.get("Id"),
|
||||||
|
title=item.get("Name"),
|
||||||
|
subtitle=item.get("ProductionYear"),
|
||||||
|
type=item_type,
|
||||||
|
image=image,
|
||||||
|
link=link
|
||||||
|
))
|
||||||
|
return ret_latest
|
||||||
|
else:
|
||||||
|
logger.error(f"Users/Items/Latest 未获取到返回数据")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"连接Users/Items/Latest出错:" + str(e))
|
||||||
|
return []
|
||||||
|
|
||||||
|
def get_user_library_folders(self):
|
||||||
|
"""
|
||||||
|
获取Emby媒体库文件夹列表(排除黑名单)
|
||||||
|
"""
|
||||||
|
if not self._host or not self._apikey:
|
||||||
|
return []
|
||||||
|
library_folders = []
|
||||||
|
black_list = (settings.MEDIASERVER_SYNC_BLACKLIST or '').split(",")
|
||||||
|
for library in self.get_jellyfin_virtual_folders() or []:
|
||||||
|
if library.get("Name") in black_list:
|
||||||
|
continue
|
||||||
|
library_folders += [folder for folder in library.get("Path")]
|
||||||
|
return library_folders
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
from pathlib import Path
|
|
||||||
from typing import Optional, Tuple, Union, Any, List, Generator
|
from typing import Optional, Tuple, Union, Any, List, Generator
|
||||||
|
|
||||||
from app import schemas
|
from app import schemas
|
||||||
@@ -26,7 +25,7 @@ class PlexModule(_ModuleBase):
|
|||||||
定时任务,每10分钟调用一次
|
定时任务,每10分钟调用一次
|
||||||
"""
|
"""
|
||||||
# 定时重连
|
# 定时重连
|
||||||
if not self.plex.is_inactive():
|
if self.plex.is_inactive():
|
||||||
self.plex.reconnect()
|
self.plex.reconnect()
|
||||||
|
|
||||||
def webhook_parser(self, body: Any, form: Any, args: Any) -> Optional[schemas.WebhookEventInfo]:
|
def webhook_parser(self, body: Any, form: Any, args: Any) -> Optional[schemas.WebhookEventInfo]:
|
||||||
@@ -88,24 +87,6 @@ class PlexModule(_ModuleBase):
|
|||||||
itemid=item_id
|
itemid=item_id
|
||||||
)
|
)
|
||||||
|
|
||||||
def refresh_mediaserver(self, mediainfo: MediaInfo, file_path: Path) -> None:
|
|
||||||
"""
|
|
||||||
刷新媒体库
|
|
||||||
:param mediainfo: 识别的媒体信息
|
|
||||||
:param file_path: 文件路径
|
|
||||||
:return: 成功或失败
|
|
||||||
"""
|
|
||||||
items = [
|
|
||||||
schemas.RefreshMediaItem(
|
|
||||||
title=mediainfo.title,
|
|
||||||
year=mediainfo.year,
|
|
||||||
type=mediainfo.type,
|
|
||||||
category=mediainfo.category,
|
|
||||||
target_path=file_path
|
|
||||||
)
|
|
||||||
]
|
|
||||||
self.plex.refresh_library_by_items(items)
|
|
||||||
|
|
||||||
def media_statistic(self) -> List[schemas.Statistic]:
|
def media_statistic(self) -> List[schemas.Statistic]:
|
||||||
"""
|
"""
|
||||||
媒体数量统计
|
媒体数量统计
|
||||||
@@ -114,11 +95,11 @@ class PlexModule(_ModuleBase):
|
|||||||
media_statistic.user_count = 1
|
media_statistic.user_count = 1
|
||||||
return [media_statistic]
|
return [media_statistic]
|
||||||
|
|
||||||
def mediaserver_librarys(self, server: str) -> Optional[List[schemas.MediaServerLibrary]]:
|
def mediaserver_librarys(self, server: str = None, **kwargs) -> Optional[List[schemas.MediaServerLibrary]]:
|
||||||
"""
|
"""
|
||||||
媒体库列表
|
媒体库列表
|
||||||
"""
|
"""
|
||||||
if server != "plex":
|
if server and server != "plex":
|
||||||
return None
|
return None
|
||||||
return self.plex.get_librarys()
|
return self.plex.get_librarys()
|
||||||
|
|
||||||
@@ -152,3 +133,27 @@ class PlexModule(_ModuleBase):
|
|||||||
season=season,
|
season=season,
|
||||||
episodes=episodes
|
episodes=episodes
|
||||||
) for season, episodes in seasoninfo.items()]
|
) for season, episodes in seasoninfo.items()]
|
||||||
|
|
||||||
|
def mediaserver_playing(self, count: int = 20, server: str = None, **kwargs) -> List[schemas.MediaServerPlayItem]:
|
||||||
|
"""
|
||||||
|
获取媒体服务器正在播放信息
|
||||||
|
"""
|
||||||
|
if server and server != "plex":
|
||||||
|
return []
|
||||||
|
return self.plex.get_resume(count)
|
||||||
|
|
||||||
|
def mediaserver_latest(self, count: int = 20, server: str = None, **kwargs) -> List[schemas.MediaServerPlayItem]:
|
||||||
|
"""
|
||||||
|
获取媒体服务器最新入库条目
|
||||||
|
"""
|
||||||
|
if server and server != "plex":
|
||||||
|
return []
|
||||||
|
return self.plex.get_latest(count)
|
||||||
|
|
||||||
|
def mediaserver_play_url(self, server: str, item_id: Union[str, int]) -> Optional[str]:
|
||||||
|
"""
|
||||||
|
获取媒体库播放地址
|
||||||
|
"""
|
||||||
|
if server != "plex":
|
||||||
|
return None
|
||||||
|
return self.plex.get_play_url(item_id)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
from functools import lru_cache
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Optional, Dict, Tuple, Generator, Any
|
from typing import List, Optional, Dict, Tuple, Generator, Any
|
||||||
from urllib.parse import quote_plus
|
from urllib.parse import quote_plus
|
||||||
@@ -15,6 +16,8 @@ from app.utils.singleton import Singleton
|
|||||||
|
|
||||||
class Plex(metaclass=Singleton):
|
class Plex(metaclass=Singleton):
|
||||||
|
|
||||||
|
_plex = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._host = settings.PLEX_HOST
|
self._host = settings.PLEX_HOST
|
||||||
if self._host:
|
if self._host:
|
||||||
@@ -22,6 +25,12 @@ class Plex(metaclass=Singleton):
|
|||||||
self._host += "/"
|
self._host += "/"
|
||||||
if not self._host.startswith("http"):
|
if not self._host.startswith("http"):
|
||||||
self._host = "http://" + self._host
|
self._host = "http://" + self._host
|
||||||
|
self._playhost = settings.PLEX_PLAY_HOST
|
||||||
|
if self._playhost:
|
||||||
|
if not self._playhost.endswith("/"):
|
||||||
|
self._playhost += "/"
|
||||||
|
if not self._playhost.startswith("http"):
|
||||||
|
self._playhost = "http://" + self._playhost
|
||||||
self._token = settings.PLEX_TOKEN
|
self._token = settings.PLEX_TOKEN
|
||||||
if self._host and self._token:
|
if self._host and self._token:
|
||||||
try:
|
try:
|
||||||
@@ -50,6 +59,43 @@ class Plex(metaclass=Singleton):
|
|||||||
self._plex = None
|
self._plex = None
|
||||||
logger.error(f"Plex服务器连接失败:{str(e)}")
|
logger.error(f"Plex服务器连接失败:{str(e)}")
|
||||||
|
|
||||||
|
@lru_cache(maxsize=10)
|
||||||
|
def __get_library_images(self, library_key: str, mtype: int) -> Optional[List[str]]:
|
||||||
|
"""
|
||||||
|
获取媒体服务器最近添加的媒体的图片列表
|
||||||
|
param: library_key
|
||||||
|
param: type type的含义: 1 电影 2 剧集 详见 plexapi/utils.py中SEARCHTYPES的定义
|
||||||
|
"""
|
||||||
|
if not self._plex:
|
||||||
|
return None
|
||||||
|
# 返回结果
|
||||||
|
poster_urls = {}
|
||||||
|
# 页码计数
|
||||||
|
container_start = 0
|
||||||
|
# 需要的总条数/每页的条数
|
||||||
|
total_size = 4
|
||||||
|
# 如果总数不足,接续获取下一页
|
||||||
|
while len(poster_urls) < total_size:
|
||||||
|
items = self._plex.fetchItems(f"/hubs/home/recentlyAdded?type={mtype}§ionID={library_key}",
|
||||||
|
container_size=total_size,
|
||||||
|
container_start=container_start)
|
||||||
|
for item in items:
|
||||||
|
if item.type == 'episode':
|
||||||
|
# 如果是剧集的单集,则去找上级的图片
|
||||||
|
if item.parentThumb is not None:
|
||||||
|
poster_urls[item.parentThumb] = None
|
||||||
|
else:
|
||||||
|
# 否则就用自己的图片
|
||||||
|
if item.thumb is not None:
|
||||||
|
poster_urls[item.thumb] = None
|
||||||
|
if len(poster_urls) == total_size:
|
||||||
|
break
|
||||||
|
if len(items) < total_size:
|
||||||
|
break
|
||||||
|
container_start += total_size
|
||||||
|
return [f"{self._host.rstrip('/') + url}?X-Plex-Token={self._token}" for url in
|
||||||
|
list(poster_urls.keys())[:total_size]]
|
||||||
|
|
||||||
def get_librarys(self) -> List[schemas.MediaServerLibrary]:
|
def get_librarys(self) -> List[schemas.MediaServerLibrary]:
|
||||||
"""
|
"""
|
||||||
获取媒体服务器所有媒体库列表
|
获取媒体服务器所有媒体库列表
|
||||||
@@ -62,12 +108,17 @@ class Plex(metaclass=Singleton):
|
|||||||
logger.error(f"获取媒体服务器所有媒体库列表出错:{str(err)}")
|
logger.error(f"获取媒体服务器所有媒体库列表出错:{str(err)}")
|
||||||
return []
|
return []
|
||||||
libraries = []
|
libraries = []
|
||||||
|
black_list = (settings.MEDIASERVER_SYNC_BLACKLIST or '').split(",")
|
||||||
for library in self._libraries:
|
for library in self._libraries:
|
||||||
|
if library.title in black_list:
|
||||||
|
continue
|
||||||
match library.type:
|
match library.type:
|
||||||
case "movie":
|
case "movie":
|
||||||
library_type = MediaType.MOVIE.value
|
library_type = MediaType.MOVIE.value
|
||||||
|
image_list = self.__get_library_images(library.key, 1)
|
||||||
case "show":
|
case "show":
|
||||||
library_type = MediaType.TV.value
|
library_type = MediaType.TV.value
|
||||||
|
image_list = self.__get_library_images(library.key, 2)
|
||||||
case _:
|
case _:
|
||||||
continue
|
continue
|
||||||
libraries.append(
|
libraries.append(
|
||||||
@@ -75,7 +126,10 @@ class Plex(metaclass=Singleton):
|
|||||||
id=library.key,
|
id=library.key,
|
||||||
name=library.title,
|
name=library.title,
|
||||||
path=library.locations,
|
path=library.locations,
|
||||||
type=library_type
|
type=library_type,
|
||||||
|
image_list=image_list,
|
||||||
|
link=f"{self._playhost or self._host}web/index.html#!/media/{self._plex.machineIdentifier}"
|
||||||
|
f"/com.plexapp.plugins.library?source={library.key}"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return libraries
|
return libraries
|
||||||
@@ -543,3 +597,63 @@ class Plex(metaclass=Singleton):
|
|||||||
获取plex对象,以便直接操作
|
获取plex对象,以便直接操作
|
||||||
"""
|
"""
|
||||||
return self._plex
|
return self._plex
|
||||||
|
|
||||||
|
def get_play_url(self, item_id: str) -> str:
|
||||||
|
"""
|
||||||
|
拼装媒体播放链接
|
||||||
|
:param item_id: 媒体的的ID
|
||||||
|
"""
|
||||||
|
return f'{self._playhost or self._host}web/index.html#!/server/{self._plex.machineIdentifier}/details?key={item_id}'
|
||||||
|
|
||||||
|
def get_resume(self, num: int = 12) -> Optional[List[schemas.MediaServerPlayItem]]:
|
||||||
|
"""
|
||||||
|
获取继续观看的媒体
|
||||||
|
"""
|
||||||
|
if not self._plex:
|
||||||
|
return []
|
||||||
|
items = self._plex.fetchItems('/hubs/continueWatching/items', container_start=0, container_size=num)
|
||||||
|
ret_resume = []
|
||||||
|
for item in items:
|
||||||
|
item_type = MediaType.MOVIE.value if item.TYPE == "movie" else MediaType.TV.value
|
||||||
|
if item_type == MediaType.MOVIE.value:
|
||||||
|
title = item.title
|
||||||
|
subtitle = item.year
|
||||||
|
else:
|
||||||
|
title = item.grandparentTitle
|
||||||
|
subtitle = f"S{item.parentIndex}:E{item.index} - {item.title}"
|
||||||
|
link = self.get_play_url(item.key)
|
||||||
|
image = item.artUrl
|
||||||
|
ret_resume.append(schemas.MediaServerPlayItem(
|
||||||
|
id=item.key,
|
||||||
|
title=title,
|
||||||
|
subtitle=subtitle,
|
||||||
|
type=item_type,
|
||||||
|
image=image,
|
||||||
|
link=link,
|
||||||
|
percent=item.viewOffset / item.duration * 100 if item.viewOffset and item.duration else 0
|
||||||
|
))
|
||||||
|
return ret_resume[:num]
|
||||||
|
|
||||||
|
def get_latest(self, num: int = 20) -> Optional[List[schemas.MediaServerPlayItem]]:
|
||||||
|
"""
|
||||||
|
获取最近添加媒体
|
||||||
|
"""
|
||||||
|
if not self._plex:
|
||||||
|
return None
|
||||||
|
items = self._plex.fetchItems('/library/recentlyAdded', container_start=0, container_size=num)
|
||||||
|
ret_resume = []
|
||||||
|
for item in items:
|
||||||
|
item_type = MediaType.MOVIE.value if item.TYPE == "movie" else MediaType.TV.value
|
||||||
|
link = self.get_play_url(item.key)
|
||||||
|
title = item.title if item_type == MediaType.MOVIE.value else \
|
||||||
|
"%s 第%s季" % (item.parentTitle, item.index)
|
||||||
|
image = item.posterUrl
|
||||||
|
ret_resume.append(schemas.MediaServerPlayItem(
|
||||||
|
id=item.key,
|
||||||
|
title=title,
|
||||||
|
subtitle=item.year,
|
||||||
|
type=item_type,
|
||||||
|
image=image,
|
||||||
|
link=link
|
||||||
|
))
|
||||||
|
return ret_resume[:num]
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from pathlib import Path
|
|||||||
from typing import Set, Tuple, Optional, Union, List
|
from typing import Set, Tuple, Optional, Union, List
|
||||||
|
|
||||||
from qbittorrentapi import TorrentFilesList
|
from qbittorrentapi import TorrentFilesList
|
||||||
|
from torrentool.torrent import Torrent
|
||||||
|
|
||||||
from app import schemas
|
from app import schemas
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
@@ -47,6 +48,21 @@ class QbittorrentModule(_ModuleBase):
|
|||||||
:param category: 分类
|
:param category: 分类
|
||||||
:return: 种子Hash,错误信息
|
:return: 种子Hash,错误信息
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def __get_torrent_info() -> Tuple[str, int]:
|
||||||
|
"""
|
||||||
|
获取种子名称
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
if isinstance(content, Path):
|
||||||
|
torrentinfo = Torrent.from_file(content)
|
||||||
|
else:
|
||||||
|
torrentinfo = Torrent.from_string(content)
|
||||||
|
return torrentinfo.name, torrentinfo.total_size
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"获取种子名称失败:{e}")
|
||||||
|
return "", 0
|
||||||
|
|
||||||
if not content:
|
if not content:
|
||||||
return
|
return
|
||||||
if isinstance(content, Path) and not content.exists():
|
if isinstance(content, Path) and not content.exists():
|
||||||
@@ -70,6 +86,28 @@ class QbittorrentModule(_ModuleBase):
|
|||||||
category=category
|
category=category
|
||||||
)
|
)
|
||||||
if not state:
|
if not state:
|
||||||
|
# 读取种子的名称
|
||||||
|
torrent_name, torrent_size = __get_torrent_info()
|
||||||
|
if not torrent_name:
|
||||||
|
return None, f"添加种子任务失败:无法读取种子文件"
|
||||||
|
# 查询所有下载器的种子
|
||||||
|
torrents, error = self.qbittorrent.get_torrents()
|
||||||
|
if error:
|
||||||
|
return None, "无法连接qbittorrent下载器"
|
||||||
|
if torrents:
|
||||||
|
for torrent in torrents:
|
||||||
|
# 名称与大小相等则认为是同一个种子
|
||||||
|
if torrent.get("name") == torrent_name and torrent.get("total_size") == torrent_size:
|
||||||
|
torrent_hash = torrent.get("hash")
|
||||||
|
torrent_tags = [str(tag).strip() for tag in torrent.get("tags").split(',')]
|
||||||
|
logger.warn(f"下载器中已存在该种子任务:{torrent_hash} - {torrent.get('name')}")
|
||||||
|
# 给种子打上标签
|
||||||
|
if "已整理" in torrent_tags:
|
||||||
|
self.qbittorrent.remove_torrents_tag(ids=torrent_hash, tag=['已整理'])
|
||||||
|
if settings.TORRENT_TAG and settings.TORRENT_TAG not in torrent_tags:
|
||||||
|
logger.info(f"给种子 {torrent_hash} 打上标签:{settings.TORRENT_TAG}")
|
||||||
|
self.qbittorrent.set_torrents_tag(ids=torrent_hash, tags=[settings.TORRENT_TAG])
|
||||||
|
return torrent_hash, f"下载任务已存在"
|
||||||
return None, f"添加种子任务失败:{content}"
|
return None, f"添加种子任务失败:{content}"
|
||||||
else:
|
else:
|
||||||
# 获取种子Hash
|
# 获取种子Hash
|
||||||
@@ -101,9 +139,15 @@ class QbittorrentModule(_ModuleBase):
|
|||||||
# 选择文件
|
# 选择文件
|
||||||
self.qbittorrent.set_files(torrent_hash=torrent_hash, file_ids=file_ids, priority=0)
|
self.qbittorrent.set_files(torrent_hash=torrent_hash, file_ids=file_ids, priority=0)
|
||||||
# 开始任务
|
# 开始任务
|
||||||
self.qbittorrent.start_torrents(torrent_hash)
|
if settings.QB_FORCE_RESUME:
|
||||||
|
# 强制继续
|
||||||
|
self.qbittorrent.torrents_set_force_start(torrent_hash)
|
||||||
|
else:
|
||||||
|
self.qbittorrent.start_torrents(torrent_hash)
|
||||||
return torrent_hash, f"添加下载成功,已选择集数:{sucess_epidised}"
|
return torrent_hash, f"添加下载成功,已选择集数:{sucess_epidised}"
|
||||||
else:
|
else:
|
||||||
|
if settings.QB_FORCE_RESUME:
|
||||||
|
self.qbittorrent.torrents_set_force_start(torrent_hash)
|
||||||
return torrent_hash, "添加下载成功"
|
return torrent_hash, "添加下载成功"
|
||||||
|
|
||||||
def list_torrents(self, status: TorrentStatus = None,
|
def list_torrents(self, status: TorrentStatus = None,
|
||||||
@@ -123,7 +167,7 @@ class QbittorrentModule(_ModuleBase):
|
|||||||
if content_path:
|
if content_path:
|
||||||
torrent_path = Path(content_path)
|
torrent_path = Path(content_path)
|
||||||
else:
|
else:
|
||||||
torrent_path = Path(settings.DOWNLOAD_PATH) / torrent.get('name')
|
torrent_path = settings.SAVE_PATH / torrent.get('name')
|
||||||
ret_torrents.append(TransferTorrent(
|
ret_torrents.append(TransferTorrent(
|
||||||
title=torrent.get('name'),
|
title=torrent.get('name'),
|
||||||
path=torrent_path,
|
path=torrent_path,
|
||||||
@@ -142,7 +186,7 @@ class QbittorrentModule(_ModuleBase):
|
|||||||
if content_path:
|
if content_path:
|
||||||
torrent_path = Path(content_path)
|
torrent_path = Path(content_path)
|
||||||
else:
|
else:
|
||||||
torrent_path = Path(settings.DOWNLOAD_PATH) / torrent.get('name')
|
torrent_path = settings.SAVE_PATH / torrent.get('name')
|
||||||
ret_torrents.append(TransferTorrent(
|
ret_torrents.append(TransferTorrent(
|
||||||
title=torrent.get('name'),
|
title=torrent.get('name'),
|
||||||
path=torrent_path,
|
path=torrent_path,
|
||||||
@@ -162,9 +206,12 @@ class QbittorrentModule(_ModuleBase):
|
|||||||
season_episode=meta.season_episode,
|
season_episode=meta.season_episode,
|
||||||
progress=torrent.get('progress') * 100,
|
progress=torrent.get('progress') * 100,
|
||||||
size=torrent.get('total_size'),
|
size=torrent.get('total_size'),
|
||||||
state="paused" if torrent.get('state') == "paused" else "downloading",
|
state="paused" if torrent.get('state') in ("paused", "pausedDL") else "downloading",
|
||||||
dlspeed=StringUtils.str_filesize(torrent.get('dlspeed')),
|
dlspeed=StringUtils.str_filesize(torrent.get('dlspeed')),
|
||||||
upspeed=StringUtils.str_filesize(torrent.get('upspeed')),
|
upspeed=StringUtils.str_filesize(torrent.get('upspeed')),
|
||||||
|
left_time=StringUtils.str_secends(
|
||||||
|
(torrent.get('total_size') - torrent.get('completed')) / torrent.get('dlspeed')) if torrent.get(
|
||||||
|
'dlspeed') > 0 else ''
|
||||||
))
|
))
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -16,14 +16,20 @@ class Qbittorrent(metaclass=Singleton):
|
|||||||
_host: str = None
|
_host: str = None
|
||||||
_port: int = None
|
_port: int = None
|
||||||
_username: str = None
|
_username: str = None
|
||||||
_passowrd: str = None
|
_password: str = None
|
||||||
|
|
||||||
qbc: Client = None
|
qbc: Client = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, host: str = None, port: int = None, username: str = None, password: str = None):
|
||||||
self._host, self._port = StringUtils.get_domain_address(address=settings.QB_HOST, prefix=True)
|
"""
|
||||||
self._username = settings.QB_USER
|
若不设置参数,则创建配置文件设置的下载器
|
||||||
self._password = settings.QB_PASSWORD
|
"""
|
||||||
|
if host and port:
|
||||||
|
self._host, self._port = host, port
|
||||||
|
else:
|
||||||
|
self._host, self._port = StringUtils.get_domain_address(address=settings.QB_HOST, prefix=True)
|
||||||
|
self._username = username if username else settings.QB_USER
|
||||||
|
self._password = password if password else settings.QB_PASSWORD
|
||||||
if self._host and self._port:
|
if self._host and self._port:
|
||||||
self.qbc = self.__login_qbittorrent()
|
self.qbc = self.__login_qbittorrent()
|
||||||
|
|
||||||
@@ -243,7 +249,7 @@ class Qbittorrent(metaclass=Singleton):
|
|||||||
is_paused=is_paused,
|
is_paused=is_paused,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
use_auto_torrent_management=is_auto,
|
use_auto_torrent_management=is_auto,
|
||||||
is_sequential_download=True,
|
is_sequential_download=settings.QB_SEQUENTIAL,
|
||||||
cookie=cookie,
|
cookie=cookie,
|
||||||
category=category,
|
category=category,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
@@ -352,26 +358,28 @@ class Qbittorrent(metaclass=Singleton):
|
|||||||
logger.error(f"设置速度限制出错:{str(err)}")
|
logger.error(f"设置速度限制出错:{str(err)}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def recheck_torrents(self, ids: Union[str, list]):
|
def recheck_torrents(self, ids: Union[str, list]) -> bool:
|
||||||
"""
|
"""
|
||||||
重新校验种子
|
重新校验种子
|
||||||
"""
|
"""
|
||||||
if not self.qbc:
|
if not self.qbc:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
return self.qbc.torrents_recheck(torrent_hashes=ids)
|
self.qbc.torrents_recheck(torrent_hashes=ids)
|
||||||
|
return True
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.error(f"重新校验种子出错:{str(err)}")
|
logger.error(f"重新校验种子出错:{str(err)}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def add_trackers(self, ids: Union[str, list], trackers: list):
|
def update_tracker(self, hash_string: str, tracker_list: list) -> bool:
|
||||||
"""
|
"""
|
||||||
添加tracker
|
添加tracker
|
||||||
"""
|
"""
|
||||||
if not self.qbc:
|
if not self.qbc:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
return self.qbc.torrents_add_trackers(torrent_hashes=ids, urls=trackers)
|
self.qbc.torrents_add_trackers(torrent_hash=hash_string, urls=tracker_list)
|
||||||
|
return True
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.error(f"添加tracker出错:{str(err)}")
|
logger.error(f"修改tracker出错:{str(err)}")
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from app.core.config import settings
|
|||||||
from app.core.context import MediaInfo, Context
|
from app.core.context import MediaInfo, Context
|
||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
|
from app.utils.common import retry
|
||||||
from app.utils.http import RequestUtils
|
from app.utils.http import RequestUtils
|
||||||
from app.utils.singleton import Singleton
|
from app.utils.singleton import Singleton
|
||||||
from app.utils.string import StringUtils
|
from app.utils.string import StringUtils
|
||||||
@@ -174,6 +175,7 @@ class Telegram(metaclass=Singleton):
|
|||||||
logger.error(f"发送消息失败:{msg_e}")
|
logger.error(f"发送消息失败:{msg_e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@retry(Exception, logger=logger)
|
||||||
def __send_request(self, userid: str = None, image="", caption="") -> bool:
|
def __send_request(self, userid: str = None, image="", caption="") -> bool:
|
||||||
"""
|
"""
|
||||||
向Telegram发送报文
|
向Telegram发送报文
|
||||||
@@ -181,7 +183,9 @@ class Telegram(metaclass=Singleton):
|
|||||||
|
|
||||||
if image:
|
if image:
|
||||||
req = RequestUtils(proxies=settings.PROXY).get_res(image)
|
req = RequestUtils(proxies=settings.PROXY).get_res(image)
|
||||||
if req and req.content:
|
if req is None:
|
||||||
|
raise Exception("获取图片失败")
|
||||||
|
if req.content:
|
||||||
image_file = Path(settings.TEMP_PATH) / Path(image).name
|
image_file = Path(settings.TEMP_PATH) / Path(image).name
|
||||||
image_file.write_bytes(req.content)
|
image_file.write_bytes(req.content)
|
||||||
photo = InputFile(image_file)
|
photo = InputFile(image_file)
|
||||||
@@ -189,12 +193,23 @@ class Telegram(metaclass=Singleton):
|
|||||||
photo=photo,
|
photo=photo,
|
||||||
caption=caption,
|
caption=caption,
|
||||||
parse_mode="Markdown")
|
parse_mode="Markdown")
|
||||||
|
if ret is None:
|
||||||
|
raise Exception("发送图片消息失败")
|
||||||
if ret:
|
if ret:
|
||||||
return True
|
return True
|
||||||
ret = self._bot.send_message(chat_id=userid or self._telegram_chat_id,
|
# 按4096分段循环发送消息
|
||||||
text=caption,
|
ret = None
|
||||||
parse_mode="Markdown")
|
if len(caption) > 4095:
|
||||||
|
for i in range(0, len(caption), 4095):
|
||||||
|
ret = self._bot.send_message(chat_id=userid or self._telegram_chat_id,
|
||||||
|
text=caption[i:i + 4095],
|
||||||
|
parse_mode="Markdown")
|
||||||
|
else:
|
||||||
|
ret = self._bot.send_message(chat_id=userid or self._telegram_chat_id,
|
||||||
|
text=caption,
|
||||||
|
parse_mode="Markdown")
|
||||||
|
if ret is None:
|
||||||
|
raise Exception("发送文本消息失败")
|
||||||
return True if ret else False
|
return True if ret else False
|
||||||
|
|
||||||
def register_commands(self, commands: Dict[str, dict]):
|
def register_commands(self, commands: Dict[str, dict]):
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
|
|
||||||
def recognize_media(self, meta: MetaBase = None,
|
def recognize_media(self, meta: MetaBase = None,
|
||||||
mtype: MediaType = None,
|
mtype: MediaType = None,
|
||||||
tmdbid: int = None) -> Optional[MediaInfo]:
|
tmdbid: int = None,
|
||||||
|
**kwargs) -> Optional[MediaInfo]:
|
||||||
"""
|
"""
|
||||||
识别媒体信息
|
识别媒体信息
|
||||||
:param meta: 识别的元数据
|
:param meta: 识别的元数据
|
||||||
@@ -51,6 +52,9 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
:param tmdbid: tmdbid
|
:param tmdbid: tmdbid
|
||||||
:return: 识别的媒体信息,包括剧集信息
|
:return: 识别的媒体信息,包括剧集信息
|
||||||
"""
|
"""
|
||||||
|
if settings.RECOGNIZE_SOURCE != "themoviedb":
|
||||||
|
return None
|
||||||
|
|
||||||
if not meta:
|
if not meta:
|
||||||
cache_info = {}
|
cache_info = {}
|
||||||
else:
|
else:
|
||||||
@@ -112,11 +116,11 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
else:
|
else:
|
||||||
# 使用缓存信息
|
# 使用缓存信息
|
||||||
if cache_info.get("title"):
|
if cache_info.get("title"):
|
||||||
logger.info(f"{meta.name} 使用识别缓存:{cache_info.get('title')}")
|
logger.info(f"{meta.name} 使用TMDB识别缓存:{cache_info.get('title')}")
|
||||||
info = self.tmdb.get_info(mtype=cache_info.get("type"),
|
info = self.tmdb.get_info(mtype=cache_info.get("type"),
|
||||||
tmdbid=cache_info.get("id"))
|
tmdbid=cache_info.get("id"))
|
||||||
else:
|
else:
|
||||||
logger.info(f"{meta.name} 使用识别缓存:无法识别")
|
logger.info(f"{meta.name} 使用TMDB识别缓存:无法识别")
|
||||||
info = None
|
info = None
|
||||||
|
|
||||||
if info:
|
if info:
|
||||||
@@ -129,11 +133,11 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
mediainfo = MediaInfo(tmdb_info=info)
|
mediainfo = MediaInfo(tmdb_info=info)
|
||||||
mediainfo.set_category(cat)
|
mediainfo.set_category(cat)
|
||||||
if meta:
|
if meta:
|
||||||
logger.info(f"{meta.name} 识别结果:{mediainfo.type.value} "
|
logger.info(f"{meta.name} TMDB识别结果:{mediainfo.type.value} "
|
||||||
f"{mediainfo.title_year} "
|
f"{mediainfo.title_year} "
|
||||||
f"{mediainfo.tmdb_id}")
|
f"{mediainfo.tmdb_id}")
|
||||||
else:
|
else:
|
||||||
logger.info(f"{tmdbid} 识别结果:{mediainfo.type.value} "
|
logger.info(f"{tmdbid} TMDB识别结果:{mediainfo.type.value} "
|
||||||
f"{mediainfo.title_year}")
|
f"{mediainfo.title_year}")
|
||||||
|
|
||||||
# 补充剧集年份
|
# 补充剧集年份
|
||||||
@@ -143,10 +147,31 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
mediainfo.season_years = episode_years
|
mediainfo.season_years = episode_years
|
||||||
return mediainfo
|
return mediainfo
|
||||||
else:
|
else:
|
||||||
logger.info(f"{meta.name if meta else tmdbid} 未匹配到媒体信息")
|
logger.info(f"{meta.name if meta else tmdbid} 未匹配到TMDB媒体信息")
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def match_tmdbinfo(self, name: str, mtype: MediaType = None,
|
||||||
|
year: str = None, season: int = None) -> dict:
|
||||||
|
"""
|
||||||
|
搜索和匹配TMDB信息
|
||||||
|
:param name: 名称
|
||||||
|
:param mtype: 类型
|
||||||
|
:param year: 年份
|
||||||
|
:param season: 季号
|
||||||
|
"""
|
||||||
|
# 搜索
|
||||||
|
logger.info(f"开始使用 名称:{name}、年份:{year} 匹配TMDB信息 ...")
|
||||||
|
info = self.tmdb.match(name=name,
|
||||||
|
year=year,
|
||||||
|
mtype=mtype,
|
||||||
|
season_year=year,
|
||||||
|
season_number=season)
|
||||||
|
if info and not info.get("genres"):
|
||||||
|
info = self.tmdb.get_info(mtype=info.get("media_type"),
|
||||||
|
tmdbid=info.get("id"))
|
||||||
|
return info
|
||||||
|
|
||||||
def tmdb_info(self, tmdbid: int, mtype: MediaType) -> Optional[dict]:
|
def tmdb_info(self, tmdbid: int, mtype: MediaType) -> Optional[dict]:
|
||||||
"""
|
"""
|
||||||
获取TMDB信息
|
获取TMDB信息
|
||||||
@@ -163,7 +188,7 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
:reutrn: 媒体信息列表
|
:reutrn: 媒体信息列表
|
||||||
"""
|
"""
|
||||||
# 未启用时返回None
|
# 未启用时返回None
|
||||||
if settings.SEARCH_SOURCE != "themoviedb":
|
if settings.RECOGNIZE_SOURCE != "themoviedb":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not meta.name:
|
if not meta.name:
|
||||||
@@ -187,12 +212,15 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
|
|
||||||
return [MediaInfo(tmdb_info=info) for info in results]
|
return [MediaInfo(tmdb_info=info) for info in results]
|
||||||
|
|
||||||
def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str) -> None:
|
def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str,
|
||||||
|
force_nfo: bool = False, force_img: bool = False) -> None:
|
||||||
"""
|
"""
|
||||||
刮削元数据
|
刮削元数据
|
||||||
:param path: 媒体文件路径
|
:param path: 媒体文件路径
|
||||||
:param mediainfo: 识别的媒体信息
|
:param mediainfo: 识别的媒体信息
|
||||||
:param transfer_type: 转移类型
|
:param transfer_type: 转移类型
|
||||||
|
:param force_nfo: 强制刮削nfo
|
||||||
|
:param force_img: 强制刮削图片
|
||||||
:return: 成功或失败
|
:return: 成功或失败
|
||||||
"""
|
"""
|
||||||
if settings.SCRAP_SOURCE != "themoviedb":
|
if settings.SCRAP_SOURCE != "themoviedb":
|
||||||
@@ -204,13 +232,17 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
scrape_path = path / path.name
|
scrape_path = path / path.name
|
||||||
self.scraper.gen_scraper_files(mediainfo=mediainfo,
|
self.scraper.gen_scraper_files(mediainfo=mediainfo,
|
||||||
file_path=scrape_path,
|
file_path=scrape_path,
|
||||||
transfer_type=transfer_type)
|
transfer_type=transfer_type,
|
||||||
|
force_nfo=force_nfo,
|
||||||
|
force_img=force_img)
|
||||||
elif path.is_file():
|
elif path.is_file():
|
||||||
# 单个文件
|
# 单个文件
|
||||||
logger.info(f"开始刮削媒体库文件:{path} ...")
|
logger.info(f"开始刮削媒体库文件:{path} ...")
|
||||||
self.scraper.gen_scraper_files(mediainfo=mediainfo,
|
self.scraper.gen_scraper_files(mediainfo=mediainfo,
|
||||||
file_path=path,
|
file_path=path,
|
||||||
transfer_type=transfer_type)
|
transfer_type=transfer_type,
|
||||||
|
force_nfo=force_nfo,
|
||||||
|
force_img=force_img)
|
||||||
else:
|
else:
|
||||||
# 目录下的所有文件
|
# 目录下的所有文件
|
||||||
logger.info(f"开始刮削目录:{path} ...")
|
logger.info(f"开始刮削目录:{path} ...")
|
||||||
@@ -219,7 +251,9 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
continue
|
continue
|
||||||
self.scraper.gen_scraper_files(mediainfo=mediainfo,
|
self.scraper.gen_scraper_files(mediainfo=mediainfo,
|
||||||
file_path=file,
|
file_path=file,
|
||||||
transfer_type=transfer_type)
|
transfer_type=transfer_type,
|
||||||
|
force_nfo=force_nfo,
|
||||||
|
force_img=force_img)
|
||||||
logger.info(f"{path} 刮削完成")
|
logger.info(f"{path} 刮削完成")
|
||||||
|
|
||||||
def tmdb_discover(self, mtype: MediaType, sort_by: str, with_genres: str, with_original_language: str,
|
def tmdb_discover(self, mtype: MediaType, sort_by: str, with_genres: str, with_original_language: str,
|
||||||
@@ -287,6 +321,8 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
:param mediainfo: 识别的媒体信息
|
:param mediainfo: 识别的媒体信息
|
||||||
:return: 更新后的媒体信息
|
:return: 更新后的媒体信息
|
||||||
"""
|
"""
|
||||||
|
if settings.RECOGNIZE_SOURCE != "themoviedb":
|
||||||
|
return None
|
||||||
if not mediainfo.tmdb_id:
|
if not mediainfo.tmdb_id:
|
||||||
return mediainfo
|
return mediainfo
|
||||||
if mediainfo.logo_path \
|
if mediainfo.logo_path \
|
||||||
@@ -357,35 +393,35 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
return f"https://{settings.TMDB_IMAGE_DOMAIN}/t/p/{image_prefix}{image_path}"
|
return f"https://{settings.TMDB_IMAGE_DOMAIN}/t/p/{image_prefix}{image_path}"
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def movie_similar(self, tmdbid: int) -> List[dict]:
|
def tmdb_movie_similar(self, tmdbid: int) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
根据TMDBID查询类似电影
|
根据TMDBID查询类似电影
|
||||||
:param tmdbid: TMDBID
|
:param tmdbid: TMDBID
|
||||||
"""
|
"""
|
||||||
return self.tmdb.get_movie_similar(tmdbid=tmdbid)
|
return self.tmdb.get_movie_similar(tmdbid=tmdbid)
|
||||||
|
|
||||||
def tv_similar(self, tmdbid: int) -> List[dict]:
|
def tmdb_tv_similar(self, tmdbid: int) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
根据TMDBID查询类似电视剧
|
根据TMDBID查询类似电视剧
|
||||||
:param tmdbid: TMDBID
|
:param tmdbid: TMDBID
|
||||||
"""
|
"""
|
||||||
return self.tmdb.get_tv_similar(tmdbid=tmdbid)
|
return self.tmdb.get_tv_similar(tmdbid=tmdbid)
|
||||||
|
|
||||||
def movie_recommend(self, tmdbid: int) -> List[dict]:
|
def tmdb_movie_recommend(self, tmdbid: int) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
根据TMDBID查询推荐电影
|
根据TMDBID查询推荐电影
|
||||||
:param tmdbid: TMDBID
|
:param tmdbid: TMDBID
|
||||||
"""
|
"""
|
||||||
return self.tmdb.get_movie_recommend(tmdbid=tmdbid)
|
return self.tmdb.get_movie_recommend(tmdbid=tmdbid)
|
||||||
|
|
||||||
def tv_recommend(self, tmdbid: int) -> List[dict]:
|
def tmdb_tv_recommend(self, tmdbid: int) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
根据TMDBID查询推荐电视剧
|
根据TMDBID查询推荐电视剧
|
||||||
:param tmdbid: TMDBID
|
:param tmdbid: TMDBID
|
||||||
"""
|
"""
|
||||||
return self.tmdb.get_tv_recommend(tmdbid=tmdbid)
|
return self.tmdb.get_tv_recommend(tmdbid=tmdbid)
|
||||||
|
|
||||||
def movie_credits(self, tmdbid: int, page: int = 1) -> List[dict]:
|
def tmdb_movie_credits(self, tmdbid: int, page: int = 1) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
根据TMDBID查询电影演职员表
|
根据TMDBID查询电影演职员表
|
||||||
:param tmdbid: TMDBID
|
:param tmdbid: TMDBID
|
||||||
@@ -393,7 +429,7 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
"""
|
"""
|
||||||
return self.tmdb.get_movie_credits(tmdbid=tmdbid, page=page)
|
return self.tmdb.get_movie_credits(tmdbid=tmdbid, page=page)
|
||||||
|
|
||||||
def tv_credits(self, tmdbid: int, page: int = 1) -> List[dict]:
|
def tmdb_tv_credits(self, tmdbid: int, page: int = 1) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
根据TMDBID查询电视剧演职员表
|
根据TMDBID查询电视剧演职员表
|
||||||
:param tmdbid: TMDBID
|
:param tmdbid: TMDBID
|
||||||
@@ -401,14 +437,14 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
"""
|
"""
|
||||||
return self.tmdb.get_tv_credits(tmdbid=tmdbid, page=page)
|
return self.tmdb.get_tv_credits(tmdbid=tmdbid, page=page)
|
||||||
|
|
||||||
def person_detail(self, person_id: int) -> dict:
|
def tmdb_person_detail(self, person_id: int) -> dict:
|
||||||
"""
|
"""
|
||||||
根据TMDBID查询人物详情
|
根据TMDBID查询人物详情
|
||||||
:param person_id: 人物ID
|
:param person_id: 人物ID
|
||||||
"""
|
"""
|
||||||
return self.tmdb.get_person_detail(person_id=person_id)
|
return self.tmdb.get_person_detail(person_id=person_id)
|
||||||
|
|
||||||
def person_credits(self, person_id: int, page: int = 1) -> List[dict]:
|
def tmdb_person_credits(self, person_id: int, page: int = 1) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
根据TMDBID查询人物参演作品
|
根据TMDBID查询人物参演作品
|
||||||
:param person_id: 人物ID
|
:param person_id: 人物ID
|
||||||
@@ -420,5 +456,7 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
"""
|
"""
|
||||||
清除缓存
|
清除缓存
|
||||||
"""
|
"""
|
||||||
|
logger.info("开始清除TMDB缓存 ...")
|
||||||
self.tmdb.clear_cache()
|
self.tmdb.clear_cache()
|
||||||
self.cache.clear()
|
self.cache.clear()
|
||||||
|
logger.info("TMDB缓存清除完成")
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ class CategoryHelper(metaclass=Singleton):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._category_path: Path = settings.CONFIG_PATH / "category.yaml"
|
self._category_path: Path = settings.CONFIG_PATH / "category.yaml"
|
||||||
|
self.init()
|
||||||
|
|
||||||
|
def init(self):
|
||||||
|
"""
|
||||||
|
初始化
|
||||||
|
"""
|
||||||
# 二级分类策略关闭
|
# 二级分类策略关闭
|
||||||
if not settings.LIBRARY_CATEGORY:
|
if not settings.LIBRARY_CATEGORY:
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -19,19 +19,26 @@ from app.utils.system import SystemUtils
|
|||||||
class TmdbScraper:
|
class TmdbScraper:
|
||||||
tmdb = None
|
tmdb = None
|
||||||
_transfer_type = settings.TRANSFER_TYPE
|
_transfer_type = settings.TRANSFER_TYPE
|
||||||
|
_force_nfo = False
|
||||||
|
_force_img = False
|
||||||
|
|
||||||
def __init__(self, tmdb):
|
def __init__(self, tmdb):
|
||||||
self.tmdb = tmdb
|
self.tmdb = tmdb
|
||||||
|
|
||||||
def gen_scraper_files(self, mediainfo: MediaInfo, file_path: Path, transfer_type: str):
|
def gen_scraper_files(self, mediainfo: MediaInfo, file_path: Path, transfer_type: str,
|
||||||
|
force_nfo: bool = False, force_img: bool = False):
|
||||||
"""
|
"""
|
||||||
生成刮削文件,包括NFO和图片,传入路径为文件路径
|
生成刮削文件,包括NFO和图片,传入路径为文件路径
|
||||||
:param mediainfo: 媒体信息
|
:param mediainfo: 媒体信息
|
||||||
:param file_path: 文件路径或者目录路径
|
:param file_path: 文件路径或者目录路径
|
||||||
:param transfer_type: 传输类型
|
:param transfer_type: 传输类型
|
||||||
|
:param force_nfo: 是否强制生成NFO
|
||||||
|
:param force_img: 是否强制生成图片
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self._transfer_type = transfer_type
|
self._transfer_type = transfer_type
|
||||||
|
self._force_nfo = force_nfo
|
||||||
|
self._force_img = force_img
|
||||||
|
|
||||||
def __get_episode_detail(_seasoninfo: dict, _episode: int):
|
def __get_episode_detail(_seasoninfo: dict, _episode: int):
|
||||||
"""
|
"""
|
||||||
@@ -46,8 +53,8 @@ class TmdbScraper:
|
|||||||
# 电影,路径为文件名 名称/名称.xxx 或者蓝光原盘目录 名称/名称
|
# 电影,路径为文件名 名称/名称.xxx 或者蓝光原盘目录 名称/名称
|
||||||
if mediainfo.type == MediaType.MOVIE:
|
if mediainfo.type == MediaType.MOVIE:
|
||||||
# 不已存在时才处理
|
# 不已存在时才处理
|
||||||
if not file_path.with_name("movie.nfo").exists() \
|
if self._force_nfo or (not file_path.with_name("movie.nfo").exists()
|
||||||
and not file_path.with_suffix(".nfo").exists():
|
and not file_path.with_suffix(".nfo").exists()):
|
||||||
# 生成电影描述文件
|
# 生成电影描述文件
|
||||||
self.__gen_movie_nfo_file(mediainfo=mediainfo,
|
self.__gen_movie_nfo_file(mediainfo=mediainfo,
|
||||||
file_path=file_path)
|
file_path=file_path)
|
||||||
@@ -59,33 +66,37 @@ class TmdbScraper:
|
|||||||
and isinstance(attr_value, str) \
|
and isinstance(attr_value, str) \
|
||||||
and attr_value.startswith("http"):
|
and attr_value.startswith("http"):
|
||||||
image_name = attr_name.replace("_path", "") + Path(attr_value).suffix
|
image_name = attr_name.replace("_path", "") + Path(attr_value).suffix
|
||||||
self.__save_image(url=attr_value,
|
image_path = file_path.with_name(image_name)
|
||||||
file_path=file_path.with_name(image_name))
|
if self._force_img or not image_path.exists():
|
||||||
|
self.__save_image(url=attr_value,
|
||||||
|
file_path=image_path)
|
||||||
# 电视剧,路径为每一季的文件名 名称/Season xx/名称 SxxExx.xxx
|
# 电视剧,路径为每一季的文件名 名称/Season xx/名称 SxxExx.xxx
|
||||||
else:
|
else:
|
||||||
# 识别
|
# 识别
|
||||||
meta = MetaInfo(file_path.stem)
|
meta = MetaInfo(file_path.stem)
|
||||||
# 根目录不存在时才处理
|
# 根目录不存在时才处理
|
||||||
if not file_path.parent.with_name("tvshow.nfo").exists():
|
if self._force_nfo or not file_path.parent.with_name("tvshow.nfo").exists():
|
||||||
# 根目录描述文件
|
# 根目录描述文件
|
||||||
self.__gen_tv_nfo_file(mediainfo=mediainfo,
|
self.__gen_tv_nfo_file(mediainfo=mediainfo,
|
||||||
dir_path=file_path.parents[1])
|
dir_path=file_path.parents[1])
|
||||||
# 生成根目录图片
|
# 生成根目录图片
|
||||||
for attr_name, attr_value in vars(mediainfo).items():
|
for attr_name, attr_value in vars(mediainfo).items():
|
||||||
if attr_value \
|
if attr_name \
|
||||||
and attr_name.endswith("_path") \
|
and attr_name.endswith("_path") \
|
||||||
and not attr_name.startswith("season") \
|
and not attr_name.startswith("season") \
|
||||||
and attr_value \
|
and attr_value \
|
||||||
and isinstance(attr_value, str) \
|
and isinstance(attr_value, str) \
|
||||||
and attr_value.startswith("http"):
|
and attr_value.startswith("http"):
|
||||||
image_name = attr_name.replace("_path", "") + Path(attr_value).suffix
|
image_name = attr_name.replace("_path", "") + Path(attr_value).suffix
|
||||||
self.__save_image(url=attr_value,
|
image_path = file_path.parent.with_name(image_name)
|
||||||
file_path=file_path.parent.with_name(image_name))
|
if self._force_img or not image_path.exists():
|
||||||
|
self.__save_image(url=attr_value,
|
||||||
|
file_path=image_path)
|
||||||
# 查询季信息
|
# 查询季信息
|
||||||
seasoninfo = self.tmdb.get_tv_season_detail(mediainfo.tmdb_id, meta.begin_season)
|
seasoninfo = self.tmdb.get_tv_season_detail(mediainfo.tmdb_id, meta.begin_season)
|
||||||
if seasoninfo:
|
if seasoninfo:
|
||||||
# 季目录NFO
|
# 季目录NFO
|
||||||
if not file_path.with_name("season.nfo").exists():
|
if self._force_nfo or not file_path.with_name("season.nfo").exists():
|
||||||
self.__gen_tv_season_nfo_file(seasoninfo=seasoninfo,
|
self.__gen_tv_season_nfo_file(seasoninfo=seasoninfo,
|
||||||
season=meta.begin_season,
|
season=meta.begin_season,
|
||||||
season_path=file_path.parent)
|
season_path=file_path.parent)
|
||||||
@@ -96,7 +107,9 @@ class TmdbScraper:
|
|||||||
ext = Path(seasoninfo.get('poster_path')).suffix
|
ext = Path(seasoninfo.get('poster_path')).suffix
|
||||||
# URL
|
# URL
|
||||||
url = f"https://{settings.TMDB_IMAGE_DOMAIN}/t/p/original{seasoninfo.get('poster_path')}"
|
url = f"https://{settings.TMDB_IMAGE_DOMAIN}/t/p/original{seasoninfo.get('poster_path')}"
|
||||||
self.__save_image(url, file_path.parent.with_name(f"season{sea_seq}-poster{ext}"))
|
image_path = file_path.parent.with_name(f"season{sea_seq}-poster{ext}")
|
||||||
|
if self._force_img or not image_path.exists():
|
||||||
|
self.__save_image(url=url, file_path=image_path)
|
||||||
# 季的其它图片
|
# 季的其它图片
|
||||||
for attr_name, attr_value in vars(mediainfo).items():
|
for attr_name, attr_value in vars(mediainfo).items():
|
||||||
if attr_value \
|
if attr_value \
|
||||||
@@ -106,13 +119,15 @@ class TmdbScraper:
|
|||||||
and isinstance(attr_value, str) \
|
and isinstance(attr_value, str) \
|
||||||
and attr_value.startswith("http"):
|
and attr_value.startswith("http"):
|
||||||
image_name = attr_name.replace("_path", "") + Path(attr_value).suffix
|
image_name = attr_name.replace("_path", "") + Path(attr_value).suffix
|
||||||
self.__save_image(url=attr_value,
|
image_path = file_path.parent.with_name(image_name)
|
||||||
file_path=file_path.parent.with_name(image_name))
|
if self._force_img or not image_path.exists():
|
||||||
|
self.__save_image(url=attr_value,
|
||||||
|
file_path=image_path)
|
||||||
# 查询集详情
|
# 查询集详情
|
||||||
episodeinfo = __get_episode_detail(seasoninfo, meta.begin_episode)
|
episodeinfo = __get_episode_detail(seasoninfo, meta.begin_episode)
|
||||||
if episodeinfo:
|
if episodeinfo:
|
||||||
# 集NFO
|
# 集NFO
|
||||||
if not file_path.with_suffix(".nfo").exists():
|
if self._force_nfo or not file_path.with_suffix(".nfo").exists():
|
||||||
self.__gen_tv_episode_nfo_file(episodeinfo=episodeinfo,
|
self.__gen_tv_episode_nfo_file(episodeinfo=episodeinfo,
|
||||||
tmdbid=mediainfo.tmdb_id,
|
tmdbid=mediainfo.tmdb_id,
|
||||||
season=meta.begin_season,
|
season=meta.begin_season,
|
||||||
@@ -120,10 +135,12 @@ class TmdbScraper:
|
|||||||
file_path=file_path)
|
file_path=file_path)
|
||||||
# 集的图片
|
# 集的图片
|
||||||
episode_image = episodeinfo.get("still_path")
|
episode_image = episodeinfo.get("still_path")
|
||||||
if episode_image:
|
image_path = file_path.with_name(file_path.stem + "-thumb.jpg").with_suffix(
|
||||||
|
Path(episode_image).suffix)
|
||||||
|
if episode_image and (self._force_img or not image_path.exists()):
|
||||||
self.__save_image(
|
self.__save_image(
|
||||||
f"https://{settings.TMDB_IMAGE_DOMAIN}/t/p/original{episode_image}",
|
f"https://{settings.TMDB_IMAGE_DOMAIN}/t/p/original{episode_image}",
|
||||||
file_path.with_suffix(Path(episode_image).suffix))
|
image_path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"{file_path} 刮削失败:{str(e)}")
|
logger.error(f"{file_path} 刮削失败:{str(e)}")
|
||||||
|
|
||||||
@@ -339,8 +356,6 @@ class TmdbScraper:
|
|||||||
"""
|
"""
|
||||||
下载图片并保存
|
下载图片并保存
|
||||||
"""
|
"""
|
||||||
if file_path.exists():
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
logger.info(f"正在下载{file_path.stem}图片:{url} ...")
|
logger.info(f"正在下载{file_path.stem}图片:{url} ...")
|
||||||
r = RequestUtils().get_res(url=url, raise_exception=True)
|
r = RequestUtils().get_res(url=url, raise_exception=True)
|
||||||
@@ -361,8 +376,6 @@ class TmdbScraper:
|
|||||||
"""
|
"""
|
||||||
保存NFO
|
保存NFO
|
||||||
"""
|
"""
|
||||||
if file_path.exists():
|
|
||||||
return
|
|
||||||
xml_str = doc.toprettyxml(indent=" ", encoding="utf-8")
|
xml_str = doc.toprettyxml(indent=" ", encoding="utf-8")
|
||||||
if self._transfer_type in ['rclone_move', 'rclone_copy']:
|
if self._transfer_type in ['rclone_move', 'rclone_copy']:
|
||||||
self.__save_remove_file(file_path, xml_str)
|
self.__save_remove_file(file_path, xml_str)
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
import pickle
|
import pickle
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
|
import traceback
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.core.meta import MetaBase
|
from app.core.meta import MetaBase
|
||||||
|
from app.log import logger
|
||||||
from app.utils.singleton import Singleton
|
from app.utils.singleton import Singleton
|
||||||
from app.schemas.types import MediaType
|
from app.schemas.types import MediaType
|
||||||
|
|
||||||
@@ -118,7 +120,7 @@ class TmdbCache(metaclass=Singleton):
|
|||||||
return data
|
return data
|
||||||
return {}
|
return {}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(str(e))
|
logger.error(f'加载缓存失败:{str(e)} - {traceback.format_exc()}')
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def update(self, meta: MetaBase, info: dict) -> None:
|
def update(self, meta: MetaBase, info: dict) -> None:
|
||||||
@@ -144,7 +146,8 @@ class TmdbCache(metaclass=Singleton):
|
|||||||
"backdrop_path": info.get("backdrop_path"),
|
"backdrop_path": info.get("backdrop_path"),
|
||||||
CACHE_EXPIRE_TIMESTAMP_STR: int(time.time()) + EXPIRE_TIMESTAMP
|
CACHE_EXPIRE_TIMESTAMP_STR: int(time.time()) + EXPIRE_TIMESTAMP
|
||||||
}
|
}
|
||||||
else:
|
elif info is not None:
|
||||||
|
# None时不缓存,此时代表网络错误,允许重复请求
|
||||||
self._meta_data[self.__get_key(meta)] = {'id': 0}
|
self._meta_data[self.__get_key(meta)] = {'id': 0}
|
||||||
|
|
||||||
def save(self, force: bool = False) -> None:
|
def save(self, force: bool = False) -> None:
|
||||||
|
|||||||
@@ -213,8 +213,7 @@ class TmdbHelper:
|
|||||||
logger.error(f"连接TMDB出错:{str(err)}")
|
logger.error(f"连接TMDB出错:{str(err)}")
|
||||||
return None
|
return None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"连接TMDB出错:{str(e)}")
|
logger.error(f"连接TMDB出错:{str(e)} - {traceback.format_exc()}")
|
||||||
print(traceback.print_exc())
|
|
||||||
return None
|
return None
|
||||||
logger.debug(f"API返回:{str(self.search.total_results)}")
|
logger.debug(f"API返回:{str(self.search.total_results)}")
|
||||||
if len(movies) == 0:
|
if len(movies) == 0:
|
||||||
@@ -261,8 +260,7 @@ class TmdbHelper:
|
|||||||
logger.error(f"连接TMDB出错:{str(err)}")
|
logger.error(f"连接TMDB出错:{str(err)}")
|
||||||
return None
|
return None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"连接TMDB出错:{str(e)}")
|
logger.error(f"连接TMDB出错:{str(e)} - {traceback.format_exc()}")
|
||||||
print(traceback.print_exc())
|
|
||||||
return None
|
return None
|
||||||
logger.debug(f"API返回:{str(self.search.total_results)}")
|
logger.debug(f"API返回:{str(self.search.total_results)}")
|
||||||
if len(tvs) == 0:
|
if len(tvs) == 0:
|
||||||
@@ -313,7 +311,7 @@ class TmdbHelper:
|
|||||||
return True
|
return True
|
||||||
except Exception as e1:
|
except Exception as e1:
|
||||||
logger.error(f"连接TMDB出错:{e1}")
|
logger.error(f"连接TMDB出错:{e1}")
|
||||||
print(traceback.print_exc())
|
print(traceback.format_exc())
|
||||||
return False
|
return False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -324,7 +322,7 @@ class TmdbHelper:
|
|||||||
return None
|
return None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"连接TMDB出错:{str(e)}")
|
logger.error(f"连接TMDB出错:{str(e)}")
|
||||||
print(traceback.print_exc())
|
print(traceback.format_exc())
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if len(tvs) == 0:
|
if len(tvs) == 0:
|
||||||
@@ -404,7 +402,7 @@ class TmdbHelper:
|
|||||||
return None
|
return None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"连接TMDB出错:{str(e)}")
|
logger.error(f"连接TMDB出错:{str(e)}")
|
||||||
print(traceback.print_exc())
|
print(traceback.format_exc())
|
||||||
return None
|
return None
|
||||||
logger.debug(f"API返回:{str(self.search.total_results)}")
|
logger.debug(f"API返回:{str(self.search.total_results)}")
|
||||||
# 返回结果
|
# 返回结果
|
||||||
|
|||||||
@@ -141,15 +141,18 @@ class TMDb(object):
|
|||||||
def cached_request(self, method, url, data, json,
|
def cached_request(self, method, url, data, json,
|
||||||
_ts=datetime.strftime(datetime.now(), '%Y%m%d')):
|
_ts=datetime.strftime(datetime.now(), '%Y%m%d')):
|
||||||
"""
|
"""
|
||||||
缓存请求,时间默认1天
|
缓存请求,时间默认1天,None不缓存
|
||||||
"""
|
"""
|
||||||
return self.request(method, url, data, json)
|
return self.request(method, url, data, json)
|
||||||
|
|
||||||
def request(self, method, url, data, json):
|
def request(self, method, url, data, json):
|
||||||
if method == "GET":
|
if method == "GET":
|
||||||
return self._req.get_res(url, params=data, json=json)
|
req = self._req.get_res(url, params=data, json=json)
|
||||||
else:
|
else:
|
||||||
return self._req.post_res(url, data=data, json=json)
|
req = self._req.post_res(url, data=data, json=json)
|
||||||
|
if req is None:
|
||||||
|
raise TMDbException("无法连接TheMovieDb,请检查网络连接!")
|
||||||
|
return req
|
||||||
|
|
||||||
def cache_clear(self):
|
def cache_clear(self):
|
||||||
return self.cached_request.cache_clear()
|
return self.cached_request.cache_clear()
|
||||||
@@ -157,7 +160,7 @@ class TMDb(object):
|
|||||||
def _request_obj(self, action, params="", call_cached=True,
|
def _request_obj(self, action, params="", call_cached=True,
|
||||||
method="GET", data=None, json=None, key=None):
|
method="GET", data=None, json=None, key=None):
|
||||||
if self.api_key is None or self.api_key == "":
|
if self.api_key is None or self.api_key == "":
|
||||||
raise TMDbException("No API key found.")
|
raise TMDbException("TheMovieDb API Key 未设置!")
|
||||||
|
|
||||||
url = "https://%s/3%s?api_key=%s&%s&language=%s" % (
|
url = "https://%s/3%s?api_key=%s&%s&language=%s" % (
|
||||||
self.domain,
|
self.domain,
|
||||||
@@ -173,7 +176,7 @@ class TMDb(object):
|
|||||||
req = self.request(method, url, data, json)
|
req = self.request(method, url, data, json)
|
||||||
|
|
||||||
if req is None:
|
if req is None:
|
||||||
raise TMDbException("Failed to establish a new connection: no response from the server.")
|
return None
|
||||||
|
|
||||||
headers = req.headers
|
headers = req.headers
|
||||||
|
|
||||||
@@ -188,11 +191,11 @@ class TMDb(object):
|
|||||||
sleep_time = self._reset - current_time
|
sleep_time = self._reset - current_time
|
||||||
|
|
||||||
if self.wait_on_rate_limit:
|
if self.wait_on_rate_limit:
|
||||||
logger.warning("Rate limit reached. Sleeping for: %d" % sleep_time)
|
logger.warning("达到请求频率限制,休眠:%d 秒..." % sleep_time)
|
||||||
time.sleep(abs(sleep_time))
|
time.sleep(abs(sleep_time))
|
||||||
return self._request_obj(action, params, call_cached, method, data, json, key)
|
return self._request_obj(action, params, call_cached, method, data, json, key)
|
||||||
else:
|
else:
|
||||||
raise TMDbException("Rate limit reached. Try again in %d seconds." % sleep_time)
|
raise TMDbException("达到请求频率限制,将在 %d 秒后重试..." % sleep_time)
|
||||||
|
|
||||||
json = req.json()
|
json = req.json()
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import shutil
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Set, Tuple, Optional, Union, List
|
from typing import Set, Tuple, Optional, Union, List
|
||||||
|
|
||||||
|
from torrentool.torrent import Torrent
|
||||||
from transmission_rpc import File
|
from transmission_rpc import File
|
||||||
|
|
||||||
from app import schemas
|
from app import schemas
|
||||||
@@ -33,7 +34,7 @@ class TransmissionModule(_ModuleBase):
|
|||||||
定时任务,每10分钟调用一次
|
定时任务,每10分钟调用一次
|
||||||
"""
|
"""
|
||||||
# 定时重连
|
# 定时重连
|
||||||
if not self.transmission.is_inactive():
|
if self.transmission.is_inactive():
|
||||||
self.transmission.reconnect()
|
self.transmission.reconnect()
|
||||||
|
|
||||||
def download(self, content: Union[Path, str], download_dir: Path, cookie: str,
|
def download(self, content: Union[Path, str], download_dir: Path, cookie: str,
|
||||||
@@ -47,6 +48,21 @@ class TransmissionModule(_ModuleBase):
|
|||||||
:param category: 分类,TR中未使用
|
:param category: 分类,TR中未使用
|
||||||
:return: 种子Hash
|
:return: 种子Hash
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def __get_torrent_info() -> Tuple[str, int]:
|
||||||
|
"""
|
||||||
|
获取种子名称
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
if isinstance(content, Path):
|
||||||
|
torrentinfo = Torrent.from_file(content)
|
||||||
|
else:
|
||||||
|
torrentinfo = Torrent.from_string(content)
|
||||||
|
return torrentinfo.name, torrentinfo.total_size
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"获取种子名称失败:{e}")
|
||||||
|
return "", 0
|
||||||
|
|
||||||
if not content:
|
if not content:
|
||||||
return
|
return
|
||||||
if isinstance(content, Path) and not content.exists():
|
if isinstance(content, Path) and not content.exists():
|
||||||
@@ -68,6 +84,33 @@ class TransmissionModule(_ModuleBase):
|
|||||||
cookie=cookie
|
cookie=cookie
|
||||||
)
|
)
|
||||||
if not torrent:
|
if not torrent:
|
||||||
|
# 读取种子的名称
|
||||||
|
torrent_name, torrent_size = __get_torrent_info()
|
||||||
|
if not torrent_name:
|
||||||
|
return None, f"添加种子任务失败:无法读取种子文件"
|
||||||
|
# 查询所有下载器的种子
|
||||||
|
torrents, error = self.transmission.get_torrents()
|
||||||
|
if error:
|
||||||
|
return None, "无法连接transmission下载器"
|
||||||
|
if torrents:
|
||||||
|
for torrent in torrents:
|
||||||
|
# 名称与大小相等则认为是同一个种子
|
||||||
|
if torrent.name == torrent_name and torrent.total_size == torrent_size:
|
||||||
|
torrent_hash = torrent.hashString
|
||||||
|
logger.warn(f"下载器中已存在该种子任务:{torrent_hash} - {torrent.name}")
|
||||||
|
# 给种子打上标签
|
||||||
|
if settings.TORRENT_TAG:
|
||||||
|
logger.info(f"给种子 {torrent_hash} 打上标签:{settings.TORRENT_TAG}")
|
||||||
|
# 种子标签
|
||||||
|
labels = [str(tag).strip()
|
||||||
|
for tag in torrent.labels] if hasattr(torrent, "labels") else []
|
||||||
|
if "已整理" in labels:
|
||||||
|
labels.remove("已整理")
|
||||||
|
self.transmission.set_torrent_tag(ids=torrent_hash, tags=labels)
|
||||||
|
if settings.TORRENT_TAG and settings.TORRENT_TAG not in labels:
|
||||||
|
labels.append(settings.TORRENT_TAG)
|
||||||
|
self.transmission.set_torrent_tag(ids=torrent_hash, tags=labels)
|
||||||
|
return torrent_hash, f"下载任务已存在"
|
||||||
return None, f"添加种子任务失败:{content}"
|
return None, f"添加种子任务失败:{content}"
|
||||||
else:
|
else:
|
||||||
torrent_hash = torrent.hashString
|
torrent_hash = torrent.hashString
|
||||||
@@ -151,6 +194,7 @@ class TransmissionModule(_ModuleBase):
|
|||||||
state="paused" if torrent.status == "stopped" else "downloading",
|
state="paused" if torrent.status == "stopped" else "downloading",
|
||||||
dlspeed=StringUtils.str_filesize(dlspeed),
|
dlspeed=StringUtils.str_filesize(dlspeed),
|
||||||
upspeed=StringUtils.str_filesize(upspeed),
|
upspeed=StringUtils.str_filesize(upspeed),
|
||||||
|
left_time=StringUtils.str_secends(torrent.left_until_done / dlspeed) if dlspeed > 0 else ''
|
||||||
))
|
))
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class Transmission(metaclass=Singleton):
|
|||||||
_host: str = None
|
_host: str = None
|
||||||
_port: int = None
|
_port: int = None
|
||||||
_username: str = None
|
_username: str = None
|
||||||
_passowrd: str = None
|
_password: str = None
|
||||||
|
|
||||||
trc: Optional[Client] = None
|
trc: Optional[Client] = None
|
||||||
|
|
||||||
@@ -24,10 +24,16 @@ class Transmission(metaclass=Singleton):
|
|||||||
"peersGettingFromUs", "peersSendingToUs", "uploadRatio", "uploadedEver", "downloadedEver", "downloadDir",
|
"peersGettingFromUs", "peersSendingToUs", "uploadRatio", "uploadedEver", "downloadedEver", "downloadDir",
|
||||||
"error", "errorString", "doneDate", "queuePosition", "activityDate", "trackers"]
|
"error", "errorString", "doneDate", "queuePosition", "activityDate", "trackers"]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, host: str = None, port: int = None, username: str = None, password: str = None):
|
||||||
self._host, self._port = StringUtils.get_domain_address(address=settings.TR_HOST, prefix=False)
|
"""
|
||||||
self._username = settings.TR_USER
|
若不设置参数,则创建配置文件设置的下载器
|
||||||
self._password = settings.TR_PASSWORD
|
"""
|
||||||
|
if host and port:
|
||||||
|
self._host, self._port = host, port
|
||||||
|
else:
|
||||||
|
self._host, self._port = StringUtils.get_domain_address(address=settings.TR_HOST, prefix=False)
|
||||||
|
self._username = username if username else settings.TR_USER
|
||||||
|
self._password = password if password else settings.TR_PASSWORD
|
||||||
if self._host and self._port:
|
if self._host and self._port:
|
||||||
self.trc = self.__login_transmission()
|
self.trc = self.__login_transmission()
|
||||||
|
|
||||||
@@ -271,36 +277,25 @@ class Transmission(metaclass=Singleton):
|
|||||||
logger.error(f"设置速度限制出错:{str(err)}")
|
logger.error(f"设置速度限制出错:{str(err)}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def recheck_torrents(self, ids: Union[str, list]):
|
def recheck_torrents(self, ids: Union[str, list]) -> bool:
|
||||||
"""
|
"""
|
||||||
重新校验种子
|
重新校验种子
|
||||||
"""
|
"""
|
||||||
if not self.trc:
|
if not self.trc:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
return self.trc.verify_torrent(ids=ids)
|
self.trc.verify_torrent(ids=ids)
|
||||||
|
return True
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.error(f"重新校验种子出错:{str(err)}")
|
logger.error(f"重新校验种子出错:{str(err)}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def add_trackers(self, ids: Union[str, list], trackers: list):
|
|
||||||
"""
|
|
||||||
添加Tracker
|
|
||||||
"""
|
|
||||||
if not self.trc:
|
|
||||||
return False
|
|
||||||
try:
|
|
||||||
return self.trc.change_torrent(ids=ids, tracker_list=[trackers])
|
|
||||||
except Exception as err:
|
|
||||||
logger.error(f"添加Tracker出错:{str(err)}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def change_torrent(self,
|
def change_torrent(self,
|
||||||
hash_string: str,
|
hash_string: str,
|
||||||
upload_limit=None,
|
upload_limit=None,
|
||||||
download_limit=None,
|
download_limit=None,
|
||||||
ratio_limit=None,
|
ratio_limit=None,
|
||||||
seeding_time_limit=None):
|
seeding_time_limit=None) -> bool:
|
||||||
"""
|
"""
|
||||||
设置种子
|
设置种子
|
||||||
:param hash_string: ID
|
:param hash_string: ID
|
||||||
@@ -346,6 +341,22 @@ class Transmission(metaclass=Singleton):
|
|||||||
seedRatioLimit=seedRatioLimit,
|
seedRatioLimit=seedRatioLimit,
|
||||||
seedIdleMode=seedIdleMode,
|
seedIdleMode=seedIdleMode,
|
||||||
seedIdleLimit=seedIdleLimit)
|
seedIdleLimit=seedIdleLimit)
|
||||||
|
return True
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.error(f"设置种子出错:{str(err)}")
|
logger.error(f"设置种子出错:{str(err)}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def update_tracker(self, hash_string: str, tracker_list: list = None) -> bool:
|
||||||
|
"""
|
||||||
|
tr4.0及以上弃用直接设置tracker 共用change方法
|
||||||
|
https://github.com/trim21/transmission-rpc/blob/8eb82629492a0eeb0bb565f82c872bf9ccdcb313/transmission_rpc/client.py#L654
|
||||||
|
"""
|
||||||
|
if not self.trc:
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
self.trc.change_torrent(ids=hash_string,
|
||||||
|
tracker_list=tracker_list)
|
||||||
|
return True
|
||||||
|
except Exception as err:
|
||||||
|
logger.error(f"修改tracker出错:{str(err)}")
|
||||||
|
return False
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user