Skip to content

Commit

Permalink
[instagram] fix and re-enable login with username&password
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed May 30, 2020
1 parent c4d06a8 commit 0f459f3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ Description The username and password to use when attempting to log in to
* ``e621``
* ``exhentai``
* ``idolcomplex``
* ``instagram``
* ``luscious``
* ``sankaku``
* ``tsumino``
Expand Down
2 changes: 1 addition & 1 deletion docs/supportedsites.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ImgBB https://imgbb.com/ Albums, individual Imag
imgbox https://imgbox.com/ Galleries, individual Images
imgth https://imgth.com/ Galleries
imgur https://imgur.com/ |imgur-C|
Instagram https://www.instagram.com/ |instagram-C|
Instagram https://www.instagram.com/ |instagram-C| Optional
Issuu https://issuu.com/ Publications, User Profiles
Jaimini's Box https://jaiminisbox.com/reader/ Chapters, Manga
Joyreactor http://joyreactor.com/ Posts, Search Results, Tag Searches, User Profiles
Expand Down
37 changes: 32 additions & 5 deletions gallery_dl/extractor/instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
"""Extractors for https://www.instagram.com/"""

from .common import Extractor, Message
from .. import text
from .. import text, exception
from ..cache import cache
import itertools
import json
import time
import re


Expand Down Expand Up @@ -66,10 +67,36 @@ def login(self):

@cache(maxage=360*24*3600, keyarg=1)
def _login_impl(self, username, password):
self.log.warning(
'Logging in with username and password is currently not possible. '
'Use cookies from your browser session instead.')
return {}
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,
"enc_password" : "#PWD_INSTAGRAM_BROWSER:0:{}:{}".format(
int(time.time()), password),
"queryParams" : "{}",
"optIntoOneTap": "false",
}
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 _request_graphql(self, variables, query_hash, csrf=None):
headers = {
Expand Down
1 change: 1 addition & 0 deletions scripts/supportedsites.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
"flickr" : "Optional (OAuth)",
"idolcomplex": "Optional",
"imgbb" : "Optional",
"instagram" : "Optional",
"mangoxo" : "Optional",
"newgrounds" : "Optional",
"nijie" : "Required",
Expand Down

0 comments on commit 0f459f3

Please sign in to comment.