From 345aad4148f133477e40c232a8e855dfd28e0654 Mon Sep 17 00:00:00 2001 From: thomasdomingos Date: Thu, 28 Oct 2021 19:59:50 +0200 Subject: Add 'Duration' to Episode Filter for podcast Auto Download Settings (#5396) --- .../danoeh/antennapod/model/feed/FeedFilter.java | 35 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'model/src/main/java/de/danoeh/antennapod') diff --git a/model/src/main/java/de/danoeh/antennapod/model/feed/FeedFilter.java b/model/src/main/java/de/danoeh/antennapod/model/feed/FeedFilter.java index 31d263b24..3b35fe5bd 100644 --- a/model/src/main/java/de/danoeh/antennapod/model/feed/FeedFilter.java +++ b/model/src/main/java/de/danoeh/antennapod/model/feed/FeedFilter.java @@ -10,18 +10,24 @@ import java.util.regex.Pattern; public class FeedFilter implements Serializable { private final String includeFilter; private final String excludeFilter; + private final int minimalDuration; public FeedFilter() { - this("", ""); + this("", "", -1); } - public FeedFilter(String includeFilter, String excludeFilter) { + public FeedFilter(String includeFilter, String excludeFilter, int minimalDuration) { // We're storing the strings and not the parsed terms because // 1. It's easier to show the user exactly what they typed in this way // (we don't have to recreate it) // 2. We don't know if we'll actually be asked to parse anything anyways. this.includeFilter = includeFilter; this.excludeFilter = excludeFilter; + this.minimalDuration = minimalDuration; + } + + public FeedFilter(String includeFilter, String excludeFilter) { + this(includeFilter, excludeFilter, -1); } /** @@ -49,11 +55,20 @@ public class FeedFilter implements Serializable { List includeTerms = parseTerms(includeFilter); List excludeTerms = parseTerms(excludeFilter); - if (includeTerms.size() == 0 && excludeTerms.size() == 0) { + if (includeTerms.size() == 0 && excludeTerms.size() == 0 && minimalDuration <= -1) { // nothing has been specified, so include everything return true; } + // Check if the episode is long enough if minimal duration filter is on + if (hasMinimalDurationFilter() && item.getMedia() != null) { + int durationInMs = item.getMedia().getDuration(); + // Minimal Duration is stored in seconds + if (durationInMs > 0 && durationInMs / 1000 < minimalDuration) { + return false; + } + } + // check using lowercase so the users don't have to worry about case. String title = item.getTitle().toLowerCase(Locale.getDefault()); @@ -78,6 +93,12 @@ public class FeedFilter implements Serializable { return true; } + // if they only set minimal duration filter and arrived here, autodownload + // should happen + if (hasMinimalDurationFilter()) { + return true; + } + return false; } @@ -89,6 +110,10 @@ public class FeedFilter implements Serializable { return excludeFilter; } + public int getMinimalDurationFilter() { + return minimalDuration; + } + /** * @return true if only include is set */ @@ -110,4 +135,8 @@ public class FeedFilter implements Serializable { public boolean hasExcludeFilter() { return excludeFilter.length() > 0; } + + public boolean hasMinimalDurationFilter() { + return minimalDuration > -1; + } } -- cgit v1.2.3