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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cookies] Move YouTubeDLCookieJar to cookies.py #7091

Merged
merged 5 commits into from May 27, 2023

Conversation

coletdjnz
Copy link
Member

@coletdjnz coletdjnz commented May 20, 2023

IMPORTANT: PRs without the template will be CLOSED

Description of your pull request and other information

ADD DESCRIPTION HERE
Backport from #2861

Also added a get_cookie_header function to the cookiejar (also from backport)

Template

Before submitting a pull request make sure you have:

In order to be accepted and merged into yt-dlp each piece of code must be in public domain or released under Unlicense. Check all of the following options that apply:

  • I am the original author of this code and I am willing to release it under Unlicense
  • I am not the original author of this code but it is in public domain or released under Unlicense (provide reliable evidence)

What is the purpose of your pull request?

Copilot Summary

馃 Generated by Copilot at dc7be9b

Summary

馃崻馃殮馃Ч

This pull request refactors the cookie management in yt-dlp by moving the YoutubeDLCookieJar class to a separate module yt_dlp/cookies.py and using it directly in the YoutubeDL and InfoExtractor classes. It also adds tests and updates imports for the new module. It maintains backward compatibility for external modules that import YoutubeDLCookieJar from utils.

CookieJar of doom, you hold the secrets of the web
We import you from cookies.py, no more legacy code to dread
You simplify our extraction, you make our requests smooth
CookieJar of doom, you are the master of our groove

Walkthrough

  • Move YoutubeDLCookieJar class from yt_dlp/utils/_utils.py to yt_dlp/cookies.py as a separate module for handling cookie files and headers (link, link)
  • Update import statements in yt_dlp/cookies.py, yt_dlp/extractor/common.py, yt_dlp/utils/_legacy.py, and test/test_YoutubeDLCookieJar.py to reflect the new location of YoutubeDLCookieJar class (link, link, link, link, link)
  • Add a wrapper function for YoutubeDLCookieJar in yt_dlp/utils/_legacy.py to maintain backward compatibility for external modules that import it from utils (link)
  • Modify _get_cookies method in InfoExtractor class and _calc_headers method in YoutubeDL class to use the cookiejar attribute instead of the _calc_cookies method to get the cookies for a url and generate the Cookie header (link, link)
  • Remove _calc_cookies method from YoutubeDL class as it is no longer needed (link)
  • Add a new test case to TestYoutubeDLCookieJar to check the functionality of the get_cookie_header method (link)
  • Import urllib.request module in yt_dlp/cookies.py to use the Request class for generating the cookie header (link)

@coletdjnz coletdjnz added the enhancement New feature or request label May 21, 2023
Copy link
Member

@Grub4K Grub4K left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of these are cosmetic, feel free to ignore

yt_dlp/cookies.py Show resolved Hide resolved
yt_dlp/cookies.py Show resolved Hide resolved
@coletdjnz
Copy link
Member Author

Most of these are cosmetic, feel free to ignore

I wasn't really planning on changing the cookiejar code itself in this PR to keep it simple - maybe worth refactoring it in another PR/commit?

@Grub4K
Copy link
Member

Grub4K commented May 21, 2023

Sure, like I said, feel free to ignore these. I can take them into another PR at some point.

@pukkandan
Copy link
Member

Don't think this needed to be it's own PR. But since you made it, we might as well merge. After merging the relevant open PRs', can you rebase/merge #2861 and we can discuss a more reasonable way to split it up?

(PS: To clarify, I don't mind the small PRs, just think I'm adding more work for you)

@pukkandan pukkandan force-pushed the master branch 2 times, most recently from ee280c7 to 7aeda6c Compare May 24, 2023 18:09
@coletdjnz coletdjnz merged commit b87e01c into yt-dlp:master May 27, 2023
11 checks passed
@coletdjnz coletdjnz deleted the nw-backport/cookies branch May 27, 2023 07:08
aalsuwaidi pushed a commit to aalsuwaidi/yt-dlp that referenced this pull request Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants