Skip to content
This repository has been archived by the owner on Jun 21, 2021. It is now read-only.

Commit

Permalink
Fix playlist_index and add playlist_autonumber (blackjack4494#302)
Browse files Browse the repository at this point in the history
Now `playlist_index` is always the position of the video in the actual playlist and `playlist_autonumber` is the position of the item in the playlist queue
  • Loading branch information
pukkandan authored May 6, 2021
1 parent e8e7384 commit 7172975
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions yt_dlp/YoutubeDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ def make_playlistitems_entries(list_ie_entries):
'playlist_title': ie_result.get('title'),
'playlist_uploader': ie_result.get('uploader'),
'playlist_uploader_id': ie_result.get('uploader_id'),
'playlist_index': 0
'playlist_index': 0,
}
ie_copy.update(dict(ie_result))

Expand Down Expand Up @@ -1370,6 +1370,11 @@ def make_playlistitems_entries(list_ie_entries):
self.report_error('Cannot write playlist description file ' + descfn)
return

# Save playlist_index before re-ordering
entries = [
((playlistitems[i - 1] if playlistitems else i), entry)
for i, entry in enumerate(entries, 1)]

if self.params.get('playlistreverse', False):
entries = entries[::-1]
if self.params.get('playlistrandom', False):
Expand All @@ -1380,7 +1385,8 @@ def make_playlistitems_entries(list_ie_entries):
self.to_screen('[%s] playlist %s: %s' % (ie_result['extractor'], playlist, msg))
failures = 0
max_failures = self.params.get('skip_playlist_after_errors') or float('inf')
for i, entry in enumerate(entries, 1):
for i, entry_tuple in enumerate(entries, 1):
playlist_index, entry = entry_tuple
self.to_screen('[download] Downloading video %s of %s' % (i, n_entries))
# This __x_forwarded_for_ip thing is a bit ugly but requires
# minimal changes
Expand All @@ -1389,12 +1395,13 @@ def make_playlistitems_entries(list_ie_entries):
extra = {
'n_entries': n_entries,
'_last_playlist_index': max(playlistitems) if playlistitems else (playlistend or n_entries),
'playlist_index': playlist_index,
'playlist_autonumber': i,
'playlist': playlist,
'playlist_id': ie_result.get('id'),
'playlist_title': ie_result.get('title'),
'playlist_uploader': ie_result.get('uploader'),
'playlist_uploader_id': ie_result.get('uploader_id'),
'playlist_index': playlistitems[i - 1] if playlistitems else i,
'extractor': ie_result['extractor'],
'webpage_url': ie_result['webpage_url'],
'webpage_url_basename': url_basename(ie_result['webpage_url']),
Expand Down

0 comments on commit 7172975

Please sign in to comment.