From a24d7f66861d0f2c7a30e55c87e70b7d63769082 Mon Sep 17 00:00:00 2001 From: Iordanis Grigoriou Date: Mon, 26 Jun 2017 12:25:03 +0200 Subject: [PATCH 1/8] Use page title for filename with :download --- qutebrowser/browser/commands.py | 3 ++- qutebrowser/browser/qtnetworkdownloads.py | 5 +++-- tests/end2end/features/downloads.feature | 7 +++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 8fead7269..f3d2473d6 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1444,7 +1444,8 @@ class CommandDispatcher: else: qnam = tab.networkaccessmanager() download_manager.get(self._current_url(), user_agent=user_agent, - qnam=qnam, target=target) + qnam=qnam, target=target, + title=self._current_title()) @cmdutils.register(instance='command-dispatcher', scope='window') def view_source(self): diff --git a/qutebrowser/browser/qtnetworkdownloads.py b/qutebrowser/browser/qtnetworkdownloads.py index 71039dc2d..6dd7c27c9 100644 --- a/qutebrowser/browser/qtnetworkdownloads.py +++ b/qutebrowser/browser/qtnetworkdownloads.py @@ -412,7 +412,7 @@ class DownloadManager(downloads.AbstractDownloadManager): mhtml.start_download_checked, tab=tab)) message.global_bridge.ask(question, blocking=False) - def get_request(self, request, *, target=None, **kwargs): + def get_request(self, request, *, target=None, title=None, **kwargs): """Start a download with a QNetworkRequest. Args: @@ -429,7 +429,8 @@ class DownloadManager(downloads.AbstractDownloadManager): QNetworkRequest.AlwaysNetwork) if request.url().scheme().lower() != 'data': - suggested_fn = urlutils.filename_from_url(request.url()) + suggested_fn = (utils.sanitize_filename(title) + ".html" if title + else urlutils.filename_from_url(request.url())) else: # We might be downloading a binary blob embedded on a page or even # generated dynamically via javascript. We try to figure out a more diff --git a/tests/end2end/features/downloads.feature b/tests/end2end/features/downloads.feature index 95b775303..ed583cb61 100644 --- a/tests/end2end/features/downloads.feature +++ b/tests/end2end/features/downloads.feature @@ -22,6 +22,13 @@ Feature: Downloading things from a website. And I wait until the download is finished Then the downloaded file download.bin should exist + Scenario: Using :download with no URL + When I set storage -> prompt-download-directory to false + And I open data/downloads/downloads.html + And I run :download + And I wait until the download is finished + Then the downloaded file Simple downloads.html should exist + Scenario: Using hints When I set storage -> prompt-download-directory to false And I open data/downloads/downloads.html From 8a5b48d374ad5ba4f826b1c5dde27322cec304a5 Mon Sep 17 00:00:00 2001 From: Iordanis Grigoriou Date: Mon, 26 Jun 2017 23:21:32 +0200 Subject: [PATCH 2/8] Add suggested_fn argument to get_request --- qutebrowser/browser/commands.py | 10 +++++++--- qutebrowser/browser/qtnetworkdownloads.py | 9 +++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index f3d2473d6..fbf3fe914 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1443,9 +1443,13 @@ class CommandDispatcher: download_manager.get_mhtml(tab, target) else: qnam = tab.networkaccessmanager() - download_manager.get(self._current_url(), user_agent=user_agent, - qnam=qnam, target=target, - title=self._current_title()) + download_manager.get( + self._current_url(), + user_agent=user_agent, + qnam=qnam, + target=target, + suggested_fn=utils.sanitize_filename(tab.title() + ".html") + ) @cmdutils.register(instance='command-dispatcher', scope='window') def view_source(self): diff --git a/qutebrowser/browser/qtnetworkdownloads.py b/qutebrowser/browser/qtnetworkdownloads.py index 6dd7c27c9..1e494b1d2 100644 --- a/qutebrowser/browser/qtnetworkdownloads.py +++ b/qutebrowser/browser/qtnetworkdownloads.py @@ -412,7 +412,7 @@ class DownloadManager(downloads.AbstractDownloadManager): mhtml.start_download_checked, tab=tab)) message.global_bridge.ask(question, blocking=False) - def get_request(self, request, *, target=None, title=None, **kwargs): + def get_request(self, request, *, target=None, suggested_fn=None, **kwargs): """Start a download with a QNetworkRequest. Args: @@ -428,9 +428,10 @@ class DownloadManager(downloads.AbstractDownloadManager): request.setAttribute(QNetworkRequest.CacheLoadControlAttribute, QNetworkRequest.AlwaysNetwork) - if request.url().scheme().lower() != 'data': - suggested_fn = (utils.sanitize_filename(title) + ".html" if title - else urlutils.filename_from_url(request.url())) + if suggested_fn is not None: + pass + elif request.url().scheme().lower() != 'data': + suggested_fn = urlutils.filename_from_url(request.url()) else: # We might be downloading a binary blob embedded on a page or even # generated dynamically via javascript. We try to figure out a more From 5e2be8a44a80257525522293cc9151971f9d3b17 Mon Sep 17 00:00:00 2001 From: Iordanis Grigoriou Date: Tue, 27 Jun 2017 08:25:59 +0200 Subject: [PATCH 3/8] Fix PEP-8 issue --- qutebrowser/browser/qtnetworkdownloads.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/qtnetworkdownloads.py b/qutebrowser/browser/qtnetworkdownloads.py index 1e494b1d2..512991bbc 100644 --- a/qutebrowser/browser/qtnetworkdownloads.py +++ b/qutebrowser/browser/qtnetworkdownloads.py @@ -412,7 +412,8 @@ class DownloadManager(downloads.AbstractDownloadManager): mhtml.start_download_checked, tab=tab)) message.global_bridge.ask(question, blocking=False) - def get_request(self, request, *, target=None, suggested_fn=None, **kwargs): + def get_request(self, request, *, target=None, + suggested_fn=None, **kwargs): """Start a download with a QNetworkRequest. Args: From 0a09758be1712e8617a9a6fc5c70118eaa7634ed Mon Sep 17 00:00:00 2001 From: Iordanis Grigoriou Date: Tue, 27 Jun 2017 12:21:25 +0200 Subject: [PATCH 4/8] Add file path to download --- tests/end2end/features/downloads.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/end2end/features/downloads.feature b/tests/end2end/features/downloads.feature index ed583cb61..8a9e8c134 100644 --- a/tests/end2end/features/downloads.feature +++ b/tests/end2end/features/downloads.feature @@ -644,7 +644,7 @@ Feature: Downloading things from a website. @qtwebengine_skip: We can't get the UA from the page there Scenario: user-agent when using :download When I open user-agent - And I run :download + And I run :download --dest user-agent And I wait until the download is finished Then the downloaded file user-agent should contain Safari/ From 57e4d4978b66fc7547e2aeafb2ddd1b708d19580 Mon Sep 17 00:00:00 2001 From: Iordanis Grigoriou Date: Thu, 6 Jul 2017 11:59:02 +0200 Subject: [PATCH 5/8] Use page title only for whitelisted extensions --- qutebrowser/browser/commands.py | 12 +++++++++++- .../data/downloads/download with no title.html | 8 ++++++++ tests/end2end/data/downloads/qutebrowser.png | Bin 0 -> 4278 bytes tests/end2end/features/downloads.feature | 14 ++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/end2end/data/downloads/download with no title.html create mode 100644 tests/end2end/data/downloads/qutebrowser.png diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index fbf3fe914..88499c412 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1443,12 +1443,22 @@ class CommandDispatcher: download_manager.get_mhtml(tab, target) else: qnam = tab.networkaccessmanager() + + # Downloads of URLs with file extensions in the whitelist will use + # the page title as the filename. + ext_whitelist = [".html", ".htm", ".php", ""] + _, ext = os.path.splitext(self._current_url().path()) + if ext.lower() in ext_whitelist and tab.title(): + suggested_fn = utils.sanitize_filename(tab.title()) + ext + else: + suggested_fn = None + download_manager.get( self._current_url(), user_agent=user_agent, qnam=qnam, target=target, - suggested_fn=utils.sanitize_filename(tab.title() + ".html") + suggested_fn=suggested_fn ) @cmdutils.register(instance='command-dispatcher', scope='window') diff --git a/tests/end2end/data/downloads/download with no title.html b/tests/end2end/data/downloads/download with no title.html new file mode 100644 index 000000000..da4352e59 --- /dev/null +++ b/tests/end2end/data/downloads/download with no title.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/tests/end2end/data/downloads/qutebrowser.png b/tests/end2end/data/downloads/qutebrowser.png new file mode 100644 index 0000000000000000000000000000000000000000..e8bbb6b5649a4300bbb55a60e79a84c3468d3ea8 GIT binary patch literal 4278 zcmV;n5J~TeP)rsbCgnS&R|uOlc#E%7;kgp?P=H1k&>}d zvLiQ1wov#Mlur|^B7LC69WVuK$dbdPop)+%%xiFXK4~E!Hc(R0D3~+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Vyp;{Dg*F9T ze|!6`I|dVCCBA>d)Sm<@8zHAm;BdM4%Xew4e&Kb#*!z8thFMV*ez{^{duDI7e`nkw zzNNX8w_KX>B+w!98RQKKgCsv(=|0_bGm(>hilS@zRF)L-#| zQp2vi)1KZz0Tbgzbw;7trz2o6~XYtz0>)O9rsL?fbwGg6<@NU0n;t+8OLq6_~c1xrr(Br>DxQC)B zB+QsaP;gk!jeCLEs4(96&nI|x&Ej@n9;A?K-MtV4lXrp%aoUcIBK-{{|I)r*5ilx3 zl3Ca{gBUkt1at3uh{zag&y77qbVMl27TwAHcTMl|QboWY60F+J?)sW$Ii|!aFJu%M zVFFgQuOAX3@zLOPiJ-y5kb!?d5Xtu}V$6i8Em6#VA}S(;#0jIBJ97$2lSZQ`ZWnXP zWUKPB86Q&x2q9#8x?Cr$G72g0?I1vaWbOz_X@lT&vB1_%Fh)^T5~j~$X7YTuxq8jZ zLU>dRbv4yE9bL7lsv5CTVZ_CTV~q@Bc)XRV6GruzqZEieda+m~2AMyb_vlj`mQo8Y zGS&lY+|ip|aQIToQ?yoGzIcw4M-Oq=!iNZtjPYa`037yaq%;r+EIz*YSzz9%9{!Bf z2|}_>FHzQb@?73yzEVn&QDpo9$OnJ;I+wC zLB$+A>?A*+!+Ep1!Mc4q9dFX`#S~10{ zeWhzkBFGLeoNtDMG&n>O=213Yey^&^mKe8w?;}rd?a2yzr?AMf|nCwl?}c5>g~~Qi8C+D5NR=*BRw-i3pd0#buzm41@%{6lAckY?>KwoCA>~Bp0M2vn6V3qE+-hOWF(k YKhMHKf literal 0 HcmV?d00001 diff --git a/tests/end2end/features/downloads.feature b/tests/end2end/features/downloads.feature index 8a9e8c134..40333aee6 100644 --- a/tests/end2end/features/downloads.feature +++ b/tests/end2end/features/downloads.feature @@ -29,6 +29,20 @@ Feature: Downloading things from a website. And I wait until the download is finished Then the downloaded file Simple downloads.html should exist + Scenario: Using :download with no URL on an image + When I set storage -> prompt-download-directory to false + And I open data/downloads/qutebrowser.png + And I run :download + And I wait until the download is finished + Then the downloaded file qutebrowser.png should exist + + Scenario: Using :download with no URL and no page title + When I set storage -> prompt-download-directory to false + And I open data/downloads/download with no title.html + And I run :download + And I wait until the download is finished + Then the downloaded file download with no title.html should exist + Scenario: Using hints When I set storage -> prompt-download-directory to false And I open data/downloads/downloads.html From 3bfafb5e5066b40dbe41cffe1e0fc3d27e504cfd Mon Sep 17 00:00:00 2001 From: Iordanis Grigoriou Date: Thu, 6 Jul 2017 17:41:54 +0200 Subject: [PATCH 6/8] Refactor suggested_fn_from_title, add unit tests --- qutebrowser/browser/commands.py | 11 +++------- qutebrowser/browser/downloads.py | 20 +++++++++++++++++ tests/end2end/features/downloads.feature | 7 ------ tests/unit/browser/webkit/test_downloads.py | 24 +++++++++++++++++++++ 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 88499c412..3e918a32a 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1444,14 +1444,9 @@ class CommandDispatcher: else: qnam = tab.networkaccessmanager() - # Downloads of URLs with file extensions in the whitelist will use - # the page title as the filename. - ext_whitelist = [".html", ".htm", ".php", ""] - _, ext = os.path.splitext(self._current_url().path()) - if ext.lower() in ext_whitelist and tab.title(): - suggested_fn = utils.sanitize_filename(tab.title()) + ext - else: - suggested_fn = None + suggested_fn = downloads.suggested_fn_from_title( + self._current_url().path(), tab.title() + ) download_manager.get( self._current_url(), diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index c7cb5ad8e..35b3d26c6 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -182,6 +182,26 @@ def transform_path(path): return path +def suggested_fn_from_title(url, title=None): + """Suggest a filename depending on the URL extension and page title. + Args: + url: a string with the URL path + title: the page title string + + Returns None if the extension is not in the whitelist + or if there is no page title. + """ + ext_whitelist = [".html", ".htm", ".php", ""] + _, ext = os.path.splitext(url) + if ext.lower() in ext_whitelist and title: + suggested_fn = utils.sanitize_filename(title) + if not suggested_fn.endswith(ext): + suggested_fn += ext + else: + suggested_fn = None + return suggested_fn + + class NoFilenameError(Exception): """Raised when we can't find out a filename in DownloadTarget.""" diff --git a/tests/end2end/features/downloads.feature b/tests/end2end/features/downloads.feature index 40333aee6..f636b3247 100644 --- a/tests/end2end/features/downloads.feature +++ b/tests/end2end/features/downloads.feature @@ -36,13 +36,6 @@ Feature: Downloading things from a website. And I wait until the download is finished Then the downloaded file qutebrowser.png should exist - Scenario: Using :download with no URL and no page title - When I set storage -> prompt-download-directory to false - And I open data/downloads/download with no title.html - And I run :download - And I wait until the download is finished - Then the downloaded file download with no title.html should exist - Scenario: Using hints When I set storage -> prompt-download-directory to false And I open data/downloads/downloads.html diff --git a/tests/unit/browser/webkit/test_downloads.py b/tests/unit/browser/webkit/test_downloads.py index 72b533cc7..d22338717 100644 --- a/tests/unit/browser/webkit/test_downloads.py +++ b/tests/unit/browser/webkit/test_downloads.py @@ -30,6 +30,30 @@ def test_download_model(qapp, qtmodeltester, config_stub, cookiejar_and_cache): qtmodeltester.check(model) +@pytest.mark.parametrize('url, title, out', [ + ('https://qutebrowser.org/img/cheatsheet-big.png', + 'cheatsheet-big.png (3342×2060)', + None), + ('http://qutebrowser.org/INSTALL.html', + 'Installing qutebrowser | qutebrowser', + 'Installing qutebrowser _ qutebrowser.html'), + ('http://qutebrowser.org/INSTALL.html.html', + 'Installing qutebrowser | qutebrowser', + 'Installing qutebrowser _ qutebrowser.html'), + ('http://qutebrowser.org/', + 'qutebrowser | qutebrowser', + 'qutebrowser _ qutebrowser'), + ('https://github.com/qutebrowser/qutebrowser/releases', + 'Releases · qutebrowser/qutebrowser', + 'Releases · qutebrowser_qutebrowser'), + ('http://qutebrowser.org/page-with-no-title.html', + '', + None), +]) +def test_page_titles(url, title, out): + assert downloads.suggested_fn_from_title(url, title) == out + + class TestDownloadTarget: def test_base(self): From 82d194cf2eb1462b385a552c2ac2d48e0aa07918 Mon Sep 17 00:00:00 2001 From: Iordanis Grigoriou Date: Thu, 6 Jul 2017 21:37:11 +0200 Subject: [PATCH 7/8] Improve function docstring, add more tests --- qutebrowser/browser/downloads.py | 14 ++++++++------ tests/unit/browser/webkit/test_downloads.py | 16 +++++++++++----- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index 35b3d26c6..e9499600e 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -182,20 +182,22 @@ def transform_path(path): return path -def suggested_fn_from_title(url, title=None): +def suggested_fn_from_title(url_path, title=None): """Suggest a filename depending on the URL extension and page title. + Args: - url: a string with the URL path + url_path: a string with the URL path title: the page title string - Returns None if the extension is not in the whitelist - or if there is no page title. + Return: + The download filename based on the title, or None if the extension is + not found in the whitelist (or if there is no page title). """ ext_whitelist = [".html", ".htm", ".php", ""] - _, ext = os.path.splitext(url) + _, ext = os.path.splitext(url_path) if ext.lower() in ext_whitelist and title: suggested_fn = utils.sanitize_filename(title) - if not suggested_fn.endswith(ext): + if not suggested_fn.lower().endswith(ext.lower()): suggested_fn += ext else: suggested_fn = None diff --git a/tests/unit/browser/webkit/test_downloads.py b/tests/unit/browser/webkit/test_downloads.py index d22338717..c9451b949 100644 --- a/tests/unit/browser/webkit/test_downloads.py +++ b/tests/unit/browser/webkit/test_downloads.py @@ -31,21 +31,27 @@ def test_download_model(qapp, qtmodeltester, config_stub, cookiejar_and_cache): @pytest.mark.parametrize('url, title, out', [ - ('https://qutebrowser.org/img/cheatsheet-big.png', - 'cheatsheet-big.png (3342×2060)', - None), ('http://qutebrowser.org/INSTALL.html', 'Installing qutebrowser | qutebrowser', 'Installing qutebrowser _ qutebrowser.html'), - ('http://qutebrowser.org/INSTALL.html.html', - 'Installing qutebrowser | qutebrowser', + ('http://qutebrowser.org/INSTALL.html', + 'Installing qutebrowser | qutebrowser.html', 'Installing qutebrowser _ qutebrowser.html'), + ('http://qutebrowser.org/INSTALL.HTML', + 'Installing qutebrowser | qutebrowser', + 'Installing qutebrowser _ qutebrowser.HTML'), + ('http://qutebrowser.org/INSTALL.html', + 'Installing qutebrowser | qutebrowser.HTML', + 'Installing qutebrowser _ qutebrowser.HTML'), ('http://qutebrowser.org/', 'qutebrowser | qutebrowser', 'qutebrowser _ qutebrowser'), ('https://github.com/qutebrowser/qutebrowser/releases', 'Releases · qutebrowser/qutebrowser', 'Releases · qutebrowser_qutebrowser'), + ('https://qutebrowser.org/img/cheatsheet-big.png', + 'cheatsheet-big.png (3342×2060)', + None), ('http://qutebrowser.org/page-with-no-title.html', '', None), From c9fd182dba0e922550873a13c7db825dfee774b7 Mon Sep 17 00:00:00 2001 From: Iordanis Grigoriou Date: Sat, 8 Jul 2017 16:28:58 +0200 Subject: [PATCH 8/8] Adjust suggested_fn_from_title, add tests --- qutebrowser/browser/downloads.py | 4 ++-- tests/unit/browser/webkit/test_downloads.py | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index e9499600e..438dfc528 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -197,8 +197,8 @@ def suggested_fn_from_title(url_path, title=None): _, ext = os.path.splitext(url_path) if ext.lower() in ext_whitelist and title: suggested_fn = utils.sanitize_filename(title) - if not suggested_fn.lower().endswith(ext.lower()): - suggested_fn += ext + if not suggested_fn.lower().endswith((".html", ".htm")): + suggested_fn += ".html" else: suggested_fn = None return suggested_fn diff --git a/tests/unit/browser/webkit/test_downloads.py b/tests/unit/browser/webkit/test_downloads.py index c9451b949..5a214f638 100644 --- a/tests/unit/browser/webkit/test_downloads.py +++ b/tests/unit/browser/webkit/test_downloads.py @@ -39,16 +39,22 @@ def test_download_model(qapp, qtmodeltester, config_stub, cookiejar_and_cache): 'Installing qutebrowser _ qutebrowser.html'), ('http://qutebrowser.org/INSTALL.HTML', 'Installing qutebrowser | qutebrowser', - 'Installing qutebrowser _ qutebrowser.HTML'), + 'Installing qutebrowser _ qutebrowser.html'), ('http://qutebrowser.org/INSTALL.html', 'Installing qutebrowser | qutebrowser.HTML', 'Installing qutebrowser _ qutebrowser.HTML'), ('http://qutebrowser.org/', 'qutebrowser | qutebrowser', - 'qutebrowser _ qutebrowser'), + 'qutebrowser _ qutebrowser.html'), ('https://github.com/qutebrowser/qutebrowser/releases', 'Releases · qutebrowser/qutebrowser', - 'Releases · qutebrowser_qutebrowser'), + 'Releases · qutebrowser_qutebrowser.html'), + ('http://qutebrowser.org/index.php', + 'qutebrowser | qutebrowser', + 'qutebrowser _ qutebrowser.html'), + ('http://qutebrowser.org/index.php', + 'qutebrowser | qutebrowser - index.php', + 'qutebrowser _ qutebrowser - index.php.html'), ('https://qutebrowser.org/img/cheatsheet-big.png', 'cheatsheet-big.png (3342×2060)', None),