1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-23 19:22:32 +01:00
gallery-dl/gallery_dl/extractor/issuu.py

107 lines
3.6 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2022-04-10 14:23:10 +02:00
# Copyright 2019-2022 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.
"""Extractors for https://issuu.com/"""
from .common import GalleryExtractor, Extractor, Message
2022-04-10 14:23:10 +02:00
from .. import text
import json
class IssuuBase():
"""Base class for issuu extractors"""
category = "issuu"
root = "https://issuu.com"
class IssuuPublicationExtractor(IssuuBase, GalleryExtractor):
"""Extractor for a single publication"""
subcategory = "publication"
2022-04-10 14:23:10 +02:00
directory_fmt = ("{category}", "{document[username]}",
"{document[date]:%Y-%m-%d} {document[title]}")
filename_fmt = "{num:>03}.{extension}"
2022-04-10 14:23:10 +02:00
archive_fmt = "{document[publicationId]}_{num}"
pattern = r"(?:https?://)?issuu\.com(/[^/?#]+/docs/[^/?#]+)"
test = ("https://issuu.com/issuu/docs/motions-1-2019/", {
"pattern": r"https://image.isu.pub/190916155301-\w+/jpg/page_\d+.jpg",
"count" : 36,
"keyword": {
"document": {
2022-04-10 14:23:10 +02:00
"access" : "PUBLIC",
"contentRating" : {
"isAdsafe" : True,
"isExplicit": False,
"isReviewed": True,
},
2020-02-23 16:48:30 +01:00
"date" : "dt:2019-09-16 00:00:00",
2020-01-12 20:37:14 +01:00
"description" : "re:Motions, the brand new publication by I",
"documentName" : "motions-1-2019",
2022-04-10 14:23:10 +02:00
"downloadable" : False,
2020-01-12 20:37:14 +01:00
"pageCount" : 36,
"publicationId" : "d99ec95935f15091b040cb8060f05510",
"title" : "Motions by Issuu - Issue 1",
2022-04-10 14:23:10 +02:00
"username" : "issuu",
},
"extension": "jpg",
"filename" : r"re:page_\d+",
"num" : int,
},
})
def metadata(self, page):
data = json.loads(text.extract(
2022-04-10 14:23:10 +02:00
page, '<script data-json="', '"')[0].replace("&quot;", '"'))
2022-04-10 14:23:10 +02:00
doc = data["initialDocumentData"]["document"]
doc["date"] = text.parse_datetime(
2022-04-10 14:23:10 +02:00
doc["originalPublishDateInISOString"], "%Y-%m-%dT%H:%M:%S.%fZ")
self._cnt = text.parse_int(doc["pageCount"])
2022-04-10 14:23:10 +02:00
self._tpl = "https://{}/{}-{}/jpg/page_{{}}.jpg".format(
data["config"]["hosts"]["image"],
doc["revisionId"],
doc["publicationId"],
)
return {"document": doc}
def images(self, page):
fmt = self._tpl.format
return [(fmt(i), None) for i in range(1, self._cnt + 1)]
class IssuuUserExtractor(IssuuBase, Extractor):
"""Extractor for all publications of a user/publisher"""
subcategory = "user"
pattern = r"(?:https?://)?issuu\.com/([^/?#]+)/?$"
test = ("https://issuu.com/issuu", {
"pattern": IssuuPublicationExtractor.pattern,
"count" : "> 25",
})
def __init__(self, match):
Extractor.__init__(self, match)
self.user = match.group(1)
def items(self):
url = "{}/call/profile/v1/documents/{}".format(self.root, self.user)
params = {"offset": 0, "limit": "25"}
while True:
data = self.request(url, params=params).json()
for publication in data["items"]:
publication["url"] = "{}/{}/docs/{}".format(
self.root, self.user, publication["uri"])
publication["_extractor"] = IssuuPublicationExtractor
yield Message.Queue, publication["url"], publication
if not data["hasMore"]:
return
params["offset"] += data["limit"]