move FileAdapter definition into recursive.py
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
## 1.5.3 - 2018-09-14
|
## 1.5.3 - 2018-09-14
|
||||||
- Added support for:
|
- Added support for:
|
||||||
- `hentaicafe` - https://hentai.cafe/ ([#101](https://github.com/mikf/gallery-dl/issues/101))
|
- `hentaicafe` - https://hentai.cafe/ ([#101](https://github.com/mikf/gallery-dl/issues/101))
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyright 2016 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.
|
|
||||||
|
|
||||||
"""Custom requests adapters"""
|
|
||||||
|
|
||||||
from requests.adapters import BaseAdapter
|
|
||||||
from requests import Response, codes
|
|
||||||
import io
|
|
||||||
|
|
||||||
|
|
||||||
class FileAdapter(BaseAdapter):
|
|
||||||
|
|
||||||
def send(self, request, **kwargs):
|
|
||||||
path = request.url[7:]
|
|
||||||
response = Response()
|
|
||||||
try:
|
|
||||||
response.raw = open(path, "rb")
|
|
||||||
response.raw.release_conn = response.raw.close
|
|
||||||
response.status_code = codes.ok
|
|
||||||
except IOError:
|
|
||||||
response.raw = io.BytesIO()
|
|
||||||
response.status_code = codes.bad_request
|
|
||||||
return response
|
|
||||||
|
|
||||||
def close(self):
|
|
||||||
pass
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright 2015-2017 Mike Fährmann
|
# Copyright 2015-2018 Mike Fährmann
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
@@ -8,9 +8,10 @@
|
|||||||
|
|
||||||
"""Recursive extractor"""
|
"""Recursive extractor"""
|
||||||
|
|
||||||
import re
|
|
||||||
from .common import Extractor, Message
|
from .common import Extractor, Message
|
||||||
from .. import extractor, adapter, util
|
from .. import extractor, util
|
||||||
|
import requests
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
class RecursiveExtractor(Extractor):
|
class RecursiveExtractor(Extractor):
|
||||||
@@ -23,7 +24,7 @@ class RecursiveExtractor(Extractor):
|
|||||||
|
|
||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
Extractor.__init__(self)
|
Extractor.__init__(self)
|
||||||
self.session.mount("file://", adapter.FileAdapter())
|
self.session.mount("file://", FileAdapter())
|
||||||
self.url = match.group(1)
|
self.url = match.group(1)
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
@@ -34,3 +35,23 @@ class RecursiveExtractor(Extractor):
|
|||||||
with extractor.blacklist(blist):
|
with extractor.blacklist(blist):
|
||||||
for match in re.finditer(r"https?://[^\s\"']+", page):
|
for match in re.finditer(r"https?://[^\s\"']+", page):
|
||||||
yield Message.Queue, match.group(0), {}
|
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
|
||||||
|
|||||||
@@ -6,4 +6,4 @@
|
|||||||
# it under the terms of the GNU General Public License version 2 as
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
# published by the Free Software Foundation.
|
# published by the Free Software Foundation.
|
||||||
|
|
||||||
__version__ = "1.5.3"
|
__version__ = "1.5.4-dev"
|
||||||
|
|||||||
Reference in New Issue
Block a user