Merge branch 'master' of https://github.com/iordanisg/qutebrowser
This commit is contained in:
commit
84c2289aa5
@ -1448,8 +1448,18 @@ class CommandDispatcher:
|
|||||||
download_manager.get_mhtml(tab, target)
|
download_manager.get_mhtml(tab, target)
|
||||||
else:
|
else:
|
||||||
qnam = tab.networkaccessmanager()
|
qnam = tab.networkaccessmanager()
|
||||||
download_manager.get(self._current_url(), user_agent=user_agent,
|
|
||||||
qnam=qnam, target=target)
|
suggested_fn = downloads.suggested_fn_from_title(
|
||||||
|
self._current_url().path(), tab.title()
|
||||||
|
)
|
||||||
|
|
||||||
|
download_manager.get(
|
||||||
|
self._current_url(),
|
||||||
|
user_agent=user_agent,
|
||||||
|
qnam=qnam,
|
||||||
|
target=target,
|
||||||
|
suggested_fn=suggested_fn
|
||||||
|
)
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||||
def view_source(self):
|
def view_source(self):
|
||||||
|
@ -182,6 +182,28 @@ def transform_path(path):
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def suggested_fn_from_title(url_path, title=None):
|
||||||
|
"""Suggest a filename depending on the URL extension and page title.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
url_path: a string with the URL path
|
||||||
|
title: the page title string
|
||||||
|
|
||||||
|
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_path)
|
||||||
|
if ext.lower() in ext_whitelist and title:
|
||||||
|
suggested_fn = utils.sanitize_filename(title)
|
||||||
|
if not suggested_fn.lower().endswith((".html", ".htm")):
|
||||||
|
suggested_fn += ".html"
|
||||||
|
else:
|
||||||
|
suggested_fn = None
|
||||||
|
return suggested_fn
|
||||||
|
|
||||||
|
|
||||||
class NoFilenameError(Exception):
|
class NoFilenameError(Exception):
|
||||||
|
|
||||||
"""Raised when we can't find out a filename in DownloadTarget."""
|
"""Raised when we can't find out a filename in DownloadTarget."""
|
||||||
|
@ -412,7 +412,8 @@ class DownloadManager(downloads.AbstractDownloadManager):
|
|||||||
mhtml.start_download_checked, tab=tab))
|
mhtml.start_download_checked, tab=tab))
|
||||||
message.global_bridge.ask(question, blocking=False)
|
message.global_bridge.ask(question, blocking=False)
|
||||||
|
|
||||||
def get_request(self, request, *, target=None, **kwargs):
|
def get_request(self, request, *, target=None,
|
||||||
|
suggested_fn=None, **kwargs):
|
||||||
"""Start a download with a QNetworkRequest.
|
"""Start a download with a QNetworkRequest.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -428,7 +429,9 @@ class DownloadManager(downloads.AbstractDownloadManager):
|
|||||||
request.setAttribute(QNetworkRequest.CacheLoadControlAttribute,
|
request.setAttribute(QNetworkRequest.CacheLoadControlAttribute,
|
||||||
QNetworkRequest.AlwaysNetwork)
|
QNetworkRequest.AlwaysNetwork)
|
||||||
|
|
||||||
if request.url().scheme().lower() != 'data':
|
if suggested_fn is not None:
|
||||||
|
pass
|
||||||
|
elif request.url().scheme().lower() != 'data':
|
||||||
suggested_fn = urlutils.filename_from_url(request.url())
|
suggested_fn = urlutils.filename_from_url(request.url())
|
||||||
else:
|
else:
|
||||||
# We might be downloading a binary blob embedded on a page or even
|
# We might be downloading a binary blob embedded on a page or even
|
||||||
|
8
tests/end2end/data/downloads/download with no title.html
Normal file
8
tests/end2end/data/downloads/download with no title.html
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
BIN
tests/end2end/data/downloads/qutebrowser.png
Normal file
BIN
tests/end2end/data/downloads/qutebrowser.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
@ -22,6 +22,20 @@ Feature: Downloading things from a website.
|
|||||||
And I wait until the download is finished
|
And I wait until the download is finished
|
||||||
Then the downloaded file download.bin should exist
|
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 :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 hints
|
Scenario: Using hints
|
||||||
When I set storage -> prompt-download-directory to false
|
When I set storage -> prompt-download-directory to false
|
||||||
And I open data/downloads/downloads.html
|
And I open data/downloads/downloads.html
|
||||||
@ -637,7 +651,7 @@ Feature: Downloading things from a website.
|
|||||||
@qtwebengine_skip: We can't get the UA from the page there
|
@qtwebengine_skip: We can't get the UA from the page there
|
||||||
Scenario: user-agent when using :download
|
Scenario: user-agent when using :download
|
||||||
When I open user-agent
|
When I open user-agent
|
||||||
And I run :download
|
And I run :download --dest user-agent
|
||||||
And I wait until the download is finished
|
And I wait until the download is finished
|
||||||
Then the downloaded file user-agent should contain Safari/
|
Then the downloaded file user-agent should contain Safari/
|
||||||
|
|
||||||
|
@ -30,6 +30,42 @@ def test_download_model(qapp, qtmodeltester, config_stub, cookiejar_and_cache):
|
|||||||
qtmodeltester.check(model)
|
qtmodeltester.check(model)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('url, title, out', [
|
||||||
|
('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/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.html'),
|
||||||
|
('https://github.com/qutebrowser/qutebrowser/releases',
|
||||||
|
'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),
|
||||||
|
('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:
|
class TestDownloadTarget:
|
||||||
|
|
||||||
def test_base(self):
|
def test_base(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user