Add blacklist filter for certain sizes
[rhynodge.git] / src / main / java / net / pterodactylus / rhynodge / watchers / PirateBayWatcher.java
index 77fbf4d..1a62e80 100644 (file)
@@ -28,7 +28,9 @@ import net.pterodactylus.rhynodge.Query;
 import net.pterodactylus.rhynodge.Trigger;
 import net.pterodactylus.rhynodge.Watcher;
 import net.pterodactylus.rhynodge.filters.HtmlFilter;
+import net.pterodactylus.rhynodge.filters.SizeBlacklistFilter;
 import net.pterodactylus.rhynodge.filters.torrents.PirateBayFilter;
+import net.pterodactylus.rhynodge.queries.FallbackQuery;
 import net.pterodactylus.rhynodge.queries.HttpQuery;
 import net.pterodactylus.rhynodge.triggers.NewTorrentTrigger;
 
@@ -47,8 +49,16 @@ public class PirateBayWatcher extends DefaultWatcher {
         * @param searchTerms
         *            The terms to search for
         */
-       public PirateBayWatcher(String searchTerms) {
-               super(createHttpQuery(searchTerms), createFilters(), createTrigger());
+       public PirateBayWatcher(String searchTerms, String proxy) {
+               super(createHttpQuery(searchTerms, extractProxyHost(proxy), extractProxyPort(proxy)), createFilters(), createTrigger());
+       }
+
+       private static String extractProxyHost(String proxy) {
+               return proxy.split(":")[0];
+       }
+
+       private static int extractProxyPort(String proxy) {
+               return Integer.valueOf(proxy.split(":")[1]);
        }
 
        //
@@ -62,9 +72,12 @@ public class PirateBayWatcher extends DefaultWatcher {
         *            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;
@@ -77,7 +90,7 @@ public class PirateBayWatcher extends DefaultWatcher {
         * @return The filters of the watcher
         */
        private static List<Filter> createFilters() {
-               return ImmutableList.of(new HtmlFilter(), new PirateBayFilter(), createDefaultBlacklistFilter());
+               return ImmutableList.of(new HtmlFilter(), new PirateBayFilter(), createDefaultBlacklistFilter(), new SizeBlacklistFilter());
        }
 
        /**