Skip to content

Commit

Permalink
增加 Docker 支持,新增实时运行模式
Browse files Browse the repository at this point in the history
  • Loading branch information
x1ao4 committed Jun 16, 2024
1 parent c0cb673 commit 2eb2f9a
Show file tree
Hide file tree
Showing 32 changed files with 2,051 additions and 244 deletions.
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 使用 Alpine Linux 作为基础镜像
FROM python:3.8-alpine

# 将工作目录设置为 /app
WORKDIR /app

# 将当前目录的内容复制到容器的 /app 目录中
COPY . /app

# 安装需要的 Python 库
RUN pip install --no-cache-dir -r requirements.txt

# 将启动脚本添加到镜像中
COPY start.sh /start.sh
RUN chmod +x /start.sh

# 设置容器的启动命令
ENTRYPOINT ["/start.sh"]
CMD ["python", "plex-edition-manager.py"]
986 changes: 882 additions & 104 deletions README.md

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions compose/plex-edition-manager-reset/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "2"
services:
pem-reset:
image: x1ao4/plex-edition-manager:latest
container_name: pem-reset
command: python plex-edition-manager.py --reset
environment:
- TZ=Asia/Shanghai
volumes:
- /自定义目录/plex-edition-manager/config:/app/config
networks: {}
36 changes: 36 additions & 0 deletions compose/plex-edition-manager/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: "2"
services:
pem-scheduler:
image: mcuadros/ofelia:latest
container_name: pem-scheduler
depends_on:
- pem-all
command: daemon --docker -f label=com.docker.compose.project=${COMPOSE_PROJECT_NAME}
labels:
ofelia.job-run.pem-all.schedule: 0 30 22 * * *
ofelia.job-run.pem-all.container: pem-all
environment:
- TZ=Asia/Shanghai
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
restart: unless-stopped
pem-all:
image: x1ao4/plex-edition-manager:latest
container_name: pem-all
command: python plex-edition-manager.py --all
environment:
- TZ=Asia/Shanghai
volumes:
- /自定义目录/plex-edition-manager/config:/app/config
pem-new:
image: x1ao4/plex-edition-manager:latest
container_name: pem-new
command: python plex-edition-manager.py --new
ports:
- 8089:8089
environment:
- TZ=Asia/Shanghai
volumes:
- /自定义目录/plex-edition-manager/config:/app/config
restart: unless-stopped
networks: {}
8 changes: 8 additions & 0 deletions config/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[server]
address = http://127.0.0.1:32400
token =
skip_libraries =
language = zh

[modules]
order = 片源版本;动态范围
35 changes: 35 additions & 0 deletions modules/AudioCodec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import requests

def get_AudioCodec(server, token, movie_id, language):
# 发送请求获取元数据
headers = {'X-Plex-Token': token, 'Accept': 'application/json'}
response = requests.get(f'{server}/library/metadata/{movie_id}', headers=headers)
data = response.json()

# 从元数据中获取视频流的 title
part = data['MediaContainer']['Metadata'][0]['Media'][0]['Part'][0]
if 'Stream' in part:
# 提取所有音频流
audio_streams = [stream for stream in part['Stream'] if stream['streamType'] == 2]
if audio_streams:
# 按照声道数排序,如果声道数相同,则按照比特率排序
audio_streams.sort(key=lambda x: (x.get('channels', 0), x.get('bitrate', 0)), reverse=True)

audio_info = audio_streams[0]['displayTitle']
# 从 displayTitle 中提取最后一组括号内的部分作为音频信息
last_parenthesis_start = audio_info.rfind("(")
last_parenthesis_end = audio_info.rfind(")")
if last_parenthesis_start != -1 and last_parenthesis_end != -1:
audio_info = audio_info[last_parenthesis_start+1:last_parenthesis_end]
else:
audio_info = audio_info

# 如果语言是中文,将 "Mono" 和 "Stereo" 翻译为中文
if language == 'zh':
audio_info = audio_info.replace('Mono', '单声道')
audio_info = audio_info.replace('Stereo', '立体声')

return audio_info

# 如果没有找到任何音频流,就返回 None
return None
33 changes: 33 additions & 0 deletions modules/Bitrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import requests

def get_Bitrate(server, token, movie_id):
# 发送请求获取元数据
headers = {'X-Plex-Token': token, 'Accept': 'application/json'}
response = requests.get(f'{server}/library/metadata/{movie_id}', headers=headers)
data = response.json()

# 初始化最大文件大小为0
max_size = 0
max_bitrate = None

# 遍历每个 Media 对象
for media in data['MediaContainer']['Metadata'][0]['Media']:
# 遍历每个 Part 对象
for part in media['Part']:
# 如果这个 Part 的文件大小大于当前的最大文件大小,就更新最大文件大小和比特率
if part['size'] > max_size:
max_size = part['size']
max_bitrate = media.get('bitrate')

# 如果没有找到任何视频文件,返回 None
if max_bitrate is None:
return None

# 将比特率从 Kbps 转换为 Mbps
video_bitrate_mbps = max_bitrate / 1000
# 如果比特率小于 1 Mbps,则使用 Kbps 作为单位,并四舍五入到整数
if video_bitrate_mbps < 1:
return f"{round(max_bitrate)} Kbps"
else:
# 四舍五入到小数点后一位,并使用 Mbps 作为单位
return f"{round(video_bitrate_mbps, 1)} Mbps"
9 changes: 9 additions & 0 deletions modules/ContentRating.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def get_ContentRating(metadata):
# 从元数据中获取内容分级信息
contentRating = metadata.get('contentRating', None)

# 如果内容分级为 "Not Rated",将其转换为 "NR"
if contentRating == 'Not Rated':
contentRating = 'NR'

return contentRating
Loading

0 comments on commit 2eb2f9a

Please sign in to comment.