* 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.thirdparty.plugins.irc.tvtome; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; 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.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.lang.Character; import net.sf.drftpd.util.ReplacerUtils; import org.apache.log4j.Logger; import org.drftpd.plugins.SiteBot; import org.tanesha.replacer.ReplacerEnvironment; /** * @author MOZ */ public class tveps { private static final Logger logger = Logger.getLogger(TVTomeParser.class); private String[] _seperators = {".", "-", "_", "[", "]"}; private static final String _url = "http://www.tvtome.com"; private boolean _foundTVeps; private String _eps; private String _title; public boolean foundFilm() { return _foundTVeps; } } url = new URL(_url); urlConn = url.openConnection(); if (!(urlConn.getContent() instanceof InputStream)) return false; try { in = new BufferedReader(new InputStreamReader(urlConn .getInputStream())); while ((line = in.readLine()) != null) data = data + line + "\n"; } finally { in.close(); } //Still need to edit this _title = parseData(data, "

", ""); _eps = parseData(data, "Genre:", "

"); } public ReplacerEnvironment getEnv() { ReplacerEnvironment env = new ReplacerEnvironment(SiteBot.GLOBAL_ENV); env.add("title", getTitle()); env.add("eps", getEps()); return env; } private String parseData(String data, String startText, String endText) { int start, end; start = data.indexOf(startText); if (start > 0) { start = start + startText.length(); end = data.indexOf(endText, start); return htmlToString(data.substring(start, end)).trim(); } return "N/A"; } private String htmlToString(String input) { String str = input.replaceAll("\n",""); while(str.indexOf("<")!=-1) { int startPos = str.indexOf("<"); int endPos = str.indexOf(">",startPos); if (endPos>startPos) { String beforeTag = str.substring(0,startPos); String afterTag = str.substring(endPos+1); str = beforeTag + afterTag; } } String mbChar; String mbs = "&#(\\d+);"; StringBuffer sb = new StringBuffer(); Pattern pat = Pattern.compile(mbs); Matcher mat = pat.matcher(str); while (mat.find()){ mbChar = getMbCharStr(mat.group(1)); mat.appendReplacement(sb, mbChar); } mat.appendTail(sb); return new String(sb); } private String getMbCharStr(String digits) { char[] cha = new char[1]; try{ int val = Integer.parseInt(digits); char ch = (char)val; cha[0] = ch; } catch(Exception e){ System.err.println("Error from getMbCharStr:"); e.printStackTrace(System.err); } return new String(cha); } }