mirror of
https://github.com/YuCat-OVO/BaiduNetdisk-Docker
synced 2025-05-10 20:10:04 +08:00
139 lines
4.6 KiB
Plaintext
139 lines
4.6 KiB
Plaintext
import re
|
|
|
|
from api_fetcher import APIFetcher
|
|
|
|
|
|
class VersionFinder:
|
|
def __init__(self) -> None:
|
|
pass
|
|
|
|
class TemplateGenerator:
|
|
"""模板创建类
|
|
|
|
Args: 从网页获取的url数组
|
|
Returns: 模板数组, 版本区域由{0}替代
|
|
"""
|
|
|
|
def __init__(self, urls: list) -> list[str]:
|
|
self.linux_link = []
|
|
self.windows_link = ""
|
|
self.mac_link = []
|
|
|
|
for i in urls:
|
|
if re.search("(deb|rpm)", i) is not None:
|
|
self.linux_link.append(i)
|
|
elif re.search("exe", i) is not None:
|
|
if self.windows_link != "":
|
|
continue
|
|
self.windows_link = i
|
|
elif re.search("dmg", i) is not None:
|
|
self.mac_link.append(i)
|
|
|
|
def linux(self):
|
|
arch = ["arm64", "amd64"]
|
|
url_template = []
|
|
|
|
for url in self.linux_link:
|
|
# print(url)
|
|
|
|
version = re.search(
|
|
r"(?P<version>(?<=[_/])((?:[0-9]{1,2}(?:\.)?){1,3})(?=[_/])).*(?P<pkg>(?<=\.)[a-z]{3,4}$)",
|
|
url,
|
|
).group("pkg", "version")
|
|
|
|
self.linux_version = version[1]
|
|
|
|
if version[0] == "rpm":
|
|
url_template.append(re.sub(version[1], "{0}", url))
|
|
else:
|
|
template = re.sub("amd64", "{0}", url)
|
|
url_template += [
|
|
re.sub(version[1], "{0}", template.format(i)) for i in arch
|
|
]
|
|
|
|
return url_template
|
|
|
|
def windows(self):
|
|
self.windows_version = re.search(
|
|
r"(?P<version>([0-9]{1,2}(\.)?){3,4}(?=\.|_|\/))", self.windows_link
|
|
).group("version")
|
|
return re.sub(self.windows_version, "{0}", self.windows_link)
|
|
|
|
def mac(self):
|
|
versions = {}
|
|
url_template = []
|
|
for url in self.mac_link:
|
|
version = re.search(
|
|
r"(?P<version>(?<=[_])((?:[0-9]{1,2}(?:\.)?){1,3})(?=[_\.]))",
|
|
url,
|
|
).group("version")
|
|
if re.search("arm", url):
|
|
versions["arm"] = version
|
|
url_template.append(re.sub(version, "{0}", url))
|
|
else:
|
|
versions["amd"] = version
|
|
url_template.append(re.sub(version, "{0}", url))
|
|
self.mac_version = versions
|
|
return url_template
|
|
|
|
def __version_compear(a: str, b: str):
|
|
a_split = a.split(".")
|
|
b_split = b.split(".")
|
|
flag = False
|
|
if len(a) == len(b):
|
|
length = len(a_split)
|
|
for i in range(length):
|
|
if a_split[i] > b_split[i]:
|
|
flag = True
|
|
if flag:
|
|
return a
|
|
else:
|
|
return b
|
|
else:
|
|
print("The two version numbers have different lengths.")
|
|
return a
|
|
|
|
def version_setter(self, api_version):
|
|
self.linux_version = self.__version_compear(
|
|
self.linux_version, api_version.linux_version()
|
|
)
|
|
self.windows_version = self.__version_compear(
|
|
self.windows_version, api_version.windows_version()
|
|
)
|
|
self.mac_version = self.__version_compear(
|
|
self.mac_version, api_version.mac_version()
|
|
)
|
|
|
|
def run(self, urls: list):
|
|
tg = self.TemplateGenerator(urls)
|
|
linux_template = tg.linux()
|
|
windows_template = tg.windows()
|
|
mac_template = tg.mac()
|
|
self.linux_version = tg.linux_version
|
|
self.windows_version = tg.windows_version
|
|
self.mac_version = tg.mac_version
|
|
api = APIFetcher()
|
|
api.run()
|
|
self.version_setter(api)
|
|
|
|
def append_json(self):
|
|
pass
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# import doctest
|
|
|
|
# doctest.testmod()
|
|
urls = [
|
|
"https://issuepcdn.baidupcs.com/issue/netdisk/yunguanjia/BaiduNetdisk_7.19.0.18.exe",
|
|
"https://issuepcdn.baidupcs.com/issue/netdisk/yunguanjia/BaiduNetdisk_6.9.10.1.exe",
|
|
"https://issuepcdn.baidupcs.com/issue/netdisk/MACguanjia/BaiduNetdisk_mac_4.11.0.dmg",
|
|
"https://issuepcdn.baidupcs.com/issue/netdisk/MACguanjia/BaiduNetdisk_mac_4.11.0_arm64.dmg",
|
|
"https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/4.11.5/baidunetdisk-4.11.5.x86_64.rpm",
|
|
"https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/4.11.5/baidunetdisk_4.11.5_amd64.deb",
|
|
]
|
|
vf = VersionFinder()
|
|
vf.run(urls)
|
|
print(vf.linux_version)
|
|
pass
|