diff --git a/examples/apis/get_all_videos_id_with_channel_by_search.py b/examples/apis/get_all_videos_id_with_channel_by_search.py index 8391fc87..aeafdaf7 100644 --- a/examples/apis/get_all_videos_id_with_channel_by_search.py +++ b/examples/apis/get_all_videos_id_with_channel_by_search.py @@ -11,21 +11,25 @@ def get_all_videos_id_by_channel(channel_id, limit=50, count=50): api = pyyoutube.Api(api_key=API_KEY) - res = api.search(channel_id=channel_id, limit=limit, count=count) - next_page = res.nextPageToken - videos = [] - while next_page: - next_page = res.nextPageToken - for item in res.items: - if item.id.videoId: - videos.append(item.id.videoId) + videos = [] + next_page = None + while True: res = api.search( channel_id=channel_id, limit=limit, count=count, - page_token=res.nextPageToken, + page_token=next_page, ) + next_page = res.nextPageToken + + for item in res.items: + if item.id.videoId: + videos.append(item.id.videoId) + + if not next_page: + break + return videos