[imgur] implement login support (#446)

This commit is contained in:
Mike Fährmann
2019-10-15 21:14:14 +02:00
parent 91643ca54b
commit 5882b00f2f
3 changed files with 31 additions and 1 deletions

View File

@@ -52,7 +52,7 @@ ImageFap https://imagefap.com/ Galleries, individual I
ImgBB https://imgbb.com/ Albums, individual Images, User Profiles Optional ImgBB https://imgbb.com/ Albums, individual Images, User Profiles Optional
imgbox https://imgbox.com/ Galleries, individual Images imgbox https://imgbox.com/ Galleries, individual Images
imgth https://imgth.com/ Galleries imgth https://imgth.com/ Galleries
imgur https://imgur.com/ |imgur-C| imgur https://imgur.com/ |imgur-C| Optional
Instagram https://www.instagram.com/ |instagram-C| Optional Instagram https://www.instagram.com/ |instagram-C| Optional
Jaimini's Box https://jaiminisbox.com/reader/ Chapters, Manga Jaimini's Box https://jaiminisbox.com/reader/ Chapters, Manga
Joyreactor http://joyreactor.com/ Posts, Search Results, Tag-Searches, User Profiles Joyreactor http://joyreactor.com/ Posts, Search Results, Tag-Searches, User Profiles

View File

@@ -10,6 +10,7 @@
from .common import Extractor, Message from .common import Extractor, Message
from .. import text, exception from .. import text, exception
from ..cache import cache
import itertools import itertools
import json import json
@@ -28,6 +29,30 @@ class ImgurExtractor(Extractor):
self.key = match.group(1) self.key = match.group(1)
self.mp4 = self.config("mp4", True) self.mp4 = self.config("mp4", True)
def login(self):
username, password = self._get_auth_info()
if username:
self._update_cookies(self._login_impl(username, password))
@cache(maxage=180*24*3600, keyarg=1)
def _login_impl(self, username, password):
self.log.info("Logging in as %s", username)
url = "{}/signin?invokedBy=Regular%20Sign%20In".format(self.root)
headers = {"Referer": url}
data = {
"username": username,
"password": password,
"remember": "remember",
"submit" : "",
}
response = self.request(url, method="POST", headers=headers, data=data)
if not response.history:
error = text.extract(response.text, 'class="error">', '<')[0] or ""
raise exception.AuthenticationError(error.strip())
return self.session.cookies
def _extract_data(self, path): def _extract_data(self, path):
response = self.request(self.root + path, notfound=self.subcategory) response = self.request(self.root + path, notfound=self.subcategory)
data = json.loads(text.extract( data = json.loads(text.extract(
@@ -49,6 +74,7 @@ class ImgurExtractor(Extractor):
return url return url
def _items_apiv3(self, urlfmt): def _items_apiv3(self, urlfmt):
self.login()
album_ex = ImgurAlbumExtractor album_ex = ImgurAlbumExtractor
image_ex = ImgurImageExtractor image_ex = ImgurImageExtractor
@@ -129,6 +155,7 @@ class ImgurImageExtractor(ImgurExtractor):
) )
def items(self): def items(self):
self.login()
image = self._extract_data("/" + self.key) image = self._extract_data("/" + self.key)
url = self._prepare(image) url = self._prepare(image)
yield Message.Version, 1 yield Message.Version, 1
@@ -190,6 +217,7 @@ class ImgurAlbumExtractor(ImgurExtractor):
) )
def items(self): def items(self):
self.login()
album = self._extract_data("/a/" + self.key + "/all") album = self._extract_data("/a/" + self.key + "/all")
images = album["album_images"]["images"] images = album["album_images"]["images"]
del album["album_images"] del album["album_images"]
@@ -222,6 +250,7 @@ class ImgurGalleryExtractor(ImgurExtractor):
) )
def items(self): def items(self):
self.login()
url = self.root + "/a/" + self.key url = self.root + "/a/" + self.key
with self.request(url, method="HEAD", fatal=False) as response: with self.request(url, method="HEAD", fatal=False) as response:
code = response.status_code code = response.status_code

View File

@@ -118,6 +118,7 @@ AUTH_MAP = {
"idolcomplex": "Optional", "idolcomplex": "Optional",
"imgbb" : "Optional", "imgbb" : "Optional",
"instagram" : "Optional", "instagram" : "Optional",
"imgur" : "Optional",
"luscious" : "Optional", "luscious" : "Optional",
"mangoxo" : "Optional", "mangoxo" : "Optional",
"nijie" : "Required", "nijie" : "Required",