Skip to content

Commit 2eb2f9a

Browse files
committed
增加 Docker 支持,新增实时运行模式
1 parent c0cb673 commit 2eb2f9a

32 files changed

Lines changed: 2051 additions & 244 deletions

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 使用 Alpine Linux 作为基础镜像
2+
FROM python:3.8-alpine
3+
4+
# 将工作目录设置为 /app
5+
WORKDIR /app
6+
7+
# 将当前目录的内容复制到容器的 /app 目录中
8+
COPY . /app
9+
10+
# 安装需要的 Python 库
11+
RUN pip install --no-cache-dir -r requirements.txt
12+
13+
# 将启动脚本添加到镜像中
14+
COPY start.sh /start.sh
15+
RUN chmod +x /start.sh
16+
17+
# 设置容器的启动命令
18+
ENTRYPOINT ["/start.sh"]
19+
CMD ["python", "plex-edition-manager.py"]

README.md

Lines changed: 882 additions & 104 deletions
Large diffs are not rendered by default.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: "2"
2+
services:
3+
pem-reset:
4+
image: x1ao4/plex-edition-manager:latest
5+
container_name: pem-reset
6+
command: python plex-edition-manager.py --reset
7+
environment:
8+
- TZ=Asia/Shanghai
9+
volumes:
10+
- /自定义目录/plex-edition-manager/config:/app/config
11+
networks: {}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: "2"
2+
services:
3+
pem-scheduler:
4+
image: mcuadros/ofelia:latest
5+
container_name: pem-scheduler
6+
depends_on:
7+
- pem-all
8+
command: daemon --docker -f label=com.docker.compose.project=${COMPOSE_PROJECT_NAME}
9+
labels:
10+
ofelia.job-run.pem-all.schedule: 0 30 22 * * *
11+
ofelia.job-run.pem-all.container: pem-all
12+
environment:
13+
- TZ=Asia/Shanghai
14+
volumes:
15+
- /var/run/docker.sock:/var/run/docker.sock:ro
16+
restart: unless-stopped
17+
pem-all:
18+
image: x1ao4/plex-edition-manager:latest
19+
container_name: pem-all
20+
command: python plex-edition-manager.py --all
21+
environment:
22+
- TZ=Asia/Shanghai
23+
volumes:
24+
- /自定义目录/plex-edition-manager/config:/app/config
25+
pem-new:
26+
image: x1ao4/plex-edition-manager:latest
27+
container_name: pem-new
28+
command: python plex-edition-manager.py --new
29+
ports:
30+
- 8089:8089
31+
environment:
32+
- TZ=Asia/Shanghai
33+
volumes:
34+
- /自定义目录/plex-edition-manager/config:/app/config
35+
restart: unless-stopped
36+
networks: {}

config/config.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[server]
2+
address = http://127.0.0.1:32400
3+
token =
4+
skip_libraries =
5+
language = zh
6+
7+
[modules]
8+
order = 片源版本;动态范围

modules/AudioCodec.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import requests
2+
3+
def get_AudioCodec(server, token, movie_id, language):
4+
# 发送请求获取元数据
5+
headers = {'X-Plex-Token': token, 'Accept': 'application/json'}
6+
response = requests.get(f'{server}/library/metadata/{movie_id}', headers=headers)
7+
data = response.json()
8+
9+
# 从元数据中获取视频流的 title
10+
part = data['MediaContainer']['Metadata'][0]['Media'][0]['Part'][0]
11+
if 'Stream' in part:
12+
# 提取所有音频流
13+
audio_streams = [stream for stream in part['Stream'] if stream['streamType'] == 2]
14+
if audio_streams:
15+
# 按照声道数排序,如果声道数相同,则按照比特率排序
16+
audio_streams.sort(key=lambda x: (x.get('channels', 0), x.get('bitrate', 0)), reverse=True)
17+
18+
audio_info = audio_streams[0]['displayTitle']
19+
# 从 displayTitle 中提取最后一组括号内的部分作为音频信息
20+
last_parenthesis_start = audio_info.rfind("(")
21+
last_parenthesis_end = audio_info.rfind(")")
22+
if last_parenthesis_start != -1 and last_parenthesis_end != -1:
23+
audio_info = audio_info[last_parenthesis_start+1:last_parenthesis_end]
24+
else:
25+
audio_info = audio_info
26+
27+
# 如果语言是中文,将 "Mono" 和 "Stereo" 翻译为中文
28+
if language == 'zh':
29+
audio_info = audio_info.replace('Mono', '单声道')
30+
audio_info = audio_info.replace('Stereo', '立体声')
31+
32+
return audio_info
33+
34+
# 如果没有找到任何音频流,就返回 None
35+
return None

modules/Bitrate.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import requests
2+
3+
def get_Bitrate(server, token, movie_id):
4+
# 发送请求获取元数据
5+
headers = {'X-Plex-Token': token, 'Accept': 'application/json'}
6+
response = requests.get(f'{server}/library/metadata/{movie_id}', headers=headers)
7+
data = response.json()
8+
9+
# 初始化最大文件大小为0
10+
max_size = 0
11+
max_bitrate = None
12+
13+
# 遍历每个 Media 对象
14+
for media in data['MediaContainer']['Metadata'][0]['Media']:
15+
# 遍历每个 Part 对象
16+
for part in media['Part']:
17+
# 如果这个 Part 的文件大小大于当前的最大文件大小,就更新最大文件大小和比特率
18+
if part['size'] > max_size:
19+
max_size = part['size']
20+
max_bitrate = media.get('bitrate')
21+
22+
# 如果没有找到任何视频文件,返回 None
23+
if max_bitrate is None:
24+
return None
25+
26+
# 将比特率从 Kbps 转换为 Mbps
27+
video_bitrate_mbps = max_bitrate / 1000
28+
# 如果比特率小于 1 Mbps,则使用 Kbps 作为单位,并四舍五入到整数
29+
if video_bitrate_mbps < 1:
30+
return f"{round(max_bitrate)} Kbps"
31+
else:
32+
# 四舍五入到小数点后一位,并使用 Mbps 作为单位
33+
return f"{round(video_bitrate_mbps, 1)} Mbps"

modules/ContentRating.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def get_ContentRating(metadata):
2+
# 从元数据中获取内容分级信息
3+
contentRating = metadata.get('contentRating', None)
4+
5+
# 如果内容分级为 "Not Rated",将其转换为 "NR"
6+
if contentRating == 'Not Rated':
7+
contentRating = 'NR'
8+
9+
return contentRating

0 commit comments

Comments
 (0)