2020-05-01 22:32:22 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright 2020 Leonardo Taccari
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2023-09-11 16:30:55 +02:00
|
|
|
"""Extractors for https://speakerdeck.com/"""
|
2020-05-01 22:32:22 +02:00
|
|
|
|
2024-06-15 21:56:51 +02:00
|
|
|
from .common import GalleryExtractor
|
2020-05-01 22:32:22 +02:00
|
|
|
from .. import text
|
2024-06-13 13:22:12 +02:00
|
|
|
import re
|
2020-05-01 22:32:22 +02:00
|
|
|
|
|
|
|
|
2024-06-15 21:56:51 +02:00
|
|
|
class SpeakerdeckPresentationExtractor(GalleryExtractor):
|
2020-05-01 22:32:22 +02:00
|
|
|
"""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}"
|
2024-06-15 21:56:51 +02:00
|
|
|
root = "https://speakerdeck.com"
|
2023-09-11 16:30:55 +02:00
|
|
|
pattern = r"(?:https?://)?(?:www\.)?speakerdeck\.com/([^/?#]+)/([^/?#]+)"
|
|
|
|
example = "https://speakerdeck.com/USER/PRESENTATION"
|
2020-05-01 22:32:22 +02:00
|
|
|
|
|
|
|
def __init__(self, match):
|
2024-06-15 21:56:51 +02:00
|
|
|
GalleryExtractor.__init__(self, match, "")
|
2020-05-01 22:32:22 +02:00
|
|
|
self.user, self.presentation = match.groups()
|
|
|
|
|
2024-06-15 21:56:51 +02:00
|
|
|
def metadata(self, _):
|
|
|
|
url = self.root + "/oembed.json"
|
2020-05-01 22:32:22 +02:00
|
|
|
params = {
|
2024-06-15 21:56:51 +02:00
|
|
|
"url": "{}/{}/{}".format(self.root, self.user, self.presentation),
|
2020-05-01 22:32:22 +02:00
|
|
|
}
|
|
|
|
data = self.request(url, params=params).json()
|
|
|
|
|
2024-06-15 21:56:51 +02:00
|
|
|
self.presentation_id = text.extr(
|
|
|
|
data["html"], 'src="//speakerdeck.com/player/', '"')
|
2020-05-01 22:32:22 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
"user": self.user,
|
|
|
|
"presentation": self.presentation,
|
|
|
|
"presentation_id": self.presentation_id,
|
|
|
|
"title": data["title"],
|
|
|
|
"author": data["author_name"],
|
|
|
|
}
|
|
|
|
|
2024-06-15 21:56:51 +02:00
|
|
|
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="', '"')
|
|
|
|
]
|