mirror of
https://github.com/mikf/gallery-dl.git
synced 2025-01-31 11:41:35 +01:00
[recursive] simplify
This commit is contained in:
parent
899df8f237
commit
9f75713e00
@ -9,7 +9,6 @@
|
||||
"""Recursive extractor"""
|
||||
|
||||
from .common import Extractor, Message
|
||||
import requests
|
||||
import re
|
||||
|
||||
|
||||
@ -20,29 +19,13 @@ class RecursiveExtractor(Extractor):
|
||||
example = "recursive:https://pastebin.com/raw/FLwrCYsT"
|
||||
|
||||
def items(self):
|
||||
self.session.mount("file://", FileAdapter())
|
||||
page = self.request(self.url.partition(":")[2]).text
|
||||
del self.session.adapters["file://"]
|
||||
url = self.url.partition(":")[2]
|
||||
|
||||
if url.startswith("file://"):
|
||||
with open(url[7:]) as fp:
|
||||
page = fp.read()
|
||||
else:
|
||||
page = self.request(url).text
|
||||
|
||||
for match in re.finditer(r"https?://[^\s\"']+", page):
|
||||
yield Message.Queue, match.group(0), {}
|
||||
|
||||
|
||||
class FileAdapter(requests.adapters.BaseAdapter):
|
||||
"""Requests adapter for local files"""
|
||||
|
||||
def send(self, request, **kwargs):
|
||||
response = requests.Response()
|
||||
try:
|
||||
response.raw = open(request.url[7:], "rb")
|
||||
except OSError:
|
||||
import io
|
||||
response.raw = io.BytesIO()
|
||||
response.status_code = requests.codes.bad_request
|
||||
else:
|
||||
response.raw.release_conn = response.raw.close
|
||||
response.status_code = requests.codes.ok
|
||||
return response
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
|
Loading…
x
Reference in New Issue
Block a user