public ArrayList<String> parseXML() throws Exception { ArrayList<String> ret = new ArrayList<String>(); handshake(); URL url = new URL( "http://mangaonweb.com/page.do?cdn=" + cdn + "&cpn=book.xml&crcod=" + crcod + "&rid=" + (int) (Math.random() * 10000)); String page = DownloaderUtils.getPage(url.toString(), "UTF-8", cookies); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(page)); Document d = builder.parse(is); Element doc = d.getDocumentElement(); NodeList pages = doc.getElementsByTagName("page"); total = pages.getLength(); for (int i = 0; i < pages.getLength(); i++) { Element e = (Element) pages.item(i); ret.add(e.getAttribute("path")); } return (ret); }
public boolean download(DownloadListener dl) throws Exception { // 1) get crcod, cdn, and cookies handshake(); // 2) get XML ArrayList<String> paths = parseXML(); dl.setTotal(getTotal()); // 3) get pages byte[] key = { 99, 49, 51, 53, 100, 54, 56, 56, 57, 57, 99, 56, 50, 54, 99, 101, 100, 55, 99, 52, 57, 98, 99, 55, 54, 97, 97, 57, 52, 56, 57, 48 }; BlowFishKey bfkey = new BlowFishKey(key); for (int i = 0; i < paths.size(); i++) { if (dl.isDownloadAborted()) return (true); // rid is just a random number from 0-9999 URL url = new URL( "http://mangaonweb.com/page.do?cdn=" + cdn + "&cpn=" + paths.get(i) + "&crcod=" + crcod + "&rid=" + (int) (Math.random() * 10000)); byte[] encrypted = downloadByteArray(url); bfkey.decrypt(encrypted, 0); RandomAccessFile output = new RandomAccessFile(dl.downloadPath(this, i), "rw"); output.write(encrypted); output.close(); dl.downloadIncrement(this); } dl.downloadFinished(this); return (true); }