Skip to content

Commit

Permalink
[realbooru] fix videos and provide fallback URLs (#2530)
Browse files Browse the repository at this point in the history
revert acc94ac.
  • Loading branch information
mikf committed May 31, 2024
1 parent deacbcb commit 807e2f7
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion gallery_dl/extractor/gelbooru_v02.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _init(self):
self.api_root = self.config_instance("api_root") or self.root

if self.category == "realbooru":
self._file_url = self._file_url_realbooru
self.items = self._items_realbooru
self._tags = self._tags_realbooru

def _api_request(self, params):
Expand Down Expand Up @@ -124,6 +124,35 @@ def _file_url_realbooru(self, post):
self.root, md5[0:2], md5[2:4], md5, url.rpartition(".")[2])
return url

def _items_realbooru(self):
from .common import Message
data = self.metadata()

for post in self.posts():
try:
html = self._html(post)
fallback = post["file_url"]
url = post["file_url"] = text.rextract(
html, 'href="', '"', html.index(">Original<"))[0]
except Exception:
self.log.debug("Unable to fetch download URL for post %s "
"(md5: %s)", post.get("id"), post.get("md5"))
continue

text.nameext_from_url(url, post)
post.update(data)
self._prepare(post)
self._tags(post, html)

path = url.rpartition("/")[0]
post["_fallback"] = (
"{}/{}.{}".format(path, post["md5"], post["extension"]),
fallback,
)

yield Message.Directory, post
yield Message.Url, url, post

def _tags_realbooru(self, post, page):
tag_container = text.extr(page, 'id="tagLink"', '</div>')
tags = collections.defaultdict(list)
Expand Down

0 comments on commit 807e2f7

Please sign in to comment.