Debian Codegraph @

gallery_dl/extractor/mixdrop.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License version 2 as
5 # published by the Free Software Foundation.
6
7 """Extractors for https://mixdrop.ag/"""
8
9 from .common import Extractor, Message
10 from .. import text
11
12 BASE_PATTERN = r"(?:https?://)?(?:www\.)?m[1i]xdrop\.(?:com|net|top|ag|bz)"
13
14
15 class MixdropFileExtractor(Extractor):
16 """Extractor for mixdrop files"""
17 category = "mixdrop"
18 subcategory = "file"
19 root = "https://mixdrop.ag"
20 filename_fmt = "{title} ({id}).{extension}"
21 archive_fmt = "{id}"
22 pattern = BASE_PATTERN + r"/[fe]/([^/?#]+)"
23 example = "https://mixdrop.ag/f/0123456789abcdef"
24
25 def items(self):
26 fid = self.groups[0]
27 page = self.request(f"{self.root}/e/{fid}").text
28 string, pos = text.extract(page, "}}return p}('", "'")
29 items = text.extract(page, ",'", "'.split(", pos)[0].split("|")
30 txt = text.re(r"\b\w+\b").sub(lambda m: items[int(m[0])], string)
31
32 data = text.nameext_from_name(text.extr(txt, '.vfile="', '"'), {
33 "id": fid,
34 "title": text.unescape(text.remove_html(text.extr(
35 page, '<div class="title">', "</div>"))),
36 "poster": text.ensure_http_scheme(text.extr(
37 txt, '.poster="', '"')),
38 })
39 yield Message.Directory, "", data
40 yield Message.Url, text.ensure_http_scheme(text.extr(
41 txt, '.wurl="', '"')), data