Add more fake groups to the blacklist filter.
[rhynodge.git] / src / main / java / net / pterodactylus / rhynodge / filters / BlacklistFilter.java
1 /*
2  * rhynodge - BlacklistFilter.java - Copyright © 2013 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.rhynodge.filters;
19
20 import static com.google.common.base.Preconditions.checkState;
21 import static com.google.common.collect.FluentIterable.from;
22 import static java.util.Arrays.asList;
23
24 import java.util.List;
25
26 import net.pterodactylus.rhynodge.Filter;
27 import net.pterodactylus.rhynodge.State;
28 import net.pterodactylus.rhynodge.states.FailedState;
29 import net.pterodactylus.rhynodge.states.TorrentState;
30 import net.pterodactylus.rhynodge.states.TorrentState.TorrentFile;
31
32 import com.google.common.base.Predicate;
33
34 /**
35  * Filter for {@link TorrentState}s that removes all {@link TorrentFile}s whose
36  * names match a list of bad words.
37  *
38  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
39  */
40 public class BlacklistFilter implements Filter {
41
42         private final Iterable<String> filterWords;
43
44         public BlacklistFilter(List<String> filterWords) {
45                 this.filterWords = filterWords;
46         }
47
48         @Override
49         public State filter(State state) {
50                 if (!state.success()) {
51                         return FailedState.from(state);
52                 }
53                 checkState(state instanceof TorrentState, "state is not a TorrentState but a %s!", state.getClass());
54
55                 TorrentState torrentState = (TorrentState) state;
56                 return new TorrentState(from(torrentState.torrentFiles()).filter(new Predicate<TorrentFile>() {
57                         @Override
58                         public boolean apply(TorrentFile torrentFile) {
59                                 return (torrentFile != null) && nameDoesNotMatchAFilterWord(torrentFile.name());
60                         }
61
62                         private boolean nameDoesNotMatchAFilterWord(final String name) {
63                                 return !from(filterWords).anyMatch(new Predicate<String>() {
64                                         @Override
65                                         public boolean apply(String word) {
66                                                 return name.toLowerCase().contains(word.toLowerCase());
67                                         }
68                                 });
69                         }
70                 }).toList());
71         }
72
73         public static BlacklistFilter createDefaultBlacklistFilter() {
74                 return new BlacklistFilter(asList(
75             "[G2G]",
76             "-3LT0N",
77             "-ADTRG",
78             "-AMIABLE",
79             "-AN0NYM0US",
80             "-AQOS",
81             "-AXED",
82             "-BiDA",
83             "-CM",
84             "-DiAMOND",
85             "-DiRTYMARY",
86             "-EDAW",
87             "-EVO",
88             "-EVOLVE",
89             "-EwDp",
90             "-Felony",
91             "-FooKaS",
92             "-Haggebulle",
93             "-HELLRAZ0R",
94             "-iJUGGA",
95             "-IMAGiNE",
96             "-iMBT",
97             "-juggs",
98             "-KILLERS",
99             "-Larceny",
100             "-LEGi0N",
101             "-MAX",
102             "-MiLLENiUM",
103             "-NeDiVx",
104             "-NoGRP",
105             "-NOiR",
106             "-NYDIC",
107             "-P2P",
108             "-PLAYNOW",
109             "-PrisM",
110             "-RARBG",
111             "-S4A",
112             "-SHODAN",
113             "-SPARKS",
114             "-SUFFiCE",
115             "-TAMILROCKERS",
116             "-TASTE",
117             "-TiTAN",
118             "-THC",
119             "-UnKnOwN",
120             "-UNiQUE",
121             "-W00D"
122         ));
123         }
124
125 }