- public State filter(State state) {
- if (!state.success()) {
- return FailedState.from(state);
- }
- checkState(state instanceof HtmlState, "state is not an HtmlState but a %s", state.getClass().getName());
-
- /* get result table. */
- Document document = ((HtmlState) state).document();
- Elements mainTable = document.select("table.data");
- if (mainTable.isEmpty()) {
- /* no main table? */
- return new FailedState();
- }
-
- /* iterate over all rows. */
- TorrentState torrentState = new TorrentState();
- Elements dataRows = mainTable.select("tr:gt(0)");
- for (Element dataRow : dataRows) {
- String name = extractName(dataRow);
- 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, fileCount, seedCount, leechCount);
- torrentState.addTorrentFile(torrentFile);
- } catch (URISyntaxException use1) {
- /* ignore; if uri was wrong, we wouldn’t be here. */
- }
- }
-
- return torrentState;