add basic support for file:// URLs
this allows you to feed local files into the recursive extractor
This commit is contained in:
30
gallery_dl/adapter.py
Normal file
30
gallery_dl/adapter.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# -*- 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
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
import re
|
||||
from .common import Extractor, Message
|
||||
from .. import adapter
|
||||
|
||||
class RecursiveExtractor(Extractor):
|
||||
|
||||
@@ -21,6 +22,7 @@ class RecursiveExtractor(Extractor):
|
||||
|
||||
def __init__(self, match):
|
||||
Extractor.__init__(self)
|
||||
self.session.mount("file://", adapter.FileAdapter())
|
||||
self.url = match.group(1)
|
||||
|
||||
def items(self):
|
||||
|
||||
Reference in New Issue
Block a user