Refactor, make default notrim

This commit is contained in:
7x11x13
2025-01-08 13:03:15 -05:00
parent ba9cfb23f2
commit 8949a4fef0
4 changed files with 20 additions and 32 deletions
+17
View File
@@ -1,3 +1,4 @@
import codecs
import sys
if sys.version_info < (3, 9):
@@ -429,6 +430,21 @@ def validate_options(opts):
}
# Other options
opts.trim_file_name_mode = 'c'
if opts.trim_file_name is not None:
mobj = re.match(r'(?:(?P<length>\d+)(?P<mode>b|c)?|notrim)', opts.trim_file_name)
validate(mobj, 'trim filenames', opts.trim_file_name)
if opts.trim_file_name == 'notrim':
opts.trim_file_name = 0
else:
opts.trim_file_name = int(mobj.group('length'))
opts.trim_file_name_mode = mobj.group('mode') or 'c'
if opts.filesystem_encoding is not None:
try:
codecs.lookup(opts.filesystem_encoding)
except LookupError:
raise ValueError(f'Invalid filesystem encoding: {opts.filesystem_encoding}')
if opts.playlist_items is not None:
try:
tuple(PlaylistEntries.parse_playlist_items(opts.playlist_items))
@@ -886,6 +902,7 @@ def parse_options(argv=None):
'max_downloads': opts.max_downloads,
'prefer_free_formats': opts.prefer_free_formats,
'trim_file_name': opts.trim_file_name,
'trim_file_name_mode': opts.trim_file_name_mode,
'filesystem_encoding': opts.filesystem_encoding,
'verbose': opts.verbose,
'dump_intermediate_pages': opts.dump_intermediate_pages,