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