def get_track(self, target): try: if utils.isint(target): return self.queue[int(target)] else: return utils.search_collection(self.queue, target)[0] except IndexError: return None
def get(cls, query=None, user=None): if query and utils.isint(query): playlists = soundcloud_get('/playlists/%s' % query) if not playlists: raise PlaylistNotFoundError(query) return cls(playlists[0]).tracks if user: playlists = user.playlists if query: playlists = utils.search_collection(playlists, query) else: playlists = soundcloud_get('/playlists', q=query) return list(map(cls, playlists))
def get_search_results(username, category, query): if category == 'sllist': items = get_silverlining_playlist().tracks if query: items = utils.search_collection(items, query) elif category == 'stream': if username == 'me': items = models.Track.get_from_stream(query) else: user = models.User.get_one(username) if username else None items = user.stream if query: items = utils.search_collection(items, query) elif category == 'user': items = models.User.get(username) else: user = models.User.get_one(username) if username else None if category == 'track': items = models.Track.get(query, user) elif category == 'playlist': items = models.Playlist.get(query, user) return items
def get(cls, query=None, user=None): if query and utils.isint(query): tracks = soundcloud_get('/tracks/%s' % query) if not tracks: raise TrackNotFoundError(query) track = cls(tracks[0]) tracks.extend(track.get_related()) return [cls(track) for track in tracks] if user: tracks = user.tracks if query: tracks = utils.search_collection(tracks, query) else: tracks = soundcloud_get('/tracks', q=query) return list(map(cls, tracks))
def get_from_stream(cls, query=None): resp = soundcloud_get('/me/activities/tracks/affiliated') tracks = [cls(i['origin']) for i in resp[0]['collection']] if query: tracks = utils.search_collection(tracks, query) return tracks