From a09f42f6b396a57e712f2c1cb25ce2d123be5fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 23 Oct 2020 00:04:43 +0200 Subject: [PATCH] improve filename_from_url() performance Manually extracting the part between the last '/' and '?' instead of relying on the standard libraries' 'urllib.parse.urlsplit()' increases performance by ~400%. urlsplit() : 3.64 secs per 1.000.000 iterations partition(): 0.87 secs per 1.000.000 iterations --- gallery_dl/text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gallery_dl/text.py b/gallery_dl/text.py index 9a716f9a..8b06384f 100644 --- a/gallery_dl/text.py +++ b/gallery_dl/text.py @@ -70,7 +70,7 @@ def ensure_http_scheme(url, scheme="https://"): def filename_from_url(url): """Extract the last part of an URL to use as a filename""" try: - return urllib.parse.urlsplit(url).path.rpartition("/")[2] + return url.partition("?")[0].rpartition("/")[2] except (TypeError, AttributeError): return ""