ee8c1f3b3f0a13baffbc01d9a946a7f1ab1fc488
[rhynodge.git] / src / main / java / net / pterodactylus / rhynodge / watchers / KickAssTorrentsEpisodeWatcher.java
1 /*
2  * Rhynodge - KickAssTorrentsWatcher.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.watchers;
19
20 import static net.pterodactylus.rhynodge.filters.BlacklistFilter.createDefaultBlacklistFilter;
21
22 import java.io.UnsupportedEncodingException;
23 import java.net.URLEncoder;
24 import java.util.List;
25
26 import net.pterodactylus.rhynodge.Filter;
27 import net.pterodactylus.rhynodge.Query;
28 import net.pterodactylus.rhynodge.Trigger;
29 import net.pterodactylus.rhynodge.Watcher;
30 import net.pterodactylus.rhynodge.filters.EpisodeFilter;
31 import net.pterodactylus.rhynodge.filters.HtmlFilter;
32 import net.pterodactylus.rhynodge.filters.SizeBlacklistFilter;
33 import net.pterodactylus.rhynodge.filters.torrents.KickAssTorrentsFilter;
34 import net.pterodactylus.rhynodge.queries.HttpQuery;
35 import net.pterodactylus.rhynodge.triggers.NewEpisodeTrigger;
36
37 import com.google.common.collect.ImmutableList;
38
39 /**
40  * {@link Watcher} implementation that watches Kick Ass Torrents for new
41  * episodes.
42  *
43  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
44  */
45 public class KickAssTorrentsEpisodeWatcher extends DefaultWatcher {
46
47         /**
48          * Creates a new Kick Ass Torrents episode watcher.
49          *
50          * @param searchTerms
51          *            The terms to search for
52          */
53         public KickAssTorrentsEpisodeWatcher(String searchTerms) {
54                 super(createHttpQuery(searchTerms), createFilters(), createTrigger());
55         }
56
57         //
58         // STATIC METHODS
59         //
60
61         /**
62          * Creates the query of the watcher.
63          *
64          * @param searchTerms
65          *            The search terms of the query
66          * @return The query of the watcher
67          */
68         private static Query createHttpQuery(String searchTerms) {
69                 try {
70                         return new HttpQuery("https://kat.cr/usearch/" + URLEncoder.encode(searchTerms, "UTF-8") + "/?field=time_add&sorder=desc");
71                 } catch (UnsupportedEncodingException uee1) {
72                         /* will not happen. */
73                         return null;
74                 }
75         }
76
77         /**
78          * Creates the filters of the watcher.
79          *
80          * @return The filters of the watcher
81          */
82         private static List<Filter> createFilters() {
83                 return ImmutableList.of(new HtmlFilter(), new KickAssTorrentsFilter(), createDefaultBlacklistFilter(), new SizeBlacklistFilter(), new EpisodeFilter());
84         }
85
86         /**
87          * Creates the trigger of the watcher.
88          *
89          * @return The trigger of the watcher
90          */
91         private static Trigger createTrigger() {
92                 return new NewEpisodeTrigger();
93         }
94
95 }