Skip to content

Passing Youtube cookies doesn't seem to work; cookies are being invalidated quickly #8227

Description

@m1bcodes

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 have been used to youtube coookies lasting a couple of weeks. But since a few weeks I have to update the cookies for yt-dlp daily.
Does anyone know what is happening here?
My guess is that youtube change its policies. If that is the case, is there a way to automate the process?
My current "workflow":

  1. Opening youtube.com in firefox,
  2. log in to my channel
  3. export cookies (all domains) using "Export cookies"
  4. Use the cookies file with yt-dlp

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

[debug] Command-line config: ['-vU']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version stable@2023.09.24 [088add956] (pip)
[debug] Python 3.11.5 (CPython armv7l 32bit) - Linux-5.10.63-v7+-armv7l-with-glibc2.28 (OpenSSL 1.1.1n  15 Mar 2022, glibc 2.28)
[debug] exe versions: ffmpeg 4.1.11-0, ffprobe 4.1.11-0
[debug] Optional libraries: Cryptodome-3.19.0, brotli-1.1.0, certifi-2023.07.22, mutagen-1.47.0, sqlite3-3.27.2, websockets-11.0.3
[debug] Proxy map: {}
[debug] Loaded 1886 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Available version: stable@2023.09.24, Current version: stable@2023.09.24
yt-dlp is up to date (stable@2023.09.24)

