mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-03-09 12:50:23 -05:00
Merge 1974b2b332
into 05c8023a27
This commit is contained in:
commit
90972e17e9
2 changed files with 15 additions and 6 deletions
|
@ -934,6 +934,15 @@ def gen():
|
||||||
# test('%(foo|)s.%(ext)s', ('.mp4', '_.mp4')) # FIXME: ?
|
# test('%(foo|)s.%(ext)s', ('.mp4', '_.mp4')) # FIXME: ?
|
||||||
# test('%(foo|)s', ('', '_')) # FIXME: ?
|
# test('%(foo|)s', ('', '_')) # FIXME: ?
|
||||||
|
|
||||||
|
# Trim filename
|
||||||
|
test('%(id)s.%(filesize)s.%(ext)s', ('1234.1024.mp4', '123.mp4'), trim_file_name=3)
|
||||||
|
test(
|
||||||
|
'%(id)s.%(filesize)s.%(ext)s',
|
||||||
|
('1234.1024.info.json', '123.info.json'),
|
||||||
|
info=dict(self.outtmpl_info, ext='info.json'), trim_file_name=3
|
||||||
|
)
|
||||||
|
test('12 34.%(filesize)s.%(ext)s', ('12 34.1024.mp4', '12 .mp4'), trim_file_name=3)
|
||||||
|
|
||||||
# Environment variable expansion for prepare_filename
|
# Environment variable expansion for prepare_filename
|
||||||
os.environ['__yt_dlp_var'] = 'expanded'
|
os.environ['__yt_dlp_var'] = 'expanded'
|
||||||
envvar = '%__yt_dlp_var%' if os.name == 'nt' else '$__yt_dlp_var'
|
envvar = '%__yt_dlp_var%' if os.name == 'nt' else '$__yt_dlp_var'
|
||||||
|
|
|
@ -1455,6 +1455,12 @@ def _prepare_filename(self, info_dict, *, outtmpl=None, tmpl_type=None):
|
||||||
if not filename:
|
if not filename:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
trim_file_name = self.params.get('trim_file_name')
|
||||||
|
if trim_file_name:
|
||||||
|
# https://github.com/yt-dlp/yt-dlp/issues/5526#issuecomment-1312783517
|
||||||
|
no_ext, *ext = filename.rsplit('.', info_dict.get('ext', '').count('.') + 1)
|
||||||
|
filename = join_nonempty(no_ext[:trim_file_name], *ext, delim='.')
|
||||||
|
|
||||||
if tmpl_type in ('', 'temp'):
|
if tmpl_type in ('', 'temp'):
|
||||||
final_ext, ext = self.params.get('final_ext'), info_dict.get('ext')
|
final_ext, ext = self.params.get('final_ext'), info_dict.get('ext')
|
||||||
if final_ext and ext and final_ext != ext and filename.endswith(f'.{final_ext}'):
|
if final_ext and ext and final_ext != ext and filename.endswith(f'.{final_ext}'):
|
||||||
|
@ -1464,12 +1470,6 @@ def _prepare_filename(self, info_dict, *, outtmpl=None, tmpl_type=None):
|
||||||
if force_ext:
|
if force_ext:
|
||||||
filename = replace_extension(filename, force_ext, info_dict.get('ext'))
|
filename = replace_extension(filename, force_ext, info_dict.get('ext'))
|
||||||
|
|
||||||
# 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='.')
|
|
||||||
|
|
||||||
return filename
|
return filename
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
self.report_error('Error in output template: ' + str(err) + ' (encoding: ' + repr(preferredencoding()) + ')')
|
self.report_error('Error in output template: ' + str(err) + ' (encoding: ' + repr(preferredencoding()) + ')')
|
||||||
|
|
Loading…
Reference in a new issue