add .netrc support (#22)
Use the '--netrc' cmdline option or set the 'netrc' config option to 'true' to enable the use of .netrc authentication data. The 'machine' names for the .netrc info are the lowercase extractor names (or categories): batoto, exhentai, nijie, pixiv, seiga.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
import os
|
||||
import time
|
||||
import netrc
|
||||
import queue
|
||||
import logging
|
||||
import requests
|
||||
@@ -42,6 +43,24 @@ class Extractor():
|
||||
return config.interpolate(
|
||||
("extractor", self.category, self.subcategory, key), default)
|
||||
|
||||
def auth_info(self):
|
||||
"""Return authentication information as (username, password) tuple"""
|
||||
username = self.config("username")
|
||||
password = None
|
||||
|
||||
if username:
|
||||
password = self.config("password")
|
||||
elif config.get(("netrc",), False):
|
||||
try:
|
||||
info = netrc.netrc().authenticators(self.category)
|
||||
username, _, password = info
|
||||
except (OSError, netrc.NetrcParseError) as exc:
|
||||
self.log.error("netrc: %s", exc)
|
||||
except TypeError:
|
||||
self.log.warning("netrc: No authentication info")
|
||||
|
||||
return username, password
|
||||
|
||||
def request(self, url, encoding=None, *args, **kwargs):
|
||||
response = safe_request(self.session, url, *args, **kwargs)
|
||||
if encoding:
|
||||
|
||||
Reference in New Issue
Block a user