From 96c6a320ec7e97a3330a629628b7d8c4560cf9ab Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 3 Jan 2013 19:55:02 +0100 Subject: [PATCH] Extract file count, seed count, and leech count. --- .../reactor/filters/KickAssTorrentsFilter.java | 38 ++++++++++++++++- .../pterodactylus/reactor/states/TorrentState.java | 47 +++++++++++++++++++++- 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/reactor/filters/KickAssTorrentsFilter.java b/src/main/java/net/pterodactylus/reactor/filters/KickAssTorrentsFilter.java index 02a356a..9241ce7 100644 --- a/src/main/java/net/pterodactylus/reactor/filters/KickAssTorrentsFilter.java +++ b/src/main/java/net/pterodactylus/reactor/filters/KickAssTorrentsFilter.java @@ -69,9 +69,12 @@ public class KickAssTorrentsFilter implements Filter { String size = extractSize(dataRow); String magnetUri = extractMagnetUri(dataRow); String downloadUri; + int fileCount = extractFileCount(dataRow); + int seedCount = extractSeedCount(dataRow); + int leechCount = extractLeechCount(dataRow); try { downloadUri = new URI(((HtmlState) state).uri()).resolve(extractDownloadUri(dataRow)).toString(); - TorrentFile torrentFile = new TorrentFile(name, size, magnetUri, downloadUri); + TorrentFile torrentFile = new TorrentFile(name, size, magnetUri, downloadUri, fileCount, seedCount, leechCount); torrentState.addTorrentFile(torrentFile); } catch (URISyntaxException use1) { /* ignore; if uri was wrong, we wouldn’t be here. */ @@ -129,4 +132,37 @@ public class KickAssTorrentsFilter implements Filter { return dataRow.select("a.idownload:not(.partner1Button)").attr("href"); } + /** + * Extracts the file count from the given row. + * + * @param dataRow + * The row to extract the file count from + * @return The extracted file count + */ + private static int extractFileCount(Element dataRow) { + return Integer.valueOf(dataRow.select("td:eq(2)").text()); + } + + /** + * Extracts the seed count from the given row. + * + * @param dataRow + * The row to extract the seed count from + * @return The extracted seed count + */ + private static int extractSeedCount(Element dataRow) { + return Integer.valueOf(dataRow.select("td:eq(4)").text()); + } + + /** + * Extracts the leech count from the given row. + * + * @param dataRow + * The row to extract the leech count from + * @return The extracted leech count + */ + private static int extractLeechCount(Element dataRow) { + return Integer.valueOf(dataRow.select("td:eq(5)").text()); + } + } diff --git a/src/main/java/net/pterodactylus/reactor/states/TorrentState.java b/src/main/java/net/pterodactylus/reactor/states/TorrentState.java index 0855195..9e9659d 100644 --- a/src/main/java/net/pterodactylus/reactor/states/TorrentState.java +++ b/src/main/java/net/pterodactylus/reactor/states/TorrentState.java @@ -99,6 +99,15 @@ public class TorrentState extends AbstractState implements Iterable /** The download URI of the file. */ private final String downloadUri; + /** The number of files in this torrent. */ + private final int fileCount; + + /** The number of seeds connected to this torrent. */ + private final int seedCount; + + /** The number of leechers connected to this torrent. */ + private final int leechCount; + /** * Creates a new torrent file. * @@ -110,12 +119,21 @@ public class TorrentState extends AbstractState implements Iterable * The magnet URI of the file * @param downloadUri * The download URI of the file + * @param fileCount + * The number of files + * @param seedCount + * The number of connected seeds + * @param leechCount + * The number of connected leechers */ - public TorrentFile(String name, String size, String magnetUri, String downloadUri) { + public TorrentFile(String name, String size, String magnetUri, String downloadUri, int fileCount, int seedCount, int leechCount) { this.name = name; this.size = size; this.magnetUri = magnetUri; this.downloadUri = downloadUri; + this.fileCount = fileCount; + this.seedCount = seedCount; + this.leechCount = leechCount; } // @@ -159,6 +177,33 @@ public class TorrentState extends AbstractState implements Iterable return downloadUri; } + /** + * Returns the number of files in this torrent. + * + * @return The number of files in this torrent + */ + public int fileCount() { + return fileCount; + } + + /** + * Returns the number of seeds connected to this torrent. + * + * @return The number of connected seeds + */ + public int seedCount() { + return seedCount; + } + + /** + * Returns the number of leechers connected to this torrent. + * + * @return The number of connected leechers + */ + public int leechCount() { + return leechCount; + } + // // PRIVATE METHODS // -- 2.7.4