Repository: yt-dlp
Issue:  When embedding yt-dlp and setting ignoreerrors to True, it is desired to capture relevant error messages programmatically rather than just printing them to stderr.
Labels: question

### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I *intentionally* remove or skip any mandatory\* field

### Checklist

- [X] I'm requesting a feature unrelated to a specific site
- [X] I've looked through the [README](https://github.com/yt-dlp/yt-dlp#readme)
- [X] I've verified that I have **updated yt-dlp to nightly or master** ([update instructions](https://github.com/yt-dlp/yt-dlp#update-channels))
- [X] I've searched [known issues](https://github.com/yt-dlp/yt-dlp/issues/3766) and the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)

### Provide a description that is worded well enough to be understood

# Requirements Explanation

When embedding yt-dlp for playlist URLs, to prevent the entire process from stopping due to an error in one of the videos, `ignoreerrors` is typically set to True. Even if an error occurs, the download continues for the next video, and any error messages for videos that could not be captured successfully are only printed directly to stderr.

```py
from yt_dlp import YoutubeDL

URLS = ['https://www.youtube.com/watch?v=XXX&list=YYY']

ydl_opts = { "ignoreerrors": True }

with YoutubeDL(ydl_opts) as ydl:
    ydl.download(URLS)
```

I seem to be unable to find relevant error messages for failures during the download process in the `ydl` variable. It would be really helpful if there were a functionality similar to `ydl.get_error_messages` (This method does not exist; it is hypothetical).

# Preliminary Solution

Before the development of this feature, I successfully achieved the functionality I needed using the `built-in function redirect_stderr in Python 3.5`. If anyone here is interested in this feature, I'll provide the code below for reference.

```py
from yt_dlp import YoutubeDL
import io
from contextlib import redirect_stderr

URLS = ['https://www.youtube.com/watch?v=XXX&list=YYY']

ydl_opts = { "ignoreerrors": True }

with redirect_stderr(io.StringIO()) as errStrIO:
    with YoutubeDL(ydl_opts) as ydl:
        ydl.download(URLS)
errMsg = errStrIO.getvalue()

print(errMsg)
```

Below is an example content printed by errMsg.
```console
WARNING: [youtube:tab] Incomplete yt initial data received. Retrying (1/3)...
WARNING: [youtube:tab] YouTube said: INFO - 4 unavailable videos are hidden
ERROR: [youtube] IOmNWXXXXX: Private video. Sign in if you've been granted access to this video
ERROR: [youtube] S3yVyXXXXX: Video unavailable. This video contains content from SME, who has blocked it in your country on copyright grounds
ERROR: [youtube] y0rxpXXXXX: Video unavailable. This video contains content from Molebeat, who has blocked it in your country on copyright grounds
ERROR: [youtube] FRivqXXXXX: Video unavailable. This video contains content from SME, who has blocked it in your country on copyright grounds
```


For detailed information about redirect_stderr, you can refer to [contextlib.redirect_stderr(new_target)](https://docs.python.org/3/library/contextlib.html#contextlib.redirect_stderr)

### 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

_No response_