Repository: yt-dlp
Issue: Output template: Support conditional statements
Labels: enhancement

### 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

I would like to format videos in playlists differently from videos out of playlists (specifically, I'm using `%(playlist_title,upload_date>%Y-%m-%d&{} - |)s%(playlist_index&{} - |)s`).

However, since the `youtube:tab` extractor presents videos from eg `/@user/videos` as a playlist, this means that unless I either manually list all the videos I want to download, or download channel updates and playlists separately, the above output template will have the wrong behaviour on channel tabs. A way to distinguish the two is desirable. For the remainder of the discussion, note that in this case `playlist_id=channel_id`.

Additional relevant context: On one of my devices, I'm using https://github.com/JunkFood02/Seal to wrap `yt-dlp`. While I have prodded them (https://github.com/JunkFood02/Seal/issues/1873) to support multiple output templates, at the moment they only support a single custom output template.

Four ways suggest themselves:
- Do nothing, and have users use the Python API or shell scripting for this (somewhat painful), or have users expand the list of urls to be downloaded manually (painful on mobile for more than a handful of videos, requires `yt-dlp --print | xargs yt-dlp` on desktop which is less than ideal)
- Change `youtube:tab`'s behaviour, perhaps by adding a new metadata field (backwards incompatible)
- Add support for conditional formatting in output templates. Note that for this to be useful here, we'd need the conditions to evaluate before alternative selection. To reduce maintenance burden, we could either reuse the match filter predicates (so perhaps something like `%(playlist_title?(playlist_id & playlist_id != channel_id),upload_date)s` or %(playlist_title[playlist_id][playlist_id != channel_id,upload_date)s`), or allow arbitrary python conditionals (`{playlist_title if playlist_id != "NA" and playlist_id != channel_id else upload_date}`)
- Other overengineered solutions also suggest themselves, such as having a JSON-based coprocess protocol, but their burden does not look like it pays off

### Provide verbose output that clearly demonstrates the problem

- [X] 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
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
[debug] Command-line config: ['--ignore-config', '-vU', '--print', '%(playlist_title,upload_date>%Y-%m-%d&{} - |)s%(playlist_index|)s', 'https://www.youtube.com/@PracticalEngineering', '--max-downloads', '1']
[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@2024.11.18 from yt-dlp/yt-dlp [7ea278792]
[debug] Python 3.12.7 (CPython x86_64 64bit) - Linux-6.11.5-arch1-1-x86_64-with-glibc2.40 (OpenSSL 3.4.0 22 Oct 2024, glibc 2.40)
[debug] exe versions: ffmpeg 7.1 (setts), ffprobe 7.1, phantomjs broken, rtmpdump 2.4
[debug] Optional libraries: Cryptodome-3.20.0, brotli-1.1.0, certifi-2024.08.30, mutagen-1.47.0, requests-2.32.3, secretstorage-3.3.3, sqlite3-3.46.1, urllib3-1.26.20, websockets-12.0
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests
[debug] Loaded 1837 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Latest version: stable@2024.11.18 from yt-dlp/yt-dlp
yt-dlp is up to date (stable@2024.11.18 from yt-dlp/yt-dlp)
[youtube:tab] Extracting URL: https://www.youtube.com/@PracticalEngineering
[youtube:tab] @PracticalEngineering: Downloading webpage
[debug] [youtube:tab] Selected tab: 'videos' (videos), Requested tab: ''
[youtube:tab] Downloading all uploads of the channel. To download only the videos in a specific tab, pass the tab's URL
[download] Downloading playlist: Practical Engineering Australia - Videos
[youtube:tab] Playlist Practical Engineering Australia - Videos: Downloading 6 items of 6
[download] Downloading item 1 of 6
[youtube] Extracting URL: https://www.youtube.com/watch?v=HmLmp06cbnU
[youtube] HmLmp06cbnU: Downloading webpage
[youtube] HmLmp06cbnU: Downloading ios player API JSON
[youtube] HmLmp06cbnU: Downloading mweb player API JSON
[debug] Loading youtube-nsig.2d24ba15 from cache
[debug] [youtube] Decrypted nsig rvtzc3BXbPfKpM2A6 => MVujBRZCtmV6LA
[debug] Loading youtube-nsig.2d24ba15 from cache
[debug] [youtube] Decrypted nsig NvO8RpuawyiuEZinn => _eQFO4S5coqzFA
[youtube] HmLmp06cbnU: Downloading m3u8 information
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, vcodec, channels, acodec, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec, channels, acodec, lang, proto, size, br, asr, vext, aext, hasaud, id
[debug] Default format spec: bestvideo*+bestaudio/best
[info] HmLmp06cbnU: Downloading 1 format(s): 136+251
Practical Engineering Australia - Videos - 1
[info] Maximum number of downloads reached, stopping due to --max-downloads
Aborting remaining downloads
```