Created
January 14, 2023 18:19
-
-
Save PinkPandaKatie/e3d58d5eab3721e72195268f4daeca28 to your computer and use it in GitHub Desktop.
Script to download the latest version of Discord on Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import re | |
import subprocess | |
import traceback | |
from pathlib import Path | |
import requests | |
def main(): | |
r = requests.head('https://discord.com/api/download?platform=linux&format=tar.gz') | |
dl_url = r.headers['location'] | |
filename = dl_url.split('?')[0].split('/')[-1] | |
m = re.search(r'(\d+\.\d+\.\d+)', filename) | |
version = m.group(1) | |
discord_dir = Path(__file__).with_name(f'discord-{version}') | |
link_path = Path(__file__).with_name(f'Discord') | |
tarpath = Path(__file__).with_name(f'discord-{version}.tar.gz') | |
if not tarpath.exists(): | |
tmppath = tarpath.with_suffix('.temp') | |
print(f'download {dl_url}') | |
with requests.get(dl_url, stream=True) as r: | |
with tmppath.open('wb') as fp: | |
for chunk in r.iter_content(chunk_size=65536): | |
fp.write(chunk) | |
tmppath.replace(tarpath) | |
if not (discord_dir / 'Discord').exists(): | |
discord_dir.mkdir(exist_ok=True) | |
subprocess.run(['tar', 'zxvfC', tarpath, discord_dir], check=True) | |
if link_path.is_symlink(): | |
link_path.unlink() | |
link_path.symlink_to(f'discord-{version}/Discord') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment