aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/recursive.py
blob: 4762fa57af0a96b5dfc417e8155e6db03ebf3476 (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
# -*- coding: utf-8 -*-

# Copyright 2015-2025 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.

"""Recursive extractor"""

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


class RecursiveExtractor(Extractor):
    """Extractor that fetches URLs from a remote or local source"""
    category = "recursive"
    pattern = r"r(?:ecursive)?:"
    example = "recursive:https://pastebin.com/raw/FLwrCYsT"

    def items(self):
        url = self.url.partition(":")[2]

        if url.startswith("file://"):
            with open(url[7:]) as fp:
                page = fp.read()
        else:
            page = self.request(text.ensure_http_scheme(url)).text

        for match in util.re(r"https?://[^\s\"']+").finditer(page):
            yield Message.Queue, match[0], {}