[speakerdeck] Add a new extractor for speakerdeck.com (#726)
This commit is contained in:
@@ -105,6 +105,7 @@ modules = [
|
||||
"slickpic",
|
||||
"slideshare",
|
||||
"smugmug",
|
||||
"speakerdeck",
|
||||
"tsumino",
|
||||
"tumblr",
|
||||
"twitter",
|
||||
|
||||
70
gallery_dl/extractor/speakerdeck.py
Normal file
70
gallery_dl/extractor/speakerdeck.py
Normal file
@@ -0,0 +1,70 @@
|
||||
# -*- 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.
|
||||
|
||||
"""Extract images from https://speakerdeck.com/"""
|
||||
|
||||
from .common import Extractor, Message
|
||||
from .. import text
|
||||
|
||||
|
||||
class SpeakerdeckPresentationExtractor(Extractor):
|
||||
"""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}"
|
||||
pattern = (r"(?:https?://)?(?:www\.)?speakerdeck\.com"
|
||||
r"/([^/?&#]+)/([^/?&#]+)")
|
||||
test = (
|
||||
(("https://speakerdeck.com/speakerdeck/introduction-to-speakerdeck"), {
|
||||
"url": "e97d4a7d5c64267e921c13eb7946d7074794a0d2",
|
||||
"content": "75c7abf0969b0bcab23e0da9712c95ee5113db3a",
|
||||
}),
|
||||
)
|
||||
|
||||
def __init__(self, match):
|
||||
Extractor.__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.Version, 1
|
||||
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"
|
||||
params = {
|
||||
"url": "https://speakerdeck.com/" + self.user +
|
||||
"/" + self.presentation,
|
||||
}
|
||||
|
||||
data = self.request(url, params=params).json()
|
||||
|
||||
self.presentation_id, pos = \
|
||||
text.extract(data["html"], 'src="//speakerdeck.com/player/', '"')
|
||||
|
||||
return {
|
||||
"user": self.user,
|
||||
"presentation": self.presentation,
|
||||
"presentation_id": self.presentation_id,
|
||||
"title": data["title"],
|
||||
"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
|
||||
return list(text.extract_iter(page, 'js-sd-slide" data-url="', '"'))
|
||||
@@ -80,6 +80,7 @@ CATEGORY_MAP = {
|
||||
"slickpic" : "SlickPic",
|
||||
"slideshare" : "SlideShare",
|
||||
"smugmug" : "SmugMug",
|
||||
"speakerdeck" : "Speaker Deck",
|
||||
"thebarchive" : "The /b/ Archive",
|
||||
"vanillarock" : "もえぴりあ",
|
||||
"vsco" : "VSCO",
|
||||
|
||||
Reference in New Issue
Block a user