Resolves the URL to an actual track from the SoundCloud API.

    If the track resolves to more than one possible track, it takes the first search result.

    :returns: The track dictionary from the SoundCloud API

def resolve(track_url):
    """
    Resolves the URL to an actual track from the SoundCloud API.

    If the track resolves to more than one possible track, it takes the first search result.

    :returns: The track dictionary from the SoundCloud API
    """
    try:
        path = urlparse.urlparse(track_url).path
        tracks = client.get('/tracks', q=path)

        if tracks:
            return tracks[0]
        else:
            raise ValueError('Track not found for URL {}'.format(track_url))
    except Exception as e:
        raise ValueError('Error obtaining track by url: {}'.format(str(e)))