[youtube] Detect when Mixes end or wrap around
This commit is contained in:
parent
26fe8ffed0
commit
2be71994c0
1 changed files with 13 additions and 8 deletions
|
@ -2961,19 +2961,24 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
|
||||||
**metadata)
|
**metadata)
|
||||||
|
|
||||||
def _extract_mix_playlist(self, playlist, playlist_id):
|
def _extract_mix_playlist(self, playlist, playlist_id):
|
||||||
page_num = 0
|
first_id = last_id = None
|
||||||
while True:
|
for page_num in itertools.count(1):
|
||||||
videos = list(self._playlist_entries(playlist))
|
videos = list(self._playlist_entries(playlist))
|
||||||
if not videos:
|
if not videos:
|
||||||
return
|
return
|
||||||
video_count = len(videos)
|
start = next((i for i, v in enumerate(videos) if v['id'] == last_id), -1) + 1
|
||||||
start = min(video_count - 24, 26) if video_count > 25 else 0
|
if start >= len(videos):
|
||||||
for item in videos[start:]:
|
return
|
||||||
yield item
|
for video in videos[start:]:
|
||||||
|
if video['id'] == first_id:
|
||||||
|
self.to_screen('First video %s found again; Assuming end of Mix' % first_id)
|
||||||
|
return
|
||||||
|
yield video
|
||||||
|
first_id = first_id or videos[0]['id']
|
||||||
|
last_id = videos[-1]['id']
|
||||||
|
|
||||||
page_num += 1
|
|
||||||
_, data = self._extract_webpage(
|
_, data = self._extract_webpage(
|
||||||
'https://www.youtube.com/watch?list=%s&v=%s' % (playlist_id, videos[-1]['id']),
|
'https://www.youtube.com/watch?list=%s&v=%s' % (playlist_id, last_id),
|
||||||
'%s page %d' % (playlist_id, page_num))
|
'%s page %d' % (playlist_id, page_num))
|
||||||
playlist = try_get(
|
playlist = try_get(
|
||||||
data, lambda x: x['contents']['twoColumnWatchNextResults']['playlist']['playlist'], dict)
|
data, lambda x: x['contents']['twoColumnWatchNextResults']['playlist']['playlist'], dict)
|
||||||
|
|
Loading…
Reference in a new issue