Use slugify?
andriyor opened this issue · 0 comments
andriyor commented
With slugify
def get_url(artist: str, title: str) -> str:
artist = slugify(artist.replace(".", "").replace("$", "s"), separator="_")
title = slugify(title.replace("&", "and"), separator="_")
if artist.startswith("the"):
artist = artist[4:]
amalgama_url = f"https://www.amalgama-lab.com/songs/{artist[0].lower()}/{artist}/{title}.html"
return amalgama_url
Without sligify
def build_url(s: str) -> str:
s = s.lower()
chars_to_underscore = [" ", "-", "/", "'", "__"]
for char in chars_to_underscore:
s = s.replace(char, "_")
s = s.replace("$", "s")
s = s.replace("&", "and")
s = s.replace("é", 'e')
s = s.replace(".", "")
return s
def get_url(artist: str, title: str) -> str:
artist, title = map(build_url, [artist, title])
if artist.startswith("the"):
artist = artist[4:]
amalgama_url = f"https://www.amalgama-lab.com/songs/{artist[0]}/{artist}/{title}.html"
return amalgama_url