-
Notifications
You must be signed in to change notification settings - Fork 406
Expand file tree
/
Copy pathentrypoint.sh
More file actions
185 lines (149 loc) · 5.16 KB
/
entrypoint.sh
File metadata and controls
185 lines (149 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
set -e
ALIST_ADDR=${ALIST_ADDR:-http://alist:5678}
echo "检查alist连通性..."
while ! curl -s --fail "${ALIST_ADDR}/api/public/settings" | grep -q 200; do
sleep 2
done
echo "alist启动完成,等待10秒后开始下载元数据..."
sleep 10
MEDIA_DIR="/media"
crontabs=""
if [ ! -d "${MEDIA_DIR}/temp" ]; then
mkdir -p "${MEDIA_DIR}/temp"
fi
if [ ! -d "${MEDIA_DIR}/xiaoya" ]; then
mkdir -p "${MEDIA_DIR}/xiaoya"
fi
if [ ! -d "${MEDIA_DIR}/config" ]; then
mkdir -p "${MEDIA_DIR}/config"
fi
echo "开始下载元数据,如果有问题无法解决,请删除目录 ${MEDIA_DIR}/temp 下的所有文件重新启动."
disk_check() {
if [ "${DISK_CHECK_ENABLED:-true}" = "false" ]; then
return
fi
# 磁盘检测
dir="$1"
size="$2"
free_size=$(df -P "${dir}" | tail -n1 | awk '{print $4}')
free_size=$((free_size))
free_size_G=$((free_size / 1024 / 1024))
if [ $free_size_G -lt "${size}" ]; then
echo "目录${dir}最少需要剩余空间:${size}G,目前仅剩:${free_size_G}G"
exit 1
fi
}
download_meta() {
file=$1
# 元数据路径
path=${2:-}
echo "Downloading ${file}..."
# 检查历史文件,如果存在残留则删除
if [ -f "${MEDIA_DIR}/temp/${file}.aria2" ]; then
echo "Found ${file}.aria2, delete it."
rm -rf "${MEDIA_DIR}/temp/${file}.aria2"
rm -rf "${MEDIA_DIR}/temp/${file}"
fi
# 如果已经存在文件,则不下载
if [ -f "${MEDIA_DIR}/temp/${file}" ]; then
echo "Found ${file}, skip."
return
fi
# 重试5次下载,包含.aria2则重试
success=false
for i in {1..5}; do
echo "Downloading ${file}, try ${i}..."
echo "Link is ${ALIST_ADDR}/d/元数据/${file}"
if aria2c -o "${file}" --allow-overwrite=true --auto-file-renaming=false --enable-color=false -c -x6 "${ALIST_ADDR}/d/元数据/${path}${file}"; then
# 下载的文件小于10M,下载失败,删除
if [ "$(stat -c %s "${file}")" -lt 10000000 ]; then
echo "Download ${file} failed, file size less than 10M, retry after 10 seconds."
rm -rf "${file}"
rm -rf "${file}.aria2"
sleep 10
continue
fi
# 下载成功
success=true
break
fi
done
# 如果还存在aria2
if [ "${success}" = "false" ]; then
echo "Download ${file} failed."
rm -rf "${file}"
rm -rf "${file}.aria2"
return 1
fi
}
download_emby_config() {
if [ -f ${MEDIA_DIR}/config/emby_meta_finished ]; then
echo "Emby metadata has been downloaded. Delete the file ${MEDIA_DIR}/config/emby_meta_finished to re-extract."
return
fi
disk_check ${MEDIA_DIR}/temp 5
disk_check ${MEDIA_DIR}/config 5
echo "Downloading Emby config..."
cd "${MEDIA_DIR}/temp"
download_meta config.mp4
echo "Extracting Emby config..."
cd ${MEDIA_DIR}
7z x -aoa -mmt=16 temp/config.mp4
touch ${MEDIA_DIR}/config/emby_meta_finished
#删除临时文件config.mp4
if [ "${CLEAR_TEMP:=false}" = "true" ]; then
rm -f $MEDIA_DIR/temp/config.mp4
fi
}
download_emby_media() {
if [ -f "${MEDIA_DIR}/xiaoya/emby_media_finished" ]; then
echo "Emby media has been downloaded. Delete the file ${MEDIA_DIR}/xiaoya/emby_media_finished to re-extract."
return
fi
echo "Cleaning up Emby media..."
rm -rf ${MEDIA_DIR}/xiaoya/*
disk_check ${MEDIA_DIR}/temp 60
disk_check ${MEDIA_DIR}/xiaoya 70
echo "Downloading Emby media..."
cd "${MEDIA_DIR}/temp"
download_meta all.mp4
download_meta pikpak.mp4
echo "Extracting Emby media..."
cd ${MEDIA_DIR}/xiaoya
7z x -aoa -mmt=16 ${MEDIA_DIR}/temp/all.mp4
cd ${MEDIA_DIR}/xiaoya
7z x -aoa -mmt=16 ${MEDIA_DIR}/temp/pikpak.mp4
chmod -R 777 ${MEDIA_DIR}/xiaoya
touch ${MEDIA_DIR}/xiaoya/emby_media_finished
#删除临时文件all.mp4,pikpak.mo4
if [ "${CLEAR_TEMP:=false}" = "true" ]; then
rm -f $MEDIA_DIR/temp/all.mp4
rm -f $MEDIA_DIR/temp/pikpak.mp4
fi
}
# emby
if [ "${EMBY_ENABLED:=false}" = "true" ]; then
download_emby_config
download_emby_media
if [ "${AUTO_UPDATE_EMBY_CONFIG_ENABLED:=false}" = "true" ]; then
echo "启动定时更新Emby配置任务..."
# 随机生成一个时间,避免给服务器造成压力
random_min=$(shuf -i 0-59 -n 1)
random_hour=$(shuf -i 1-6 -n 1)
crontabs="${crontabs}\n${random_min} ${random_hour} */${AUTO_UPDATE_EMBY_INTERVAL:=7} * * /emby.sh update"
fi
if [ "${AUTO_UPDATE_EMBY_METADATA_ENABLED:=false}" = "true" ]; then
echo "启动定时更新Emby媒体数据任务..."
# 随机生成一个时间,避免给服务器造成压力
random_min=$(shuf -i 0-59 -n 1)
random_hour=$(shuf -i 1-6 -n 1)
crontabs="${crontabs}\n${random_min} ${random_hour} * * * /usr/local/bin/python3 /solid.py --media ${MEDIA_DIR}/xiaoya"
fi
fi
# 添加定时任务
if [ -n "${crontabs}" ]; then
echo -e "$crontabs" | crontab -
fi
echo "Complete."
cron -f