Simplify with itertools.islice().
authorreiv <metareiv@gmail.com>
Sat, 17 Oct 2015 20:36:08 +0000 (22:36 +0200)
committerSergey M․ <dstftw@gmail.com>
Sat, 21 Nov 2015 13:41:19 +0000 (19:41 +0600)
youtube_dl/extractor/soundcloud.py

index 3fe991849b67fb7ebf447715c7c34301ebc190ca..959f27975da7d6d4a930b8bd3dde92f30e4c4b60 100644 (file)
@@ -532,11 +532,7 @@ class SoundcloudSearchIE(SearchInfoExtractor, SoundcloudIE):
             collection_id='Query "{0}"'.format(query),
             q=query.encode('utf-8'))
 
-        for _ in range(n):
-            try:
-                track = next(tracks)
-            except StopIteration:
-                break
+        for track in itertools.islice(tracks, n):
             uri = track['uri']
             title = track['title']
             results.append(self.url_result(url=uri))