mikf / gallery-dl

Command-line program to download image galleries and collections from several image hosting sites
GNU General Public License v2.0
11.29k stars 921 forks source link

[Bug] Error when attempting to download individual Instagram post URLs #3553

Open ULBAZOR opened 1 year ago

ULBAZOR commented 1 year ago

When I attempt to download individual Instagram posts, for example https://www.instagram.com/p/CnFNEqhhfJh/ I receive this error: "[instagram][error] HTTP redirect to login page (https://www.instagram.com/accounts/login/)"

I can still view the individual Instagram posts in my browser without being logged into an Instagram account with no problem, even posts that are slideshows containing multiple images and/or videos. Instagram allows you to view a certain number of posts before requiring you to log in. Gallery-dl can for example download the first 50 or so posts on a page before it's forced to log in. So Gallery-dl should be able to download individual posts without needing to use cookies or login authentication.

It was possible to use Gallery-dl to download individual posts before, I'm not sure what changed.

ClosedPort22 commented 1 year ago

So Gallery-dl should be able to download individual posts without needing to use cookies or login authentication.

Not necessarily. Meet the army of bot detection techniques:

Instagram probably uses a combination of these methods. Given how aggressively Meta bans accounts which show automated behavior, I wouldn't be surprised if CLI-based Instagram downloaders completely stop working someday.

mikf commented 1 year ago

It was possible to use Gallery-dl to download individual posts before, I'm not sure what changed.

The internally used API endpoints changed, as well as IGs/Metas "bot" blocking techniques and limits.

You can try -o api=graphql, but that will only work for ~5 posts and only download a lower quality version.

mikf commented 1 year ago

I did some small changes that might possibly help: https://github.com/mikf/gallery-dl/commit/fc6ea8ee5ca3ff4205fe9fd5fc711eca5f5794fb, https://github.com/mikf/gallery-dl/commit/d817d23ccb2a109316a07bbbc761f7e20c3649a8

heubergen commented 1 year ago

I'm also facing a similar issue with version 1.24.5, though the post I want to download is privat.

{
    "extractor":
    {
        "instagram":
        {
            "cookies": ["brave"]
        },
 @<LOCAL_USER>  gallery-dl -v "https://www.instagram.com/p/<PRIVAT>/"
[gallery-dl][debug] Version 1.24.5
[gallery-dl][debug] Python 3.11.1 - macOS-12.6.3-x86_64-i386-64bit
[gallery-dl][debug] requests 2.28.2 - urllib3 1.26.14
[gallery-dl][debug] Configuration Files ['${HOME}/.gallery-dl.conf']
[gallery-dl][debug] Starting DownloadJob for 'https://www.instagram.com/p/<PRIVAT>/'
[cookies][debug] Extracting cookies from /Users/<LOCAL_USER>/Library/Application Support/BraveSoftware/Brave-Browser/Default/Cookies
[cookies][debug] using find-generic-password to obtain password from OSX keychain
[cookies][info] Extracted 3707 cookies from brave
[cookies][debug] cookie version breakdown: {'v10': 3626, 'other': 0, 'unencrypted': 81}
[instagram][debug] Using InstagramPostExtractor for 'https://www.instagram.com/p/<PRIVAT>/'
[urllib3.connectionpool][debug] Starting new HTTPS connection (1): www.instagram.com:443
[urllib3.connectionpool][debug] https://www.instagram.com:443 "GET /api/v1/media/<PRIVAT>/info/ HTTP/1.1" 400 117
[instagram][error] HttpError: '400 Bad Request' for 'https://www.instagram.com/api/v1/media/<PRIVAT>/info/'

If I open the URL that gets the 400 in the browser I get: {"message":"useragent mismatch","status":"fail"}