Debian Codegraph @

gallery_dl/extractor/recursive.py

raw
1 # -*- coding: utf-8 -*-
2
3 # Copyright 2015-2025 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 """Recursive extractor"""
10
11 from .common import Extractor, Message
12 from .. import text
13
14
15 class RecursiveExtractor(Extractor):
16 """Extractor that fetches URLs from a remote or local source"""
17 category = "recursive"
18 pattern = r"r(?:ecursive)?:"
19 example = "recursive:https://pastebin.com/raw/FLwrCYsT"
20
21 def items(self):
22 url = self.url.partition(":")[2]
23
24 if url.startswith("file://"):
25 with open(url[7:], encoding="utf-8") as fp:
26 page = fp.read()
27 else:
28 page = self.request(text.ensure_http_scheme(url)).text
29
30 for match in text.re(r"https?://[^\s\"']+").finditer(page):
31 yield Message.Queue, match[0], {}