feat(genius): fetch artist avatars by name and match names with transliteration suffix
ci / api / api (push) Successful in 27s
ci / db / db (push) Successful in 53s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
mrleo1nidandClaude Sonnet 5.5 committed 2026-10-28 13:50:55 +03:00
1 parent 795bb7de46
commit 139dd226fa
5 files changed
+144 -1

No files matched your search

+13 -1
View File
@@ -16,11 +16,23 @@ func normalize(s string) string {
return strings.Join(strings.FieldsFunc(strings.ToLower(s), func(r rune) bool { return !unicode.IsLetter(r) && !unicode.IsNumber(r) }), " ")
}
// sameArtist сравнивает имя на Genius с нашим: у Genius часто «имя (транслитерация)»,
// поэтому скобочный хвост допустим.
func sameArtist(geniusName, name string) bool {
if normalize(geniusName) == normalize(name) {
return true
}
if i := strings.Index(geniusName, "("); i > 0 && strings.HasSuffix(strings.TrimSpace(geniusName), ")") {
return normalize(geniusName[:i]) == normalize(name)
}
return false
}
// Exact normalized identity; retain version qualifiers such as live/remix.
func matchSong(songs []Song, artist, title string) (Song, bool) {
var matched Song
for _, s := range songs {
if normalize(s.Title) == normalize(title) && normalize(s.Artist.Name) == normalize(artist) {
if normalize(s.Title) == normalize(title) && sameArtist(s.Artist.Name, artist) {
if matched.ID != 0 && matched.ID != s.ID {
return Song{}, false
}