Skip to content

Commit

Permalink
[bunkr] fix .mp4 downloads (closes #2239)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Jan 28, 2022
1 parent e2be199 commit ebd3d5c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
14 changes: 10 additions & 4 deletions gallery_dl/downloader/http.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

# Copyright 2014-2021 Mike Fährmann
# Copyright 2014-2022 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
Expand Down Expand Up @@ -148,9 +148,15 @@ def _download_impl(self, url, pathfmt):

# check for invalid responses
validate = kwdict.get("_http_validate")
if validate and not validate(response):
self.log.warning("Invalid response")
return False
if validate:
result = validate(response)
if isinstance(result, str):
url = result
tries -= 1
continue
if not result:
self.log.warning("Invalid response")
return False

# set missing filename extension from MIME type
if not pathfmt.extension:
Expand Down
22 changes: 21 additions & 1 deletion gallery_dl/extractor/lolisafe.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

# Copyright 2021 Mike Fährmann
# Copyright 2021-2022 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
Expand Down Expand Up @@ -42,6 +42,11 @@ class LolisafelbumExtractor(LolisafeExtractor):
"num": int,
},
}),
# mp4 (#2239)
("https://bunkr.is/a/ptRHaCn2", {
"pattern": r"https://cdn\.bunkr\.is/_-RnHoW69L\.mp4",
"content": "80e61d1dbc5896ae7ef9a28734c747b28b320471",
}),
("https://bunkr.to/a/Lktg9Keq"),
("https://zz.ht/a/lop7W6EZ", {
"pattern": r"https://z\.zz\.fo/(4anuY|ih560)\.png",
Expand All @@ -66,6 +71,11 @@ def items(self):
url = file["file"]
text.nameext_from_url(url, data)
data["name"], sep, data["id"] = data["filename"].rpartition("-")

if data["extension"] == "mp4":
data["_http_validate"] = self._check_rewrite
else:
data["_http_validate"] = None
yield Message.Url, url, data

def fetch_album(self, album_id):
Expand All @@ -77,3 +87,13 @@ def fetch_album(self, album_id):
"album_name": text.unescape(data["title"]),
"count" : data["count"],
}

@staticmethod
def _check_rewrite(response):
if response.history and response.headers.get(
"Content-Type").startswith("text/html"):
# consume content to reuse connection
response.content
# rewrite to download URL
return response.url.replace("/v/", "/d/", 1)
return True

0 comments on commit ebd3d5c

Please sign in to comment.