Skip to content

Commit

Permalink
[pixiv] add single work/illust extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Nov 22, 2015
1 parent 9251ea5 commit 2a97296
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion gallery_dl/extractor/pixiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import json
import time

class PixivExtractor(Extractor):
class PixivUserExtractor(Extractor):
"""Extract all works of a single pixiv-user"""

category = "pixiv"
directory_fmt = ["{category}", "{artist-id}-{artist-nick}"]
Expand Down Expand Up @@ -121,6 +122,31 @@ def get_job_metadata(self):
}


class PixivWorkExtractor(PixivUserExtractor):
"""Extract a single pixiv work/illustration"""

pattern = [(r"(?:https?://)?(?:www\.)?pixiv\.net/member(?:_illust)?\.php"
r"\?(?:[^&]+&)*illust_id=(\d+)")]

def __init__(self, match):
PixivUserExtractor.__init__(self, match)
self.illust_id = match.group(1)
self.work = None

def get_works(self):
url = self.work["image_urls"]["large"]
self.work["num"] = ""
self.work["url"] = url
self.work["extension"] = url[url.rfind(".")+1:]
return (self.work,)

def get_job_metadata(self):
"""Collect metadata for extractor-job"""
self.work = self.api.work(self.illust_id)["response"][0]
self.artist_id = self.work["user"]["id"]
return PixivUserExtractor.get_job_metadata(self)


def require_login(func):
"""Decorator: auto-login before api-calls"""
def wrap(self, *args):
Expand Down Expand Up @@ -193,6 +219,18 @@ def user(self, user_id):
)
return self._parse(response)

@require_login
def work(self, illust_id):
"""Query information about a single pixiv work/illustration"""
params = {
'image_sizes': 'large',
}
response = self.session.get(
"https://public-api.secure.pixiv.net/v1/works/"
"{illust}.json".format(illust=illust_id), params=params
)
return self._parse(response)

@require_login
def user_works(self, user_id, page, per_page=20):
"""Query information about the works of a pixiv user"""
Expand Down

0 comments on commit 2a97296

Please sign in to comment.