Add Pirate Bay torrent site filter.
[rhynodge.git] / src / main / java / net / pterodactylus / reactor / filters / PirateBayFilter.java
1 /*
2  * Reactor - PirateBayFilter.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.reactor.filters;
19
20 import java.util.regex.Pattern;
21
22 import org.jsoup.nodes.Document;
23 import org.jsoup.nodes.Element;
24 import org.jsoup.select.Elements;
25
26 /**
27  * {@link TorrentSiteFilter} implementation that can parse
28  * {@code thepiratebay.se} result pages.
29  *
30  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
31  */
32 public class PirateBayFilter extends TorrentSiteFilter {
33
34         /**
35          * {@inheritDoc}
36          */
37         @Override
38         protected Elements getDataRows(Document document) {
39                 return document.select("table#searchResult tbody tr:has(.vertTh)");
40         }
41
42         /**
43          * {@inheritDoc}
44          */
45         @Override
46         protected String extractName(Element dataRow) {
47                 return dataRow.select(".detName a").text();
48         }
49
50         /**
51          * {@inheritDoc}
52          */
53         @Override
54         protected String extractSize(Element dataRow) {
55                 return dataRow.select(".detDesc").text().split(Pattern.quote(","))[1].trim();
56         }
57
58         /**
59          * {@inheritDoc}
60          */
61         @Override
62         protected String extractMagnetUri(Element dataRow) {
63                 return dataRow.select("a[href^=magnet:]").attr("href");
64         }
65
66         /**
67          * {@inheritDoc}
68          */
69         @Override
70         protected String extractDownloadUri(Element dataRow) {
71                 return dataRow.select("a[href^=//torrents.]").attr("href");
72         }
73
74         /**
75          * {@inheritDoc}
76          */
77         @Override
78         protected int extractFileCount(Element dataRow) {
79                 return 0;
80         }
81
82         /**
83          * {@inheritDoc}
84          */
85         @Override
86         protected int extractSeedCount(Element dataRow) {
87                 return Integer.valueOf(dataRow.select("td:eq(2)").text());
88         }
89
90         /**
91          * {@inheritDoc}
92          */
93         @Override
94         protected int extractLeechCount(Element dataRow) {
95                 return Integer.valueOf(dataRow.select("td:eq(3)").text());
96         }
97
98 }