From 189acbeac95903771b5e27220f0a030ab5900f37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 5 Aug 2019 22:52:08 +0200 Subject: [PATCH] [imgbb] add extractor for individual images (closes #363) --- docs/supportedsites.rst | 5 +++-- gallery_dl/extractor/imgbb.py | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/docs/supportedsites.rst b/docs/supportedsites.rst index a37c5aae1a..cce36542d9 100644 --- a/docs/supportedsites.rst +++ b/docs/supportedsites.rst @@ -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 @@ -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 diff --git a/gallery_dl/extractor/imgbb.py b/gallery_dl/extractor/imgbb.py index 442634b3ee..4aa670b363 100644 --- a/gallery_dl/extractor/imgbb.py +++ b/gallery_dl/extractor/imgbb.py @@ -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" @@ -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", @@ -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