From 64846da36024d04b5bdbed3dde6b63b72c0fe916 Mon Sep 17 00:00:00 2001 From: Peter Marheine Date: Sat, 7 Oct 2017 18:19:37 +1100 Subject: [PATCH] Localize artist bios from last.fm Using the current user's locale. Signed-off-by: Peter Marheine --- .../java/org/airsonic/player/ajax/MultiService.java | 5 ++++- .../player/controller/SubsonicRESTController.java | 7 +++++-- .../org/airsonic/player/service/LastFmService.java | 12 ++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/airsonic-main/src/main/java/org/airsonic/player/ajax/MultiService.java b/airsonic-main/src/main/java/org/airsonic/player/ajax/MultiService.java index 4a6fc432..82e5bba3 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/ajax/MultiService.java +++ b/airsonic-main/src/main/java/org/airsonic/player/ajax/MultiService.java @@ -62,9 +62,12 @@ public class MultiService { private SettingsService settingsService; public ArtistInfo getArtistInfo(int mediaFileId, int maxSimilarArtists, int maxTopSongs) { + HttpServletRequest request = WebContextFactory.get().getHttpServletRequest(); + UserSettings userSettings = settingsService.getUserSettings(securityService.getCurrentUsername(request)); + MediaFile mediaFile = mediaFileService.getMediaFile(mediaFileId); List similarArtists = getSimilarArtists(mediaFileId, maxSimilarArtists); - ArtistBio artistBio = lastFmService.getArtistBio(mediaFile); + ArtistBio artistBio = lastFmService.getArtistBio(mediaFile, userSettings.getLocale()); List topSongs = getTopSongs(mediaFile, maxTopSongs); return new ArtistInfo(similarArtists, artistBio, topSongs); diff --git a/airsonic-main/src/main/java/org/airsonic/player/controller/SubsonicRESTController.java b/airsonic-main/src/main/java/org/airsonic/player/controller/SubsonicRESTController.java index 32be8d12..ae32d507 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/controller/SubsonicRESTController.java +++ b/airsonic-main/src/main/java/org/airsonic/player/controller/SubsonicRESTController.java @@ -431,7 +431,7 @@ public class SubsonicRESTController { for (MediaFile similarArtist : similarArtists) { result.getSimilarArtist().add(createJaxbArtist(similarArtist, username)); } - ArtistBio artistBio = lastFmService.getArtistBio(mediaFile); + ArtistBio artistBio = lastFmService.getArtistBio(mediaFile, getUserLocale(request)); if (artistBio != null) { result.setBiography(artistBio.getBiography()); result.setMusicBrainzId(artistBio.getMusicBrainzId()); @@ -468,7 +468,7 @@ public class SubsonicRESTController { for (org.airsonic.player.domain.Artist similarArtist : similarArtists) { result.getSimilarArtist().add(createJaxbArtist(new ArtistID3(), similarArtist, username)); } - ArtistBio artistBio = lastFmService.getArtistBio(artist); + ArtistBio artistBio = lastFmService.getArtistBio(artist, getUserLocale(request)); if (artistBio != null) { result.setBiography(artistBio.getBiography()); result.setMusicBrainzId(artistBio.getMusicBrainzId()); @@ -2402,6 +2402,9 @@ public class SubsonicRESTController { return !players.isEmpty() ? players.get(0).getId() : null; } + private Locale getUserLocale(HttpServletRequest request) { + return settingsService.getUserSettings(securityService.getCurrentUsername(request)).getLocale(); + } public enum ErrorCode { diff --git a/airsonic-main/src/main/java/org/airsonic/player/service/LastFmService.java b/airsonic-main/src/main/java/org/airsonic/player/service/LastFmService.java index e721f81a..d5efa6de 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/service/LastFmService.java +++ b/airsonic-main/src/main/java/org/airsonic/player/service/LastFmService.java @@ -223,8 +223,8 @@ public class LastFmService { * @param mediaFile The media file (song, album or artist). * @return Artist bio. */ - public ArtistBio getArtistBio(MediaFile mediaFile) { - return getArtistBio(getCanonicalArtistName(getArtistName(mediaFile))); + public ArtistBio getArtistBio(MediaFile mediaFile, Locale locale) { + return getArtistBio(getCanonicalArtistName(getArtistName(mediaFile)), locale); } /** @@ -233,8 +233,8 @@ public class LastFmService { * @param artist The artist. * @return Artist bio. */ - public ArtistBio getArtistBio(org.airsonic.player.domain.Artist artist) { - return getArtistBio(getCanonicalArtistName(artist.getName())); + public ArtistBio getArtistBio(org.airsonic.player.domain.Artist artist, Locale locale) { + return getArtistBio(getCanonicalArtistName(artist.getName()), locale); } /** @@ -370,13 +370,13 @@ public class LastFmService { } - private ArtistBio getArtistBio(String artistName) { + private ArtistBio getArtistBio(String artistName, Locale locale) { try { if (artistName == null) { return null; } - Artist info = Artist.getInfo(artistName, LAST_FM_KEY); + Artist info = Artist.getInfo(artistName, locale, null /* username */, LAST_FM_KEY); if (info == null) { return null; }