Add play count filter

master
François-Xavier Thomas 8 years ago
parent 1311e0220a
commit 76f42dfc1f
No known key found for this signature in database
GPG Key ID: 64337406D2DD45CE
  1. 34
      libresonic-main/src/main/java/org/libresonic/player/controller/RandomPlayQueueController.java
  2. 14
      libresonic-main/src/main/java/org/libresonic/player/dao/MediaFileDao.java
  3. 18
      libresonic-main/src/main/java/org/libresonic/player/domain/RandomSearchCriteria.java
  4. 5
      libresonic-main/src/main/resources/org/libresonic/player/i18n/ResourceBundle_en.properties
  5. 78
      libresonic-main/src/main/webapp/WEB-INF/jsp/more.jsp

@ -56,6 +56,8 @@ public class RandomPlayQueueController extends ParameterizableViewController {
Integer toYear = null;
Integer minAlbumRating = null;
Integer maxAlbumRating = null;
Integer minPlayCount = null;
Integer maxPlayCount = null;
Date minLastPlayedDate = null;
Date maxLastPlayedDate = null;
boolean doesShowStarredSongs = false;
@ -159,6 +161,36 @@ public class RandomPlayQueueController extends ParameterizableViewController {
}
}
// 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;
@ -180,6 +212,8 @@ public class RandomPlayQueueController extends ParameterizableViewController {
maxLastPlayedDate,
minAlbumRating,
maxAlbumRating,
minPlayCount,
maxPlayCount,
doesShowStarredSongs,
doesShowUnstarredSongs,
format

@ -498,6 +498,8 @@ public class MediaFileDao extends AbstractDao {
put("maxLastPlayed", criteria.getMaxLastPlayedDate());
put("minAlbumRating", criteria.getMinAlbumRating());
put("maxAlbumRating", criteria.getMaxAlbumRating());
put("minPlayCount", criteria.getMinPlayCount());
put("maxPlayCount", criteria.getMaxPlayCount());
put("starred", criteria.isShowStarredSongs());
put("unstarred", criteria.isShowUnstarredSongs());
put("format", criteria.getFormat());
@ -563,6 +565,18 @@ public class MediaFileDao extends AbstractDao {
}
}
if (criteria.getMinPlayCount() != null) {
query += " and media_file.play_count >= :minPlayCount";
}
if (criteria.getMaxPlayCount() != null) {
if (criteria.getMinPlayCount() == null) {
query += " and (media_file.play_count is null or media_file.play_count <= :maxPlayCount)";
} else {
query += " and media_file.play_count <= :maxPlayCount";
}
}
if (criteria.isShowStarredSongs() && !criteria.isShowUnstarredSongs()) {
query += " and starred_media_file.id is not null";
}

@ -39,6 +39,8 @@ public class RandomSearchCriteria {
private final Date maxLastPlayedDate;
private final Integer minAlbumRating;
private final Integer maxAlbumRating;
private final Integer minPlayCount;
private final Integer maxPlayCount;
private final boolean showStarredSongs;
private final boolean showUnstarredSongs;
private final String format;
@ -55,7 +57,7 @@ public class RandomSearchCriteria {
public RandomSearchCriteria(int count, String genre, Integer fromYear, Integer toYear, List<MusicFolder> musicFolders) {
this(
count, genre, fromYear, toYear, musicFolders,
null, null, null, null, true, true, null
null, null, null, null, null, null, true, true, null
);
}
@ -71,6 +73,8 @@ public class RandomSearchCriteria {
* @param maxLastPlayedDate Only return songs last played before this date. May be <code>null</code>.
* @param minAlbumRating Only return songs rated more or equalt to this value. May be <code>null</code>.
* @param maxAlbumRating Only return songs rated less or equal to this value. May be <code>null</code>.
* @param minPlayCount Only return songs whose play count is more or equal to this value. May be <code>null</code>.
* @param maxPlayCount Only return songs whose play count is less or equal to this value. May be <code>null</code>.
* @param showStarredSongs Show starred songs. May NOT be <code>null</code>.
* @param showUnstarredSongs Show unstarred songs. May NOT be <code>null</code>.
* @param format Only return songs whose file format is equal to this value. May be <code>null</code>.
@ -85,6 +89,8 @@ public class RandomSearchCriteria {
Date maxLastPlayedDate,
Integer minAlbumRating,
Integer maxAlbumRating,
Integer minPlayCount,
Integer maxPlayCount,
boolean showStarredSongs,
boolean showUnstarredSongs,
String format
@ -99,6 +105,8 @@ public class RandomSearchCriteria {
this.maxLastPlayedDate = maxLastPlayedDate;
this.minAlbumRating = minAlbumRating;
this.maxAlbumRating = maxAlbumRating;
this.minPlayCount = minPlayCount;
this.maxPlayCount = maxPlayCount;
this.showStarredSongs = showStarredSongs;
this.showUnstarredSongs = showUnstarredSongs;
this.format = format;
@ -151,4 +159,12 @@ public class RandomSearchCriteria {
public String getFormat() {
return format;
}
public Integer getMinPlayCount() {
return minPlayCount;
}
public Integer getMaxPlayCount() {
return maxPlayCount;
}
}

@ -233,11 +233,9 @@ more.random.text = Shuffle play
more.random.songs = {0} songs
more.random.auto = Play more random songs when end of play queue is reached.
more.random.ok = OK
more.random.add = Add to current playlist
more.random.addtoplaylist = Add to current playlist
more.random.any = Any
more.random.format = Format
more.random.before = Before
more.random.after = After
more.random.genre = Genre
more.random.anygenre = Any
more.random.year = Year
@ -251,6 +249,7 @@ more.random.unstarred = Unstarred
more.random.songrating = Song rating
more.random.albumrating = Album rating
more.random.lastplayed = Last played
more.random.playcount = Play count
more.random.1day = 1 day ago
more.random.1week = 1 week ago
more.random.1month = 1 month ago

@ -5,6 +5,7 @@
<style type="text/css">
#progressBar {width: 350px; height: 10px; border: 1px solid black; display:none;}
#progressBarContent {width: 0; height: 10px; background: url("<c:url value="/icons/default_light/progress.png"/>") repeat;}
#randomPlayQueue td { padding: 0 5px; }
</style>
<script type="text/javascript" src="<c:url value="/dwr/interface/transferService.js"/>"></script>
<script type="text/javascript" src="<c:url value="/dwr/engine.js"/>"></script>
@ -52,12 +53,12 @@
<span style="vertical-align: middle"><fmt:message key="more.random.title"/></span>
</h2>
<form method="post" action="randomPlayQueue.view?">
<form id="randomPlayQueue" method="post" action="randomPlayQueue.view?">
<table>
<tr>
<td><fmt:message key="more.random.text"/></td>
<td>
<select name="size">
<select style="width: 100%;" name="size">
<option value="10"><fmt:message key="more.random.songs"><fmt:param value="10"/></fmt:message></option>
<option value="20" selected><fmt:message key="more.random.songs"><fmt:param value="20"/></fmt:message></option>
<option value="30"><fmt:message key="more.random.songs"><fmt:param value="30"/></fmt:message></option>
@ -66,22 +67,9 @@
<option value="100"><fmt:message key="more.random.songs"><fmt:param value="100"/></fmt:message></option>
</select>
</td>
</tr>
<tr>
<td><fmt:message key="more.random.genre"/></td>
<td>
<select name="genre">
<option value="any"><fmt:message key="more.random.anygenre"/></option>
<c:forEach items="${model.genres}" var="genre">
<option value="${genre.name}"><str:truncateNicely upper="20">${genre.name} (${genre.songCount})</str:truncateNicely></option>
</c:forEach>
</select>
</td>
</tr>
<tr>
<td><fmt:message key="more.random.year"/></td>
<td>
<select name="year">
<select style="width: 100%;" name="year">
<option value="any"><fmt:message key="more.random.anyyear"/></option>
<c:forEach begin="0" end="${model.currentYear - 2010}" var="yearOffset">
@ -102,16 +90,15 @@
</td>
</tr>
<tr>
<td><fmt:message key="more.random.songrating"/></td>
<td><fmt:message key="more.random.genre"/></td>
<td>
<select name="songRating">
<option value="any" selected="selected"><fmt:message key="more.random.any"/></option>
<option value="starred"><fmt:message key="more.random.starred"/></option>
<option value="unstarred"><fmt:message key="more.random.unstarred"/></option>
<select style="width: 100%;" name="genre">
<option value="any"><fmt:message key="more.random.anygenre"/></option>
<c:forEach items="${model.genres}" var="genre">
<option value="${genre.name}"><str:truncateNicely upper="20">${genre.name} (${genre.songCount})</str:truncateNicely></option>
</c:forEach>
</select>
</td>
</tr>
<tr>
<td><fmt:message key="more.random.albumrating"/></td>
<td>
<select name="albumRatingComp">
@ -133,11 +120,19 @@
</td>
</tr>
<tr>
<td><fmt:message key="more.random.songrating"/></td>
<td>
<select style="width: 100%;" name="songRating">
<option value="any" selected="selected"><fmt:message key="more.random.any"/></option>
<option value="starred"><fmt:message key="more.random.starred"/></option>
<option value="unstarred"><fmt:message key="more.random.unstarred"/></option>
</select>
</td>
<td><fmt:message key="more.random.lastplayed"/></td>
<td>
<select name="lastPlayedComp">
<option value="lt" selected="selected"><fmt:message key="more.random.before"/></option>
<option value="gt"><fmt:message key="more.random.after"/></option>
<option value="lt" selected="selected">&lt;</option>
<option value="gt">&gt;</option>
</select>
<select name="lastPlayedValue">
<option value="any" selected="selected"><fmt:message key="more.random.any"/></option>
@ -150,31 +145,42 @@
</select>
</td>
</tr>
<tr>
<td><fmt:message key="more.random.folder"/></td>
<td>
<select style="width: 100%;" name="musicFolderId">
<option value="-1"><fmt:message key="more.random.anyfolder"/></option>
<c:forEach items="${model.musicFolders}" var="musicFolder">
<option value="${musicFolder.id}">${musicFolder.name}</option>
</c:forEach>
</select>
</td>
<td><fmt:message key="more.random.playcount"/></td>
<td>
<select name="playCountComp">
<option value="lt" selected="selected">&lt;</option>
<option value="gt">&gt;</option>
</select>
<input type="number" name="playCountValue"/> times
</td>
</tr>
<tr>
<td><fmt:message key="more.random.format"/></td>
<td>
<select name="format">
<select style="width: 100%;" name="format">
<option value="any" selected="selected"><fmt:message key="more.random.any"/></option>
<option value="flac">FLAC</option>
<option value="mp3">MP3</option>
</select>
</td>
</tr>
<tr>
<td><fmt:message key="more.random.folder"/></td>
<td><fmt:message key="more.random.addtoplaylist"/></td>
<td>
<select name="musicFolderId">
<option value="-1"><fmt:message key="more.random.anyfolder"/></option>
<c:forEach items="${model.musicFolders}" var="musicFolder">
<option value="${musicFolder.id}">${musicFolder.name}</option>
</c:forEach>
</select>
<input name="addToPlaylist" value="true" type="checkbox"/>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="<fmt:message key="more.random.ok"/>">
<input type="checkbox" name="addToPlaylist" value="true"/> <fmt:message key="more.random.add"/>
</td>
</tr>
<c:if test="${not model.clientSidePlaylist}">

Loading…
Cancel
Save