mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-27 10:31:29 +00:00
parent
b5c5d84f60
commit
639f1cea92
|
@ -735,6 +735,11 @@ def fname(templ):
|
||||||
ydl = YoutubeDL(params)
|
ydl = YoutubeDL(params)
|
||||||
return ydl.prepare_filename(self.outtmpl_info)
|
return ydl.prepare_filename(self.outtmpl_info)
|
||||||
|
|
||||||
|
self.assertEqual(fname('%(height)06d.%(ext)s'), '001080.mp4')
|
||||||
|
self.assertEqual(fname('%(foo|)s-%(bar|)s.%(ext)s'), '-.mp4')
|
||||||
|
# self.assertEqual(fname('%(foo|)s.%(ext)s'), '_.mp4') # fixme
|
||||||
|
# self.assertEqual(fname('%(foo|)s'), '_') # fixme
|
||||||
|
|
||||||
self.assertEqual(fname('%%'), '%')
|
self.assertEqual(fname('%%'), '%')
|
||||||
self.assertEqual(fname('%%%%'), '%%')
|
self.assertEqual(fname('%%%%'), '%%')
|
||||||
self.assertEqual(fname('%%(width)06d.%(ext)s'), '%(width)06d.mp4')
|
self.assertEqual(fname('%%(width)06d.%(ext)s'), '%(width)06d.mp4')
|
||||||
|
@ -746,7 +751,7 @@ def fname(templ):
|
||||||
self.assertEqual(fname('Hello %(title2)s'), 'Hello %PATH%')
|
self.assertEqual(fname('Hello %(title2)s'), 'Hello %PATH%')
|
||||||
|
|
||||||
self.assertEqual(fname('%(title3)s'), 'foo_bar_test')
|
self.assertEqual(fname('%(title3)s'), 'foo_bar_test')
|
||||||
self.assertEqual(fname('%(formats.0)s'), "{'id' - 'id1'}")
|
self.assertEqual(fname('%(formats.0) 15s'), " {'id' - 'id1'}")
|
||||||
|
|
||||||
self.assertEqual(fname('%(id)r %(height)r'), "'1234' 1080")
|
self.assertEqual(fname('%(id)r %(height)r'), "'1234' 1080")
|
||||||
self.assertEqual(fname('%(formats.0)r'), "{'id' - 'id1'}")
|
self.assertEqual(fname('%(formats.0)r'), "{'id' - 'id1'}")
|
||||||
|
|
|
@ -126,6 +126,7 @@ def test_timeconvert(self):
|
||||||
self.assertTrue(timeconvert('bougrg') is None)
|
self.assertTrue(timeconvert('bougrg') is None)
|
||||||
|
|
||||||
def test_sanitize_filename(self):
|
def test_sanitize_filename(self):
|
||||||
|
self.assertEqual(sanitize_filename(''), '')
|
||||||
self.assertEqual(sanitize_filename('abc'), 'abc')
|
self.assertEqual(sanitize_filename('abc'), 'abc')
|
||||||
self.assertEqual(sanitize_filename('abc_d-e'), 'abc_d-e')
|
self.assertEqual(sanitize_filename('abc_d-e'), 'abc_d-e')
|
||||||
|
|
||||||
|
|
|
@ -936,6 +936,7 @@ def create_key(outer_mobj):
|
||||||
# If value is an object, sanitize might convert it to a string
|
# If value is an object, sanitize might convert it to a string
|
||||||
# So we convert it to repr first
|
# So we convert it to repr first
|
||||||
value, fmt = repr(value), '%ss' % fmt[:-1]
|
value, fmt = repr(value), '%ss' % fmt[:-1]
|
||||||
|
if fmt[-1] in 'csr':
|
||||||
value = sanitize(key, value)
|
value = sanitize(key, value)
|
||||||
tmpl_dict[key] = value
|
tmpl_dict[key] = value
|
||||||
return '%({key}){fmt}'.format(key=key, fmt=fmt)
|
return '%({key}){fmt}'.format(key=key, fmt=fmt)
|
||||||
|
|
|
@ -2107,6 +2107,8 @@ def replace_insane(char):
|
||||||
return '_'
|
return '_'
|
||||||
return char
|
return char
|
||||||
|
|
||||||
|
if s == '':
|
||||||
|
return ''
|
||||||
# Handle timestamps
|
# Handle timestamps
|
||||||
s = re.sub(r'[0-9]+(?::[0-9]+)+', lambda m: m.group(0).replace(':', '_'), s)
|
s = re.sub(r'[0-9]+(?::[0-9]+)+', lambda m: m.group(0).replace(':', '_'), s)
|
||||||
result = ''.join(map(replace_insane, s))
|
result = ''.join(map(replace_insane, s))
|
||||||
|
|
Loading…
Reference in a new issue