#!/usr/bin/env python3 import bs4 import patoolib import requests import os import platform import shutil import sys # Setup path path = os.path.dirname(os.path.realpath(__file__)) path = os.path.dirname(path) sys.path.append(path) import downloader url = "https://bearware.dk/teamtalksdk" def get_url_suffix_from_platform() -> str: machine = platform.machine() if sys.platform == "win32": architecture = platform.architecture() if machine in ["AMD64", "x86"]: return "win64" if architecture[0] == "64bit" else "win32" else: sys.exit("Native Windows on ARM is not supported.") elif sys.platform == "darwin": sys.exit("macOS is not supported.") else: if machine in ["AMD64", "x86_64"]: return "ubuntu18_x86_64" elif "arm" in machine: return "raspbian_armhf" else: sys.exit("Your system architecture is not supported.") def download() -> None: headers = {'User-Agent': 'Mozilla/5.0'} r = requests.get(url, headers=headers) page = bs4.BeautifulSoup(r.text, features="html.parser") versions = page.find_all("li") version = [i for i in versions if "5.12" in i.text][-1].a.get("href")[0:-1] download_url = ( url + "/" + version + "/" + "tt5sdk_{v}_{p}.7z".format(v=version, p=get_url_suffix_from_platform()) ) print("Downloading from: " + download_url) downloader.download_file(download_url, os.path.join(os.getcwd(), "ttsdk.7z")) def extract() -> None: try: os.mkdir(os.path.join(os.getcwd(), "ttsdk")) except FileExistsError: shutil.rmtree(os.path.join(os.getcwd(), "ttsdk")) os.mkdir(os.path.join(os.getcwd(), "ttsdk")) patoolib.extract_archive( os.path.join(os.getcwd(), "ttsdk.7z"), outdir=os.path.join(os.getcwd(), "ttsdk") ) def move() -> None: sdk_root = os.path.join(os.getcwd(), "ttsdk") 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"] dest_dir = os.path.join(os.getcwd(), os.pardir) if os.path.basename(os.getcwd()) == "tools" else os.getcwd() 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: os.rename(src, dst) except OSError: if os.path.exists(dst): shutil.rmtree(dst) os.rename(src, dst) license_path = os.path.join(path, "License.txt") dst_license = os.path.join(dest_dir, "TTSDK_license.txt") if os.path.exists(license_path): if os.path.exists(dst_license): os.remove(dst_license) os.rename(license_path, dst_license) def clean() -> None: os.remove(os.path.join(os.getcwd(), "ttsdk.7z")) shutil.rmtree(os.path.join(os.getcwd(), "ttsdk")) def install() -> None: print("Starting TeamTalk SDK installation...") print("Downloading the latest SDK version...") download() print("Download complete. Extracting...") extract() print("Extraction complete. Moving files...") move() print("Move complete. Cleaning up...") clean() print("Cleanup done.") print("TeamTalk SDK successfully installed.") if __name__ == "__main__": install()