From f59ae58163ae801e06f77618b3a87514852b5f7f Mon Sep 17 00:00:00 2001 From: pukkandan Date: Mon, 3 May 2021 20:41:33 +0530 Subject: [PATCH] Fix number of digits in `%(playlist_index)s` When used with `--playlist-(items|start|end)`, the number of digits should depend on the last index in the playlist, not number of items --- yt_dlp/YoutubeDL.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index 98f320b2e..0791cfd9c 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -827,7 +827,7 @@ def prepare_outtmpl(self, outtmpl, info_dict, sanitize=None): # For fields playlist_index and autonumber convert all occurrences # of %(field)s to %(field)0Nd for backward compatibility field_size_compat_map = { - 'playlist_index': len(str(template_dict.get('n_entries', na))), + 'playlist_index': len(str(template_dict.get('_last_playlist_index') or '')), 'autonumber': autonumber_size, } FIELD_SIZE_COMPAT_RE = r'(?autonumber|playlist_index)\)s' @@ -1348,6 +1348,7 @@ def make_playlistitems_entries(list_ie_entries): entry['__x_forwarded_for_ip'] = x_forwarded_for extra = { 'n_entries': n_entries, + '_last_playlist_index': max(playlistitems) if playlistitems else (playlistend or n_entries), 'playlist': playlist, 'playlist_id': ie_result.get('id'), 'playlist_title': ie_result.get('title'),