net: improve parsing filenames from URL

This is more relevant to issuebot than fdroidserver, but it can't hurt here
also.
This commit is contained in:
Hans-Christoph Steiner 2022-05-09 18:51:41 +02:00
parent f8789f2997
commit 107593d3ba
2 changed files with 72 additions and 1 deletions

View file

@ -18,12 +18,13 @@
import os
import requests
import urllib
HEADERS = {'User-Agent': 'F-Droid'}
def download_file(url, local_filename=None, dldir='tmp'):
filename = url.split('/')[-1]
filename = urllib.parse.urlparse(url).path.split('/')[-1]
if local_filename is None:
local_filename = os.path.join(dldir, filename)
# the stream=True parameter keeps memory usage low