From 677c8ced1172abd9675c2053a25854f20d39b974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Wed, 10 May 2017 17:21:33 +0200 Subject: [PATCH] [deviantart] add "journal" extractor (#14) --- docs/supportedsites.rst | 2 +- gallery_dl/extractor/deviantart.py | 41 +++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/docs/supportedsites.rst b/docs/supportedsites.rst index ef3cecf8..10912d70 100644 --- a/docs/supportedsites.rst +++ b/docs/supportedsites.rst @@ -13,7 +13,7 @@ Supported Sites +-------------------+---------------------------------------+----------------------------------------------------------+ |Danbooru |https://danbooru.donmai.us/ |Pools, Posts, Tag-Searches | +-------------------+---------------------------------------+----------------------------------------------------------+ -|DeviantArt |https://www.deviantart.com/ |Images from Users, Favorites, individual Images | +|DeviantArt |https://www.deviantart.com/ |Deviations, Favorites, Galleries, Journals | +-------------------+---------------------------------------+----------------------------------------------------------+ |Doki Reader |https://kobato.hologfx.com/ |Chapters, Manga | +-------------------+---------------------------------------+----------------------------------------------------------+ diff --git a/gallery_dl/extractor/deviantart.py b/gallery_dl/extractor/deviantart.py index 1412927c..b32a64d5 100644 --- a/gallery_dl/extractor/deviantart.py +++ b/gallery_dl/extractor/deviantart.py @@ -61,10 +61,18 @@ class DeviantartExtractor(Extractor): dev = self.api.deviation_content(deviation["deviationid"]) deviation["extension"] = "htm" + if "css" in dev: + css = dev["css"] + cssclass = "withskin" + else: + css = "" + cssclass = "journal-green" + html = JOURNAL_TEMPLATE.format( title=text.escape(deviation["title"]), html=dev["html"], - css=dev["css"] if "css" in dev else "", + css=css, + cls=cssclass, ) yield Message.Url, html, deviation @@ -97,7 +105,7 @@ class DeviantartExtractor(Extractor): class DeviantartGalleryExtractor(DeviantartExtractor): """Extractor for all deviations from an artist's gallery""" subcategory = "gallery" - pattern = [r"(?:https?://)?([^\.]+)\.deviantart\.com(?:/gallery)?/?$"] + pattern = [r"(?:https?://)?([^.]+)\.deviantart\.com(?:/gallery)?/?$"] test = [("http://shimoda7.deviantart.com/gallery/", { "url": "63bfa8efba199e27181943c9060f6770f91a8441", "keyword": "b02f5487481142ca44c22542333191aa2cdfb7ee", @@ -114,7 +122,8 @@ class DeviantartGalleryExtractor(DeviantartExtractor): class DeviantartDeviationExtractor(DeviantartExtractor): """Extractor for single deviations""" subcategory = "deviation" - pattern = [r"(?:https?://)?([^\.]+\.deviantart\.com/art/.+-\d+)", + pattern = [(r"(?:https?://)?([^\.]+\.deviantart\.com/" + r"(?:art|journal)/[^/?&#]+-\d+)"), r"(?:https?://)?(sta\.sh/[a-z0-9]+)"] test = [ (("http://shimoda7.deviantart.com/art/" @@ -202,6 +211,23 @@ class DeviantartFavoriteExtractor(DeviantartExtractor): deviation["collection"] = self.collection +class DeviantartJournalExtractor(DeviantartExtractor): + """Extractor for single deviations""" + subcategory = "journal" + pattern = [r"(?:https?://)?([^.]+)\.deviantart\.com/journal/?$"] + test = [("http://shimoda7.deviantart.com/journal/", { + "url": "05204bddf5ebba330d73cec76bcd55b1249c6159", + "keyword": "8434f8bdd4b38634e206c8689a0906ac10c3fa77", + })] + + def __init__(self, match): + DeviantartExtractor.__init__(self) + self.user = match.group(1) + + def deviations(self): + return self.api.browse_user_journals(self.user, self.offset) + + class DeviantartAPI(): """Minimal interface for the deviantart API""" def __init__(self, extractor, client_id="5388", @@ -216,6 +242,13 @@ class DeviantartAPI(): if not isinstance(self.mature, str): self.mature = "true" if self.mature else "false" + def browse_user_journals(self, username, offset=0): + """Yield all journal entries of a specific user""" + endpoint = "browse/user/journals" + params = {"username": username, "offset": offset, "limit": 10, + "mature_content": self.mature, "featured": "false"} + return self._pagination(endpoint, params) + def collections(self, username, folder_id, offset=0): """Yield all Deviation-objects contained in a collection folder""" endpoint = "collections/" + folder_id @@ -343,7 +376,7 @@ roses/cssmin/desktop.css?1491362542749" >
-
+
{html}