From 7b5711ee04b90f5eefb75c83f63cb78df22bd02c Mon Sep 17 00:00:00 2001
From: Bepis <36346617+bbepis@users.noreply.github.com>
Date: Tue, 19 May 2020 03:02:56 +1000
Subject: [PATCH] [imagechest] Add new extractor for ImageChest (#750)
* [imagechest] Add new extractor for ImageChest
* [imagechest] Fix flake8 compliance issues
---
gallery_dl/extractor/__init__.py | 1 +
gallery_dl/extractor/imagechest.py | 66 ++++++++++++++++++++++++++++++
scripts/supportedsites.py | 1 +
3 files changed, 68 insertions(+)
create mode 100644 gallery_dl/extractor/imagechest.py
diff --git a/gallery_dl/extractor/__init__.py b/gallery_dl/extractor/__init__.py
index bd59e6f2..cde59d61 100644
--- a/gallery_dl/extractor/__init__.py
+++ b/gallery_dl/extractor/__init__.py
@@ -48,6 +48,7 @@ modules = [
"hypnohub",
"idolcomplex",
"imagebam",
+ "imagechest",
"imagefap",
"imgbb",
"imgbox",
diff --git a/gallery_dl/extractor/imagechest.py b/gallery_dl/extractor/imagechest.py
new file mode 100644
index 00000000..b2e8068d
--- /dev/null
+++ b/gallery_dl/extractor/imagechest.py
@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2014-2020 Leonid "Bepis" Pavel
+#
+# 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 galleries at https://imgchest.com/"""
+
+from .common import GalleryExtractor
+from .. import text, exception
+import re
+
+
+class ImagechestGalleryExtractor(GalleryExtractor):
+ """Extractor for image galleries from imgchest.com"""
+
+ category = "imagechest"
+ root = "https://imgchest.com"
+
+ pattern = r"(?:https?://)?(?:www\.)?imgchest\.com/p/([A-Za-z0-9]{11})"
+ test = (
+ ("https://imgchest.com/p/3na7kr3by8d", {
+ "url": "f095b4f78c051e5a94e7c663814d1e8d4c93c1f7",
+ "content": "076959e65be30249a2c651fbe6090dc30ba85193",
+ "count": 3
+ }),
+ )
+
+ def __init__(self, match):
+
+ self.gallery_id = match.group(1)
+ url = self.root + "/p/" + self.gallery_id
+
+ GalleryExtractor.__init__(self, match, url)
+
+ def metadata(self, page):
+ """Return a dict with general metadata"""
+
+ if "Sorry, but the page you requested could not be found." in page:
+ raise exception.NotFoundError("gallery")
+
+ title_match = re.search(
+ r'',
+ page)
+
+ title = title_match.group(1).strip()
+
+ return {
+ "gallery_id": self.gallery_id,
+ "title": text.unescape(title)
+ }
+
+ def images(self, page):
+ """Return a list of all (image-url, metadata)-tuples"""
+
+ image_keys = re.findall(
+ r'',
+ page)
+
+ for imgurl in image_keys:
+
+ data = text.nameext_from_url(imgurl)
+
+ yield imgurl, data
diff --git a/scripts/supportedsites.py b/scripts/supportedsites.py
index f3c27c23..45a0d33f 100755
--- a/scripts/supportedsites.py
+++ b/scripts/supportedsites.py
@@ -44,6 +44,7 @@ CATEGORY_MAP = {
"imagefap" : "ImageFap",
"imgbb" : "ImgBB",
"imgbox" : "imgbox",
+ "imagechest" : "ImageChest",
"imgth" : "imgth",
"imgur" : "imgur",
"jaiminisbox" : "Jaimini's Box",