Debian Codegraph @

gallery_dl/extractor/webmshare.py

raw
1 # -*- coding: utf-8 -*-
2
3 # Copyright 2022-2026 Mike Fährmann
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 2 as
7 # published by the Free Software Foundation.
8
9 """Extractors for https://webmshare.com/"""
10
11 from .common import Extractor, Message
12 from .. import text
13
14
15 class WebmshareExtractor(Extractor):
16 """Base class for webmshare extractors"""
17 category = "webmshare"
18 root = "https://webmshare.com"
19
20 def _init(self):
21 if not self.cookies.get("is_adult", domain="webmshare.com"):
22 self.cookies.set(
23 "is_adult", "eyJpdiI6Iis4UmlSK1wvM3ZRTVwvQ0lEVmtaU3hFdz09Iiwid"
24 "mFsdWUiOiJKR0tRUytMeHh1ekhZRTN2STg3VEV3PT0iLCJtYWMiOiI5OTE0N2"
25 "VhMGNmOTM3ZDc5OTZkNzNiOWI2NzI2YWExOTRhYjBkNDlkZTJhMjk5YzVlZDc"
26 "xOTRmNGM2NThmNzM2In0%3D", domain="webmshare.com")
27
28
29 class WebmshareSearchExtractor(WebmshareExtractor):
30 """Extractor for webmshare search results"""
31 subcategory = "search"
32 pattern = r"(?:https?://)?webmshare\.com/results\?q=([^&#]+)"
33 example = "https://webmshare.com/results?q=QUERY"
34
35 def items(self):
36 query = self.groups[0]
37 tags = text.unquote(query)
38 page = self.request(f"{self.root}/results?q={query}").text
39
40 if not tags.strip():
41 self.log.warning("Empty search query")
42
43 data = {
44 "_extractor" : WebmshareVideoExtractor,
45 "search_tags": tags,
46 }
47
48 base = self.root + "/"
49 for video_id in text.extract_iter(page, '<a href="/', '"'):
50 yield Message.Queue, base + video_id, data
51
52
53 class WebmshareVideoExtractor(WebmshareExtractor):
54 """Extractor for webmshare videos"""
55 subcategory = "video"
56 filename_fmt = "{id}{title:? //}.{extension}"
57 archive_fmt = "{id}"
58 pattern = (r"(?:https?://)?(?:s\d+\.)?webmshare\.com"
59 r"/(?:play/|download-webm/)?(\w{3,})")
60 example = "https://webmshare.com/_ID_"
61
62 def items(self):
63 video_id = self.groups[0]
64 url = f"{self.root}/{video_id}"
65 extr = text.extract_from(self.request(url).text)
66
67 title = extr('property="og:title" content="', '"')
68 if not title:
69 url_r18 = self.root + "/is_adult"
70 data = {
71 "url_to_go": text.unescape(extr(
72 'name="url_to_go" value="', '"')),
73 "_token" : text.unescape(extr(
74 'name="_token" value="', '"')),
75 }
76 response = self.request(url_r18, method="POST", data=data)
77 extr = text.extract_from(response.text)
78 title = extr('property="og:title" content="', '"')
79
80 data = {
81 "title": text.unescape(title.rpartition(" — ")[0]),
82 "thumb": "https:" + extr('property="og:image" content="', '"'),
83 "url" : "https:" + extr('property="og:video" content="', '"'),
84 "width": text.parse_int(extr(
85 'property="og:video:width" content="', '"')),
86 "height": text.parse_int(extr(
87 'property="og:video:height" content="', '"')),
88 "date" : self.parse_datetime(extr(
89 "<small>Added ", "<"), "%B %d, %Y"),
90 "views": text.parse_int(extr('glyphicon-eye-open"></span>', '<')),
91 "id" : video_id,
92 "filename" : video_id,
93 "extension": "webm",
94 }
95
96 if data["title"] == "webmshare":
97 data["title"] = ""
98
99 yield Message.Directory, "", data
100 yield Message.Url, data["url"], data