1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-23 11:12:40 +01:00
gallery-dl/gallery_dl/extractor/slideshare.py

88 lines
3.3 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2021-02-08 22:29:30 +01:00
# Copyright 2016-2021 Mike Fährmann, 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.
2021-04-15 17:15:59 +02:00
"""Extractors for https://www.slideshare.net/"""
from .common import Extractor, Message
from .. import text
2018-04-18 18:06:30 +02:00
class SlidesharePresentationExtractor(Extractor):
"""Extractor for images from a presentation on slideshare.net"""
category = "slideshare"
subcategory = "presentation"
directory_fmt = ("{category}", "{user}")
filename_fmt = "{presentation}-{num:>02}.{extension}"
archive_fmt = "{presentation}_{num}"
pattern = (r"(?:https?://)?(?:www\.)?slideshare\.net"
r"/(?:mobile/)?([^/?#]+)/([^/?#]+)")
test = (
(("https://www.slideshare.net"
"/Slideshare/get-started-with-slide-share"), {
"url": "23685fb9b94b32c77a547d45dc3a82fe7579ea18",
2021-11-01 02:58:53 +01:00
"content": "2e90a01c6ca225579ebf8f98ab46f97a28a5e45c",
}),
# long title
(("https://www.slideshare.net/pragmaticsolutions/warum-sie-nicht-ihren"
"-mitarbeitenden-ndern-sollten-sondern-ihr-managementsystem"), {
"url": "cf70ca99f57f61affab47ebf8583eb564b21e3a7",
}),
# mobile URL
(("https://www.slideshare.net"
"/mobile/uqudent/introduction-to-fixed-prosthodontics"), {
"url": "59993ad7b0cb93c73011547eedcd02c622649e9d",
}),
)
def __init__(self, match):
Extractor.__init__(self, match)
self.user, self.presentation = match.groups()
def items(self):
page = self.request("https://www.slideshare.net/" + self.user +
"/" + self.presentation).text
data = self.get_job_metadata(page)
imgs = self.get_image_urls(page)
data["count"] = len(imgs)
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, page):
"""Collect metadata for extractor-job"""
descr, pos = text.extract(
page, '<meta name="description" content="', '"')
2021-04-15 17:15:59 +02:00
category, pos = text.extract(
page, '<div class="metadata-item">', '</div>', pos)
views, pos = text.extract(
2021-04-15 17:15:59 +02:00
page, '<div class="metadata-item">', '</div>', pos)
published, pos = text.extract(
2021-04-15 17:15:59 +02:00
page, '<div class="metadata-item">', '</div>', pos)
title, pos = text.extract(
page, '<span class="j-title-breadcrumb">', '</span>', pos)
alt_descr, pos = text.extract(
2021-04-15 17:15:59 +02:00
page, '<p class="slideshow-description notranslate">', '</p>', pos)
if descr.endswith("") and alt_descr:
descr = text.remove_html(alt_descr).strip()
return {
"user": self.user,
"presentation": self.presentation,
"title": text.unescape(title.strip()),
"description": text.unescape(descr),
2021-04-15 17:15:59 +02:00
"views": text.parse_int(views.rpartition(
" views")[0].replace(",", "")),
"published": published.strip(),
}
@staticmethod
def get_image_urls(page):
"""Extract and return a list of all image-urls"""
return list(text.extract_iter(page, 'data-full="', '"'))