Beispiel #1
0
    def next_track(self):
        if self.buffer == None:
            self.buffer = []
            try:
                sp = get_spotify()
                limit = 50
                offset = 0
                total = 50

                while offset < total:
                    results = sp.current_user_saved_tracks(limit = limit, offset = offset)
                    for item in results['items']:
                        track = item['track']
                        if track and 'id' in track:
                            self.buffer.append(track['id'])
                            spotify_plugs._add_track(self.name, track)
                        else:
                            raise pbl.engine.PBLException(self, 'bad track')
                    offset += limit
                    total = results['total']
                # print self.name, len(self.buffer), offset, total
            except spotipy.SpotifyException as e:
                raise pbl.engine.PBLException(self, e.msg)

        if len(self.buffer) > 0:
            tid =  self.buffer.pop(0)
            # print 'ret', self.name, tid
            return tid
        else:
            # print 'ret', self.name, 'empty'
            return None
Beispiel #2
0
    def next_track(self):
        if self.buffer == None:
            self.buffer = []
            try:
                sp = get_spotify()
                limit = 50
                offset = 0

                remaining = 1
                while remaining > 0:
                    results = sp.current_user_saved_tracks(limit=limit,
                                                           offset=offset)
                    for item in results['items']:
                        track = item['track']
                        if track and 'id' in track:
                            self.buffer.append(track['id'])
                            spotify_plugs._add_track(self.name, track)
                        else:
                            raise pbl.engine.PBLException(self, 'bad track')

                    if len(results['items']) < limit:
                        remaining = 0
                    else:
                        remaining = results['total'] - (results['offset'] +
                                                        len(results['items']))
                    offset += limit

            except spotipy.SpotifyException as e:
                raise pbl.engine.PBLException(self, e.msg)

        if len(self.buffer) > 0:
            return self.buffer.pop(0)
        else:
            return None
Beispiel #3
0
    def next_track(self):
        if self.buffer == None:
            self.buffer = []
            try:
                sp = get_spotify()
                limit = 50
                offset = 0
                total = 50

                while offset < total:
                    results = sp.current_user_saved_tracks(limit = limit, offset = offset)
                    for item in results['items']:
                        track = item['track']
                        if track and 'id' in track:
                            self.buffer.append(track['id'])
                            spotify_plugs._add_track(self.name, track)
                        else:
                            raise pbl.engine.PBLException(self, 'bad track')
                    offset += limit
                    total = results['total']
                # print self.name, len(self.buffer), offset, total
            except spotipy.SpotifyException as e:
                raise pbl.engine.PBLException(self, e.msg)

        if len(self.buffer) > 0:
            tid =  self.buffer.pop(0)
            # print 'ret', self.name, tid
            return tid
        else:
            # print 'ret', self.name, 'empty'
            return None
Beispiel #4
0
    def _get_more_tracks(self):
        _,_,user,_,playlist_id = self.uri.split(':')
        try:
            results = get_spotify().user_playlist_tracks(user, playlist_id,
                limit=self.limit, offset=self.next_offset)
        except spotipy.SpotifyException as e:
            raise engine.PBLException(self, e.msg)

        self.total = results['total']
        for item in results['items']:
            self.track_count += 1
            good_track = True
            ts = parse_date(item['added_at'])
            if self.tracks_added_before >= 0 and ts >= 0 and ts > self.tracks_added_before:
                good_track = False
            if self.tracks_added_since >=0 and ts >=0 and ts  < self.tracks_added_since:
                good_track = False
            track = item['track']
            if good_track and ts >= 0 and track and 'id' in track:
                self.tracks.append( (track['id'], ts) )
                spotify_plugs._add_track(self.name, track)
        self.next_offset += self.limit
Beispiel #5
0
    def next_track(self):
        if self.buffer == None:
            self.buffer = []
            sp = get_spotify()
            limit = 50
            total = limit
            offset = 0

            while offset < total:
                try:
                    results = get_spotify().current_user_saved_albums(limit = limit, offset = offset)
                    # print 'cusa', self.name, limit, offset, results['limit'], results['offset'], results['total']
                except spotipy.SpotifyException as e:
                    # print 'woah'
                    raise pbl.engine.PBLException(self, e.msg)

                items = results['items']
                #print json.dumps(results, indent=4)
                #break

                for item in items:
                    album = item['album']
                    for track in album['tracks']['items']:
                        self.buffer.append(track['id'])
                        spotify_plugs._add_track(self.name, track)
                offset += limit
                total = results['total']
                # print 'interim', self.name, len(self.buffer), offset, total
                if results['next'] == None:
                    break
            # print 'final', self.name, len(self.buffer), offset, total

        if len(self.buffer) > 0:
            tid =  self.buffer.pop(0)
            # print 'ret', self.name, tid
            return tid
        else:
            # print 'ret', self.name, 'empty'
            return None
