aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/webmshare.py
blob: 7e2b5ea32282fbc27ad809e7cbd5ca8009a842ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-

# Copyright 2022-2023 Mike Fährmann
#
# 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.

"""Extractors for https://webmshare.com/"""

from .common import Extractor, Message
from .. import text


class WebmshareVideoExtractor(Extractor):
    """Extractor for webmshare videos"""
    category = "webmshare"
    subcategory = "video"
    root = "https://webmshare.com"
    filename_fmt = "{id}{title:? //}.{extension}"
    archive_fmt = "{id}"
    pattern = (r"(?:https?://)?(?:s\d+\.)?webmshare\.com"
               r"/(?:play/|download-webm/)?(\w{3,})")
    example = "https://webmshare.com/_ID_"

    def __init__(self, match):
        Extractor.__init__(self, match)
        self.video_id = match.group(1)

    def items(self):
        url = "{}/{}".format(self.root, self.video_id)
        extr = text.extract_from(self.request(url).text)

        data = {
            "title": text.unescape(extr(
                'property="og:title" content="', '"').rpartition(" — ")[0]),
            "thumb": "https:" + extr('property="og:image" content="', '"'),
            "url"  : "https:" + extr('property="og:video" content="', '"'),
            "width": text.parse_int(extr(
                'property="og:video:width" content="', '"')),
            "height": text.parse_int(extr(
                'property="og:video:height" content="', '"')),
            "date" : text.parse_datetime(extr(
                "<small>Added ", "<"), "%B %d, %Y"),
            "views": text.parse_int(extr('glyphicon-eye-open"></span>', '<')),
            "id"       : self.video_id,
            "filename" : self.video_id,
            "extension": "webm",
        }

        if data["title"] == "webmshare":
            data["title"] = ""

        yield Message.Directory, data
        yield Message.Url, data["url"], data