question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

--trim-filenames fails to clip file name properly when there is a dot in a video title

See original GitHub issue

Checklist

  • I’m reporting a bug unrelated to a specific site
  • I’ve verified that I’m running yt-dlp version 2021.12.27. (update instructions)
  • I’ve checked that all provided URLs are alive and playable in a browser
  • I’ve checked that all URLs and arguments with special characters are properly quoted or escaped
  • I’ve searched the bugtracker for similar issues including closed ones. DO NOT post duplicates
  • I’ve read the guidelines for 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

[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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
letalvojcommented, Dec 2, 2022

I honestly suggest using something like %(title).30s.%(ext)s instead

Why does not it use the sanitized id to name the file. Like %(id)s.%(ext)? Or similar. I made a bash alias which includes the -o parameter by default such that I do not need to rename the files all the time.

2reactions
pukkandancommented, Dec 2, 2022

I am aware of this issue 😓. The --trim-filename option is just overall poorly implemented, making this tricky to fix. I honestly suggest using something like %(title).30B.%(ext)s instead

Read more comments on GitHub >

github_iconTop Results From Across the Web

Any way to have YouTube-DL intelligently rename files if the ...
There are 2 ways to do this depending on your preference: --trim-filenames . Eg: --trim-filenames 200 will trim the whole filename to 200...
Read more >
When Renaming Video Files in Explorer, new names not in ...
Hi,. Windows media player might be showing the Title of the music file and not the file name. Please try changing Title of...
Read more >
yt-dlp(1) - Arch manual pages
Make filenames Windows-compatible only if using Windows (default); --trim-filenames LENGTH: Limit the filename length (excluding extension) to the specified ...
Read more >
Video File Naming Best Practices for a Smooth Post ... - Avid
These video file naming best practices will streamline the post-production workflow, freeing up your time and energy for more creative work.
Read more >
Premiere confuses files of same name - 9590525
MTS is the common starting point for many cameras, it is likely we will have files with the same name. The video seems...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found