Beispiel #6
0
    def next_track(self):
        if self.buffer == None:
            self.buffer = []
            try:
                sp = get_spotify()
                limit = 50
                after = None
                while True:
                    try:
                        results = get_spotify().current_user_followed_artists(
                            limit=limit, after=after)
                    except spotipy.SpotifyException as e:
                        raise pbl.engine.PBLException(self, e.msg)

                    artists = results['artists']
                    items = artists['items']

                    for item in items:
                        artist_id = item['id']
                        after = artist_id
                        try:
                            results = get_spotify().artist_top_tracks(
                                artist_id)
                        except spotipy.SpotifyException as e:
                            raise pbl.engine.PBLException(self, e.msg)

                        for track in results['tracks'][:self.num_tracks]:
                            self.buffer.append(track['id'])
                            spotify_plugs._add_track(self.name, track)
                    if len(items) < limit:
                        break

            except spotipy.SpotifyException as e:
                raise pbl.engine.PBLException(self, e.msg)

        if len(self.buffer) > 0:
            return self.buffer.pop(0)
        else:
            return None
Beispiel #7
0
    def _get_more_tracks(self):
        _,_,user,_,playlist_id = self.uri.split(':')
        try:
            results = get_spotify().user_playlist_tracks(user, playlist_id,
                limit=self.limit, offset=self.next_offset)
        except spotipy.SpotifyException as e:
            raise engine.PBLException(self, e.msg)

        self.total = results['total']
        for item in results['items']:
            self.track_count += 1
            good_track = True
            ts = parse_date(item['added_at'])
            if self.tracks_added_before >= 0 and ts >= 0 and ts > self.tracks_added_before:
                good_track = False
            if self.tracks_added_since >=0 and ts >=0 and ts  < self.tracks_added_since:
                good_track = False
            track = item['track']
            if good_track and ts >= 0 and track and 'id' in track:
                self.tracks.append( (track['id'], ts) )
                spotify_plugs._add_track(self.name, track)
        self.next_offset += self.limit
Beispiel #8
0
    def next_track(self):
        if self.buffer == None:
            self.buffer = []
            sp = get_spotify()
            limit = 50
            total = limit
            offset = 0

            while offset < total:
                try:
                    results = get_spotify().current_user_saved_albums(limit = limit, offset = offset)
                    # print 'cusa', self.name, limit, offset, results['limit'], results['offset'], results['total']
                except spotipy.SpotifyException as e:
                    # print 'woah'
                    raise pbl.engine.PBLException(self, e.msg)

                items = results['items']
                #print json.dumps(results, indent=4)
                #break

                for item in items:
                    album = item['album']
                    for track in album['tracks']['items']:
                        self.buffer.append(track['id'])
                        spotify_plugs._add_track(self.name, track)
                offset += limit
                total = results['total']
                # print 'interim', self.name, len(self.buffer), offset, total
                if results['next'] == None:
                    break
            # print 'final', self.name, len(self.buffer), offset, total

        if len(self.buffer) > 0:
            tid =  self.buffer.pop(0)
            # print 'ret', self.name, tid
            return tid
        else:
            # print 'ret', self.name, 'empty'
            return None
Beispiel #9
0
    def next_track(self):
        if self.buffer == None:
            self.buffer = []
            try:
                sp = get_spotify()
                limit = 50
                after = None
                while True:
                    try:
                        results = get_spotify().current_user_followed_artists(limit = limit, after = after)
                    except spotipy.SpotifyException as e:
                        raise pbl.engine.PBLException(self, e.msg)

                    artists = results['artists']
                    items = artists['items']

                    for item in items:
                        artist_id = item['id']
                        after = artist_id
                        try:
                            results = get_spotify().artist_top_tracks(artist_id)
                        except spotipy.SpotifyException as e:
                            raise pbl.engine.PBLException(self, e.msg)

                        for track in results['tracks'][:self.num_tracks]:
                            self.buffer.append(track['id'])
                            spotify_plugs._add_track(self.name, track)
                    if len(items) < limit:
                        break

            except spotipy.SpotifyException as e:
                raise pbl.engine.PBLException(self, e.msg)

        if len(self.buffer) > 0:
            return self.buffer.pop(0)
        else:
            return None