Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookie not loading when downloading instagram videos #10462

Closed
8 of 9 tasks
radian462 opened this issue Jul 14, 2024 · 2 comments
Closed
8 of 9 tasks

Cookie not loading when downloading instagram videos #10462

radian462 opened this issue Jul 14, 2024 · 2 comments
Labels
question Question

Comments

@radian462
Copy link

radian462 commented Jul 14, 2024

DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

  • I understand that I will be blocked if I intentionally remove or skip any mandatory* field

Checklist

Please make sure the question is worded well enough to be understood

I tried to download instagram videos with this code but the cookie does not load.

But with yt-dlp --cookies instagram_cookie.txt "https://www.instagram.com/p/C9SEsmYCx_M/?hl=ja" it does.
Is there something wrong with my code? If so, please let me know the solution.
Sorry if I have missed something.

from yt_dlp import YoutubeDL
import subprocess

def download_video(url):
    if url in ".m3u8":
        subprocess.run(f'ffmpeg -i {url} -c copy "%name%.mp4"', shell=True)
        print("m3u8ファイルをダウンロードました")
    else:
        ydl_opts = {
          'format': 'best[ext=mp4]',
          'outtmpl': '%(title)s.%(ext)s',
          'verbose': True,
        }

        if "instagram.com" in url:
            ydl_opts["cookies"] = "instagram_cookie.txt"
            print(ydl_opts)
            
        with YoutubeDL(ydl_opts) as ydl:
            result = ydl.extract_info(url, download=True)
            file_path = ydl.prepare_filename(result)
            print(f"{file_path}をダウンロードました")
            
        return file_path

if __name__ == "__main__":
    download_video(input("URL:"))

Provide verbose output that clearly demonstrates the problem

  • Run your yt-dlp command with -vU flag added (yt-dlp -vU <your command line>)
  • If using API, add 'verbose': True to YoutubeDL params instead
  • Copy the WHOLE output (starting with [debug] Command-line config) and insert it below

Complete Verbose Output

URL:https://www.instagram.com/p/C9SEsmYCx_M/?hl=ja
{'format': 'best[ext=mp4]', 'outtmpl': '%(title)s.%(ext)s', 'verbose': True, 'cookies': 'instagram_cookie.txt'}
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version nightly@2024.07.13.232701 from yt-dlp/yt-dlp-nightly-builds [150ecc45d] (pip) API
[debug] params: {'format': 'best[ext=mp4]', 'outtmpl': '%(title)s.%(ext)s', 'verbose': True, 'cookies': 'instagram_cookie.txt', 'compat_opts': set(), 'http_headers': {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.74 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'en-us,en;q=0.5', 'Sec-Fetch-Mode': 'navigate'}}
[debug] Python 3.10.14 (CPython x86_64 64bit) - Linux-6.5.0-1023-gcp-x86_64-with-glibc2.39 (OpenSSL 3.0.13 30 Jan 2024, glibc 2.39)
[debug] exe versions: none
[debug] Optional libraries: Cryptodome-3.20.0, brotli-1.1.0, certifi-2024.07.04, mutagen-1.47.0, requests-2.32.3, sqlite3-3.45.3, urllib3-2.2.2, websockets-12.0
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests, websockets
[debug] Loaded 1834 extractors
[Instagram] Extracting URL: https://www.instagram.com/p/C9SEsmYCx_M/?hl=ja
[Instagram] C9SEsmYCx_M: Setting up session
[Instagram] C9SEsmYCx_M: Downloading JSON metadata
WARNING: [Instagram] C9SEsmYCx_M: General metadata extraction failed (some metadata might be missing).
[Instagram] C9SEsmYCx_M: Downloading webpage
WARNING: [Instagram] unable to extract shared data; please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
WARNING: [Instagram] Main webpage is locked behind the login page. Retrying with embed webpage (some metadata might be missing).
[Instagram] C9SEsmYCx_M: Downloading embed webpage
WARNING: [Instagram] unable to extract additional data; please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
ERROR: [Instagram] C9SEsmYCx_M: Requested content is not available, rate-limit reached or login required. Use --cookies, --cookies-from-browser, --username and --password, --netrc-cmd, or --netrc (instagram) to provide account credentials
  File "/home/runner/moive-download-exe/.pythonlibs/lib/python3.10/site-packages/yt_dlp/extractor/common.py", line 740, in extract
    ie_result = self._real_extract(url)
  File "/home/runner/moive-download-exe/.pythonlibs/lib/python3.10/site-packages/yt_dlp/extractor/instagram.py", line 460, in _real_extract
    self.raise_login_required('Requested content is not available, rate-limit reached or login required')
  File "/home/runner/moive-download-exe/.pythonlibs/lib/python3.10/site-packages/yt_dlp/extractor/common.py", line 1245, in raise_login_required
    raise ExtractorError(msg, expected=True)

