| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
# Copyright 2020 Leonardo Taccari |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License version 2 as |
| 7 |
# published by the Free Software Foundation. |
| 8 |
|
| 9 |
"""Extractors for https://speakerdeck.com/""" |
| 10 |
|
| 11 |
from .common import GalleryExtractor |
| 12 |
from .. import text |
| 13 |
|
| 14 |
|
| 15 |
class SpeakerdeckPresentationExtractor(GalleryExtractor): |
| 16 |
"""Extractor for images from a presentation on speakerdeck.com""" |
| 17 |
category = "speakerdeck" |
| 18 |
subcategory = "presentation" |
| 19 |
directory_fmt = ("{category}", "{user}") |
| 20 |
filename_fmt = "{presentation}-{num:>02}.{extension}" |
| 21 |
archive_fmt = "{presentation}_{num}" |
| 22 |
root = "https://speakerdeck.com" |
| 23 |
pattern = r"(?:https?://)?(?:www\.)?speakerdeck\.com/([^/?#]+)/([^/?#]+)" |
| 24 |
example = "https://speakerdeck.com/USER/PRESENTATION" |
| 25 |
|
| 26 |
def metadata(self, _): |
| 27 |
user, presentation = self.groups |
| 28 |
|
| 29 |
url = self.root + "/oembed.json" |
| 30 |
params = { |
| 31 |
"url": f"{self.root}/{user}/{presentation}", |
| 32 |
} |
| 33 |
data = self.request_json(url, params=params) |
| 34 |
|
| 35 |
self.presentation_id = text.extr( |
| 36 |
data["html"], 'src="//speakerdeck.com/player/', '"') |
| 37 |
|
| 38 |
return { |
| 39 |
"user": user, |
| 40 |
"presentation": presentation, |
| 41 |
"presentation_id": self.presentation_id, |
| 42 |
"title": data["title"], |
| 43 |
"author": data["author_name"], |
| 44 |
} |
| 45 |
|
| 46 |
def images(self, _): |
| 47 |
url = f"{self.root}/player/{self.presentation_id}" |
| 48 |
page = self.request(url).text |
| 49 |
page = text.re(r"\s+").sub(" ", page) |
| 50 |
return [ |
| 51 |
(url, None) |
| 52 |
for url in text.extract_iter(page, 'js-sd-slide" data-url="', '"') |
| 53 |
] |