Skip to content

Commit

Permalink
[imgbb] add extractor for individual images (closes #363)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Aug 5, 2019
1 parent ad3ac02 commit 189acbe
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
5 changes: 3 additions & 2 deletions docs/supportedsites.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ Hypnohub https://hypnohub.net/ Pools, Popular Images,
Idol Complex https://idol.sankakucomplex.com/ Pools, Posts, Tag-Searches Optional
ImageBam http://www.imagebam.com/ Galleries, individual Images
ImageFap https://imagefap.com/ Images from Users, Galleries, individual Images
ImgBB https://imgbb.com/ Images from Users, Albums Optional
ImgBB https://imgbb.com/ Images from Users, Albums, individual Images Optional
imgbox https://imgbox.com/ Galleries, individual Images
imgth https://imgth.com/ Galleries
imgur https://imgur.com/ Albums, individual Images
Instagram https://www.instagram.com/ Images from Users, individual Images, Tag-Searches Optional
Instagram https://www.instagram.com/ |instagram-C| Optional
Jaimini's Box https://jaiminisbox.com/reader/ Chapters, Manga
Joyreactor http://joyreactor.cc/ |joyreactor-C|
Keenspot http://www.keenspot.com/ Comics
Expand Down Expand Up @@ -135,6 +135,7 @@ Turboimagehost https://www.turboimagehost.com/ individual Images
.. |deviantart-C| replace:: Collections, Deviations, Favorites, Folders, Galleries, Journals, Popular Images, Scraps, Sta.sh
.. |flickr-C| replace:: Images from Users, Albums, Favorites, Galleries, Groups, individual Images, Search Results
.. |hentaifoundry-C| replace:: Images from Users, Favorites, individual Images, Popular Images, Recent Images, Scraps
.. |instagram-C| replace:: Images from Users, individual Images, Stories, Tag-Searches
.. |joyreactor-C| replace:: Images from Users, Posts, Search Results, Tag-Searches
.. |nijie-C| replace:: Images from Users, Doujin, Favorites, individual Images
.. |pixiv-C| replace:: Images from Users, Favorites, Follows, pixiv.me Links, Rankings, Search Results, Individual Images
Expand Down
33 changes: 32 additions & 1 deletion gallery_dl/extractor/imgbb.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class ImgbbExtractor(Extractor):
"""Base class for imgbb extractors"""
category = "imgbb"
directory_fmt = ("{category}", "{user}")
filename_fmt = "{title} {id}.{extension}"
archive_fmt = "{id}"
root = "https://imgbb.com"
Expand Down Expand Up @@ -145,7 +146,6 @@ def images(self, page):
class ImgbbUserExtractor(ImgbbExtractor):
"""Extractor for user profiles in imgbb.com"""
subcategory = "user"
directory_fmt = ("{category}", "{user}")
pattern = r"(?:https?://)?([^.]+)\.imgbb\.com/?(?:\?([^#]+))?$"
test = ("https://folkie.imgbb.com", {
"range": "1-80",
Expand Down Expand Up @@ -177,3 +177,34 @@ def images(self, page):
"params_hidden[userid]": user,
"params_hidden[from]" : "user",
})


class ImgbbImageExtractor(ImgbbExtractor):
subcategory = "image"
pattern = r"(?:https?://)?ibb\.co/(?!album/)([^/?&#]+)"
test = ("https://ibb.co/NLZHgqS", {
"url": "fbca86bac09de6fc0304054b2170b423ca1e84fa",
"keyword": "5d70e779bad03b2dc5273b627638045168671157",
})

def __init__(self, match):
ImgbbExtractor.__init__(self, match)
self.image_id = match.group(1)

def items(self):
url = "https://ibb.co/" + self.image_id
extr = text.extract_from(self.request(url).text)

image = {
"id" : self.image_id,
"title" : text.unescape(extr('"og:title" content="', '"')),
"url" : extr('"og:image" content="', '"'),
"width" : text.parse_int(extr('"og:image:width" content="', '"')),
"height": text.parse_int(extr('"og:image:height" content="', '"')),
"user" : extr('rel="author">', '<').lower(),
}
image["extension"] = text.ext_from_url(image["url"])

yield Message.Version, 1
yield Message.Directory, image
yield Message.Url, image["url"], image

0 comments on commit 189acbe

Please sign in to comment.