Add blacklist filter for certain sizes
[rhynodge.git] / src / main / kotlin / net / pterodactylus / rhynodge / filters / SizeBlacklistFilter.kt
1 package net.pterodactylus.rhynodge.filters
2
3 import net.pterodactylus.rhynodge.Filter
4 import net.pterodactylus.rhynodge.State
5 import net.pterodactylus.rhynodge.states.FailedState
6 import net.pterodactylus.rhynodge.states.TorrentState
7
8 /**
9  * Blacklist that filters torrents with a certain size.
10  */
11 class SizeBlacklistFilter(private val blacklistedSizes: Iterable<String> = listOf("313.97 MiB", "331.97 MiB")): Filter {
12
13         override fun filter(state: State): State {
14                 val torrentState = state as? TorrentState ?: return FailedState()
15                 return TorrentState(torrentState.torrentFiles().filterNot { it.size() in blacklistedSizes })
16         }
17
18 }