2017-12-13 17:38:29 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2023-09-11 16:30:55 +02:00
|
|
|
# Copyright 2016-2017 Leonardo Taccari
|
|
|
|
# Copyright 2017-2023 Mike Fährmann
|
2017-12-13 17:38:29 +01:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2021-04-15 17:15:59 +02:00
|
|
|
"""Extractors for https://www.slideshare.net/"""
|
2017-12-13 17:38:29 +01:00
|
|
|
|
2022-02-21 02:52:45 +01:00
|
|
|
from .common import GalleryExtractor
|
2023-02-07 23:14:53 +01:00
|
|
|
from .. import text, util
|
2017-12-13 17:38:29 +01:00
|
|
|
|
|
|
|
|
2022-02-21 02:52:45 +01:00
|
|
|
class SlidesharePresentationExtractor(GalleryExtractor):
|
2017-12-13 17:38:29 +01:00
|
|
|
"""Extractor for images from a presentation on slideshare.net"""
|
|
|
|
category = "slideshare"
|
|
|
|
subcategory = "presentation"
|
2019-02-08 13:45:40 +01:00
|
|
|
directory_fmt = ("{category}", "{user}")
|
2017-12-13 21:15:05 +01:00
|
|
|
filename_fmt = "{presentation}-{num:>02}.{extension}"
|
2018-01-30 22:49:16 +01:00
|
|
|
archive_fmt = "{presentation}_{num}"
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = (r"(?:https?://)?(?:www\.)?slideshare\.net"
|
2020-10-22 23:12:59 +02:00
|
|
|
r"/(?:mobile/)?([^/?#]+)/([^/?#]+)")
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://www.slideshare.net/USER/PRESENTATION"
|
2017-12-13 17:38:29 +01:00
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
self.user, self.presentation = match.groups()
|
2022-02-21 02:52:45 +01:00
|
|
|
url = "https://www.slideshare.net/{}/{}".format(
|
|
|
|
self.user, self.presentation)
|
|
|
|
GalleryExtractor.__init__(self, match, url)
|
2017-12-13 17:38:29 +01:00
|
|
|
|
2022-02-21 02:52:45 +01:00
|
|
|
def metadata(self, page):
|
2023-07-14 21:52:53 +02:00
|
|
|
data = util.json_loads(text.extr(
|
|
|
|
page, 'id="__NEXT_DATA__" type="application/json">', '</script>'))
|
|
|
|
self.slideshow = slideshow = data["props"]["pageProps"]["slideshow"]
|
2017-12-13 17:38:29 +01:00
|
|
|
|
2017-12-13 21:15:05 +01:00
|
|
|
return {
|
2023-07-14 21:52:53 +02:00
|
|
|
"user" : slideshow["username"],
|
2017-12-13 21:15:05 +01:00
|
|
|
"presentation": self.presentation,
|
2023-07-14 21:52:53 +02:00
|
|
|
"title" : slideshow["title"].strip(),
|
|
|
|
"description" : slideshow["description"].strip(),
|
|
|
|
"views" : slideshow["views"],
|
|
|
|
"likes" : slideshow["likes"],
|
|
|
|
"date" : text.parse_datetime(
|
|
|
|
slideshow["createdAt"], "%Y-%m-%d %H:%M:%S %Z"),
|
2017-12-13 21:15:05 +01:00
|
|
|
}
|
2017-12-13 17:38:29 +01:00
|
|
|
|
2023-07-14 21:52:53 +02:00
|
|
|
def images(self, page):
|
|
|
|
parts = self.slideshow["slideImages"][0]["baseUrl"].split("/")
|
2022-02-21 02:52:45 +01:00
|
|
|
|
2023-07-14 21:52:53 +02:00
|
|
|
begin = "{}/95/{}-".format(
|
|
|
|
"/".join(parts[:4]),
|
|
|
|
self.slideshow["strippedTitle"],
|
|
|
|
)
|
|
|
|
end = "-1024.jpg?" + parts[-1].rpartition("?")[2]
|
2022-02-21 02:52:45 +01:00
|
|
|
|
|
|
|
return [
|
|
|
|
(begin + str(n) + end, None)
|
2023-07-14 21:52:53 +02:00
|
|
|
for n in range(1, self.slideshow["totalSlides"]+1)
|
2022-02-21 02:52:45 +01:00
|
|
|
]
|