Activity

  1. bashonly commented on Sep 29, 2023

    @bashonly
  2. Tmalll commented on Nov 3, 2023

    @Tmalll

    This has also happened to me. It usually happens when I download a member-only video of a certain channel, and the cookies of yt-dlp often expire, and it will prompt that member permissions are required.

    Like this
    ERROR: [youtube] IIqoefSX61U: This video is available to this channel's members on level: Lifeano Premium (or any higher level). Join this channel to get access to members-only content and other exclusive perks.

  3. added
    site-bugIssue with a specific website
    needs-investigatingNeeds research, information is welcome
    and removed on Nov 3, 2023
  4. coletdjnz commented on Nov 3, 2023

    @coletdjnz
    Member

    I'm noticing this too. Will need some investigation.

    I suspect there might have been a change where active requests in the browser are causing cookies to be replemised.

  5. Tmalll commented on Nov 3, 2023

    @Tmalll

    I'm noticing this too. Will need some investigation.

    I suspect there might have been a change where active requests in the browser are causing cookies to be replemised.

    I first tried to export cookies and use --cookies "%~dp0\cookies.txt" to specify cookies, but after a few minutes, it became invalid. When I downloaded member-only videos, it prompted me to need a higher level. permission.

    Later, I used the --cookies-from-browser firefox parameter and logged in to YouTube in the browser. Everything worked fine at first, but after a few minutes to dozens of minutes, the same cookie failure occurred.

  6. Tmalll commented on Nov 3, 2023

    @Tmalll

    I'm noticing this too. Will need some investigation.

    I suspect there might have been a change where active requests in the browser are causing cookies to be replemised.

    I also tried adding a plug-in to firefox to automatically refresh the page, but it also didn't work.

    If this is a new mechanism added by YouTube, then maybe a function needs to be added,
    For example, re-obtain cookies from the browser when downloading each playlist and video.

  7. coletdjnz commented on Nov 4, 2023

    @coletdjnz
    Member

    From a quick look: the browser appears to be callinghttps://accounts.youtube.com/RotateCookiesPage?origin=https://www.youtube.com&yt_pid=1. This runs another javascript rube goldberg machine to transform a value akin to nsig. It then calls https://accounts.youtube.com/RotateCookies with that transformed value which refreshes the cookies.

    I'm guessing this is required or else the cookies are invalidated by YouTube if they are not refreshed.

    We could attempt to implement this, but, I don't think its really feasible or worthwhile to maintain.

    Probably better off spending that time implementing oauth support for YouTube.

  8. jim60105 commented on Nov 4, 2023

    @jim60105

    From a quick look: the browser appears to be callinghttps://accounts.youtube.com/RotateCookiesPage?origin=https://www.youtube.com&yt_pid=1. This runs another javascript rube goldberg machine to transform a value akin to nsig. It then calls https://accounts.youtube.com/RotateCookies with that transformed value which refreshes the cookies.

    I'm guessing this is required or else the cookies are invalidated by YouTube if they are not refreshed.

    We could attempt to implement this, but, I don't think its really feasible or worthwhile to maintain.

    Probably better off spending that time implementing oauth support for YouTube.

    A simple workaround would be to generate the cookies file in an incognito window, where the cookies are never used again in browser and therefore will never be rotated.

    A few weeks ago, I saw this workaround somewhere (without knowing why) and tried it out. And my cookies file is still valid until now.

  9. 22 remaining items

  10. assassinliujie commented on Jun 14, 2024

    @assassinliujie

    I found a very strange bug, I have two accounts. Both have exported the cookie from private mode as instructed above. But one of them is very durable, I've been using it for almost two months, and did a lot of downloads without invalidating. However, the other account only downloaded a few videos, and it was invalid within a few hours. I want to know if it's because the durable cookie was exported from Chrome, and I also usually log in to this YouTube account on Chrome, whereas the other not durable one is because, although I also exported the cookie from Chrome, I usually use the Opera browser for that YouTube account.

  11. donnaken15 commented on Sep 14, 2024

    @donnaken15

    I used to rely on cookie files that worked for months after export, but then cookies were expiring within an hour or less of exporting them recently
    Right now, I'm dumping metadata from channels and it gives me the "Sign in" error minutes after (also because I was downloading anonymously just before and getting rate limited)

  12. eirnym commented on Sep 17, 2024

    @eirnym

    I don't know if NVidia scandal is related to it. YouTube service might do this to limit such downloads. Also it's possible that YouTube has some kind of server side heuristic to give a cookie appropriate expiration time. I don't know if yt-dlp might to do anything with it.

  13. bashonly commented on Sep 17, 2024

    @bashonly
    Member

    I'd guess that this cookie rotation is actually intended to protect their users from cookie stealing

  14. changed the title [-]Youtube cookies expire within hours[/-] [+]Passing Youtube cookies seems to not be working; cookies are being invalidated within hours/minutes/seconds[/+] on Oct 22, 2024
  15. changed the title [-]Passing Youtube cookies seems to not be working; cookies are being invalidated within hours/minutes/seconds[/-] [+]Passing Youtube cookies seems to not be working; cookies are being invalidated within minutes[/+] on Oct 22, 2024
  16. changed the title [-]Passing Youtube cookies seems to not be working; cookies are being invalidated within minutes[/-] [+]Passing Youtube cookies seems to not be working; cookies are being invalidated quickly[/+] on Oct 22, 2024
  17. changed the title [-]Passing Youtube cookies seems to not be working; cookies are being invalidated quickly[/-] [+]Passing Youtube cookies doesn't seem to work; cookies are being invalidated quickly[/+] on Oct 24, 2024
  18. Goshin commented on Nov 18, 2024

    @Goshin

    Since logging in with OAuth2 is gone, and cookies extracted from an incognito session still expire after a certain period of time, would implementing Cookie rotation now be the reliable way to prolong the login state?

  19. d0verenny commented on Dec 24, 2024

    @d0verenny

    The issue persists to this day... Can't downloads vids without cookies -- and cookies keep rotating like crazy. It's not even an hour passes till they expire...

    Please, consider reopenning the issue.

  20. coletdjnz commented on Dec 24, 2024

    @coletdjnz
    Member

    The issue persists to this day... Can't downloads vids without cookies -- and cookies keep rotating like crazy. It's not even an hour passes till they expire...

    Please, consider reopenning the issue.

    See https://github.com/yt-dlp/yt-dlp/wiki/Extractors#exporting-youtube-cookies

  21. locked and limited conversation to collaborators on Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    account-neededAccount details are needed to test/fix thisexternal-issueIssue with an external tool or sitesite-bugIssue with a specific websitesite:youtube

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions