@Override public synchronized void setParameters() { Common.downloadFile(webSite, SetUp.getTempDirectory(), indexName, false, ""); Common.newEncodeFile(SetUp.getTempDirectory(), indexName, indexEncodeName, Encoding.GBK); String tempStr = Common.getFileString(SetUp.getTempDirectory(), indexEncodeName); String[] lines = tempStr.split("\n"); for (int i = 0; i < lines.length; i++) { String line = Common.getTraditionalChinese(lines[i]); // ".": contain all characters except "\r" and "\n" // "(?s).": contain all characters if (line.matches("(?s).*title(?s).*")) { // get title ex.<title>尸錄 4話</title> String[] temp = line.split("<|>"); if (getWholeTitle() == null || getWholeTitle().equals("")) setWholeTitle(Common.getStringRemovedIllegalChar(temp[2])); } else if (line.matches("(?s).*page(?s).*")) { // get total page ex. | 共34頁 | int beginIndex = line.indexOf(Common.getStringUsingDefaultLanguage("共", "共")); int endIndex = line.indexOf(Common.getStringUsingDefaultLanguage("頁", "頁")); String temp = line.substring(beginIndex + 1, endIndex); totalPage = Integer.parseInt(temp); break; } } comicURL = new String[totalPage]; // totalPage = amount of comic pic SetUp.setWholeTitle(wholeTitle); }
@Override public String getAllPageString(String urlString) { String indexName = Common.getStoredFileName(SetUp.getTempDirectory(), "index_xindm_", "html"); String indexEncodeName = Common.getStoredFileName(SetUp.getTempDirectory(), "index_xindm_encode_", "html"); Common.downloadFile(urlString, SetUp.getTempDirectory(), indexName, false, ""); Common.newEncodeFile(SetUp.getTempDirectory(), indexName, indexEncodeName); return Common.getFileString(SetUp.getTempDirectory(), indexEncodeName); }
@Override public void parseComicURL() { // parse URL and save all URLs in comicURL // // 先取得前面的下載伺服器網址 String allPageString = Common.getFileString(SetUp.getTempDirectory(), indexName); Common.debugPrint("開始解析這一集有幾頁 : "); int beginIndex = 0, endIndex = 0; totalPage = allPageString.split("<option ").length; Common.debugPrintln("共 " + totalPage + " 頁"); comicURL = new String[totalPage]; String picURL = ""; int p = 0; // 目前頁數 for (int i = 0; i < totalPage && Run.isAlive; i++) { beginIndex = allPageString.indexOf("<img id"); beginIndex = allPageString.indexOf("\"", beginIndex) + 1; endIndex = allPageString.indexOf("\"", beginIndex); String tempURL = allPageString.substring(beginIndex, endIndex); if (Common.isLegalURL(tempURL)) { comicURL[p++] = tempURL; Common.debugPrintln(p + " " + comicURL[p - 1]); // debug // 每解析一個網址就下載一張圖 singlePageDownload(getTitle(), getWholeTitle(), comicURL[p - 1], totalPage, p, 0); } else { totalPage--; } // Common.downloadFile( comicURL[p - 1], "", p + ".jpg", false, "" ); if (p < totalPage) { beginIndex = allPageString.indexOf("</select>"); beginIndex = allPageString.indexOf("\"", beginIndex) + 1; endIndex = allPageString.indexOf("\"", beginIndex); tempURL = allPageString.substring(beginIndex, endIndex); if ("#".equals(tempURL)) { Common.debugPrintln("THE LAST PAGE !!"); break; } String nextPageURL = "http://comic101.com" + tempURL; Common.downloadFile(nextPageURL, SetUp.getTempDirectory(), indexName, false, ""); allPageString = Common.getFileString(SetUp.getTempDirectory(), indexName); } } // System.exit( 0 ); // debug }
@Override public synchronized void parseComicURL() { System.out.print("parse the pic URL:"); for (int i = 0; i < totalPage && Run.isAlive; i++) { // 檢查下一張圖是否存在同個資料夾,若存在就跳下一張 if (!Common.existPicFile(getDownloadDirectory(), i + 2) || !Common.existPicFile(getDownloadDirectory(), i + 1)) { int endIndex = webSite.lastIndexOf("/"); String tempWebSite = webSite.substring(0, endIndex + 1) + (i + 1) + ".htm"; Common.downloadFile(tempWebSite, SetUp.getTempDirectory(), indexName, false, ""); Common.newEncodeFile(SetUp.getTempDirectory(), indexName, indexEncodeName, Encoding.GBK); String tempStr = Common.getFileString(SetUp.getTempDirectory(), indexEncodeName); String[] lines = tempStr.split("\n"); for (int count = 0; count < lines.length && Run.isAlive; count++) { String line = lines[count]; if (line.matches("(?s).*document.write(?s).*")) { String[] temp = line.split("'\"|\"|'|>"); System.out.println(baseURL + temp[3]); // replace %20 from white space in URL String frontURL = temp[3].replaceAll("\\s", "%20"); comicURL[i] = Common.getFixedChineseURL(baseURL + frontURL); // Common.debugPrintln( i + " " + comicURL[i] ); // debug // 每解析一個網址就下載一張圖 singlePageDownload(getTitle(), getWholeTitle(), comicURL[i], totalPage, i + 1, 0); break; } } } } // System.exit( 0 ); // debug }
@Override public void setParameters() { Common.debugPrintln("開始解析各參數 :"); Common.downloadFile(webSite, SetUp.getTempDirectory(), indexName, false, ""); if (getWholeTitle() == null || getWholeTitle().equals("")) { Common.debugPrintln("開始解析title和wholeTitle :"); String allPageString = Common.getFileString(SetUp.getTempDirectory(), indexEncodeName); int beginIndex = allPageString.indexOf("alt="); beginIndex = allPageString.indexOf("\"", beginIndex) + 1; int endIndex = allPageString.indexOf("\"", beginIndex); String tempTitleString = allPageString.substring(beginIndex, endIndex).trim(); setWholeTitle( getVolumeWithFormatNumber( Common.getStringRemovedIllegalChar( Common.getTraditionalChinese(tempTitleString.trim())))); } Common.debugPrintln("作品名稱(title) : " + getTitle()); Common.debugPrintln("章節名稱(wholeTitle) : " + getWholeTitle()); }