Repository: yt-dlp
Issue: Limit filename by bytes and unicode normalize at the same time
Labels: enhancement,triage

### 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

Currently, you can limit by characters but this will fail sometimes on linux
`%(title).100s - %(uploader).30s [%(id)s].%(ext)s`

So you can limit by bytes, but this will lead to much smaller titles than what you want with cjk or special fonts
`%(title).100B - %(uploader).50B [%(id)s].%(ext)s`

So, you can force it into unicode, but then you can't limit by bytes, only character count, which will have an error on cjk characters
`%(title)+.100U - %(uploader).50B [%(id)s].%(ext)s`

So the one you should use depends on the title of the video, but the title will vary when you are downloading a playlist so, there's no best solution to this.

I provided logs that show the output of all of those examples with different videos. They aren't verbose because verbosity is not necessary here. Here are the videos if you want to try it

https://www.youtube.com/watch?v=pnWh5JlJ9ys
https://www.youtube.com/watch?v=cirDXY3CkSk
https://www.youtube.com/watch?v=8c7CrrMsBvI
https://www.youtube.com/watch?v=oR2cuFgVQBI
https://www.youtube.com/watch?v=J6_vSNtCWs4

Also, a neat little trick to create a temporary playlist you can test this on, since my use case is playlist and youtube channels https://youtube.com/watch_videos?video_ids=pnWh5JlJ9ys,cirDXY3CkSk,8c7CrrMsBvI,oR2cuFgVQBI,J6_vSNtCWs4 

I am currently using %(title)+.176B - %(uploader).50B [%(id)s].%(ext)s for now since character counts are more unpredictable. The best I can get while normalizing unicode is %(title)+.50U - %(uploader).50B [%(id)s].%(ext)s but I can go higher if I limit the channel name further or I don't include it. At first I wanted to limit channel names further, but I looked for the longest channel I could find that made sense (Salome's) and that removed some of the name.

### 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

