import net.pterodactylus.rhynodge.Watcher;
import net.pterodactylus.rhynodge.filters.EpisodeFilter;
import net.pterodactylus.rhynodge.filters.HtmlFilter;
+import net.pterodactylus.rhynodge.filters.SizeBlacklistFilter;
import net.pterodactylus.rhynodge.filters.torrents.KickAssTorrentsFilter;
import net.pterodactylus.rhynodge.queries.HttpQuery;
import net.pterodactylus.rhynodge.triggers.NewEpisodeTrigger;
* @return The filters of the watcher
*/
private static List<Filter> createFilters() {
- return ImmutableList.of(new HtmlFilter(), new KickAssTorrentsFilter(), createDefaultBlacklistFilter(), new EpisodeFilter());
+ return ImmutableList.of(new HtmlFilter(), new KickAssTorrentsFilter(), createDefaultBlacklistFilter(), new SizeBlacklistFilter(), new EpisodeFilter());
}
/**
import net.pterodactylus.rhynodge.Trigger;
import net.pterodactylus.rhynodge.Watcher;
import net.pterodactylus.rhynodge.filters.HtmlFilter;
+import net.pterodactylus.rhynodge.filters.SizeBlacklistFilter;
import net.pterodactylus.rhynodge.filters.torrents.KickAssTorrentsFilter;
import net.pterodactylus.rhynodge.queries.HttpQuery;
import net.pterodactylus.rhynodge.triggers.NewTorrentTrigger;
* @return The filters of the watcher
*/
private static List<Filter> createFilters() {
- return ImmutableList.of(new HtmlFilter(), new KickAssTorrentsFilter(), createDefaultBlacklistFilter());
+ return ImmutableList.of(new HtmlFilter(), new KickAssTorrentsFilter(), createDefaultBlacklistFilter(), new SizeBlacklistFilter());
}
/**
import net.pterodactylus.rhynodge.Watcher;
import net.pterodactylus.rhynodge.filters.EpisodeFilter;
import net.pterodactylus.rhynodge.filters.HtmlFilter;
+import net.pterodactylus.rhynodge.filters.SizeBlacklistFilter;
import net.pterodactylus.rhynodge.filters.torrents.PirateBayFilter;
import net.pterodactylus.rhynodge.queries.FallbackQuery;
import net.pterodactylus.rhynodge.queries.HttpQuery;
* @return The filters of the watcher
*/
private static List<Filter> createFilters() {
- return ImmutableList.of(new HtmlFilter(), new PirateBayFilter(), createDefaultBlacklistFilter(), new EpisodeFilter());
+ return ImmutableList.of(new HtmlFilter(), new PirateBayFilter(), createDefaultBlacklistFilter(), new SizeBlacklistFilter(), new EpisodeFilter());
}
/**
import net.pterodactylus.rhynodge.Trigger;
import net.pterodactylus.rhynodge.Watcher;
import net.pterodactylus.rhynodge.filters.HtmlFilter;
+import net.pterodactylus.rhynodge.filters.SizeBlacklistFilter;
import net.pterodactylus.rhynodge.filters.torrents.PirateBayFilter;
import net.pterodactylus.rhynodge.queries.FallbackQuery;
import net.pterodactylus.rhynodge.queries.HttpQuery;
* @return The filters of the watcher
*/
private static List<Filter> createFilters() {
- return ImmutableList.of(new HtmlFilter(), new PirateBayFilter(), createDefaultBlacklistFilter());
+ return ImmutableList.of(new HtmlFilter(), new PirateBayFilter(), createDefaultBlacklistFilter(), new SizeBlacklistFilter());
}
/**
import net.pterodactylus.rhynodge.Trigger;
import net.pterodactylus.rhynodge.filters.EpisodeFilter;
import net.pterodactylus.rhynodge.filters.HtmlFilter;
+import net.pterodactylus.rhynodge.filters.SizeBlacklistFilter;
import net.pterodactylus.rhynodge.filters.torrents.TorrentHoundFilter;
import net.pterodactylus.rhynodge.queries.HttpQuery;
import net.pterodactylus.rhynodge.triggers.NewEpisodeTrigger;
* @return The filters of the watcher
*/
private static List<Filter> createFilters() {
- return ImmutableList.of(new HtmlFilter(), new TorrentHoundFilter(), createDefaultBlacklistFilter(), new EpisodeFilter());
+ return ImmutableList.of(new HtmlFilter(), new TorrentHoundFilter(), createDefaultBlacklistFilter(), new SizeBlacklistFilter(), new EpisodeFilter());
}
/**
import net.pterodactylus.rhynodge.Query;
import net.pterodactylus.rhynodge.Trigger;
import net.pterodactylus.rhynodge.filters.HtmlFilter;
+import net.pterodactylus.rhynodge.filters.SizeBlacklistFilter;
import net.pterodactylus.rhynodge.filters.torrents.TorrentHoundFilter;
import net.pterodactylus.rhynodge.queries.HttpQuery;
import net.pterodactylus.rhynodge.triggers.NewTorrentTrigger;
* @return The filters of the watcher
*/
private static List<Filter> createFilters() {
- return ImmutableList.of(new HtmlFilter(), new TorrentHoundFilter(), createDefaultBlacklistFilter());
+ return ImmutableList.of(new HtmlFilter(), new TorrentHoundFilter(), createDefaultBlacklistFilter(), new SizeBlacklistFilter());
}
/**
import net.pterodactylus.rhynodge.Trigger;
import net.pterodactylus.rhynodge.filters.EpisodeFilter;
import net.pterodactylus.rhynodge.filters.HtmlFilter;
+import net.pterodactylus.rhynodge.filters.SizeBlacklistFilter;
import net.pterodactylus.rhynodge.filters.torrents.TorrentzEuFilter;
import net.pterodactylus.rhynodge.queries.HttpQuery;
import net.pterodactylus.rhynodge.triggers.NewEpisodeTrigger;
* @return The filters of the watcher
*/
private static List<Filter> createFilters() {
- return ImmutableList.of(new HtmlFilter(), new TorrentzEuFilter(), createDefaultBlacklistFilter(), new EpisodeFilter());
+ return ImmutableList.of(new HtmlFilter(), new TorrentzEuFilter(), createDefaultBlacklistFilter(), new SizeBlacklistFilter(), new EpisodeFilter());
}
/**
import net.pterodactylus.rhynodge.Trigger;
import net.pterodactylus.rhynodge.filters.EpisodeFilter;
import net.pterodactylus.rhynodge.filters.HtmlFilter;
+import net.pterodactylus.rhynodge.filters.SizeBlacklistFilter;
import net.pterodactylus.rhynodge.filters.torrents.TorrentzEuFilter;
import net.pterodactylus.rhynodge.queries.HttpQuery;
import net.pterodactylus.rhynodge.triggers.NewEpisodeTrigger;
* @return The filters of the watcher
*/
private static List<Filter> createFilters() {
- return ImmutableList.of(new HtmlFilter(), new TorrentzEuFilter(), createDefaultBlacklistFilter());
+ return ImmutableList.of(new HtmlFilter(), new TorrentzEuFilter(), createDefaultBlacklistFilter(), new SizeBlacklistFilter());
}
/**
--- /dev/null
+package net.pterodactylus.rhynodge.filters
+
+import net.pterodactylus.rhynodge.Filter
+import net.pterodactylus.rhynodge.State
+import net.pterodactylus.rhynodge.states.FailedState
+import net.pterodactylus.rhynodge.states.TorrentState
+
+/**
+ * Blacklist that filters torrents with a certain size.
+ */
+class SizeBlacklistFilter(private val blacklistedSizes: Iterable<String> = listOf("313.97 MiB", "331.97 MiB")): Filter {
+
+ override fun filter(state: State): State {
+ val torrentState = state as? TorrentState ?: return FailedState()
+ return TorrentState(torrentState.torrentFiles().filterNot { it.size() in blacklistedSizes })
+ }
+
+}
--- /dev/null
+package net.pterodactylus.rhynodge.filters
+
+import net.pterodactylus.rhynodge.states.FailedState
+import net.pterodactylus.rhynodge.states.TorrentState
+import net.pterodactylus.rhynodge.states.TorrentState.TorrentFile
+import org.hamcrest.MatcherAssert
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers
+import org.hamcrest.Matchers.equalTo
+import org.junit.Test
+
+/**
+ * Unit test for [SizeBlacklistFilter].
+ */
+class SizeBlacklistFilterTest {
+
+ private val filter = SizeBlacklistFilter(listOf("123 MiB", "234 GiB"))
+ private val notMatchingTorrentFile1 = TorrentFile("The Vampire Diaries S05E05 2013 HDRip 720p-3LT0N", "123 GiB", "magnet:?xt=a", "http://", 1, 2, 3)
+ private val notMatchingTorrentFile2 = TorrentFile("The Vampire Diaries S05E05 2013 HDRip 720p-HELLRAZ0R", "123 MB", "magnet:?xt=b", "http://", 1, 2, 3)
+ private val matchingTorrentFile1 = TorrentFile("The Vampire Diaries S05E05 2013 HDRip 720p-Haggebulle", "123 MiB", "magnet:?xt=c", "http://", 1, 2, 3)
+ private val matchingTorrentFile2 = TorrentFile("The Vampire Diaries S05E05 2013 HDRip 720p-FooKaS", "234 GiB", "magnet:?xt=d", "http://", 1, 2, 3)
+
+ @Test
+ fun `filter removes the correct torrents`() {
+ val filteredState = filter.filter(TorrentState(listOf(
+ notMatchingTorrentFile1,
+ notMatchingTorrentFile2,
+ matchingTorrentFile1,
+ matchingTorrentFile2
+ ))) as TorrentState
+ assertThat(filteredState.torrentFiles(), Matchers.containsInAnyOrder(
+ notMatchingTorrentFile1,
+ notMatchingTorrentFile2
+ ))
+ }
+
+ @Test
+ fun `filter returns failed state for a failed state`() {
+ assertThat(filter.filter(FailedState()).success(), equalTo(false))
+ }
+
+}