Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
6 tasks done
letalvoj opened this issue Jan 12, 2022 · 10 comments · May be fixed by #7954
Open
6 tasks done

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

letalvoj opened this issue Jan 12, 2022 · 10 comments · May be fixed by #7954
Labels
bug Bug that is not site-specific

Comments

@letalvoj
Copy link

letalvoj commented Jan 12, 2022

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:

yt-dlp/yt_dlp/YoutubeDL.py

Lines 1221 to 1225 in e04938a

# https://github.com/blackjack4494/youtube-dlc/issues/85
trim_file_name = self.params.get('trim_file_name', False)
if trim_file_name:
no_ext, *ext = filename.rsplit('.', 2)
filename = join_nonempty(no_ext[:trim_file_name], *ext, delim='.')

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
@letalvoj letalvoj added bug Bug that is not site-specific triage Untriaged issue labels Jan 12, 2022
@pukkandan pukkandan removed the triage Untriaged issue label Jan 12, 2022
@pukkandan
Copy link
Member

pukkandan commented Jan 12, 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

@pukkandan
Copy link
Member

Related: #1837

@letalvoj

This comment was marked as off-topic.

@pukkandan pukkandan self-assigned this Feb 10, 2022
@ssokolow

This comment was marked as off-topic.

@JoakimCh

This comment was marked as off-topic.

@pukkandan
Copy link
Member

@JoakimCh Yes, and the answer is even pinned! #1136 (comment)

@ssokolow

This comment was marked as off-topic.

@pukkandan

This comment was marked as off-topic.

@ssokolow

This comment was marked as off-topic.

@yt-dlp yt-dlp locked as off-topic and limited conversation to collaborators Dec 2, 2022
@pukkandan
Copy link
Member

I suggest you read the discussion under the linked comment.

This issue is about the bug in --trim-filenames, and there's not a single on-topic comment here! I'm locking the issue.

For reference, here's a potential solution for the actual issue #5526 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug that is not site-specific
Projects
Status: Filename
Development

Successfully merging a pull request may close this issue.

4 participants