🐛 Fix broken change detection
[rhynodge.git] / src / main / java / net / pterodactylus / rhynodge / watchers / TorrentHoundEpisodeWatcher.java
1 /*
2  * rhynodge - TorrentzEuEpisodeWatcher.java - Copyright © 2014 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.filters.EpisodeFilter;
29 import net.pterodactylus.rhynodge.filters.HtmlFilter;
30 import net.pterodactylus.rhynodge.filters.SizeBlacklistFilter;
31 import net.pterodactylus.rhynodge.filters.torrents.TorrentHoundFilter;
32 import net.pterodactylus.rhynodge.mergers.EpisodeMerger;
33 import net.pterodactylus.rhynodge.queries.HttpQuery;
34
35 import com.google.common.collect.ImmutableList;
36
37 /**
38  * {@link net.pterodactylus.rhynodge.Watcher} implementation that watches
39  * TorrentHound for new episodes.
40  *
41  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
42  */
43 public class TorrentHoundEpisodeWatcher extends DefaultWatcher {
44
45         /**
46          * Creates a new TorrentHound episode watcher.
47          *
48          * @param searchTerms
49          *              The terms to search for
50          */
51         public TorrentHoundEpisodeWatcher(String searchTerms) {
52                 super(createHttpQuery(searchTerms), createFilters(), new EpisodeMerger());
53         }
54
55         //
56         // STATIC METHODS
57         //
58
59         /**
60          * Creates the query of the watcher.
61          *
62          * @param searchTerms
63          *              The search terms of the query
64          * @return The query of the watcher
65          */
66         private static Query createHttpQuery(String searchTerms) {
67                 try {
68                         return new HttpQuery("http://www.torrenthound.com/search/1/" + URLEncoder.encode(searchTerms, "UTF-8") + "/added:desc");
69                 } catch (UnsupportedEncodingException uee1) {
70                         /* will not happen. */
71                         return null;
72                 }
73         }
74
75         /**
76          * Creates the filters of the watcher.
77          *
78          * @return The filters of the watcher
79          */
80         private static List<Filter> createFilters() {
81                 return ImmutableList.of(new HtmlFilter(), new TorrentHoundFilter(), createDefaultBlacklistFilter(), new SizeBlacklistFilter(), new EpisodeFilter());
82         }
83
84 }