mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-02-04 16:47:32 +01:00
Trim all path parts
This commit is contained in:
parent
8949a4fef0
commit
25dca22cb7
@ -12,6 +12,7 @@ import json
|
|||||||
import locale
|
import locale
|
||||||
import operator
|
import operator
|
||||||
import os
|
import os
|
||||||
|
from pathlib import Path
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
@ -1446,18 +1447,15 @@ class YoutubeDL:
|
|||||||
|
|
||||||
encoding = self.params.get('filesystem_encoding') or sys.getfilesystemencoding()
|
encoding = self.params.get('filesystem_encoding') or sys.getfilesystemencoding()
|
||||||
|
|
||||||
def trim_filename(name: str, length: int):
|
def trim_filename(name: str):
|
||||||
if mode == 'b':
|
if mode == 'b':
|
||||||
name = name.encode(encoding)
|
name = name.encode(encoding)
|
||||||
name = name[:length]
|
name = name[:max_file_name]
|
||||||
return name.decode(encoding, 'ignore')
|
return name.decode(encoding, 'ignore')
|
||||||
else:
|
else:
|
||||||
return name[:length]
|
return name[:max_file_name]
|
||||||
|
|
||||||
# only trim last component of path - assume the directories are valid names
|
filename = os.path.join(*map(trim_filename, Path(filename).parts))
|
||||||
head, tail = os.path.split(filename)
|
|
||||||
tail = trim_filename(tail, max_file_name)
|
|
||||||
filename = os.path.join(head, tail)
|
|
||||||
return filename + suffix
|
return filename + suffix
|
||||||
|
|
||||||
@_catch_unsafe_extension_error
|
@_catch_unsafe_extension_error
|
||||||
|
Loading…
x
Reference in New Issue
Block a user