|
|
@ -19,35 +19,18 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.libresonic.player.controller; |
|
|
|
package org.libresonic.player.controller; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import org.libresonic.player.domain.*; |
|
|
|
import java.util.ArrayList; |
|
|
|
import org.libresonic.player.service.*; |
|
|
|
import java.util.Calendar; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import java.util.Collections; |
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
import java.util.Date; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import java.util.HashMap; |
|
|
|
import org.springframework.web.bind.annotation.RequestMethod; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.web.servlet.ModelAndView; |
|
|
|
import org.springframework.web.servlet.ModelAndView; |
|
|
|
import org.springframework.web.servlet.mvc.ParameterizableViewController; |
|
|
|
|
|
|
|
import org.springframework.web.servlet.view.RedirectView; |
|
|
|
import org.springframework.web.servlet.view.RedirectView; |
|
|
|
|
|
|
|
|
|
|
|
import org.libresonic.player.domain.AlbumListType; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import org.libresonic.player.domain.CoverArtScheme; |
|
|
|
import java.io.IOException; |
|
|
|
import org.libresonic.player.domain.Genre; |
|
|
|
import java.util.*; |
|
|
|
import org.libresonic.player.domain.MediaFile; |
|
|
|
|
|
|
|
import org.libresonic.player.domain.MusicFolder; |
|
|
|
|
|
|
|
import org.libresonic.player.domain.User; |
|
|
|
|
|
|
|
import org.libresonic.player.domain.UserSettings; |
|
|
|
|
|
|
|
import org.libresonic.player.service.MediaFileService; |
|
|
|
|
|
|
|
import org.libresonic.player.service.MediaScannerService; |
|
|
|
|
|
|
|
import org.libresonic.player.service.RatingService; |
|
|
|
|
|
|
|
import org.libresonic.player.service.SearchService; |
|
|
|
|
|
|
|
import org.libresonic.player.service.SecurityService; |
|
|
|
|
|
|
|
import org.libresonic.player.service.SettingsService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.springframework.web.bind.ServletRequestUtils.getIntParameter; |
|
|
|
import static org.springframework.web.bind.ServletRequestUtils.getIntParameter; |
|
|
|
import static org.springframework.web.bind.ServletRequestUtils.getStringParameter; |
|
|
|
import static org.springframework.web.bind.ServletRequestUtils.getStringParameter; |
|
|
@ -57,18 +40,27 @@ import static org.springframework.web.bind.ServletRequestUtils.getStringParamete |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Sindre Mehus |
|
|
|
* @author Sindre Mehus |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class HomeController extends ParameterizableViewController { |
|
|
|
@Controller |
|
|
|
|
|
|
|
@RequestMapping("/home") |
|
|
|
|
|
|
|
public class HomeController { |
|
|
|
|
|
|
|
|
|
|
|
private static final int LIST_SIZE = 40; |
|
|
|
private static final int LIST_SIZE = 40; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SettingsService settingsService; |
|
|
|
private SettingsService settingsService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private MediaScannerService mediaScannerService; |
|
|
|
private MediaScannerService mediaScannerService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RatingService ratingService; |
|
|
|
private RatingService ratingService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SecurityService securityService; |
|
|
|
private SecurityService securityService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private MediaFileService mediaFileService; |
|
|
|
private MediaFileService mediaFileService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SearchService searchService; |
|
|
|
private SearchService searchService; |
|
|
|
|
|
|
|
|
|
|
|
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { |
|
|
|
@RequestMapping(method = RequestMethod.GET) |
|
|
|
|
|
|
|
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
User user = securityService.getCurrentUser(request); |
|
|
|
User user = securityService.getCurrentUser(request); |
|
|
|
if (user.isAdminRole() && settingsService.isGettingStartedEnabled()) { |
|
|
|
if (user.isAdminRole() && settingsService.isGettingStartedEnabled()) { |
|
|
@ -85,7 +77,7 @@ public class HomeController extends ParameterizableViewController { |
|
|
|
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(user.getUsername(), |
|
|
|
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(user.getUsername(), |
|
|
|
selectedMusicFolder == null ? null : selectedMusicFolder.getId()); |
|
|
|
selectedMusicFolder == null ? null : selectedMusicFolder.getId()); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>(); |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
List<Album> albums = Collections.emptyList(); |
|
|
|
List<Album> albums = Collections.emptyList(); |
|
|
|
switch (listType) { |
|
|
|
switch (listType) { |
|
|
|
case HIGHEST: |
|
|
|
case HIGHEST: |
|
|
@ -142,13 +134,11 @@ public class HomeController extends ParameterizableViewController { |
|
|
|
map.put("musicFolder", selectedMusicFolder); |
|
|
|
map.put("musicFolder", selectedMusicFolder); |
|
|
|
map.put("listReloadDelay", userSettings.getListReloadDelay()); |
|
|
|
map.put("listReloadDelay", userSettings.getListReloadDelay()); |
|
|
|
|
|
|
|
|
|
|
|
ModelAndView result = super.handleRequestInternal(request, response); |
|
|
|
return new ModelAndView("home","model",map); |
|
|
|
result.addObject("model", map); |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<Album> getHighestRated(int offset, int count, List<MusicFolder> musicFolders) { |
|
|
|
private List<Album> getHighestRated(int offset, int count, List<MusicFolder> musicFolders) { |
|
|
|
List<Album> result = new ArrayList<Album>(); |
|
|
|
List<Album> result = new ArrayList<>(); |
|
|
|
for (MediaFile mediaFile : ratingService.getHighestRatedAlbums(offset, count, musicFolders)) { |
|
|
|
for (MediaFile mediaFile : ratingService.getHighestRatedAlbums(offset, count, musicFolders)) { |
|
|
|
Album album = createAlbum(mediaFile); |
|
|
|
Album album = createAlbum(mediaFile); |
|
|
|
album.setRating((int) Math.round(ratingService.getAverageRating(mediaFile) * 10.0D)); |
|
|
|
album.setRating((int) Math.round(ratingService.getAverageRating(mediaFile) * 10.0D)); |
|
|
@ -158,7 +148,7 @@ public class HomeController extends ParameterizableViewController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<Album> getMostFrequent(int offset, int count, List<MusicFolder> musicFolders) { |
|
|
|
private List<Album> getMostFrequent(int offset, int count, List<MusicFolder> musicFolders) { |
|
|
|
List<Album> result = new ArrayList<Album>(); |
|
|
|
List<Album> result = new ArrayList<>(); |
|
|
|
for (MediaFile mediaFile : mediaFileService.getMostFrequentlyPlayedAlbums(offset, count, musicFolders)) { |
|
|
|
for (MediaFile mediaFile : mediaFileService.getMostFrequentlyPlayedAlbums(offset, count, musicFolders)) { |
|
|
|
Album album = createAlbum(mediaFile); |
|
|
|
Album album = createAlbum(mediaFile); |
|
|
|
album.setPlayCount(mediaFile.getPlayCount()); |
|
|
|
album.setPlayCount(mediaFile.getPlayCount()); |
|
|
@ -168,7 +158,7 @@ public class HomeController extends ParameterizableViewController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<Album> getMostRecent(int offset, int count, List<MusicFolder> musicFolders) { |
|
|
|
private List<Album> getMostRecent(int offset, int count, List<MusicFolder> musicFolders) { |
|
|
|
List<Album> result = new ArrayList<Album>(); |
|
|
|
List<Album> result = new ArrayList<>(); |
|
|
|
for (MediaFile mediaFile : mediaFileService.getMostRecentlyPlayedAlbums(offset, count, musicFolders)) { |
|
|
|
for (MediaFile mediaFile : mediaFileService.getMostRecentlyPlayedAlbums(offset, count, musicFolders)) { |
|
|
|
Album album = createAlbum(mediaFile); |
|
|
|
Album album = createAlbum(mediaFile); |
|
|
|
album.setLastPlayed(mediaFile.getLastPlayed()); |
|
|
|
album.setLastPlayed(mediaFile.getLastPlayed()); |
|
|
@ -178,7 +168,7 @@ public class HomeController extends ParameterizableViewController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<Album> getNewest(int offset, int count, List<MusicFolder> musicFolders) throws IOException { |
|
|
|
private List<Album> getNewest(int offset, int count, List<MusicFolder> musicFolders) throws IOException { |
|
|
|
List<Album> result = new ArrayList<Album>(); |
|
|
|
List<Album> result = new ArrayList<>(); |
|
|
|
for (MediaFile file : mediaFileService.getNewestAlbums(offset, count, musicFolders)) { |
|
|
|
for (MediaFile file : mediaFileService.getNewestAlbums(offset, count, musicFolders)) { |
|
|
|
Album album = createAlbum(file); |
|
|
|
Album album = createAlbum(file); |
|
|
|
Date created = file.getCreated(); |
|
|
|
Date created = file.getCreated(); |
|
|
@ -192,7 +182,7 @@ public class HomeController extends ParameterizableViewController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<Album> getStarred(int offset, int count, String username, List<MusicFolder> musicFolders) throws IOException { |
|
|
|
private List<Album> getStarred(int offset, int count, String username, List<MusicFolder> musicFolders) throws IOException { |
|
|
|
List<Album> result = new ArrayList<Album>(); |
|
|
|
List<Album> result = new ArrayList<>(); |
|
|
|
for (MediaFile file : mediaFileService.getStarredAlbums(offset, count, username, musicFolders)) { |
|
|
|
for (MediaFile file : mediaFileService.getStarredAlbums(offset, count, username, musicFolders)) { |
|
|
|
result.add(createAlbum(file)); |
|
|
|
result.add(createAlbum(file)); |
|
|
|
} |
|
|
|
} |
|
|
@ -200,7 +190,7 @@ public class HomeController extends ParameterizableViewController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<Album> getRandom(int count, List<MusicFolder> musicFolders) throws IOException { |
|
|
|
private List<Album> getRandom(int count, List<MusicFolder> musicFolders) throws IOException { |
|
|
|
List<Album> result = new ArrayList<Album>(); |
|
|
|
List<Album> result = new ArrayList<>(); |
|
|
|
for (MediaFile file : searchService.getRandomAlbums(count, musicFolders)) { |
|
|
|
for (MediaFile file : searchService.getRandomAlbums(count, musicFolders)) { |
|
|
|
result.add(createAlbum(file)); |
|
|
|
result.add(createAlbum(file)); |
|
|
|
} |
|
|
|
} |
|
|
@ -208,7 +198,7 @@ public class HomeController extends ParameterizableViewController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<Album> getAlphabetical(int offset, int count, boolean byArtist, List<MusicFolder> musicFolders) throws IOException { |
|
|
|
private List<Album> getAlphabetical(int offset, int count, boolean byArtist, List<MusicFolder> musicFolders) throws IOException { |
|
|
|
List<Album> result = new ArrayList<Album>(); |
|
|
|
List<Album> result = new ArrayList<>(); |
|
|
|
for (MediaFile file : mediaFileService.getAlphabeticalAlbums(offset, count, byArtist, musicFolders)) { |
|
|
|
for (MediaFile file : mediaFileService.getAlphabeticalAlbums(offset, count, byArtist, musicFolders)) { |
|
|
|
result.add(createAlbum(file)); |
|
|
|
result.add(createAlbum(file)); |
|
|
|
} |
|
|
|
} |
|
|
@ -216,7 +206,7 @@ public class HomeController extends ParameterizableViewController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<Album> getByYear(int offset, int count, int fromYear, int toYear, List<MusicFolder> musicFolders) { |
|
|
|
private List<Album> getByYear(int offset, int count, int fromYear, int toYear, List<MusicFolder> musicFolders) { |
|
|
|
List<Album> result = new ArrayList<Album>(); |
|
|
|
List<Album> result = new ArrayList<>(); |
|
|
|
for (MediaFile file : mediaFileService.getAlbumsByYear(offset, count, fromYear, toYear, musicFolders)) { |
|
|
|
for (MediaFile file : mediaFileService.getAlbumsByYear(offset, count, fromYear, toYear, musicFolders)) { |
|
|
|
Album album = createAlbum(file); |
|
|
|
Album album = createAlbum(file); |
|
|
|
album.setYear(file.getYear()); |
|
|
|
album.setYear(file.getYear()); |
|
|
@ -226,7 +216,7 @@ public class HomeController extends ParameterizableViewController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<Integer> createDecades() { |
|
|
|
private List<Integer> createDecades() { |
|
|
|
List<Integer> result = new ArrayList<Integer>(); |
|
|
|
List<Integer> result = new ArrayList<>(); |
|
|
|
int decade = Calendar.getInstance().get(Calendar.YEAR) / 10; |
|
|
|
int decade = Calendar.getInstance().get(Calendar.YEAR) / 10; |
|
|
|
for (int i = 0; i < 10; i++) { |
|
|
|
for (int i = 0; i < 10; i++) { |
|
|
|
result.add((decade - i) * 10); |
|
|
|
result.add((decade - i) * 10); |
|
|
@ -235,7 +225,7 @@ public class HomeController extends ParameterizableViewController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<Album> getByGenre(int offset, int count, String genre, List<MusicFolder> musicFolders) { |
|
|
|
private List<Album> getByGenre(int offset, int count, String genre, List<MusicFolder> musicFolders) { |
|
|
|
List<Album> result = new ArrayList<Album>(); |
|
|
|
List<Album> result = new ArrayList<>(); |
|
|
|
for (MediaFile file : mediaFileService.getAlbumsByGenre(offset, count, genre, musicFolders)) { |
|
|
|
for (MediaFile file : mediaFileService.getAlbumsByGenre(offset, count, genre, musicFolders)) { |
|
|
|
result.add(createAlbum(file)); |
|
|
|
result.add(createAlbum(file)); |
|
|
|
} |
|
|
|
} |
|
|
@ -252,30 +242,6 @@ public class HomeController extends ParameterizableViewController { |
|
|
|
return album; |
|
|
|
return album; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setSettingsService(SettingsService settingsService) { |
|
|
|
|
|
|
|
this.settingsService = settingsService; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setMediaScannerService(MediaScannerService mediaScannerService) { |
|
|
|
|
|
|
|
this.mediaScannerService = mediaScannerService; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setRatingService(RatingService ratingService) { |
|
|
|
|
|
|
|
this.ratingService = ratingService; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setSecurityService(SecurityService securityService) { |
|
|
|
|
|
|
|
this.securityService = securityService; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setMediaFileService(MediaFileService mediaFileService) { |
|
|
|
|
|
|
|
this.mediaFileService = mediaFileService; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setSearchService(SearchService searchService) { |
|
|
|
|
|
|
|
this.searchService = searchService; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Contains info for a single album. |
|
|
|
* Contains info for a single album. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|