Repository: yt-dlp
Issue: --trim-filenames fails to clip file name properly when there is a dot in a video title
Labels: bug

### Checklist

- [X] I'm reporting a bug unrelated to a specific site
- [X] I've verified that I'm running yt-dlp version **2021.12.27**. ([update instructions](https://github.com/yt-dlp/yt-dlp#update))
- [X] I've checked that all provided URLs are alive and playable in a browser
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/ytdl-org/youtube-dl#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 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)

### Description

This procedure:
https://github.com/yt-dlp/yt-dlp/blob/e04938ab88fc1fb4560f6cceb32525ef6e7f47a4/yt_dlp/YoutubeDL.py#L1221-L1225

Assumes that there is at most 2 extensions appended to the current filename. This fails when there is a dot in a video title. Yeah, that happens.

*Proposed fixes*
a. assuming there is only one extension => using `os.path.splitext()` to split the filename before trimming
b. trimming the file name _before_ appending the ext.
  - might cause artefacts (trimming `foo-bar-foo.mp4` to 14 chars would produce `foo-bar-foo.mp.mp4`)

c. mask dots from extracted video titles  
d. _let me know if you have some other idea_

I am happy to fix that, just let me know which (a-d) would the maintainers prefer.

### Verbose log

```shell
[debug] Command-line config: ['-Uv', '--trim-filenames', '30', 'https://www.dvtv.cz/video/slavme-odchod-delty-a-prichod-omikronu-ockovat-se-kvuli-byrokracii-a-ne-kvuli-zdravi-je-ulet-rika-hostomsky']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8 (No ANSI), err utf-8 (No ANSI), pref UTF-8
[debug] yt-dlp version 2021.12.27 [6223f67a8]
[debug] Python version 3.10.1 (CPython 64bit) - macOS-12.0.1-x86_64-i386-64bit
[debug] exe versions: ffmpeg 4.4.1 (setts), ffprobe 4.4.1
[debug] Optional libraries: Cryptodome, mutagen, sqlite, websockets
[debug] Proxy map: {}
Latest version: 2021.12.27, Current version: 2021.12.27
yt-dlp is up to date (2021.12.27)
[debug] [generic] Extracting URL: https://www.dvtv.cz/video/slavme-odchod-delty-a-prichod-omikronu-ockovat-se-kvuli-byrokracii-a-ne-kvuli-zdravi-je-ulet-rika-hostomsky
[generic] slavme-odchod-delty-a-prichod-omikronu-ockovat-se-kvuli-byrokracii-a-ne-kvuli-zdravi-je-ulet-rika-hostomsky: Requesting header
WARNING: [generic] Falling back on generic information extractor.
[generic] slavme-odchod-delty-a-prichod-omikronu-ockovat-se-kvuli-byrokracii-a-ne-kvuli-zdravi-je-ulet-rika-hostomsky: Downloading webpage
[generic] slavme-odchod-delty-a-prichod-omikronu-ockovat-se-kvuli-byrokracii-a-ne-kvuli-zdravi-je-ulet-rika-hostomsky: Extracting information
[debug] Looking for video embeds
[debug] Identified a HTML5 media
[debug] Formats sorted by: hasvid, ie_pref, lang, quality, res, fps, hdr:12(7), vcodec:vp9.2(10), acodec, filesize, fs_approx, tbr, vbr, abr, asr, proto, vext, aext, hasaud, source, id
[download] Downloading playlist: Slavme odchod delty a příchod omikronu. Očkovat se kvůli byrokracii a ne kvůli zdraví je úlet, říká Hostomský | DVTV - první internetová televize
[generic] playlist Slavme odchod delty a příchod omikronu. Očkovat se kvůli byrokracii a ne kvůli zdraví je úlet, říká Hostomský | DVTV - první internetová televize: Collected 1 videos; downloading 1 of them
[download] Downloading video 1 of 1
[debug] Default format spec: bestvideo*+bestaudio/best
[info] slavme-odchod-delty-a-prichod-omikronu-ockovat-se-kvuli-byrokracii-a-ne-kvuli-zdravi-je-ulet-rika-hostomsky: Downloading 1 format(s): 0
[debug] Invoking downloader on "https://www.dvtv.cz/uploads/videa-fotky/2022-01-10-dvtv-mr-hostomsky.mp3"
ERROR: unable to open for writing: [Errno 63] File name too long: 'Slavme odchod delty a příchod . Očkovat se kvůli byrokracii a ne kvůli zdraví je úlet, říká Hostomský _ DVTV - první internetová televize [slavme-odchod-delty-a-prichod-omikronu-ockovat-se-kvuli-byrokracii-a-ne-kvuli-zdravi-je-ulet-rika-hostomsky].mp3.part'
Traceback (most recent call last):
  File "/usr/local/Cellar/yt-dlp/2021.12.27/libexec/lib/python3.10/site-packages/yt_dlp/downloader/http.py", line 265, in download
    ctx.stream, ctx.tmpfilename = self.sanitize_open(
  File "/usr/local/Cellar/yt-dlp/2021.12.27/libexec/lib/python3.10/site-packages/yt_dlp/downloader/common.py", line 218, in sanitize_open
    return sanitize_open(filename, open_mode)
  File "/usr/local/Cellar/yt-dlp/2021.12.27/libexec/lib/python3.10/site-packages/yt_dlp/utils.py", line 557, in sanitize_open
    stream = open(encodeFilename(filename), open_mode)
OSError: [Errno 63] File name too long: 'Slavme odchod delty a příchod . Očkovat se kvůli byrokracii a ne kvůli zdraví je úlet, říká Hostomský _ DVTV - první internetová televize [slavme-odchod-delty-a-prichod-omikronu-ockovat-se-kvuli-byrokracii-a-ne-kvuli-zdravi-je-ulet-rika-hostomsky].mp3.part'


[download] Finished downloading playlist: Slavme odchod delty a příchod omikronu. Očkovat se kvůli byrokracii a ne kvůli zdraví je úlet, říká Hostomský | DVTV - první internetová televize
```