Mercurial > codedump
comparison qbittorrent_update.py @ 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 | |
children |
comparison
equal
deleted
inserted
replaced
61:c615532e6572 | 62:8be9281d7ade |
---|---|
1 """ | |
2 qBittorrent Updater for Windows (x64) | |
3 by Paper | |
4 | |
5 This could be easily ported to macOS/Linux, but for the former it | |
6 would just be easier to do it in AppleScript, and for the latter | |
7 you should already be using a package manager to do this for you. | |
8 """ | |
9 import urllib.request | |
10 import re | |
11 import psutil | |
12 import os | |
13 import platform | |
14 import time | |
15 | |
16 | |
17 def _check_running(exename): | |
18 for proc in psutil.process_iter(): | |
19 try: | |
20 if proc.name() == exename: | |
21 return True | |
22 except psutil.NoSuchProcess as err: | |
23 return False | |
24 except psutil.AccessDenied: | |
25 return False | |
26 | |
27 | |
28 QBITTORRENT_DIRECTORY = "C:\\Program Files\\qBittorrent" | |
29 TEMP_DIRECTORY = os.getenv("TEMP") | |
30 BIT_STR = "_x64" if platform.machine().endswith('64') else "" | |
31 | |
32 if _check_running("qbittorrent.exe"): | |
33 print("qBittorrent is currently running! Please exit it and try again.") | |
34 quit(1) | |
35 | |
36 # Get the link for the latest version, courtesy of SourceForge | |
37 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")) | |
38 | |
39 # Run the installer and wait for it to finish | |
40 os.system(os.path.join(TEMP_DIRECTORY, "qbittorrent_setup.exe") + " /S") | |
41 while _check_running("qbittorrent_setup.exe"): | |
42 time.sleep(5) | |
43 | |
44 # Cleanup | |
45 os.remove(os.path.join(TEMP_DIRECTORY, "qbittorrent_setup.exe")) |