Mercurial > codedump
changeset 62:8be9281d7ade
Add `qbittorrent_update.py`
yes, there is a long ass line. no, i don't want to shrink it
committer: GitHub <noreply@github.com>
author | Paper <37962225+mrpapersonic@users.noreply.github.com> |
---|---|
date | Sun, 30 Jan 2022 20:31:44 -0500 |
parents | c615532e6572 |
children | bdcdd9c42043 1508aee998df |
files | qbittorrent_update.py |
diffstat | 1 files changed, 45 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /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("\<a href=\"(https:\/\/sourceforge\.net\/projects\/qbittorrent\/files\/qbittorrent-win32\/qbittorrent-[0-9\.]+\/qbittorrent_[0-9\.]+" + BIT_STR + "_setup\.exe\/download)\"\>", 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"))