Ejemplo n.º 1
0
def get_search_interp(username, category, query, action='search'):
    interp = ""
    if category == 'sllist':
        interp += "silverlining playlist"
    elif category == 'stream':
        if username == 'me':
            interp += "your stream"
        else:
            interp = "%s's stream" % username
    elif username:
        if category == 'user':
            if action == 'search':
                interp += "users matching %s" % username
            else:
                interp += "%s's stream" % username
        else:
            interp += "%s's %ss" % (username, category)
    else:
        if query and utils.isint(query):
            interp += "%s id %s" % (category, query)
        else:
            interp += "%ss" % category
    if query and not utils.isint(query):
        interp += " for %s" % query
    return interp
Ejemplo n.º 2
0
def get_search_interp(username, category, query, action='search'):
    interp = ""
    if category == 'sllist':
        interp += "silverlining playlist"
    elif category == 'stream':
        if username == 'me':
            interp += "your stream"
        else:
            interp = "%s's stream" % username
    elif username:
        if category == 'user':
            if action == 'search':
                interp += "users matching %s" % username
            else:
                interp += "%s's stream" % username
        else:
            interp += "%s's %ss" % (username, category)
    else:
        if query and utils.isint(query):
            interp += "%s id %s" % (category, query)
        else:
            interp += "%ss" % category
    if query and not utils.isint(query):
        interp += " for %s" % query
    return interp
Ejemplo n.º 3
0
 def __init__(self, query, user=None):
     if utils.isint(query):
         msg = u"Playlist with id %s not found" % query
     else:
         msg = u'No playlists found named %s' % query
         if user:
             msg += u' for %s' % user['username']
     super(PlaylistNotFoundError, self).__init__(msg)
Ejemplo n.º 4
0
 def __init__(self, query, user=None):
     if utils.isint(query):
         msg = u"Playlist with id %s not found" % query
     else:
         msg = u'No playlists found named %s' % query
         if user:
             msg += u' for %s' % user['username']
     super(PlaylistNotFoundError, self).__init__(msg)
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
def parse_search_arguments(args):
    if not args or args[0] == '':
        return None, 'sllist', None
    if args[0].startswith('http'):
        # it's a url
        resp = requests.get("https://api.soundcloud.com/resolve.json",
                            params={
                                'url': args[0],
                                'client_id': CLIENT_ID
                            })
        data = resp.json()
        return None, data['kind'], data['id']
    elif len(args) == 1 and utils.isint(args[0]):
        # it's an id, try it as a track and then as a playlist
        try:
            track = models.Track.get_one(args[0])
            return None, 'track', args[0]
        except models.TrackNotFoundError:
            pass
        try:
            playlist = models.Playlist.get_one(args[0])
            return None, 'playlist', args[0]
        except models.PlaylistNotFoundError:
            raise Exception("Unable to find item with id %s" % args[0])
    elif args[0] in ['me', 'stream']:
        if len(args) > 1:
            return 'me', 'stream', args[1]
        return 'me', 'stream', None
    elif args[0] in ['t', 'track', 'tracks']:
        if len(args) > 1:
            return None, 'track', args[1]
        raise Exception("not enough arguments")
    elif args[0] in ['p', 'playlist', 'playlists']:
        if len(args) > 1:
            return None, 'playlist', args[1]
        raise Exception("not enough arguments")
    else:
        if len(args) == 1:
            return args[0], 'user', None
        elif args[1] in ['t', 'track', 'tracks']:
            if len(args) > 2:
                return args[0], 'track', args[2]
            return args[0], 'track', None
        elif args[1] in ['p', 'playlist', 'playlists']:
            if len(args) > 2:
                return args[0], 'playlist', args[2]
            return args[0], 'playlist', None
        elif args[1] in ['s', 'stream']:
            if len(args) > 2:
                return args[0], 'stream', args[2]
            return args[0], 'stream', None
    raise Exception("unable to parse command %s" % ' '.join(args))
Ejemplo n.º 7
0
    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))
Ejemplo n.º 8
0
    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))
Ejemplo n.º 9
0
def parse_search_arguments(args):
    if not args or args[0] == '':
        return None, 'sllist', None
    if args[0].startswith('http'):
        # it's a url
        resp = requests.get("https://api.soundcloud.com/resolve.json",
                            params={'url': args[0], 'client_id': CLIENT_ID})
        data = resp.json()
        return None, data['kind'], data['id']
    elif len(args) == 1 and utils.isint(args[0]):
        # it's an id, try it as a track and then as a playlist
        try:
            track = models.Track.get_one(args[0])
            return None, 'track', args[0]
        except models.TrackNotFoundError:
            pass
        try:
            playlist = models.Playlist.get_one(args[0])
            return None, 'playlist', args[0]
        except models.PlaylistNotFoundError:
            raise Exception("Unable to find item with id %s" % args[0])
    elif args[0] in ['me', 'stream']:
        if len(args) > 1:
            return 'me', 'stream', args[1]
        return 'me', 'stream', None
    elif args[0] in ['t', 'track', 'tracks']:
        if len(args) > 1:
            return None, 'track', args[1]
        raise Exception("not enough arguments")
    elif args[0] in ['p', 'playlist', 'playlists']:
        if len(args) > 1:
            return None, 'playlist', args[1]
        raise Exception("not enough arguments")
    else:
        if len(args) == 1:
            return args[0], 'user', None
        elif args[1] in ['t', 'track', 'tracks']:
            if len(args) > 2:
                return args[0], 'track', args[2]
            return args[0], 'track', None
        elif args[1] in ['p', 'playlist', 'playlists']:
            if len(args) > 2:
                return args[0], 'playlist', args[2]
            return args[0], 'playlist', None
        elif args[1] in ['s', 'stream']:
            if len(args) > 2:
                return args[0], 'stream', args[2]
            return args[0], 'stream', None
    raise Exception("unable to parse command %s" % ' '.join(args))
Ejemplo n.º 10
0
    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))
Ejemplo n.º 11
0
    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))
Ejemplo n.º 12
0
 def get(cls, username=None):
     if utils.isint(username):
         users = soundcloud_get('/users/%s' % username)
     else:
         users = soundcloud_get('/users', q=username)
     return list(map(cls, users))
Ejemplo n.º 13
0
 def __init__(self, username):
     if utils.isint(query):
         msg = u"User with id %s not found" % username
     else:
         msg = u"No user found for %s" % username
     super(UserNotFoundError, self).__init__(msg)
Ejemplo n.º 14
0
 def get(cls, username=None):
     if utils.isint(username):
         users = soundcloud_get('/users/%s' % username)
     else:
         users = soundcloud_get('/users', q=username)
     return list(map(cls, users))
Ejemplo n.º 15
0
 def __init__(self, username):
     if utils.isint(query):
         msg = u"User with id %s not found" % username
     else:
         msg = u"No user found for %s" % username
     super(UserNotFoundError, self).__init__(msg)