* This file is part of DrFTPD, Distributed FTP Daemon. * * DrFTPD 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 2 of the License, or * (at your option) any later version. * * DrFTPD 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 DrFTPD; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package net.drmods.plugins.irc.imdb; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.log4j.Logger; import org.drftpd.plugins.SiteBot; import org.tanesha.replacer.ReplacerEnvironment; /** * @author Teflon */ public class IMDBParser { private static final Logger logger = Logger.getLogger(IMDBParser.class); private String[] _seperators = {".", "-", "_", "[", "]"}; private String[] _filters; private static final String _baseUrl = "http://www.imdb.com"; private static final String _searchUrl = "http://www.imdb.com/find?tt=on;nm=on;mx=5;q="; private boolean _foundFilm; private String _title; private String _genre; private String _plot; private String _votes; private String _rating; private String _year; private String _url; private String _comments; private String _language; private String _runtime; private String _country; private String _limited; public IMDBParser(String searchStr, String filters) { _filters = filters.split(";"); _foundFilm = getInfo(searchStr); } public String getGenre() { return foundFilm() ? _genre : "N/A"; } public String getPlot() { return foundFilm() ? _plot : "N/A"; } public String getRating() { return foundFilm() ? _rating : "N/A"; } public String getTitle() { return foundFilm() ? _title : "N/A"; } public String getVotes() { return foundFilm() ? _votes : "N/A"; } public String getYear() { return foundFilm() ? _year : "N/A"; } public String getURL() { return foundFilm() ? _url : "N/A"; } public String getComments() { return foundFilm() ? _comments : "N/A"; } public String getLanguage() { return foundFilm() ? _language : "N/A"; } public String getRuntime() { return foundFilm() ? _runtime : "N/A"; } public String getCountry() { return foundFilm() ? _country : "N/A"; } public String getLimited() { return foundFilm() ? _limited : "N/A"; } public boolean foundFilm() { return _foundFilm; } private boolean getInfo(String searchString) { try { String urlString = _searchUrl + filterTitle(searchString); URL url = new URL(urlString); URLConnection urlConn = url.openConnection(); if (!(urlConn.getContent() instanceof InputStream)) return false; boolean redirect = false; String data = ""; BufferedReader in = null; String line; try { in = new BufferedReader(new InputStreamReader(urlConn .getInputStream())); while ((line = in.readLine()) != null) { data += line + "\n"; } } finally { in.close(); } if (data.indexOf("No Matches.") > 0) return false; if (data.indexOf("