Skip to content

Commit

Permalink
[downloader:http] disable filename extension changes for ugoira
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Apr 26, 2021
1 parent e5123f5 commit 221015e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
17 changes: 10 additions & 7 deletions gallery_dl/downloader/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def _download_impl(self, url, pathfmt):
tries = 0
msg = ""

kwdict = pathfmt.kwdict
adjust_extension = kwdict.get(
"_http_adjust_extension", self.adjust_extension)

if self.part:
pathfmt.part_enable(self.partdir)

Expand All @@ -105,7 +109,7 @@ def _download_impl(self, url, pathfmt):
if self.headers:
headers.update(self.headers)
# file-specific headers
extra = pathfmt.kwdict.get("_http_headers")
extra = kwdict.get("_http_headers")
if extra:
headers.update(extra)

Expand Down Expand Up @@ -139,7 +143,7 @@ def _download_impl(self, url, pathfmt):
return False

# check for invalid responses
validate = pathfmt.kwdict.get("_http_validate")
validate = kwdict.get("_http_validate")
if validate and not validate(response):
self.log.warning("Invalid response")
return False
Expand Down Expand Up @@ -168,7 +172,7 @@ def _download_impl(self, url, pathfmt):
content = response.iter_content(self.chunk_size)

# check filename extension against file header
if self.adjust_extension and not offset and \
if adjust_extension and not offset and \
pathfmt.extension in FILE_SIGNATURES:
try:
file_header = next(
Expand Down Expand Up @@ -198,7 +202,7 @@ def _download_impl(self, url, pathfmt):
if file_header:
fp.write(file_header)
elif offset:
if self.adjust_extension and \
if adjust_extension and \
pathfmt.extension in FILE_SIGNATURES:
self._adjust_extension(pathfmt, fp.read(16))
fp.seek(offset)
Expand All @@ -222,10 +226,9 @@ def _download_impl(self, url, pathfmt):

self.downloading = False
if self.mtime:
pathfmt.kwdict.setdefault(
"_mtime", response.headers.get("Last-Modified"))
kwdict.setdefault("_mtime", response.headers.get("Last-Modified"))
else:
pathfmt.kwdict["_mtime"] = None
kwdict["_mtime"] = None

return True

Expand Down
1 change: 1 addition & 0 deletions gallery_dl/extractor/danbooru.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def items(self):
"{}/posts/{}.json?only=pixiv_ugoira_frame_data".format(
self.root, post["id"])
).json()["pixiv_ugoira_frame_data"]["data"]
post["_http_adjust_extension"] = False
else:
url = post["large_file_url"]
post["extension"] = "webm"
Expand Down
1 change: 1 addition & 0 deletions gallery_dl/extractor/pixiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def items(self):
url = ugoira["zip_urls"]["medium"].replace(
"_ugoira600x600", "_ugoira1920x1080")
work["frames"] = ugoira["frames"]
work["_http_adjust_extension"] = False
yield Message.Url, url, text.nameext_from_url(url, work)

elif work["page_count"] == 1:
Expand Down

0 comments on commit 221015e

Please sign in to comment.