X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Frhynodge%2Fwatchers%2FPirateBayEpisodeWatcher.java;h=eed6c9005538b8bed8b10a93d40d3c39a35229c5;hb=15e9d53a33f0b1b6070243d7d3f1aba4c647f38c;hp=753a4ad693c9f26ea98c4e95cec184f216ef9214;hpb=cf86c044b5ec687fcf44eae6536d1e143c205fc4;p=rhynodge.git
diff --git a/src/main/java/net/pterodactylus/rhynodge/watchers/PirateBayEpisodeWatcher.java b/src/main/java/net/pterodactylus/rhynodge/watchers/PirateBayEpisodeWatcher.java
index 753a4ad..eed6c90 100644
--- a/src/main/java/net/pterodactylus/rhynodge/watchers/PirateBayEpisodeWatcher.java
+++ b/src/main/java/net/pterodactylus/rhynodge/watchers/PirateBayEpisodeWatcher.java
@@ -17,23 +17,27 @@
package net.pterodactylus.rhynodge.watchers;
+import static net.pterodactylus.rhynodge.filters.BlacklistFilter.createDefaultBlacklistFilter;
+
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;
import net.pterodactylus.rhynodge.Filter;
import net.pterodactylus.rhynodge.Query;
-import net.pterodactylus.rhynodge.Trigger;
+import net.pterodactylus.rhynodge.Watcher;
import net.pterodactylus.rhynodge.filters.EpisodeFilter;
import net.pterodactylus.rhynodge.filters.HtmlFilter;
-import net.pterodactylus.rhynodge.filters.PirateBayFilter;
+import net.pterodactylus.rhynodge.filters.SizeBlacklistFilter;
+import net.pterodactylus.rhynodge.filters.torrents.PirateBayFilter;
+import net.pterodactylus.rhynodge.mergers.EpisodeMerger;
+import net.pterodactylus.rhynodge.queries.FallbackQuery;
import net.pterodactylus.rhynodge.queries.HttpQuery;
-import net.pterodactylus.rhynodge.triggers.NewEpisodeTrigger;
import com.google.common.collect.ImmutableList;
/**
- * {@Watcher} implementation that watches The Pirate Bay for new episodes.
+ * {@link Watcher} implementation that watches The Pirate Bay for new episodes.
*
* @author David âBombeâ Roden
*/
@@ -45,24 +49,28 @@ public class PirateBayEpisodeWatcher extends DefaultWatcher {
* @param searchTerms
* The terms to search for
*/
- public PirateBayEpisodeWatcher(String searchTerms) {
- super(createHttpQuery(searchTerms), createFilters(), createTrigger());
+ public PirateBayEpisodeWatcher(String searchTerms, String proxy) {
+ super(createHttpQuery(searchTerms, extractProxyHost(proxy), extractProxyPort(proxy)), createFilters(), new EpisodeMerger());
+ }
+
+ private static String extractProxyHost(String proxy) {
+ return proxy.split(":")[0];
+ }
+
+ private static int extractProxyPort(String proxy) {
+ return Integer.valueOf(proxy.split(":")[1]);
}
//
// STATIC METHODS
//
- /**
- * Creates the query of the watcher.
- *
- * @param searchTerms
- * The search terms of the query
- * @return The query of the watcher
- */
- private static Query createHttpQuery(String searchTerms) {
+ private static Query createHttpQuery(String searchTerms, String proxyHost, int proxyPort) {
try {
- return new HttpQuery("http://thepiratebay.se/search/" + URLEncoder.encode(searchTerms, "UTF-8") + "/0/3/0");
+ HttpQuery hiddenServiceQuery = new HttpQuery("http://uj3wazyk5u4hnvtk.onion/search/" + URLEncoder.encode(searchTerms, "UTF-8") + "/0/3/0", proxyHost, proxyPort);
+ HttpQuery torQuery = new HttpQuery("http://thepiratebay.org/search/" + URLEncoder.encode(searchTerms, "UTF-8") + "/0/3/0", proxyHost, proxyPort);
+ HttpQuery plainInternetQuery = new HttpQuery("http://thepiratebay.org/search/" + URLEncoder.encode(searchTerms, "UTF-8") + "/0/3/0");
+ return new FallbackQuery(hiddenServiceQuery, torQuery, plainInternetQuery);
} catch (UnsupportedEncodingException uee1) {
/* will not happen. */
return null;
@@ -75,16 +83,7 @@ public class PirateBayEpisodeWatcher extends DefaultWatcher {
* @return The filters of the watcher
*/
private static List createFilters() {
- return ImmutableList. of(new HtmlFilter(), new PirateBayFilter(), new EpisodeFilter());
- }
-
- /**
- * Creates the trigger of the watcher.
- *
- * @return The trigger of the watcher
- */
- private static Trigger createTrigger() {
- return new NewEpisodeTrigger();
+ return ImmutableList.of(new HtmlFilter(), new PirateBayFilter(), createDefaultBlacklistFilter(), new SizeBlacklistFilter(), new EpisodeFilter());
}
}