Skip to content

Instantly share code, notes, and snippets.

@PinkPandaKatie
Created January 14, 2023 18:19
Show Gist options
  • Save PinkPandaKatie/e3d58d5eab3721e72195268f4daeca28 to your computer and use it in GitHub Desktop.
Save PinkPandaKatie/e3d58d5eab3721e72195268f4daeca28 to your computer and use it in GitHub Desktop.
Script to download the latest version of Discord on Linux
#!/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