```shell
yt-dlp -S +size,+br,+res,+fps https://www.youtube.com/watch?v=cirDXY3CkSk -o "%(title).100s - %(uploader).50B [%(id)s].%(ext)s"
[youtube] Extracting URL: https://www.youtube.com/watch?v=cirDXY3CkSk
[youtube] cirDXY3CkSk: Downloading webpage
[youtube] cirDXY3CkSk: Downloading ios player API JSON
[youtube] cirDXY3CkSk: Downloading mweb player API JSON
[youtube] cirDXY3CkSk: Downloading m3u8 information
[info] cirDXY3CkSk: Downloading 1 format(s): 598+599
ERROR: unable to open for writing: [Errno 36] File name too long: 'ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ￤モミアゲヲシャカアゲヲ￤Momiagewo Shakaagewo - ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ [cirDXY3CkSk].f598.webm.part'

ERROR: unable to open for writing: [Errno 36] File name too long: 'ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ￤モミアゲヲシャカアゲヲ￤Momiagewo Shakaagewo - ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ [cirDXY3CkSk].f599.m4a.part'

yt-dlp -S +size,+br,+res,+fps https://www.youtube.com/watch?v=cirDXY3CkSk -o "%(title).100U - %(uploader).50B [%(id)s].%(ext)s"
[youtube] Extracting URL: https://www.youtube.com/watch?v=cirDXY3CkSk
[youtube] cirDXY3CkSk: Downloading webpage
[youtube] cirDXY3CkSk: Downloading ios player API JSON
[youtube] cirDXY3CkSk: Downloading mweb player API JSON
[youtube] cirDXY3CkSk: Downloading m3u8 information
[info] cirDXY3CkSk: Downloading 1 format(s): 598+599
ERROR: unable to open for writing: [Errno 36] File name too long: 'ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ￤モミアゲヲシャカアゲヲ￤Momiagewo Shakaagewo - ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ [cirDXY3CkSk].f598.webm.part'

ERROR: unable to open for writing: [Errno 36] File name too long: 'ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ￤モミアゲヲシャカアゲヲ￤Momiagewo Shakaagewo - ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ [cirDXY3CkSk].f599.m4a.part'

yt-dlp -S +size,+br,+res,+fps https://www.youtube.com/watch?v=cirDXY3CkSk -o "%(title).100B - %(uploader).50B [%(id)s].%(ext)s"
[youtube] Extracting URL: https://www.youtube.com/watch?v=cirDXY3CkSk
[youtube] cirDXY3CkSk: Downloading webpage
[youtube] cirDXY3CkSk: Downloading ios player API JSON
[youtube] cirDXY3CkSk: Downloading mweb player API JSON
[youtube] cirDXY3CkSk: Downloading m3u8 information
[info] cirDXY3CkSk: Downloading 1 format(s): 598+599
[download] Destination: ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ - ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ [cirDXY3CkSk].f598.webm
[download] 100% of  701.10KiB in 00:00:01 at 623.58KiB/s
[download] Destination: ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ - ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ [cirDXY3CkSk].f599.m4a
[download] 100% of  781.66KiB in 00:00:00 at 1.50MiB/s
[Merger] Merging formats into "ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ - ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ [cirDXY3CkSk].mkv"
Deleting original file ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ - ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ [cirDXY3CkSk].f598.webm (pass -k to keep)
Deleting original file ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ - ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ [cirDXY3CkSk].f599.m4a (pass -k to keep)
yt-dlp -S +size,+br,+res,+fps https://www.youtube.com/watch?v=pnWh5JlJ9ys -o "%(title).100B - %(uploader).50B [%(id)s].%(ext)s"
[youtube] Extracting URL: https://www.youtube.com/watch?v=pnWh5JlJ9ys
[youtube] pnWh5JlJ9ys: Downloading webpage
[youtube] pnWh5JlJ9ys: Downloading ios player API JSON
[youtube] pnWh5JlJ9ys: Downloading mweb player API JSON
[youtube] pnWh5JlJ9ys: Downloading m3u8 information
[info] pnWh5JlJ9ys: Downloading 1 format(s): 598+599
[download] Destination: 𝗡𝗲𝗿𝗶𝘀𝘀𝗮 𝗳𝗼𝘂𝗻𝗱 𝗮 𝗚𝗹𝗶𝘁𝗰𝗵 𝗶𝗻 𝗠𝗶 - Gomi Simpington Ch. [pnWh5JlJ9ys].f598.webm
[download] 100% of    2.50MiB in 00:00:02 at 1.14MiB/s
[download] Destination: 𝗡𝗲𝗿𝗶𝘀𝘀𝗮 𝗳𝗼𝘂𝗻𝗱 𝗮 𝗚𝗹𝗶𝘁𝗰𝗵 𝗶𝗻 𝗠𝗶 - Gomi Simpington Ch. [pnWh5JlJ9ys].f599.m4a
[download] 100% of    2.66MiB in 00:00:01 at 1.82MiB/s
[Merger] Merging formats into "𝗡𝗲𝗿𝗶𝘀𝘀𝗮 𝗳𝗼𝘂𝗻𝗱 𝗮 𝗚𝗹𝗶𝘁𝗰𝗵 𝗶𝗻 𝗠𝗶 - Gomi Simpington Ch. [pnWh5JlJ9ys].mkv"
Deleting original file 𝗡𝗲𝗿𝗶𝘀𝘀𝗮 𝗳𝗼𝘂𝗻𝗱 𝗮 𝗚𝗹𝗶𝘁𝗰𝗵 𝗶𝗻 𝗠𝗶 - Gomi Simpington Ch. [pnWh5JlJ9ys].f598.webm (pass -k to keep)
Deleting original file 𝗡𝗲𝗿𝗶𝘀𝘀𝗮 𝗳𝗼𝘂𝗻𝗱 𝗮 𝗚𝗹𝗶𝘁𝗰𝗵 𝗶𝗻 𝗠𝗶 - Gomi Simpington Ch. [pnWh5JlJ9ys].f599.m4a (pass -k to keep)

yt-dlp -S +size,+br,+res,+fps https://www.youtube.com/watch?v=pnWh5JlJ9ys -o "%(title)+.100U - %(uploader).50B [%(id)s].%(ext)s"
[youtube] Extracting URL: https://www.youtube.com/watch?v=pnWh5JlJ9ys
[youtube] pnWh5JlJ9ys: Downloading webpage
[youtube] pnWh5JlJ9ys: Downloading ios player API JSON
[youtube] pnWh5JlJ9ys: Downloading mweb player API JSON
[youtube] pnWh5JlJ9ys: Downloading m3u8 information
[info] pnWh5JlJ9ys: Downloading 1 format(s): 598+599
[download] Destination: Nerissa found a Glitch in Minecraft and Exploits it, but the Devs are watching ｜Hololive｜ - Gomi Simpington Ch. [pnWh5JlJ9ys].f598.webm
[download] 100% of    2.50MiB in 00:00:01 at 1.30MiB/s
[download] Destination: Nerissa found a Glitch in Minecraft and Exploits it, but the Devs are watching ｜Hololive｜ - Gomi Simpington Ch. [pnWh5JlJ9ys].f599.m4a
[download] 100% of    2.66MiB in 00:00:01 at 1.94MiB/s
[Merger] Merging formats into "Nerissa found a Glitch in Minecraft and Exploits it, but the Devs are watching ｜Hololive｜ - Gomi Simpington Ch. [pnWh5JlJ9ys].mkv"
Deleting original file Nerissa found a Glitch in Minecraft and Exploits it, but the Devs are watching ｜Hololive｜ - Gomi Simpington Ch. [pnWh5JlJ9ys].f598.webm (pass -k to keep)
Deleting original file Nerissa found a Glitch in Minecraft and Exploits it, but the Devs are watching ｜Hololive｜ - Gomi Simpington Ch. [pnWh5JlJ9ys].f599.m4a (pass -k to keep)

yt-dlp -S +size,+br,+res,+fps https://www.youtube.com/watch?v=cirDXY3CkSk -o "%(title)+.100U - %(uploader).50B [%(id)s].%(ext)s"
[youtube] Extracting URL: https://www.youtube.com/watch?v=cirDXY3CkSk
[youtube] cirDXY3CkSk: Downloading webpage
[youtube] cirDXY3CkSk: Downloading ios player API JSON
[youtube] cirDXY3CkSk: Downloading mweb player API JSON
[youtube] cirDXY3CkSk: Downloading m3u8 information
[info] cirDXY3CkSk: Downloading 1 format(s): 598+599
ERROR: unable to open for writing: [Errno 36] File name too long: 'ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ¦モミアゲヲシャカアゲヲ¦Momiagewo Shakaagewo - ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ [cirDXY3CkSk].f598.webm.part'

ERROR: unable to open for writing: [Errno 36] File name too long: 'ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ¦モミアゲヲシャカアゲヲ¦Momiagewo Shakaagewo - ぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬぬ [cirDXY3CkSk].f599.m4a.part'

yt-dlp -S +size,+br,+res,+fps https://www.youtube.com/watch?v=pnWh5JlJ9ys -o "%(title)+.176B - %(uploader).50B [%(id)s].%(ext)s"
[youtube] Extracting URL: https://www.youtube.com/watch?v=pnWh5JlJ9ys
[youtube] pnWh5JlJ9ys: Downloading webpage
[youtube] pnWh5JlJ9ys: Downloading ios player API JSON
[youtube] pnWh5JlJ9ys: Downloading mweb player API JSON
[youtube] pnWh5JlJ9ys: Downloading m3u8 information
[info] pnWh5JlJ9ys: Downloading 1 format(s): 598+599
[download] Destination: 𝗡𝗲𝗿𝗶𝘀𝘀𝗮 𝗳𝗼𝘂𝗻𝗱 𝗮 𝗚𝗹𝗶𝘁𝗰𝗵 𝗶𝗻 𝗠𝗶𝗻𝗲𝗰𝗿𝗮𝗳𝘁 𝗮𝗻𝗱 𝗘𝘅𝗽𝗹𝗼𝗶𝘁𝘀 𝗶 - Gomi Simpington Ch. [pnWh5JlJ9ys].f598.webm
[download] 100% of    2.50MiB in 00:00:01 at 1.27MiB/s
[download] Destination: 𝗡𝗲𝗿𝗶𝘀𝘀𝗮 𝗳𝗼𝘂𝗻𝗱 𝗮 𝗚𝗹𝗶𝘁𝗰𝗵 𝗶𝗻 𝗠𝗶𝗻𝗲𝗰𝗿𝗮𝗳𝘁 𝗮𝗻𝗱 𝗘𝘅𝗽𝗹𝗼𝗶𝘁𝘀 𝗶 - Gomi Simpington Ch. [pnWh5JlJ9ys].f599.m4a
[download] 100% of    2.66MiB in 00:00:01 at 2.07MiB/s
[Merger] Merging formats into "𝗡𝗲𝗿𝗶𝘀𝘀𝗮 𝗳𝗼𝘂𝗻𝗱 𝗮 𝗚𝗹𝗶𝘁𝗰𝗵 𝗶𝗻 𝗠𝗶𝗻𝗲𝗰𝗿𝗮𝗳𝘁 𝗮𝗻𝗱 𝗘𝘅𝗽𝗹𝗼𝗶𝘁𝘀 𝗶 - Gomi Simpington Ch. [pnWh5JlJ9ys].mkv"
Deleting original file 𝗡𝗲𝗿𝗶𝘀𝘀𝗮 𝗳𝗼𝘂𝗻𝗱 𝗮 𝗚𝗹𝗶𝘁𝗰𝗵 𝗶𝗻 𝗠𝗶𝗻𝗲𝗰𝗿𝗮𝗳𝘁 𝗮𝗻𝗱 𝗘𝘅𝗽𝗹𝗼𝗶𝘁𝘀 𝗶 - Gomi Simpington Ch. [pnWh5JlJ9ys].f599.m4a (pass -k to keep)
Deleting original file 𝗡𝗲𝗿𝗶𝘀𝘀𝗮 𝗳𝗼𝘂𝗻𝗱 𝗮 𝗚𝗹𝗶𝘁𝗰𝗵 𝗶𝗻 𝗠𝗶𝗻𝗲𝗰𝗿𝗮𝗳𝘁 𝗮𝗻𝗱 𝗘𝘅𝗽𝗹𝗼𝗶𝘁𝘀 𝗶 - Gomi Simpington Ch. [pnWh5JlJ9ys].f598.webm (pass -k to keep)
```