Use base class for kat.ph torrent site filter.
[rhynodge.git] / src / main / java / net / pterodactylus / reactor / filters / KickAssTorrentsFilter.java
1 /*
2  * Reactor - KickAssTorrentsFilter.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 net.pterodactylus.reactor.Filter;
21 import net.pterodactylus.reactor.queries.HttpQuery;
22 import net.pterodactylus.reactor.states.HtmlState;
23 import net.pterodactylus.reactor.states.TorrentState;
24
25 import org.jsoup.nodes.Document;
26 import org.jsoup.nodes.Element;
27 import org.jsoup.select.Elements;
28
29 /**
30  * {@link Filter} implementation that parses a {@link TorrentState} from an
31  * {@link HtmlState} which was generated by a {@link HttpQuery} to
32  * {@code kickasstorrents.ph}.
33  *
34  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
35  */
36 public class KickAssTorrentsFilter extends TorrentSiteFilter {
37
38         //
39         // TORRENTSITEFILTER METHODS
40         //
41
42         /**
43          * {@inheritDoc}
44          */
45         @Override
46         protected Elements getDataRows(Document document) {
47                 return document.select("table.data").select("tr:gt(0)");
48         }
49
50         /**
51          * {@inheritDoc}
52          */
53         @Override
54         protected String extractName(Element dataRow) {
55                 return dataRow.select("div.torrentname a.normalgrey").text();
56         }
57
58         /**
59          * {@inheritDoc}
60          */
61         @Override
62         protected String extractSize(Element dataRow) {
63                 return dataRow.select("td:eq(1)").text();
64         }
65
66         /**
67          * {@inheritDoc}
68          */
69         @Override
70         protected String extractMagnetUri(Element dataRow) {
71                 return dataRow.select("a.imagnet").attr("href");
72         }
73
74         /**
75          * {@inheritDoc}
76          */
77         @Override
78         protected String extractDownloadUri(Element dataRow) {
79                 return dataRow.select("a.idownload:not(.partner1Button)").attr("href");
80         }
81
82         /**
83          * {@inheritDoc}
84          */
85         @Override
86         protected int extractFileCount(Element dataRow) {
87                 return Integer.valueOf(dataRow.select("td:eq(2)").text());
88         }
89
90         /**
91          * {@inheritDoc}
92          */
93         @Override
94         protected int extractSeedCount(Element dataRow) {
95                 return Integer.valueOf(dataRow.select("td:eq(4)").text());
96         }
97
98         /**
99          * {@inheritDoc}
100          */
101         @Override
102         protected int extractLeechCount(Element dataRow) {
103                 return Integer.valueOf(dataRow.select("td:eq(5)").text());
104         }
105
106 }