X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/66ab038f6f74eb2ebcaf945cf85bb0d7813f791c..a9226097c8eea0591fd3249f62a71becc6d2be93:/src/education/models.py diff --git a/src/education/models.py b/src/education/models.py index 5d11004b8..33064a113 100644 --- a/src/education/models.py +++ b/src/education/models.py @@ -49,15 +49,18 @@ class YPlaylist(models.Model): super().save() self.download() - def download(self): - response = YouTubeToken.objects.first().call( - "GET", - "https://www.googleapis.com/youtube/v3/playlistItems", - params={ + def download(self, page_token=None): + params = { 'part': 'snippet', 'playlistId': self.youtube_id, 'maxResults': 50, - }, + } + if page_token: + params['pageToken'] = page_token + response = YouTubeToken.objects.first().call( + "GET", + "https://www.googleapis.com/youtube/v3/playlistItems", + params=params ) data = response.json() for item in data['items']: @@ -68,6 +71,8 @@ class YPlaylist(models.Model): 'order': item['snippet']['position'], } ) + if data.get('nextPageToken'): + self.download(page_token=data['nextPageToken'])