1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-25 04:02:32 +01:00

[speakerdeck] inherit from GalleryExtractor

This commit is contained in:
Mike Fährmann 2024-06-15 21:56:51 +02:00
parent 4ffaa7fabf
commit ae3706286a
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 24 additions and 26 deletions

View File

@ -8,46 +8,35 @@
"""Extractors for https://speakerdeck.com/"""
from .common import Extractor, Message
from .common import GalleryExtractor
from .. import text
import re
class SpeakerdeckPresentationExtractor(Extractor):
class SpeakerdeckPresentationExtractor(GalleryExtractor):
"""Extractor for images from a presentation on speakerdeck.com"""
category = "speakerdeck"
subcategory = "presentation"
directory_fmt = ("{category}", "{user}")
filename_fmt = "{presentation}-{num:>02}.{extension}"
archive_fmt = "{presentation}_{num}"
root = "https://speakerdeck.com"
pattern = r"(?:https?://)?(?:www\.)?speakerdeck\.com/([^/?#]+)/([^/?#]+)"
example = "https://speakerdeck.com/USER/PRESENTATION"
def __init__(self, match):
Extractor.__init__(self, match)
GalleryExtractor.__init__(self, match, "")
self.user, self.presentation = match.groups()
self.presentation_id = None
def items(self):
data = self.get_job_metadata()
imgs = self.get_image_urls()
data["count"] = len(imgs)
yield Message.Directory, data
for data["num"], url in enumerate(imgs, 1):
yield Message.Url, url, text.nameext_from_url(url, data)
def get_job_metadata(self):
"""Collect metadata for extractor-job"""
url = "https://speakerdeck.com/oembed.json"
def metadata(self, _):
url = self.root + "/oembed.json"
params = {
"url": "https://speakerdeck.com/" + self.user +
"/" + self.presentation,
"url": "{}/{}/{}".format(self.root, self.user, self.presentation),
}
data = self.request(url, params=params).json()
self.presentation_id, pos = \
text.extract(data["html"], 'src="//speakerdeck.com/player/', '"')
self.presentation_id = text.extr(
data["html"], 'src="//speakerdeck.com/player/', '"')
return {
"user": self.user,
@ -57,9 +46,10 @@ class SpeakerdeckPresentationExtractor(Extractor):
"author": data["author_name"],
}
def get_image_urls(self):
"""Extract and return a list of all image-urls"""
page = self.request("https://speakerdeck.com/player/" +
self.presentation_id).text
page = re.sub(r"\s+", " ", page)
return list(text.extract_iter(page, 'js-sd-slide" data-url="', '"'))
def images(self, _):
url = "{}/player/{}".format(self.root, self.presentation_id)
page = re.sub(r"\s+", " ", self.request(url).text)
return [
(url, None)
for url in text.extract_iter(page, 'js-sd-slide" data-url="', '"')
]

View File

@ -15,6 +15,14 @@ __tests__ = (
"#pattern" : r"https://files.speakerdeck.com/presentations/50021f75cf1db900020005e7/slide_\d+.jpg",
"#count" : 6,
"#sha1_content": "75c7abf0969b0bcab23e0da9712c95ee5113db3a",
"author" : "Speaker Deck",
"count" : 6,
"num" : range(1, 6),
"presentation" : "introduction-to-speakerdeck",
"presentation_id": "50021f75cf1db900020005e7",
"title" : "Introduction to SpeakerDeck",
"user" : "speakerdeck",
},
)