From 69fd61ea86501088875559f01dbf56f1a00eb1e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 13 Sep 2018 20:13:12 +0200 Subject: [PATCH] [bobx] add gallery and model extractors --- docs/supportedsites.rst | 1 + gallery_dl/extractor/__init__.py | 1 + gallery_dl/extractor/bobx.py | 114 +++++++++++++++++++++++++++++++ scripts/build_supportedsites.py | 1 + 4 files changed, 117 insertions(+) create mode 100644 gallery_dl/extractor/bobx.py diff --git a/docs/supportedsites.rst b/docs/supportedsites.rst index 88f5a7b3..8b8294bb 100644 --- a/docs/supportedsites.rst +++ b/docs/supportedsites.rst @@ -13,6 +13,7 @@ Archive of Sins https://archiveofsins.com/ Threads Archived.Moe https://archived.moe/ Threads ArtStation https://www.artstation.com/ |Images from Use-0| Behance https://www.behance.net/ Images from Users, Galleries +BobX http://www.bobx.com/dark/ Galleries, Models Danbooru https://danbooru.donmai.us/ Pools, Popular Images, Posts, Tag-Searches Desuarchive https://desuarchive.org/ Threads DeviantArt https://www.deviantart.com/ |Collections, De-1| Optional (OAuth) diff --git a/gallery_dl/extractor/__init__.py b/gallery_dl/extractor/__init__.py index 9176ed31..7036a6be 100644 --- a/gallery_dl/extractor/__init__.py +++ b/gallery_dl/extractor/__init__.py @@ -20,6 +20,7 @@ modules = [ "artstation", "b4k", "behance", + "bobx", "danbooru", "desuarchive", "deviantart", diff --git a/gallery_dl/extractor/bobx.py b/gallery_dl/extractor/bobx.py new file mode 100644 index 00000000..5ca3f79c --- /dev/null +++ b/gallery_dl/extractor/bobx.py @@ -0,0 +1,114 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 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 +# published by the Free Software Foundation. + +"""Extract images from http://www.bobx.com/dark/""" + +from .common import Extractor, Message +from .. import text + + +class BobxExtractor(Extractor): + """Base class for bobx extractors""" + category = "bobx" + root = "http://www.bobx.com" + per_page = 80 + + +class BobxGalleryExtractor(BobxExtractor): + """Extractor for individual image galleries on bobx.com""" + subcategory = "gallery" + directory_fmt = ["{category}", "{model}", "{title}"] + filename_fmt = "{model}_{image_id}_{num:>03}.{extension}" + archive_fmt = "{image_id}" + pattern = [r"(?:https?://)?(?:www\.)?bobx\.com" + r"/([^/]+/[^/]+/photoset/[\w-]+)-\d+-\d+-\d+\.html"] + test = [ + (("http://www.bobx.com/idol/mikoto-hibi" + "/photoset/wpb-2018-_11-0-2-8.html"), { + "url": "93972d6a661f6627e963d62c9d15531e6b36a389", + "keyword": "03505f6d3cdab7b5579431bfe8622eeffd36f533", + "content": "3f176b7fe752524cec21a763aa55567e41181e07", + }), + (("http://www.bobx.com/idol/nashiko-momotsuki" + "/photoset/wpb-net-_221---2018-08---magic-of-summer-0-10-10.html"), { + "url": "f5d6c0cd0881ae6f504c21a90d86e3464dc54e8e", + "keyword": "43395ac200deaaa50627da666bd02c8f1f86a59d", + }), + ] + + def __init__(self, match): + BobxExtractor.__init__(self) + self.path = match.group(1) + + def items(self): + num = 0 + while True: + url = "{}/{}-{}-10-8.html".format(self.root, self.path, num) + page = self.request(url, encoding="utf-8").text + + if num == 0: + data = self.metadata(page) + yield Message.Version, 1 + yield Message.Directory, data + data["num"] = 0 + + for url in self.images(page): + url = text.urljoin(self.root, url.replace("-preview-", "-")) + data = text.nameext_from_url(url, data) + data["image_id"] = text.parse_int( + data["name"].rpartition("-")[2]) + data["num"] += 1 + yield Message.Url, url, data + + num += self.per_page + if num >= data["count"]: + return + + @staticmethod + def metadata(page): + """Collect metadata for extractor-job""" + info = text.extract(page, "", "")[0] + model, _, info = info.partition(" in ") + info, _, count = info.rpartition(" of ") + title = info.rpartition(" - @")[0] + return { + "title": text.unquote(title), + "model": text.unquote(model), + "count": text.parse_int(count), + } + + @staticmethod + def images(page): + """Extract all image-urls""" + page = text.extract(page, "