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

Add separate Logger instance on YoutubeDL #7517

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Grub4K
Copy link
Member

@Grub4K Grub4K commented Jul 5, 2023

IMPORTANT: PRs without the template will be CLOSED

Description of your pull request and other information

This PR adds a logging interface at YoutubeDL.logger, resembling #5680. While the class and interface is not final, its methods can already be used.

It also redirects warnings.warn messages to the logger.

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 e889cb8

Summary

馃摑馃帹馃殌

This pull request introduces a new _Logger class that handles all the output and warning functionality of the YoutubeDL class, and refactors the existing code to use it. It also adds some helper functions to redirect the warnings module and set the return code based on the error messages. The changes affect the yt_dlp/YoutubeDL.py, yt_dlp/output/helper.py, and yt_dlp/output/logger.py files.

To improve the logging and warning
The YoutubeDL class was reforming
It now uses a _Logger
With colors and VT toggler
And some functions for output conforming

Walkthrough

  • Refactor the logging and warning functionality of YoutubeDL by using a _Logger instance from the output.logger module (link, link, link, link, link)
  • Add the redirect_warnings and _wrap_download_retcode functions to the output.helper module, which are used to redirect the messages from the warnings module to the _Logger instance, and to set the return code of the YoutubeDL instance based on the error messages, respectively (link)
  • Add the _Logger class to the output.logger module, which encapsulates the logic for handling the output files, color policies, VT mode, bidirectional workaround, and logging and warning messages. It also defines the _Styles namespace, which contains the color codes for different types of messages (link)
  • Make the tb and is_error arguments of the trouble method of the YoutubeDL class keyword-only, to avoid confusion and errors when calling the method with positional arguments (link)
  • Remove the unused imports and attributes from YoutubeDL.py (link, link, link, link, link, link)

@Grub4K Grub4K added the docs/meta/cleanup related to docs, code cleanup, templates, devscripts etc label Jul 5, 2023
pukkandan added a commit to pukkandan/yt-dlp-dev that referenced this pull request Jul 15, 2023
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
docs/meta/cleanup related to docs, code cleanup, templates, devscripts etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant