Repository: yt-dlp
Issue: Formatting conversions aren't applied if a replacement value is specified in the output template
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 reporting a bug unrelated to a specific site
- [X] I've verified that I'm running yt-dlp version **2023.07.06** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
- [X] I've checked that all provided URLs are playable in a browser with the same IP and same login details
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#video-url-contains-an-ampersand--and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [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

When using special format types (such as `%()l`) together with replacement values in output templates, the value gets formatted incorrectly.

For example, I would expect that downloading https://music.youtube.com/watch?v=XjJWF2Qi_ZI with the output template `%(title)s %(tags&[{}] |)l[%(id)s].%(ext)s` would give me a file with name `Deathfire Grasp [Pentakill, Smite and Ignite, Deathfire Grasp] [XjJWF2Qi_ZI].webm`, but yt-dlp names it `Deathfire Grasp [['Pentakill', 'Smite and Ignite', 'Deathfire Grasp']] [XjJWF2Qi_ZI].webm` instead.

I think the problem is in the `create_key()` function inside `YoutubeDL.prepare_outtmpl()`, as the replacement is applied (and thus, the value is converted into a string) before its formatting is applied. In my example, the value is a list, so it gets formatted using the list's `__str__` method instead of yt-dlp's list formatter.

I've opened a PR that fixes this in #7661.

### 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: ['--verbose', '-o', '%(title)s %(tags&[{}] |)l[%(id)s].%(ext)s', 'https://music.youtube.com/watch?v=XjJWF2Qi_ZI']
[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.07.06 [b532a3481]
[debug] Python 3.11.3 (CPython x86_64 64bit) - Linux-6.4.4-zen1-1-zen-x86_64-with-glibc2.37 (OpenSSL 3.1.1 30 May 2023, glibc 2.37)
[debug] exe versions: ffmpeg 6.0 (setts), ffprobe 6.0, phantomjs broken, rtmpdump 2.4
[debug] Optional libraries: Cryptodome-3.12.0, brotli-1.0.9, certifi-2023.05.07, mutagen-1.46.0, sqlite3-2.6.0, websockets-10.4
[debug] Proxy map: {}
[debug] Loaded 1855 extractors
[youtube] Extracting URL: https://music.youtube.com/watch?v=XjJWF2Qi_ZI
[youtube] XjJWF2Qi_ZI: Downloading webpage
[youtube] XjJWF2Qi_ZI: Downloading ios player API JSON
[youtube] XjJWF2Qi_ZI: Downloading android player API JSON
[youtube] XjJWF2Qi_ZI: Downloading ios music player API JSON
[youtube] XjJWF2Qi_ZI: Downloading android music player API JSON
[youtube] XjJWF2Qi_ZI: Downloading web music client config
[youtube] XjJWF2Qi_ZI: Downloading player 8e83803a
[youtube] XjJWF2Qi_ZI: Downloading web music player API JSON
[youtube] XjJWF2Qi_ZI: Downloading m3u8 information
[youtube] XjJWF2Qi_ZI: Downloading m3u8 information
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, vcodec:vp9.2, channels, acodec, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec:vp9.2(10), channels, acodec, lang, proto, size, br, asr, vext, aext, hasaud, id
[debug] Default format spec: bestvideo*+bestaudio/best
[info] XjJWF2Qi_ZI: Downloading 1 format(s): 248+251
[debug] Invoking http downloader on "https://rr2---sn-2vgu0b5auxaxjvh-v2vz.googlevideo.com/videoplayback?expire=1690016573&ei=3Ua7ZJqsC5ygxN8P09GpoAU&ip=redacted&id=o-AJJ_ynO62PNZGLcmB1NlTSLpA0jZEbcSFE0IChuzihV8&itag=248&source=youtube&requiressl=yes&mh=3T&mm=31%2C29&mn=sn-2vgu0b5auxaxjvh-v2vz%2Csn-apn7en7e&ms=au%2Crdu&mv=m&mvi=2&pl=24&pcm2=yes&gcr=pt&initcwndbps=1633750&vprv=1&svpuc=1&mime=video%2Fwebm&gir=yes&clen=20103975&dur=240.000&lmt=1586825991883668&mt=1689994618&fvip=2&keepalive=yes&fexp=24007246&beids=24350018&c=IOS&txp=2331224&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cpcm2%2Cgcr%2Cvprv%2Csvpuc%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRAIgDPZfnOXXuuwpShtT_JDt0kyElsNgTnxFKwS29eZ3dMsCIALwbVfmqXw3_1UnaAu2XjX8-9lK49z8xGwCe4ByWlGx&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIgK8eAViULGWrB5HU3MssWHooIkRzxBBToiGgQfc4UevQCIQCRAgZx11yu-U50Hcfr6AFlpAmpUNp9GnuUfd6cfin5PQ%3D%3D"
[download] Destination: Deathfire Grasp [['Pentakill', 'Smite and Ignite', 'Deathfire Grasp']] [XjJWF2Qi_ZI].f248.webm
[download] 100% of   19.17MiB in 00:00:00 at 20.57MiB/s
[debug] Invoking http downloader on "https://rr2---sn-2vgu0b5auxaxjvh-v2vz.googlevideo.com/videoplayback?expire=1690016573&ei=3Ua7ZJiZFZqtxN8P1NScyA8&ip=redacted&id=o-AKb1uJUldqp0DCTp7d_Bk_Hc61JBst35qE1fMxTGwAvx&itag=251&source=youtube&requiressl=yes&mh=3T&mm=31%2C29&mn=sn-2vgu0b5auxaxjvh-v2vz%2Csn-apn7en7e&ms=au%2Crdu&mv=m&mvi=2&pl=24&gcr=pt&initcwndbps=1633750&spc=Ul2Sq4Sua3eCV_ueCuTvQIvc9exwF9g&vprv=1&svpuc=1&mime=audio%2Fwebm&gir=yes&clen=3903844&dur=240.041&lmt=1586825953417116&mt=1689994618&fvip=2&keepalive=yes&fexp=24007246%2C24363391&c=ANDROID&txp=2331224&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cgcr%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRAIgEq5FAilchBJqbOE6CaJwW2x52J6CB0AGofXSRNZnFk8CICcHlmplo5_N-LaS3ewsRgnBHXXlcHuYonSum2eZwEja&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIgVLe61JTJkwUro84LiAl8TDUNbJF2DwH8giHbJWtdvyYCIQCGT5F23Cic9sDNmszD9p1-qvrHA_BI-vZrH1vpOtnvPg%3D%3D"
[download] Destination: Deathfire Grasp [['Pentakill', 'Smite and Ignite', 'Deathfire Grasp']] [XjJWF2Qi_ZI].f251.webm
[download] 100% of    3.72MiB in 00:00:00 at 34.33MiB/s
[Merger] Merging formats into "Deathfire Grasp [['Pentakill', 'Smite and Ignite', 'Deathfire Grasp']] [XjJWF2Qi_ZI].webm"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:Deathfire Grasp [['"'"'Pentakill'"'"', '"'"'Smite and Ignite'"'"', '"'"'Deathfire Grasp'"'"']] [XjJWF2Qi_ZI].f248.webm' -i 'file:Deathfire Grasp [['"'"'Pentakill'"'"', '"'"'Smite and Ignite'"'"', '"'"'Deathfire Grasp'"'"']] [XjJWF2Qi_ZI].f251.webm' -c copy -map 0:v:0 -map 1:a:0 -movflags +faststart 'file:Deathfire Grasp [['"'"'Pentakill'"'"', '"'"'Smite and Ignite'"'"', '"'"'Deathfire Grasp'"'"']] [XjJWF2Qi_ZI].temp.webm'
Deleting original file Deathfire Grasp [['Pentakill', 'Smite and Ignite', 'Deathfire Grasp']] [XjJWF2Qi_ZI].f251.webm (pass -k to keep)
Deleting original file Deathfire Grasp [['Pentakill', 'Smite and Ignite', 'Deathfire Grasp']] [XjJWF2Qi_ZI].f248.webm (pass -k to keep)
```