Traceback (most recent call last):
  File "/home/runner/moive-download-exe/.pythonlibs/lib/python3.10/site-packages/yt_dlp/YoutubeDL.py", line 1622, in wrapper
    return func(self, *args, **kwargs)
  File "/home/runner/moive-download-exe/.pythonlibs/lib/python3.10/site-packages/yt_dlp/YoutubeDL.py", line 1757, in __extract_info
    ie_result = ie.extract(url)
  File "/home/runner/moive-download-exe/.pythonlibs/lib/python3.10/site-packages/yt_dlp/extractor/common.py", line 740, in extract
    ie_result = self._real_extract(url)
  File "/home/runner/moive-download-exe/.pythonlibs/lib/python3.10/site-packages/yt_dlp/extractor/instagram.py", line 460, in _real_extract
    self.raise_login_required('Requested content is not available, rate-limit reached or login required')
  File "/home/runner/moive-download-exe/.pythonlibs/lib/python3.10/site-packages/yt_dlp/extractor/common.py", line 1245, in raise_login_required
    raise ExtractorError(msg, expected=True)
yt_dlp.utils.ExtractorError: [Instagram] C9SEsmYCx_M: Requested content is not available, rate-limit reached or login required. Use --cookies, --cookies-from-browser, --username and --password, --netrc-cmd, or --netrc (instagram) to provide account credentials

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/runner/moive-download-exe/main.py", line 27, in <module>
    download_video(input("URL:"))
  File "/home/runner/moive-download-exe/main.py", line 20, in download_video
    result = ydl.extract_info(url, download=True)
  File "/home/runner/moive-download-exe/.pythonlibs/lib/python3.10/site-packages/yt_dlp/YoutubeDL.py", line 1611, in extract_info
    return self.__extract_info(url, self.get_info_extractor(key), download, extra_info, process)
  File "/home/runner/moive-download-exe/.pythonlibs/lib/python3.10/site-packages/yt_dlp/YoutubeDL.py", line 1640, in wrapper
    self.report_error(str(e), e.format_traceback())
  File "/home/runner/moive-download-exe/.pythonlibs/lib/python3.10/site-packages/yt_dlp/YoutubeDL.py", line 1088, in report_error
    self.trouble(f'{self._format_err("ERROR:", self.Styles.ERROR)} {message}', *args, **kwargs)
  File "/home/runner/moive-download-exe/.pythonlibs/lib/python3.10/site-packages/yt_dlp/YoutubeDL.py", line 1027, in trouble
    raise DownloadError(message, exc_info)
yt_dlp.utils.DownloadError: ERROR: [Instagram] C9SEsmYCx_M: Requested content is not available, rate-limit reached or login required. Use --cookies, --cookies-from-browser, --username and --password, --netrc-cmd, or --netrc (instagram) to provide account credentials
@radian462 radian462 added the question Question label Jul 14, 2024
@seproDev
Copy link
Member

The option is called cookiefile. You can use devscripts/cli_to_api.py to figure out how api options should be used.

@radian462
Copy link
Author

Thank you. That downloaded fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question
Projects
None yet
Development

No branches or pull requests

2 participants