-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateStrm.py
More file actions
59 lines (48 loc) · 2.57 KB
/
createStrm.py
File metadata and controls
59 lines (48 loc) · 2.57 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
from utils.rclonetools import *
import json
import os
import mimetypes
def getDownloadQueue(src, dst, host):
srcFiles = json.loads(executeCommand(f"rclone lsjson --dirs-only --max-depth 1 \"{src}\"")["out"])
dstFiles = json.loads(executeCommand(f"rclone lsjson --dirs-only --max-depth 1 \"{dst}\"")["out"])
lackDirs = setDifference(srcFiles, dstFiles, lambda a, b: a["Path"] == b["Path"]) # 只比对路径
copyList = []
strmList = []
for dirItem in lackDirs:
dirBackend = rcloneJoin(src, dirItem["Path"])
for file in json.loads(executeCommand(f'rclone lsjson --files-only --max-depth 9999 "{ dirBackend }"')["out"]):
if get_content_type(file["Name"]).startswith("video"):
strmUrl = rcloneJoin(rcloneJoin(host, dirItem["Path"]), file["Path"])
fileDst = rcloneJoin(rcloneJoin(dst, dirItem["Path"]), file["Path"])
name, _ = os.path.splitext(fileDst)
fileDst = f"{name}.strm"
strmList.append((strmUrl, fileDst))
else:
fileSrc = rcloneJoin(rcloneJoin(src, dirItem["Path"]), file["Path"])
fileDst = rcloneJoin(rcloneJoin(dst, dirItem["Path"]), file["Path"])
copyList.append((fileSrc, fileDst))
return copyList, strmList
syncList = [
("123readonly:电视剧/", "/mnt/storage/Media/EmbyMedia/123pan/电视剧/", "http://emby.nas.local/strm/123pan/电视剧"),
("123readonly:电影/", "/mnt/storage/Media/EmbyMedia/123pan/电影/", "http://emby.nas.local/strm/123pan/电影"),
("123readonly:番剧/", "/mnt/storage/Media/EmbyMedia/123pan/番剧/", "http://emby.nas.local/strm/123pan/番剧"),
]
# syncList = [
# ("/mnt/storage/Downloads/link/[VCB-Studio] TenSura", "/mnt/storage/Media/EmbyMedia/123pan/番剧/[VCB-Studio] TenSura", "http://emby.nas.local/strm/123pan/番剧/[VCB-Studio] TenSura"),
# ]
result = [getDownloadQueue(src, dst, host) for src, dst, host in syncList]
for copyList, _ in result:
rcloneCopy(copyList, True, 8)
for _, strmList in result:
[print(f"🔗 {url} 📝 {filePath}") for url, filePath in strmList]
if input("输入 y 来继续") == "y":
for copyList, _ in result:
rcloneCopy(copyList, False, 8)
for _, strmList in result:
for url, filePath in strmList:
print(f"🔗 {url} 📝 {filePath}")
directory = os.path.dirname(filePath)
os.makedirs(directory, exist_ok=True)
with open(filePath, "w", encoding="UTF-8") as f:
f.write(url)
os.system("chmod 777 -R /mnt/storage/Media/EmbyMedia")