2 * rhynodge - LeastICouldDoWatcher.java - Copyright © 2013 David Roden
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.
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.
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/>.
18 package net.pterodactylus.rhynodge.watchers;
20 import java.util.List;
22 import net.pterodactylus.rhynodge.Filter;
23 import net.pterodactylus.rhynodge.Watcher;
24 import net.pterodactylus.rhynodge.filters.ExtractUrlFilter;
25 import net.pterodactylus.rhynodge.filters.HtmlFilter;
26 import net.pterodactylus.rhynodge.filters.HttpQueryFilter;
27 import net.pterodactylus.rhynodge.filters.comics.LeastICouldDoComicFilter;
28 import net.pterodactylus.rhynodge.queries.HttpQuery;
29 import net.pterodactylus.rhynodge.triggers.NewComicTrigger;
31 import com.google.common.base.Optional;
32 import com.google.common.collect.ImmutableList;
33 import org.jsoup.nodes.Document;
34 import org.jsoup.select.Elements;
37 * {@link Watcher} implementation that watched “Least I Could Do” for new
40 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
42 public class LeastICouldDoWatcher extends DefaultWatcher {
44 /** Creates a new “Least I Could Do” watcher. */
45 public LeastICouldDoWatcher() {
46 super(new HttpQuery("http://www.leasticoulddo.com/"), createFilters(), new NewComicTrigger());
54 * Creates the filters to parse LICD. Because LICD does not show the comic on
55 * the front page, and there’s no fixed URL for the latest comic, LICD requires
56 * a two-step process: first get the main page, parse the URL of the comic page
57 * from it, then get the comic page and parse the comic from that.
59 * @return The filters to parse LICD
61 private static List<Filter> createFilters() {
62 ImmutableList.Builder<Filter> filters = ImmutableList.builder();
64 filters.add(new HtmlFilter());
65 filters.add(new ExtractUrlFilter() {
68 protected Optional<String> extractUrl(Document document) {
69 Elements linkTag = document.select("a#feature-comic");
70 return linkTag.hasAttr("href") ? Optional.of(linkTag.attr("href")) : Optional.<String>absent();
73 filters.add(new HttpQueryFilter());
74 filters.add(new HtmlFilter());
75 filters.add(new LeastICouldDoComicFilter());
77 return filters.build();