From 2cfb47378cd3a35030c659e516825e90b36269d0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 24 Feb 2013 15:30:31 +0100 Subject: [PATCH] Move torrent-related filters to their own package. --- .../rhynodge/filters/KickAssTorrentsFilter.java | 106 -------------------- .../rhynodge/filters/PirateBayFilter.java | 98 ------------------- .../filters/torrents/KickAssTorrentsFilter.java | 107 +++++++++++++++++++++ .../rhynodge/filters/torrents/PirateBayFilter.java | 100 +++++++++++++++++++ .../watchers/KickAssTorrentsEpisodeWatcher.java | 2 +- .../rhynodge/watchers/KickAssTorrentsWatcher.java | 2 +- .../rhynodge/watchers/PirateBayEpisodeWatcher.java | 2 +- .../rhynodge/watchers/PirateBayWatcher.java | 2 +- .../resources/chains/kickasstorrents-example.json | 2 +- .../resources/chains/thepiratebay-example.json | 2 +- 10 files changed, 213 insertions(+), 210 deletions(-) delete mode 100644 src/main/java/net/pterodactylus/rhynodge/filters/KickAssTorrentsFilter.java delete mode 100644 src/main/java/net/pterodactylus/rhynodge/filters/PirateBayFilter.java create mode 100644 src/main/java/net/pterodactylus/rhynodge/filters/torrents/KickAssTorrentsFilter.java create mode 100644 src/main/java/net/pterodactylus/rhynodge/filters/torrents/PirateBayFilter.java diff --git a/src/main/java/net/pterodactylus/rhynodge/filters/KickAssTorrentsFilter.java b/src/main/java/net/pterodactylus/rhynodge/filters/KickAssTorrentsFilter.java deleted file mode 100644 index c368bf3..0000000 --- a/src/main/java/net/pterodactylus/rhynodge/filters/KickAssTorrentsFilter.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Rhynodge - KickAssTorrentsFilter.java - Copyright © 2013 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.rhynodge.filters; - -import net.pterodactylus.rhynodge.Filter; -import net.pterodactylus.rhynodge.queries.HttpQuery; -import net.pterodactylus.rhynodge.states.HtmlState; -import net.pterodactylus.rhynodge.states.TorrentState; - -import org.jsoup.nodes.Document; -import org.jsoup.nodes.Element; -import org.jsoup.select.Elements; - -/** - * {@link Filter} implementation that parses a {@link TorrentState} from an - * {@link HtmlState} which was generated by a {@link HttpQuery} to - * {@code kickasstorrents.ph}. - * - * @author David ‘Bombe’ Roden - */ -public class KickAssTorrentsFilter extends TorrentSiteFilter { - - // - // TORRENTSITEFILTER METHODS - // - - /** - * {@inheritDoc} - */ - @Override - protected Elements getDataRows(Document document) { - return document.select("table.data").select("tr:gt(0)"); - } - - /** - * {@inheritDoc} - */ - @Override - protected String extractName(Element dataRow) { - return dataRow.select("div.torrentname a.normalgrey").text(); - } - - /** - * {@inheritDoc} - */ - @Override - protected String extractSize(Element dataRow) { - return dataRow.select("td:eq(1)").text(); - } - - /** - * {@inheritDoc} - */ - @Override - protected String extractMagnetUri(Element dataRow) { - return dataRow.select("a.imagnet").attr("href"); - } - - /** - * {@inheritDoc} - */ - @Override - protected String extractDownloadUri(Element dataRow) { - return dataRow.select("a.idownload:not(.partner1Button)").attr("href"); - } - - /** - * {@inheritDoc} - */ - @Override - protected int extractFileCount(Element dataRow) { - return Integer.valueOf(dataRow.select("td:eq(2)").text()); - } - - /** - * {@inheritDoc} - */ - @Override - protected int extractSeedCount(Element dataRow) { - return Integer.valueOf(dataRow.select("td:eq(4)").text()); - } - - /** - * {@inheritDoc} - */ - @Override - protected int extractLeechCount(Element dataRow) { - return Integer.valueOf(dataRow.select("td:eq(5)").text()); - } - -} diff --git a/src/main/java/net/pterodactylus/rhynodge/filters/PirateBayFilter.java b/src/main/java/net/pterodactylus/rhynodge/filters/PirateBayFilter.java deleted file mode 100644 index a935261..0000000 --- a/src/main/java/net/pterodactylus/rhynodge/filters/PirateBayFilter.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Rhynodge - PirateBayFilter.java - Copyright © 2013 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.rhynodge.filters; - -import java.util.regex.Pattern; - -import org.jsoup.nodes.Document; -import org.jsoup.nodes.Element; -import org.jsoup.select.Elements; - -/** - * {@link TorrentSiteFilter} implementation that can parse - * {@code thepiratebay.se} result pages. - * - * @author David ‘Bombe’ Roden - */ -public class PirateBayFilter extends TorrentSiteFilter { - - /** - * {@inheritDoc} - */ - @Override - protected Elements getDataRows(Document document) { - return document.select("table#searchResult tbody tr:has(.vertTh)"); - } - - /** - * {@inheritDoc} - */ - @Override - protected String extractName(Element dataRow) { - return dataRow.select(".detName a").text(); - } - - /** - * {@inheritDoc} - */ - @Override - protected String extractSize(Element dataRow) { - return dataRow.select(".detDesc").text().split(Pattern.quote(","))[1].split(Pattern.quote("Size"))[1]; - } - - /** - * {@inheritDoc} - */ - @Override - protected String extractMagnetUri(Element dataRow) { - return dataRow.select("a[href^=magnet:]").attr("href"); - } - - /** - * {@inheritDoc} - */ - @Override - protected String extractDownloadUri(Element dataRow) { - return dataRow.select("a[href^=//torrents.]").attr("href"); - } - - /** - * {@inheritDoc} - */ - @Override - protected int extractFileCount(Element dataRow) { - return 0; - } - - /** - * {@inheritDoc} - */ - @Override - protected int extractSeedCount(Element dataRow) { - return Integer.valueOf(dataRow.select("td:eq(2)").text()); - } - - /** - * {@inheritDoc} - */ - @Override - protected int extractLeechCount(Element dataRow) { - return Integer.valueOf(dataRow.select("td:eq(3)").text()); - } - -} diff --git a/src/main/java/net/pterodactylus/rhynodge/filters/torrents/KickAssTorrentsFilter.java b/src/main/java/net/pterodactylus/rhynodge/filters/torrents/KickAssTorrentsFilter.java new file mode 100644 index 0000000..dd47bbf --- /dev/null +++ b/src/main/java/net/pterodactylus/rhynodge/filters/torrents/KickAssTorrentsFilter.java @@ -0,0 +1,107 @@ +/* + * Rhynodge - KickAssTorrentsFilter.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.rhynodge.filters.torrents; + +import net.pterodactylus.rhynodge.Filter; +import net.pterodactylus.rhynodge.filters.TorrentSiteFilter; +import net.pterodactylus.rhynodge.queries.HttpQuery; +import net.pterodactylus.rhynodge.states.HtmlState; +import net.pterodactylus.rhynodge.states.TorrentState; + +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +/** + * {@link Filter} implementation that parses a {@link TorrentState} from an + * {@link HtmlState} which was generated by a {@link HttpQuery} to + * {@code kickasstorrents.ph}. + * + * @author David ‘Bombe’ Roden + */ +public class KickAssTorrentsFilter extends TorrentSiteFilter { + + // + // TORRENTSITEFILTER METHODS + // + + /** + * {@inheritDoc} + */ + @Override + protected Elements getDataRows(Document document) { + return document.select("table.data").select("tr:gt(0)"); + } + + /** + * {@inheritDoc} + */ + @Override + protected String extractName(Element dataRow) { + return dataRow.select("div.torrentname a.normalgrey").text(); + } + + /** + * {@inheritDoc} + */ + @Override + protected String extractSize(Element dataRow) { + return dataRow.select("td:eq(1)").text(); + } + + /** + * {@inheritDoc} + */ + @Override + protected String extractMagnetUri(Element dataRow) { + return dataRow.select("a.imagnet").attr("href"); + } + + /** + * {@inheritDoc} + */ + @Override + protected String extractDownloadUri(Element dataRow) { + return dataRow.select("a.idownload:not(.partner1Button)").attr("href"); + } + + /** + * {@inheritDoc} + */ + @Override + protected int extractFileCount(Element dataRow) { + return Integer.valueOf(dataRow.select("td:eq(2)").text()); + } + + /** + * {@inheritDoc} + */ + @Override + protected int extractSeedCount(Element dataRow) { + return Integer.valueOf(dataRow.select("td:eq(4)").text()); + } + + /** + * {@inheritDoc} + */ + @Override + protected int extractLeechCount(Element dataRow) { + return Integer.valueOf(dataRow.select("td:eq(5)").text()); + } + +} diff --git a/src/main/java/net/pterodactylus/rhynodge/filters/torrents/PirateBayFilter.java b/src/main/java/net/pterodactylus/rhynodge/filters/torrents/PirateBayFilter.java new file mode 100644 index 0000000..06b1a9c --- /dev/null +++ b/src/main/java/net/pterodactylus/rhynodge/filters/torrents/PirateBayFilter.java @@ -0,0 +1,100 @@ +/* + * Rhynodge - PirateBayFilter.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.rhynodge.filters.torrents; + +import java.util.regex.Pattern; + +import net.pterodactylus.rhynodge.filters.TorrentSiteFilter; + +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +/** + * {@link net.pterodactylus.rhynodge.filters.TorrentSiteFilter} implementation that can parse + * {@code thepiratebay.se} result pages. + * + * @author David ‘Bombe’ Roden + */ +public class PirateBayFilter extends TorrentSiteFilter { + + /** + * {@inheritDoc} + */ + @Override + protected Elements getDataRows(Document document) { + return document.select("table#searchResult tbody tr:has(.vertTh)"); + } + + /** + * {@inheritDoc} + */ + @Override + protected String extractName(Element dataRow) { + return dataRow.select(".detName a").text(); + } + + /** + * {@inheritDoc} + */ + @Override + protected String extractSize(Element dataRow) { + return dataRow.select(".detDesc").text().split(Pattern.quote(","))[1].split(Pattern.quote("Size"))[1]; + } + + /** + * {@inheritDoc} + */ + @Override + protected String extractMagnetUri(Element dataRow) { + return dataRow.select("a[href^=magnet:]").attr("href"); + } + + /** + * {@inheritDoc} + */ + @Override + protected String extractDownloadUri(Element dataRow) { + return dataRow.select("a[href^=//torrents.]").attr("href"); + } + + /** + * {@inheritDoc} + */ + @Override + protected int extractFileCount(Element dataRow) { + return 0; + } + + /** + * {@inheritDoc} + */ + @Override + protected int extractSeedCount(Element dataRow) { + return Integer.valueOf(dataRow.select("td:eq(2)").text()); + } + + /** + * {@inheritDoc} + */ + @Override + protected int extractLeechCount(Element dataRow) { + return Integer.valueOf(dataRow.select("td:eq(3)").text()); + } + +} diff --git a/src/main/java/net/pterodactylus/rhynodge/watchers/KickAssTorrentsEpisodeWatcher.java b/src/main/java/net/pterodactylus/rhynodge/watchers/KickAssTorrentsEpisodeWatcher.java index fc65209..e8a8574 100644 --- a/src/main/java/net/pterodactylus/rhynodge/watchers/KickAssTorrentsEpisodeWatcher.java +++ b/src/main/java/net/pterodactylus/rhynodge/watchers/KickAssTorrentsEpisodeWatcher.java @@ -27,7 +27,7 @@ import net.pterodactylus.rhynodge.Trigger; import net.pterodactylus.rhynodge.Watcher; import net.pterodactylus.rhynodge.filters.EpisodeFilter; import net.pterodactylus.rhynodge.filters.HtmlFilter; -import net.pterodactylus.rhynodge.filters.KickAssTorrentsFilter; +import net.pterodactylus.rhynodge.filters.torrents.KickAssTorrentsFilter; import net.pterodactylus.rhynodge.queries.HttpQuery; import net.pterodactylus.rhynodge.triggers.NewEpisodeTrigger; diff --git a/src/main/java/net/pterodactylus/rhynodge/watchers/KickAssTorrentsWatcher.java b/src/main/java/net/pterodactylus/rhynodge/watchers/KickAssTorrentsWatcher.java index 9c68cdb..631bd2e 100644 --- a/src/main/java/net/pterodactylus/rhynodge/watchers/KickAssTorrentsWatcher.java +++ b/src/main/java/net/pterodactylus/rhynodge/watchers/KickAssTorrentsWatcher.java @@ -26,7 +26,7 @@ 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.KickAssTorrentsFilter; +import net.pterodactylus.rhynodge.filters.torrents.KickAssTorrentsFilter; import net.pterodactylus.rhynodge.queries.HttpQuery; import net.pterodactylus.rhynodge.triggers.NewTorrentTrigger; diff --git a/src/main/java/net/pterodactylus/rhynodge/watchers/PirateBayEpisodeWatcher.java b/src/main/java/net/pterodactylus/rhynodge/watchers/PirateBayEpisodeWatcher.java index 753a4ad..30bd376 100644 --- a/src/main/java/net/pterodactylus/rhynodge/watchers/PirateBayEpisodeWatcher.java +++ b/src/main/java/net/pterodactylus/rhynodge/watchers/PirateBayEpisodeWatcher.java @@ -26,7 +26,7 @@ import net.pterodactylus.rhynodge.Query; import net.pterodactylus.rhynodge.Trigger; import net.pterodactylus.rhynodge.filters.EpisodeFilter; import net.pterodactylus.rhynodge.filters.HtmlFilter; -import net.pterodactylus.rhynodge.filters.PirateBayFilter; +import net.pterodactylus.rhynodge.filters.torrents.PirateBayFilter; import net.pterodactylus.rhynodge.queries.HttpQuery; import net.pterodactylus.rhynodge.triggers.NewEpisodeTrigger; diff --git a/src/main/java/net/pterodactylus/rhynodge/watchers/PirateBayWatcher.java b/src/main/java/net/pterodactylus/rhynodge/watchers/PirateBayWatcher.java index ef6f743..9a77393 100644 --- a/src/main/java/net/pterodactylus/rhynodge/watchers/PirateBayWatcher.java +++ b/src/main/java/net/pterodactylus/rhynodge/watchers/PirateBayWatcher.java @@ -25,7 +25,7 @@ import net.pterodactylus.rhynodge.Filter; import net.pterodactylus.rhynodge.Query; import net.pterodactylus.rhynodge.Trigger; import net.pterodactylus.rhynodge.filters.HtmlFilter; -import net.pterodactylus.rhynodge.filters.PirateBayFilter; +import net.pterodactylus.rhynodge.filters.torrents.PirateBayFilter; import net.pterodactylus.rhynodge.queries.HttpQuery; import net.pterodactylus.rhynodge.triggers.NewTorrentTrigger; diff --git a/src/main/resources/chains/kickasstorrents-example.json b/src/main/resources/chains/kickasstorrents-example.json index 2962ea2..32bc1a2 100644 --- a/src/main/resources/chains/kickasstorrents-example.json +++ b/src/main/resources/chains/kickasstorrents-example.json @@ -18,7 +18,7 @@ "class": "HtmlFilter" }, { - "class": "KickAssTorrentsFilter" + "class": "torrents.KickAssTorrentsFilter" }, { "class": "EpisodeFilter" diff --git a/src/main/resources/chains/thepiratebay-example.json b/src/main/resources/chains/thepiratebay-example.json index ad79213..09e07e1 100644 --- a/src/main/resources/chains/thepiratebay-example.json +++ b/src/main/resources/chains/thepiratebay-example.json @@ -18,7 +18,7 @@ "class": "HtmlFilter" }, { - "class": "PirateBayFilter" + "class": "torrents.PirateBayFilter" } ], -- 2.7.4