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