Commit 1b47fea4 authored by Fjen Undso's avatar Fjen Undso
Browse files

get_playlist: IDs as strings. limit IDs per api request. fixes #1

parent 4f17fe05
*.egg-info
*.pyc
*.swp
.cache/
.coverage
.tox/
MANIFEST
build/
dist/
xunit-*.xml
*~
......@@ -78,16 +78,20 @@ class YouTubeLibraryProvider(backend.LibraryProvider):
def _get_tracks(self, ids):
"""Process YouTube IDs and return tracks"""
fancy_ids = ' '.join([str(x) for x in ids])
logger.info("Get YouTube tracks for IDs: %s", fancy_ids)
query = {
'part': 'id,snippet,contentDetails',
'fields': 'items(id,snippet(title,channelTitle,thumbnails(high(url))),contentDetails(duration))',
'id': ','.join(ids),
'key': yt_key
}
results = session.get(yt_api_endpoint + 'videos',
params=query).json()['items']
ids_per_req = 50
results = []
ids2 = [ids[i:i + ids_per_req] for i in xrange(0, len(ids), ids_per_req)]
for i in ids2:
fancy_ids = ','.join(i)
logger.info("Get YouTube tracks for IDs: %s", fancy_ids)
query = {
'part': 'id,snippet,contentDetails',
'fields': 'items(id,snippet(title,channelTitle,thumbnails(high(url))),contentDetails(duration))',
'id': fancy_ids,
'key': yt_key
}
results += session.get(yt_api_endpoint + 'videos',
params=query).json()['items']
tracks = []
for result in results:
......@@ -121,7 +125,7 @@ class YouTubeLibraryProvider(backend.LibraryProvider):
results = session.get(yt_api_endpoint + 'playlistItems',
params=query).json()
for res in results['items']:
video_ids.append(res['snippet']['resourceId']['videoId'])
video_ids.append(str(res['snippet']['resourceId']['videoId']))
page = results.get('nextPageToken') or None
return self._get_tracks(video_ids)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment