<commit_before>from plugins.util import command, get_url
import json
import re

SPOTIFY_URI_REGEX = r"(?<=spotify:)(?:track|album|artist):[a-zA-Z0-9]{22}"
ENDPOINT = "https://api.spotify.com/v1/{0}s/{1}"

@command()
def spotify(m):
    spotify_uris = re.findall(SPOTIFY_URI_REGEX, m.body)
    for spotify_uri in spotify_uris:
        try:
            type, id = _parse_spotify_uri(spotify_uri)
            req = get_url(m, ENDPOINT.format(type, id))
            if req:
                blob = json.loads(req)
                if type == "track" or type == "album":
                    m.bot.private_message(m.location,
                                          blob["artists"][0]["name"] + " - " + blob["name"])
                else:
                    m.bot.private_message(m.location, blob["name"])
        except ValueError:
            m.bot.logger.error("Invalid Spotify URI: " + spotify_uri)

def _parse_spotify_uri(s):
    [type, id] = s.split(':')
    return type, id<commit_msg>Change formatting of response, add URL<commit_after>from plugins.util import command, get_url
import json
import re

SPOTIFY_URI_REGEX = r"(?<=spotify:)(?:track|album|artist):[a-zA-Z0-9]{22}"
ENDPOINT = "https://api.spotify.com/v1/{0}s/{1}"

@command()
def spotify(m):
    spotify_uris = re.findall(SPOTIFY_URI_REGEX, m.body)
    for spotify_uri in spotify_uris:
        try:
            type, id = _parse_spotify_uri(spotify_uri)
        except ValueError:
            m.bot.logger.error("Invalid Spotify URI: " + spotify_uri)
        else:
            req = get_url(m, ENDPOINT.format(type, id))
            if req:
                blob = json.loads(req)
                if type == "track" or type == "album":
                    m.bot.private_message(m.location, '"{0}" by {1} - {2}'
                                          .format(blob["name"], blob["artists"][0]["name"],
                                                  blob["external_urls"]["spotify"]))
                else:
                    m.bot.private_message(m.location, "{0} - {1}"
                                          .format(blob["name"], blob["external_urls"]["spotify"]))

def _parse_spotify_uri(s):
    [type, id] = s.split(':')
    return type, id
{'fraction_non_alphanumeric': 0.1471783295711061, 'fraction_numerical': 0.009480812641083521, 'mean_word_length': 1.974496644295302, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2084878', 'n_tokens_mistral': 722, 'n_tokens_neox': 714, 'n_words': 135}