import json
import re


def uri_soundcloud(bot, response, matches):
    """ Extract SoundCloud song information. """
    song = json.loads(response.text)

    title = song['title'].replace('\n', ' ')
    title = re.sub(r'\s+', ' ', title).strip()
    duration = int(round(song['duration'] / 1000))
    meta = '{}:{:02}'.format(*divmod(duration, 60))

    return 'SoundCloud: {}'.format(song['user']['username']), title, meta