From 731ffd49866515a4b26fe20520a4e58b9d9e5bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 18 Feb 2018 16:50:07 +0100 Subject: [PATCH] improve text.filename_from_url() performance - urlsplit() is faster than urlparse() - rpartition() is faster than rindex() + slicing - new version is 2.3 times as fast --- gallery_dl/text.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/gallery_dl/text.py b/gallery_dl/text.py index 49328ab6..82c56a8b 100644 --- a/gallery_dl/text.py +++ b/gallery_dl/text.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2015-2017 Mike Fährmann +# Copyright 2015-2018 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -36,9 +36,7 @@ def remove_html(text): def filename_from_url(url): """Extract the last part of an url to use as a filename""" try: - path = urllib.parse.urlparse(url).path - pos = path.rindex("/") - return path[pos+1:] + return urllib.parse.urlsplit(url).path.rpartition("/")[2] except ValueError: return url