2017-12-13 17:38:29 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2023-02-07 23:14:53 +01:00
|
|
|
# Copyright 2016-2023 Mike Fährmann, Leonardo Taccari
|
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/)?([^/?#]+)/([^/?#]+)")
|
2019-02-08 13:45:40 +01:00
|
|
|
test = (
|
2018-01-10 14:11:54 +01:00
|
|
|
(("https://www.slideshare.net"
|
|
|
|
"/Slideshare/get-started-with-slide-share"), {
|
2022-02-21 02:52:45 +01:00
|
|
|
"pattern": r"https://image\.slidesharecdn\.com/getstartedwithslide"
|
|
|
|
r"share-150520173821-lva1-app6892/95/get-started-with-s"
|
|
|
|
r"lide-share-\d+-1024\.jpg\?cb=\d+",
|
|
|
|
"count": 19,
|
|
|
|
"content": "2b6a191eab60b3978fdacfecf2da302dd45bc108",
|
|
|
|
"keyword": {
|
|
|
|
"comments": "0",
|
|
|
|
"description": "Get Started with SlideShare - "
|
|
|
|
"A Beginngers Guide for Creators",
|
|
|
|
"likes": r"re:\d{3,}",
|
|
|
|
"presentation": "get-started-with-slide-share",
|
|
|
|
"published": "dt:2015-05-20 00:00:00",
|
|
|
|
"title": "Getting Started With SlideShare",
|
|
|
|
"user": "Slideshare",
|
|
|
|
"views": r"re:\d{7,}",
|
|
|
|
},
|
2017-12-13 17:38:29 +01:00
|
|
|
}),
|
2022-02-21 02:52:45 +01:00
|
|
|
# long title and description
|
2017-12-13 21:15:05 +01:00
|
|
|
(("https://www.slideshare.net/pragmaticsolutions/warum-sie-nicht-ihren"
|
|
|
|
"-mitarbeitenden-ndern-sollten-sondern-ihr-managementsystem"), {
|
|
|
|
"url": "cf70ca99f57f61affab47ebf8583eb564b21e3a7",
|
2022-02-21 02:52:45 +01:00
|
|
|
"keyword": {
|
|
|
|
"title": "Warum Sie nicht Ihren Mitarbeitenden ändern "
|
|
|
|
"sollten, sondern Ihr Managementsystem",
|
|
|
|
"description": "Mitarbeitende verhalten sich mehrheitlich so, "
|
|
|
|
"wie das System es ihnen vorgibt. Welche Voraus"
|
|
|
|
"setzungen es braucht, damit Ihre Mitarbeitende"
|
|
|
|
"n ihr ganzes Herzblut einsetzen, bespricht Fre"
|
|
|
|
"di Schmidli in diesem Referat.",
|
|
|
|
},
|
2017-12-13 21:15:05 +01:00
|
|
|
}),
|
2018-01-10 14:11:54 +01:00
|
|
|
# mobile URL
|
|
|
|
(("https://www.slideshare.net"
|
|
|
|
"/mobile/uqudent/introduction-to-fixed-prosthodontics"), {
|
2022-08-28 10:52:28 +02:00
|
|
|
"url": "43eda2adf4dd221a251c8df794dfb82649e94647",
|
2018-01-10 14:11:54 +01:00
|
|
|
}),
|
2019-02-08 13:45:40 +01:00
|
|
|
)
|
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):
|
|
|
|
extr = text.extract_from(page)
|
|
|
|
descr = extr('<meta name="description" content="', '"')
|
|
|
|
comments = extr('content="UserComments:', '"')
|
|
|
|
likes = extr('content="UserLikes:', '"')
|
|
|
|
views = extr('content="UserPageVisits:', '"')
|
2022-08-28 10:52:28 +02:00
|
|
|
title = extr('<span class="j-title-breadcrumb">', '</span>')
|
|
|
|
published = extr('<div class="metadata-item">', '</div>')
|
2017-12-13 17:38:29 +01:00
|
|
|
|
2022-02-21 02:52:45 +01:00
|
|
|
if descr.endswith("…"):
|
2022-08-28 10:52:28 +02:00
|
|
|
alt_descr = extr('slideshow-description-text"', '</p>')
|
2022-02-21 02:52:45 +01:00
|
|
|
if alt_descr:
|
2022-07-12 18:38:44 +02:00
|
|
|
descr = text.remove_html(alt_descr.partition(">")[2]).strip()
|
2017-12-13 17:38:29 +01:00
|
|
|
|
2017-12-13 21:15:05 +01:00
|
|
|
return {
|
|
|
|
"user": self.user,
|
|
|
|
"presentation": self.presentation,
|
|
|
|
"title": text.unescape(title.strip()),
|
|
|
|
"description": text.unescape(descr),
|
2022-02-21 02:52:45 +01:00
|
|
|
"views": views,
|
|
|
|
"likes": likes,
|
|
|
|
"comments": comments,
|
|
|
|
"published": text.parse_datetime(
|
|
|
|
published.strip(), "%b. %d, %Y"),
|
2017-12-13 21:15:05 +01:00
|
|
|
}
|
2017-12-13 17:38:29 +01:00
|
|
|
|
|
|
|
@staticmethod
|
2022-02-21 02:52:45 +01:00
|
|
|
def images(page):
|
2023-02-07 23:14:53 +01:00
|
|
|
data = util.json_loads(text.extract(
|
2022-02-21 02:52:45 +01:00
|
|
|
page, "xtend(true, slideshare_object.slideshow_config, ", ");")[0])
|
|
|
|
|
|
|
|
# useing 'stripped_title' here is technically wrong, but it works all
|
|
|
|
# the same, slideshare doesn't seem to care what characters go there
|
|
|
|
begin = "https://image.slidesharecdn.com/{}/95/{}-".format(
|
|
|
|
data["ppt_location"], data["stripped_title"])
|
|
|
|
end = "-1024.jpg?cb=" + str(data["timestamp"])
|
|
|
|
|
|
|
|
return [
|
|
|
|
(begin + str(n) + end, None)
|
|
|
|
for n in range(1, data["slide_count"]+1)
|
|
|
|
]
|