fixed ttsdk, again.
Some checks failed
Build-nightly / docker (push) Has been cancelled

This commit is contained in:
Umiko 2025-05-18 09:21:27 +07:00
parent 2d513bbcab
commit 776fb7da75

View File

@ -9,40 +9,45 @@ import platform
import shutil import shutil
import sys import sys
# Setup path
path = os.path.dirname(os.path.realpath(__file__)) path = os.path.dirname(os.path.realpath(__file__))
path = os.path.dirname(path) path = os.path.dirname(path)
sys.path.append(path) sys.path.append(path)
import downloader import downloader
url = "https://bearware.dk/teamtalksdk" url = "https://bearware.dk/teamtalksdk"
def get_url_suffix_from_platform() -> str: def get_url_suffix_from_platform() -> str:
machine = platform.machine() machine = platform.machine()
if sys.platform == "win32": if sys.platform == "win32":
architecture = platform.architecture() architecture = platform.architecture()
if machine in ["AMD64", "x86"]: if machine == "AMD64" or machine == "x86":
return "win64" if architecture[0] == "64bit" else "win32" if architecture[0] == "64bit":
return "win64"
else: else:
sys.exit("Native Windows on ARM is not supported.") return "win32"
else:
sys.exit("Native Windows on ARM is not supported")
elif sys.platform == "darwin": elif sys.platform == "darwin":
sys.exit("macOS is not supported.") sys.exit("Darwin is not supported")
else: else:
if machine in ["AMD64", "x86_64"]: if machine == "AMD64" or machine == "x86_64":
return "ubuntu18_x86_64" return "ubuntu22_x86_64"
elif "arm" in machine: elif "arm" in machine:
return "raspbian_armhf" return "raspbian_armhf"
else: else:
sys.exit("Your system architecture is not supported.") sys.exit("Your architecture is not supported")
def download() -> None: def download() -> None:
headers = {'User-Agent': 'Mozilla/5.0'} headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
r = requests.get(url, headers=headers) r = requests.get(url, headers=headers)
page = bs4.BeautifulSoup(r.text, features="html.parser") page = bs4.BeautifulSoup(r.text, features="html.parser")
# The last tested version series is v5.15x
versions = page.find_all("li") versions = page.find_all("li")
version = [i for i in versions if "5.12" in i.text][-1].a.get("href")[0:-1] version = [i for i in versions if "5.15" in i.text][-1].a.get("href")[0:-1]
download_url = ( download_url = (
url url
+ "/" + "/"
@ -50,7 +55,7 @@ def download() -> None:
+ "/" + "/"
+ "tt5sdk_{v}_{p}.7z".format(v=version, p=get_url_suffix_from_platform()) + "tt5sdk_{v}_{p}.7z".format(v=version, p=get_url_suffix_from_platform())
) )
print("Downloading from: " + download_url) print("Downloading from " + download_url)
downloader.download_file(download_url, os.path.join(os.getcwd(), "ttsdk.7z")) downloader.download_file(download_url, os.path.join(os.getcwd(), "ttsdk.7z"))
@ -61,51 +66,32 @@ def extract() -> None:
shutil.rmtree(os.path.join(os.getcwd(), "ttsdk")) shutil.rmtree(os.path.join(os.getcwd(), "ttsdk"))
os.mkdir(os.path.join(os.getcwd(), "ttsdk")) os.mkdir(os.path.join(os.getcwd(), "ttsdk"))
patoolib.extract_archive( patoolib.extract_archive(
os.path.join(os.getcwd(), "ttsdk.7z"), os.path.join(os.getcwd(), "ttsdk.7z"), outdir=os.path.join(os.getcwd(), "ttsdk")
outdir=os.path.join(os.getcwd(), "ttsdk")
) )
def move() -> None: def move() -> None:
sdk_root = os.path.join(os.getcwd(), "ttsdk") path = os.path.join(os.getcwd(), "ttsdk", os.listdir(os.path.join(os.getcwd(), "ttsdk"))[0])
contents = os.listdir(sdk_root)
if not contents:
raise RuntimeError("SDK extraction failed: 'ttsdk/' folder is empty.")
for entry in contents:
entry_path = os.path.join(sdk_root, entry)
if os.path.isdir(entry_path) and os.path.isdir(os.path.join(entry_path, "Library")):
path = entry_path
break
else:
raise RuntimeError("No 'Library' folder found in extracted SDK.")
libraries = ["TeamTalk_DLL", "TeamTalkPy"] libraries = ["TeamTalk_DLL", "TeamTalkPy"]
dest_dir = os.path.join(os.getcwd(), os.pardir) if os.path.basename(os.getcwd()) == "tools" else os.getcwd() dest_dir = os.path.join(os.getcwd(), os.pardir) if os.path.basename(os.getcwd()) == "tools" else os.getcwd()
for library in libraries: for library in libraries:
src = os.path.join(path, "Library", library)
dst = os.path.join(dest_dir, library)
if not os.path.exists(src):
print(f"WARNING: {library} not found.")
continue
try: try:
os.rename(src, dst) os.rename(
os.path.join(path, "Library", library), os.path.join(dest_dir, library)
)
except OSError: except OSError:
if os.path.exists(dst): shutil.rmtree(os.path.join(dest_dir, library))
shutil.rmtree(dst) os.rename(
os.rename(src, dst) os.path.join(path, "Library", library), os.path.join(dest_dir, library)
)
license_path = os.path.join(path, "License.txt") try:
dst_license = os.path.join(dest_dir, "TTSDK_license.txt") os.rename(
os.path.join(path, "License.txt"), os.path.join(dest_dir, "TTSDK_license.txt")
if os.path.exists(license_path): )
if os.path.exists(dst_license): except FileExistsError:
os.remove(dst_license) os.remove(os.path.join(dest_dir, "TTSDK_license.txt"))
os.rename(license_path, dst_license) os.rename(
os.path.join(path, "License.txt"), os.path.join(dest_dir, "TTSDK_license.txt")
)
def clean() -> None: def clean() -> None:
@ -114,18 +100,17 @@ def clean() -> None:
def install() -> None: def install() -> None:
print("Starting TeamTalk SDK installation...") print("Installing TeamTalk sdk components")
print("Downloading the latest SDK version...") print("Downloading latest sdk version")
download() download()
print("Download complete. Extracting...") print("Downloaded. extracting")
extract() extract()
print("Extraction complete. Moving files...") print("Extracted. moving")
move() move()
print("Move complete. Cleaning up...") print("moved. cleaning")
clean() clean()
print("Cleanup done.") print("cleaned.")
print("TeamTalk SDK successfully installed.") print("Installed, exiting.")
if __name__ == "__main__": if __name__ == "__main__":
install() install()