lastfm bio fetch to fallback to english if not found in user locale

This commit is contained in:
2020-04-05 20:30:46 +02:00
parent 66f7773598
commit b5f06c7d5d
@@ -244,7 +244,23 @@ public class LastFmService {
if (info == null) {
return null;
}
return new ArtistBio(processWikiText(info.getWikiSummary()),
String wiki = info.getWikiSummary().trim();
boolean isEnglish = locale.getLanguage().equals(Locale.ENGLISH.getLanguage());
// try to detect empty bio
if (!isEnglish && (wiki.length() < 250 &&
wiki.startsWith("<a href=\"https://www.last.fm/music/") && wiki.endsWith("on Last.fm</a>"))
) {
LOG.debug("Got empty bio for " + artistName + ", retry English");
Artist info1 = Artist.getInfo(artistName, Locale.ENGLISH, null /* username */, LAST_FM_KEY);
if (info1 != null) {
// ensure we do not replace non-null with null & NPE...
info = info1;
wiki = info.getWikiSummary().trim();
}
}
return new ArtistBio(processWikiText(wiki),
info.getMbid(),
info.getUrl(),
info.getImageURL(ImageSize.MEDIUM),