|
|
@ -19,30 +19,21 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.libresonic.player.controller; |
|
|
|
package org.libresonic.player.controller; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.text.NumberFormat; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.*; |
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
|
|
|
|
import org.apache.taglibs.standard.lang.jstl.IntegerDivideOperator; |
|
|
|
|
|
|
|
import org.libresonic.player.domain.*; |
|
|
|
|
|
|
|
import org.libresonic.player.service.*; |
|
|
|
import org.springframework.web.bind.ServletRequestBindingException; |
|
|
|
import org.springframework.web.bind.ServletRequestBindingException; |
|
|
|
import org.springframework.web.bind.ServletRequestUtils; |
|
|
|
import org.springframework.web.bind.ServletRequestUtils; |
|
|
|
import org.springframework.web.servlet.ModelAndView; |
|
|
|
import org.springframework.web.servlet.ModelAndView; |
|
|
|
import org.springframework.web.servlet.mvc.ParameterizableViewController; |
|
|
|
import org.springframework.web.servlet.mvc.ParameterizableViewController; |
|
|
|
|
|
|
|
|
|
|
|
import org.libresonic.player.domain.MusicFolder; |
|
|
|
|
|
|
|
import org.libresonic.player.domain.PlayQueue; |
|
|
|
|
|
|
|
import org.libresonic.player.domain.Player; |
|
|
|
|
|
|
|
import org.libresonic.player.domain.RandomSearchCriteria; |
|
|
|
|
|
|
|
import org.libresonic.player.service.PlayerService; |
|
|
|
|
|
|
|
import org.libresonic.player.service.SearchService; |
|
|
|
|
|
|
|
import org.libresonic.player.service.SecurityService; |
|
|
|
|
|
|
|
import org.libresonic.player.service.SettingsService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Controller for the creating a random play queue. |
|
|
|
* Controller for the creating a random play queue. |
|
|
|
* |
|
|
|
* |
|
|
@ -52,21 +43,33 @@ public class RandomPlayQueueController extends ParameterizableViewController { |
|
|
|
|
|
|
|
|
|
|
|
private PlayerService playerService; |
|
|
|
private PlayerService playerService; |
|
|
|
private List<ReloadFrame> reloadFrames; |
|
|
|
private List<ReloadFrame> reloadFrames; |
|
|
|
private SearchService searchService; |
|
|
|
private MediaFileService mediaFileService; |
|
|
|
private SecurityService securityService; |
|
|
|
private SecurityService securityService; |
|
|
|
private SettingsService settingsService; |
|
|
|
private SettingsService settingsService; |
|
|
|
|
|
|
|
|
|
|
|
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { |
|
|
|
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
int size = ServletRequestUtils.getRequiredIntParameter(request, "size"); |
|
|
|
int size = ServletRequestUtils.getRequiredIntParameter(request, "size"); |
|
|
|
String genre = request.getParameter("genre"); |
|
|
|
|
|
|
|
if (StringUtils.equalsIgnoreCase("any", genre)) { |
|
|
|
|
|
|
|
genre = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String genre; |
|
|
|
Integer fromYear = null; |
|
|
|
Integer fromYear = null; |
|
|
|
Integer toYear = null; |
|
|
|
Integer toYear = null; |
|
|
|
|
|
|
|
Integer minAlbumRating = null; |
|
|
|
|
|
|
|
Integer maxAlbumRating = null; |
|
|
|
|
|
|
|
Integer minPlayCount = null; |
|
|
|
|
|
|
|
Integer maxPlayCount = null; |
|
|
|
|
|
|
|
Date minLastPlayedDate = null; |
|
|
|
|
|
|
|
Date maxLastPlayedDate = null; |
|
|
|
|
|
|
|
boolean doesShowStarredSongs = false; |
|
|
|
|
|
|
|
boolean doesShowUnstarredSongs = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle the genre filter
|
|
|
|
|
|
|
|
genre = request.getParameter("genre"); |
|
|
|
|
|
|
|
if (StringUtils.equalsIgnoreCase("any", genre)) { |
|
|
|
|
|
|
|
genre = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle the release year filter
|
|
|
|
String year = request.getParameter("year"); |
|
|
|
String year = request.getParameter("year"); |
|
|
|
if (!StringUtils.equalsIgnoreCase("any", year)) { |
|
|
|
if (!StringUtils.equalsIgnoreCase("any", year)) { |
|
|
|
String[] tmp = StringUtils.split(year); |
|
|
|
String[] tmp = StringUtils.split(year); |
|
|
@ -74,12 +77,151 @@ public class RandomPlayQueueController extends ParameterizableViewController { |
|
|
|
toYear = Integer.parseInt(tmp[1]); |
|
|
|
toYear = Integer.parseInt(tmp[1]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle the song rating filter
|
|
|
|
|
|
|
|
String songRating = request.getParameter("songRating"); |
|
|
|
|
|
|
|
if (StringUtils.equalsIgnoreCase("any", songRating)) { |
|
|
|
|
|
|
|
doesShowStarredSongs = true; |
|
|
|
|
|
|
|
doesShowUnstarredSongs = true; |
|
|
|
|
|
|
|
} else if (StringUtils.equalsIgnoreCase("starred", songRating)) { |
|
|
|
|
|
|
|
doesShowStarredSongs = true; |
|
|
|
|
|
|
|
doesShowUnstarredSongs = false; |
|
|
|
|
|
|
|
} else if (StringUtils.equalsIgnoreCase("unstarred", songRating)) { |
|
|
|
|
|
|
|
doesShowStarredSongs = false; |
|
|
|
|
|
|
|
doesShowUnstarredSongs = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle the last played date filter
|
|
|
|
|
|
|
|
String lastPlayedValue = request.getParameter("lastPlayedValue"); |
|
|
|
|
|
|
|
String lastPlayedComp = request.getParameter("lastPlayedComp"); |
|
|
|
|
|
|
|
Calendar lastPlayed = Calendar.getInstance(); |
|
|
|
|
|
|
|
lastPlayed.setTime(new Date()); |
|
|
|
|
|
|
|
switch (lastPlayedValue) { |
|
|
|
|
|
|
|
case "any": |
|
|
|
|
|
|
|
lastPlayed = null; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "1day": |
|
|
|
|
|
|
|
lastPlayed.add(Calendar.DAY_OF_YEAR, -1); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "1week": |
|
|
|
|
|
|
|
lastPlayed.add(Calendar.WEEK_OF_YEAR, -1); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "1month": |
|
|
|
|
|
|
|
lastPlayed.add(Calendar.MONTH, -1); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "3months": |
|
|
|
|
|
|
|
lastPlayed.add(Calendar.MONTH, -3); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "6months": |
|
|
|
|
|
|
|
lastPlayed.add(Calendar.MONTH, -6); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "1year": |
|
|
|
|
|
|
|
lastPlayed.add(Calendar.YEAR, -1); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (lastPlayed != null) { |
|
|
|
|
|
|
|
switch (lastPlayedComp) { |
|
|
|
|
|
|
|
case "lt": |
|
|
|
|
|
|
|
minLastPlayedDate = null; |
|
|
|
|
|
|
|
maxLastPlayedDate = lastPlayed.getTime(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "gt": |
|
|
|
|
|
|
|
minLastPlayedDate = lastPlayed.getTime(); |
|
|
|
|
|
|
|
maxLastPlayedDate = null; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle the album rating filter
|
|
|
|
|
|
|
|
Integer albumRatingValue = null; |
|
|
|
|
|
|
|
try { albumRatingValue = Integer.parseInt(request.getParameter("albumRatingValue")); } |
|
|
|
|
|
|
|
catch (NumberFormatException e) { } |
|
|
|
|
|
|
|
String albumRatingComp = request.getParameter("albumRatingComp"); |
|
|
|
|
|
|
|
if (albumRatingValue != null) { |
|
|
|
|
|
|
|
switch (albumRatingComp) { |
|
|
|
|
|
|
|
case "lt": |
|
|
|
|
|
|
|
minAlbumRating = null; |
|
|
|
|
|
|
|
maxAlbumRating = albumRatingValue - 1; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "gt": |
|
|
|
|
|
|
|
minAlbumRating = albumRatingValue + 1; |
|
|
|
|
|
|
|
maxAlbumRating = null; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "le": |
|
|
|
|
|
|
|
minAlbumRating = null; |
|
|
|
|
|
|
|
maxAlbumRating = albumRatingValue; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "ge": |
|
|
|
|
|
|
|
minAlbumRating = albumRatingValue; |
|
|
|
|
|
|
|
maxAlbumRating = null; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "eq": |
|
|
|
|
|
|
|
minAlbumRating = albumRatingValue; |
|
|
|
|
|
|
|
maxAlbumRating = albumRatingValue; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle the play count filter
|
|
|
|
|
|
|
|
Integer playCountValue = null; |
|
|
|
|
|
|
|
try { playCountValue = Integer.parseInt(request.getParameter("playCountValue")); } |
|
|
|
|
|
|
|
catch (NumberFormatException e) { } |
|
|
|
|
|
|
|
String playCountComp = request.getParameter("playCountComp"); |
|
|
|
|
|
|
|
if (playCountValue != null) { |
|
|
|
|
|
|
|
switch (playCountComp) { |
|
|
|
|
|
|
|
case "lt": |
|
|
|
|
|
|
|
minPlayCount = null; |
|
|
|
|
|
|
|
maxPlayCount = playCountValue - 1; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "gt": |
|
|
|
|
|
|
|
minPlayCount = playCountValue + 1; |
|
|
|
|
|
|
|
maxPlayCount = null; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "le": |
|
|
|
|
|
|
|
minPlayCount = null; |
|
|
|
|
|
|
|
maxPlayCount = playCountValue; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "ge": |
|
|
|
|
|
|
|
minPlayCount = playCountValue; |
|
|
|
|
|
|
|
maxPlayCount = null; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "eq": |
|
|
|
|
|
|
|
minPlayCount = playCountValue; |
|
|
|
|
|
|
|
maxPlayCount = playCountValue; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle the format filter
|
|
|
|
|
|
|
|
String format = request.getParameter("format"); |
|
|
|
|
|
|
|
if (StringUtils.equalsIgnoreCase(format, "any")) format = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle the music folder filter
|
|
|
|
List<MusicFolder> musicFolders = getMusicFolders(request); |
|
|
|
List<MusicFolder> musicFolders = getMusicFolders(request); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Do we add to the current playlist or do we replace it?
|
|
|
|
|
|
|
|
boolean shouldAddToPlayList = ServletRequestUtils.getBooleanParameter(request, "addToPlaylist", false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Search the database using these criteria
|
|
|
|
|
|
|
|
RandomSearchCriteria criteria = new RandomSearchCriteria( |
|
|
|
|
|
|
|
size, |
|
|
|
|
|
|
|
genre, |
|
|
|
|
|
|
|
fromYear, |
|
|
|
|
|
|
|
toYear, |
|
|
|
|
|
|
|
musicFolders, |
|
|
|
|
|
|
|
minLastPlayedDate, |
|
|
|
|
|
|
|
maxLastPlayedDate, |
|
|
|
|
|
|
|
minAlbumRating, |
|
|
|
|
|
|
|
maxAlbumRating, |
|
|
|
|
|
|
|
minPlayCount, |
|
|
|
|
|
|
|
maxPlayCount, |
|
|
|
|
|
|
|
doesShowStarredSongs, |
|
|
|
|
|
|
|
doesShowUnstarredSongs, |
|
|
|
|
|
|
|
format |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
User user = securityService.getCurrentUser(request); |
|
|
|
Player player = playerService.getPlayer(request, response); |
|
|
|
Player player = playerService.getPlayer(request, response); |
|
|
|
PlayQueue playQueue = player.getPlayQueue(); |
|
|
|
PlayQueue playQueue = player.getPlayQueue(); |
|
|
|
|
|
|
|
playQueue.addFiles(shouldAddToPlayList, mediaFileService.getRandomSongs(criteria, user.getUsername())); |
|
|
|
RandomSearchCriteria criteria = new RandomSearchCriteria(size, genre, fromYear, toYear, musicFolders); |
|
|
|
|
|
|
|
playQueue.addFiles(false, searchService.getRandomSongs(criteria)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (request.getParameter("autoRandom") != null) { |
|
|
|
if (request.getParameter("autoRandom") != null) { |
|
|
|
playQueue.setRandomSearchCriteria(criteria); |
|
|
|
playQueue.setRandomSearchCriteria(criteria); |
|
|
@ -110,10 +252,6 @@ public class RandomPlayQueueController extends ParameterizableViewController { |
|
|
|
this.reloadFrames = reloadFrames; |
|
|
|
this.reloadFrames = reloadFrames; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setSearchService(SearchService searchService) { |
|
|
|
|
|
|
|
this.searchService = searchService; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setSecurityService(SecurityService securityService) { |
|
|
|
public void setSecurityService(SecurityService securityService) { |
|
|
|
this.securityService = securityService; |
|
|
|
this.securityService = securityService; |
|
|
|
} |
|
|
|
} |
|
|
@ -121,4 +259,8 @@ public class RandomPlayQueueController extends ParameterizableViewController { |
|
|
|
public void setSettingsService(SettingsService settingsService) { |
|
|
|
public void setSettingsService(SettingsService settingsService) { |
|
|
|
this.settingsService = settingsService; |
|
|
|
this.settingsService = settingsService; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setMediaFileService(MediaFileService mediaFileService) { |
|
|
|
|
|
|
|
this.mediaFileService = mediaFileService; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|