# HG changeset patch # User Paper <37962225+mrpapersonic@users.noreply.github.com> # Date 1643592704 18000 # Node ID 8be9281d7adea139660ee8584a95afa42c64a04a # Parent c615532e657249379237b05f3cb1bdc0a27cea51 Add `qbittorrent_update.py` yes, there is a long ass line. no, i don't want to shrink it committer: GitHub diff -r c615532e6572 -r 8be9281d7ade qbittorrent_update.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qbittorrent_update.py Sun Jan 30 20:31:44 2022 -0500 @@ -0,0 +1,45 @@ +""" +qBittorrent Updater for Windows (x64) +by Paper + +This could be easily ported to macOS/Linux, but for the former it +would just be easier to do it in AppleScript, and for the latter +you should already be using a package manager to do this for you. +""" +import urllib.request +import re +import psutil +import os +import platform +import time + + +def _check_running(exename): + for proc in psutil.process_iter(): + try: + if proc.name() == exename: + return True + except psutil.NoSuchProcess as err: + return False + except psutil.AccessDenied: + return False + + +QBITTORRENT_DIRECTORY = "C:\\Program Files\\qBittorrent" +TEMP_DIRECTORY = os.getenv("TEMP") +BIT_STR = "_x64" if platform.machine().endswith('64') else "" + +if _check_running("qbittorrent.exe"): + print("qBittorrent is currently running! Please exit it and try again.") + quit(1) + +# Get the link for the latest version, courtesy of SourceForge +urllib.request.urlretrieve(re.search("\", urllib.request.urlopen("https://www.qbittorrent.org/download.php").read().decode("utf-8")).group(1), os.path.join(TEMP_DIRECTORY, "qbittorrent_setup.exe")) + +# Run the installer and wait for it to finish +os.system(os.path.join(TEMP_DIRECTORY, "qbittorrent_setup.exe") + " /S") +while _check_running("qbittorrent_setup.exe"): + time.sleep(5) + +# Cleanup +os.remove(os.path.join(TEMP_DIRECTORY, "qbittorrent_setup.exe"))