Beispiel #1
0
    def fetch_tracks(self, batch_size=100):
        position = 0

        while position < self.length:
            if position >= len(self.items):
                # Can we extend the playlist?
                if not self.extend(position, batch_size):
                    break

            # Get URI for each item
            uris = [item.uri for item in self.items[position:position + batch_size]]

            # Request full track metadata
            event = REvent()
            self.sp.metadata(uris, callback=lambda items: event.set(items))

            tracks = event.wait(10)

            # Check if there was a request timeout
            if tracks is None:
                log.warn('Timeout while fetching track metadata')
                break

            # Yield each track
            for track in tracks:
                yield track

            position += len(uris)
Beispiel #2
0
    def fetch_tracks(self, batch_size=100):
        position = 0

        while position < self.length:
            if position >= len(self.items):
                # Can we extend the playlist?
                if not self.extend(position, batch_size):
                    break

            # Get URI for each item
            uris = [
                item.uri for item in self.items[position:position + batch_size]
            ]

            # Request full track metadata
            event = REvent()
            self.sp.metadata(uris, callback=lambda items: event.set(items))

            tracks = event.wait(10)

            # Check if there was a request timeout
            if tracks is None:
                log.warn('Timeout while fetching track metadata')
                break

            # Yield each track
            for track in tracks:
                yield track

            position += len(uris)
Beispiel #3
0
    def fetch(self, start=0, count=100, callback=None):
        if callback:
            return self.sp.playlist(self.uri, start, count, callback)

        # Fetch full playlist detail
        event = REvent()
        self.sp.playlist(self.uri, start, count, callback=lambda pl: event.set(pl))

        # Wait until result is available
        return event.wait()
Beispiel #4
0
    def fetch(self, start=0, count=100, callback=None):
        if callback:
            return self.sp.playlist(self.uri, start, count, callback)

        # Fetch full playlist detail
        event = REvent()
        self.sp.playlist(self.uri,
                         start,
                         count,
                         callback=lambda pl: event.set(pl))

        # Wait until result is available
        return event.wait()
Beispiel #5
0
    def extend(self, start, count=100):
        # Can only extend truncated playlists
        if not self.truncated:
            return False

        event = REvent()
        self.sp.playlist(self.uri, start, count, callback=lambda pl: event.set(pl))

        playlist = event.wait(5)

        # Check if there was a request timeout
        if playlist is None:
            return False

        # Extend our 'items' collection
        self.items.extend(playlist.items)

        return True
Beispiel #6
0
    def extend(self, start, count=100):
        # Can only extend truncated playlists
        if not self.truncated:
            return False

        event = REvent()
        self.sp.playlist(self.uri,
                         start,
                         count,
                         callback=lambda pl: event.set(pl))

        playlist = event.wait(5)

        # Check if there was a request timeout
        if playlist is None:
            return False

        # Extend our 'items' collection
        self.items.extend(playlist.items)

        return True