From 44d98e562ba348037866ad986f389b989f1c425c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 25 Jun 2017 20:18:27 +0200 Subject: [PATCH] [pixiv] support pixiv.me URLs (#23) --- gallery_dl/extractor/pixiv.py | 37 +++++++++++++++++++++++++++++++---- test/test_extractors.py | 2 +- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/gallery_dl/extractor/pixiv.py b/gallery_dl/extractor/pixiv.py index 0bb9cb9c..dbb3feef 100644 --- a/gallery_dl/extractor/pixiv.py +++ b/gallery_dl/extractor/pixiv.py @@ -140,15 +140,44 @@ class PixivUserExtractor(PixivExtractor): def __init__(self, match): PixivExtractor.__init__(self) self.user_id, tag = match.groups() - self.tag = tag.lower() if tag else None + if tag: + self.tag = tag.lower() + self.works = self._tagged_works def works(self): + return self.api.user_works(self.user_id) + + def _tagged_works(self): for work in self.api.user_works(self.user_id): - if (not self.tag or - self.tag in [tag.lower() for tag in work["tags"]]): + if self.tag in [tag.lower() for tag in work["tags"]]: yield work +class PixivMeExtractor(PixivExtractor): + """Extractor for pixiv.me URLs""" + subcategory = "me" + pattern = [r"(?:https?://)?pixiv\.me/([^/?&#]+)"] + test = [ + ("https://pixiv.me/del_shannon", { + "url": "0b1a18c3e3553c44ee6e0ccc36a7fd906c498e8f", + }), + ("https://pixiv.me/del_shanno", { + "exception": exception.NotFoundError, + }), + ] + + def __init__(self, match): + PixivExtractor.__init__(self) + self.account = match.group(1) + + def items(self): + response = self.session.head("https://pixiv.me/" + self.account) + if response.status_code == 404: + raise exception.NotFoundError("user") + yield Message.Version, 1 + yield Message.Queue, response.headers["Location"] + + class PixivWorkExtractor(PixivExtractor): """Extractor for a single pixiv work/illustration""" subcategory = "work" @@ -158,7 +187,7 @@ class PixivWorkExtractor(PixivExtractor): r"(?:(?:.*/)?img-[^/]+/img/\d{4}(?:/\d\d){5}" r"|img\d+/img/[^/]+)/(\d+)"), (r"(?:https?://)?img\d*\.pixiv\.net/img/[^/]+/(\d+)"), - (r"(?:https?://)?(?:www\.)?pixiv\.net/i/(\d+)"),] + (r"(?:https?://)?(?:www\.)?pixiv\.net/i/(\d+)")] test = [ (("http://www.pixiv.net/member_illust.php" "?mode=medium&illust_id=966412"), { diff --git a/test/test_extractors.py b/test/test_extractors.py index 03f75ba2..46f43f0a 100644 --- a/test/test_extractors.py +++ b/test/test_extractors.py @@ -54,7 +54,7 @@ skip = [ # dont work on travis-ci "exhentai", "kissmanga", "mangafox", "dynastyscans", "nijie", # temporary issues - "hbrowse", + "chronos", "coreimg", ] # enable selective testing for direct calls if __name__ == '__main__' and len(sys.argv) > 1: