]> jfr.im git - yt-dlp.git/commitdiff
[outtmpl] Fix replacement for `playlist_index`
authorpukkandan <redacted>
Sat, 22 Jul 2023 02:22:55 +0000 (07:52 +0530)
committerpukkandan <redacted>
Sat, 22 Jul 2023 03:27:43 +0000 (08:57 +0530)
test/test_YoutubeDL.py
yt_dlp/YoutubeDL.py

index b4f770ca585235a7f3ff02db34a1e285c65e97ed..c54c3ea5ce2fb34c22dd70e9e61ba48ef0bf381b 100644 (file)
@@ -687,6 +687,7 @@ def test(tmpl, expected, *, info=None, **params):
         test('%(duration_string)s', ('27:46:40', '27-46-40'))
         test('%(resolution)s', '1080p')
         test('%(playlist_index|)s', '001')
+        test('%(playlist_index&{}!)s', '001!')
         test('%(playlist_autonumber)s', '02')
         test('%(autonumber)s', '00001')
         test('%(autonumber+2)03d', '005', autonumber_start=3)
index 324f9e99c4d5f3f504207ce8ec9f67a2adef9af0..dae29d9f95b1b8f0f299d0f3736c3543390a8cd7 100644 (file)
@@ -1300,16 +1300,16 @@ def create_key(outer_mobj):
                 else:
                     break
 
-            fmt = outer_mobj.group('format')
-            if fmt == 's' and value is not None and last_field in field_size_compat_map.keys():
-                fmt = f'0{field_size_compat_map[last_field]:d}d'
-
             if None not in (value, replacement):
                 try:
                     value = replacement_formatter.format(replacement, value)
                 except ValueError:
                     value, default = None, na
 
+            fmt = outer_mobj.group('format')
+            if fmt == 's' and last_field in field_size_compat_map.keys() and isinstance(value, int):
+                fmt = f'0{field_size_compat_map[last_field]:d}d'
+
             flags = outer_mobj.group('conversion') or ''
             str_fmt = f'{fmt[:-1]}s'
             if value is None: