mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-02 12:56:24 -05:00
Trimming video file name to avoid error when file name is too long.
This commit is contained in:
parent
37ff1ab2cd
commit
cdc73d9d16
13 changed files with 140 additions and 27 deletions
|
|
@ -223,6 +223,7 @@ __all__ = [
|
|||
'slow_logger',
|
||||
'split_lines_by_length',
|
||||
'timer',
|
||||
'trim_file_name',
|
||||
'truncate_generator_bytes',
|
||||
'truncate_object_bytes',
|
||||
'tsvector',
|
||||
|
|
@ -994,6 +995,25 @@ def escape_file_name(name: str) -> str:
|
|||
return name.strip()
|
||||
|
||||
|
||||
# Maximum length is probably 255, but we need more length for large suffixes like `.readability.json`, and temporary
|
||||
# downloading suffixes.
|
||||
MAXIMUM_FILE_LENGTH = 180
|
||||
|
||||
|
||||
def trim_file_name(name: str) -> str:
|
||||
"""Shorten the file name only if it is longer than the file system supports. Trim from the end of the name until
|
||||
the name is short enough, excluding suffix."""
|
||||
if len(name) < MAXIMUM_FILE_LENGTH:
|
||||
return name
|
||||
|
||||
# Don't trim the filename to exactly 256 characters.
|
||||
# This is because a FileGroup will have varying filename lengths.
|
||||
from wrolpi.files.lib import split_path_stem_and_suffix
|
||||
stem, suffix = split_path_stem_and_suffix(name)
|
||||
excess = MAXIMUM_FILE_LENGTH - len(suffix)
|
||||
return stem[:excess].strip() + suffix
|
||||
|
||||
|
||||
def native_only(func: callable):
|
||||
"""Wraps a function. Raises NativeOnly if run while Dockerized."""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue