From 76f42dfc1f307d4b55fdcd7740015748f2acd400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20Thomas?= Date: Fri, 25 Nov 2016 21:29:39 +0100 Subject: [PATCH] Add play count filter --- .../controller/RandomPlayQueueController.java | 34 ++++++++ .../libresonic/player/dao/MediaFileDao.java | 14 ++++ .../player/domain/RandomSearchCriteria.java | 18 ++++- .../player/i18n/ResourceBundle_en.properties | 5 +- .../src/main/webapp/WEB-INF/jsp/more.jsp | 78 ++++++++++--------- 5 files changed, 109 insertions(+), 40 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/RandomPlayQueueController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/RandomPlayQueueController.java index 9759ead5..e741635d 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/RandomPlayQueueController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/RandomPlayQueueController.java @@ -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 diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/MediaFileDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/MediaFileDao.java index d6b9dd7d..3d964a4b 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/MediaFileDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/MediaFileDao.java @@ -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"; } diff --git a/libresonic-main/src/main/java/org/libresonic/player/domain/RandomSearchCriteria.java b/libresonic-main/src/main/java/org/libresonic/player/domain/RandomSearchCriteria.java index 3e746316..535cbe8d 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/domain/RandomSearchCriteria.java +++ b/libresonic-main/src/main/java/org/libresonic/player/domain/RandomSearchCriteria.java @@ -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 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 null. * @param minAlbumRating Only return songs rated more or equalt to this value. May be null. * @param maxAlbumRating Only return songs rated less or equal to this value. May be null. + * @param minPlayCount Only return songs whose play count is more or equal to this value. May be null. + * @param maxPlayCount Only return songs whose play count is less or equal to this value. May be null. * @param showStarredSongs Show starred songs. May NOT be null. * @param showUnstarredSongs Show unstarred songs. May NOT be null. * @param format Only return songs whose file format is equal to this value. May be null. @@ -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; + } } diff --git a/libresonic-main/src/main/resources/org/libresonic/player/i18n/ResourceBundle_en.properties b/libresonic-main/src/main/resources/org/libresonic/player/i18n/ResourceBundle_en.properties index cfb7dcc2..1691ec04 100644 --- a/libresonic-main/src/main/resources/org/libresonic/player/i18n/ResourceBundle_en.properties +++ b/libresonic-main/src/main/resources/org/libresonic/player/i18n/ResourceBundle_en.properties @@ -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 diff --git a/libresonic-main/src/main/webapp/WEB-INF/jsp/more.jsp b/libresonic-main/src/main/webapp/WEB-INF/jsp/more.jsp index 0d5271ad..ce337650 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/jsp/more.jsp +++ b/libresonic-main/src/main/webapp/WEB-INF/jsp/more.jsp @@ -5,6 +5,7 @@ @@ -52,12 +53,12 @@ -
+ - - - - - - - + - - + + + + + + + + - - - +
- @@ -66,22 +67,9 @@
- -
- @@ -102,16 +90,15 @@
- + + + +
+ +
+ + + + times +
-
- +
"> -