[instagram] implement login support (#195)
This commit is contained in:
@@ -46,7 +46,7 @@ ImageFap https://imagefap.com/ Images from Users, Gall
|
|||||||
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/ Albums, individual Images
|
imgur https://imgur.com/ Albums, individual Images
|
||||||
Instagram https://www.instagram.com/ Images from Users, individual Images, Tag-Searches
|
Instagram https://www.instagram.com/ Images from Users, individual Images, Tag-Searches Optional
|
||||||
Jaimini's Box https://jaiminisbox.com/reader/ Chapters, Manga
|
Jaimini's Box https://jaiminisbox.com/reader/ Chapters, Manga
|
||||||
Joyreactor http://joyreactor.cc/ |joyreactor-C|
|
Joyreactor http://joyreactor.cc/ |joyreactor-C|
|
||||||
Keenspot http://www.keenspot.com/ Comics
|
Keenspot http://www.keenspot.com/ Comics
|
||||||
|
|||||||
@@ -11,7 +11,8 @@
|
|||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
from .common import Extractor, Message
|
from .common import Extractor, Message
|
||||||
from .. import text
|
from .. import text, exception
|
||||||
|
from ..cache import cache
|
||||||
|
|
||||||
|
|
||||||
class InstagramExtractor(Extractor):
|
class InstagramExtractor(Extractor):
|
||||||
@@ -21,11 +22,14 @@ class InstagramExtractor(Extractor):
|
|||||||
filename_fmt = "{sidecar_media_id:?/_/}{media_id}.{extension}"
|
filename_fmt = "{sidecar_media_id:?/_/}{media_id}.{extension}"
|
||||||
archive_fmt = "{media_id}"
|
archive_fmt = "{media_id}"
|
||||||
root = "https://www.instagram.com"
|
root = "https://www.instagram.com"
|
||||||
|
cookiedomain = ".instagram.com"
|
||||||
|
cookienames = ("sessionid",)
|
||||||
|
|
||||||
def get_metadata(self):
|
def get_metadata(self):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
|
self.login()
|
||||||
yield Message.Version, 1
|
yield Message.Version, 1
|
||||||
|
|
||||||
metadata = self.get_metadata()
|
metadata = self.get_metadata()
|
||||||
@@ -40,6 +44,46 @@ class InstagramExtractor(Extractor):
|
|||||||
yield Message.Url, \
|
yield Message.Url, \
|
||||||
'ytdl:{}/p/{}/'.format(self.root, data['shortcode']), data
|
'ytdl:{}/p/{}/'.format(self.root, data['shortcode']), data
|
||||||
|
|
||||||
|
def login(self):
|
||||||
|
if self._check_cookies(self.cookienames):
|
||||||
|
return
|
||||||
|
username, password = self._get_auth_info()
|
||||||
|
if username:
|
||||||
|
self.session.cookies.set("ig_cb", "1", domain="www.instagram.com")
|
||||||
|
self._update_cookies(self._login_impl(username, password))
|
||||||
|
|
||||||
|
@cache(maxage=360*24*3600, keyarg=1)
|
||||||
|
def _login_impl(self, username, password):
|
||||||
|
self.log.info("Logging in as %s", username)
|
||||||
|
|
||||||
|
page = self.request(self.root + "/accounts/login/").text
|
||||||
|
headers = {
|
||||||
|
"Referer" : self.root + "/accounts/login/",
|
||||||
|
"X-IG-App-ID" : "936619743392459",
|
||||||
|
"X-Requested-With": "XMLHttpRequest",
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.request(self.root + "/web/__mid/", headers=headers)
|
||||||
|
headers["X-CSRFToken"] = response.cookies["csrftoken"]
|
||||||
|
headers["X-Instagram-AJAX"] = text.extract(
|
||||||
|
page, '"rollout_hash":"', '"')[0]
|
||||||
|
|
||||||
|
url = self.root + "/accounts/login/ajax/"
|
||||||
|
data = {
|
||||||
|
"username" : username,
|
||||||
|
"password" : password,
|
||||||
|
"queryParams" : "{}",
|
||||||
|
"optIntoOneTap": "true",
|
||||||
|
}
|
||||||
|
response = self.request(url, method="POST", headers=headers, data=data)
|
||||||
|
|
||||||
|
if not response.json().get("authenticated"):
|
||||||
|
raise exception.AuthenticationError()
|
||||||
|
return {
|
||||||
|
key: self.session.cookies.get(key)
|
||||||
|
for key in ("sessionid", "mid", "csrftoken")
|
||||||
|
}
|
||||||
|
|
||||||
def _extract_shared_data(self, page):
|
def _extract_shared_data(self, page):
|
||||||
return json.loads(text.extract(page,
|
return json.loads(text.extract(page,
|
||||||
'window._sharedData = ', ';</script>')[0])
|
'window._sharedData = ', ';</script>')[0])
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ AUTH_MAP = {
|
|||||||
"exhentai" : "Optional",
|
"exhentai" : "Optional",
|
||||||
"flickr" : "Optional (OAuth)",
|
"flickr" : "Optional (OAuth)",
|
||||||
"idolcomplex": "Optional",
|
"idolcomplex": "Optional",
|
||||||
|
"instagram" : "Optional",
|
||||||
"luscious" : "Optional",
|
"luscious" : "Optional",
|
||||||
"mangoxo" : "Optional",
|
"mangoxo" : "Optional",
|
||||||
"nijie" : "Required",
|
"nijie" : "Required",
|
||||||
|
|||||||
@@ -251,9 +251,10 @@ def setup_test_config():
|
|||||||
config.set(("extractor", "password"), name)
|
config.set(("extractor", "password"), name)
|
||||||
config.set(("extractor", "nijie", "username"), email)
|
config.set(("extractor", "nijie", "username"), email)
|
||||||
config.set(("extractor", "seiga", "username"), email)
|
config.set(("extractor", "seiga", "username"), email)
|
||||||
config.set(("extractor", "danbooru", "username"), None)
|
config.set(("extractor", "danbooru" , "username"), None)
|
||||||
config.set(("extractor", "twitter" , "username"), None)
|
config.set(("extractor", "instagram", "username"), None)
|
||||||
config.set(("extractor", "mangoxo" , "password"), "VZ8DL3983u")
|
config.set(("extractor", "twitter" , "username"), None)
|
||||||
|
config.set(("extractor", "mangoxo" , "password"), "VZ8DL3983u")
|
||||||
|
|
||||||
config.set(("extractor", "deviantart", "client-id"), "7777")
|
config.set(("extractor", "deviantart", "client-id"), "7777")
|
||||||
config.set(("extractor", "deviantart", "client-secret"),
|
config.set(("extractor", "deviantart", "client-secret"),
|
||||||
|
|||||||
Reference in New Issue
Block a user