From e6467dab58ebfad5bed47e0882c6a0e65e6b47a7 Mon Sep 17 00:00:00 2001 From: Andyfoo Date: Thu, 18 Jul 2019 10:08:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=AD=97=E5=B9=95=E5=BA=93?= =?UTF-8?q?=E6=8A=93=E5=8F=96=E9=99=90=E5=88=B6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- src/main/java/zimu/AppConfig.java | 2 +- .../java/zimu/common/sites/ZIMuKuCommon.java | 38 +++++++++++++++---- src/main/java/zimu/tests/Test2.java | 24 ++++++++++++ src/main/java/zimu/util/ExeJsUtil.java | 28 ++++++++++++++ 5 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 src/main/java/zimu/tests/Test2.java create mode 100644 src/main/java/zimu/util/ExeJsUtil.java diff --git a/pom.xml b/pom.xml index 6d462c2..e02c049 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ SubTitleSearcher SubTitleSearcher - 2.0.3.0 + 2.0.4.0 UTF-8 Copyright 2019 pslib.com diff --git a/src/main/java/zimu/AppConfig.java b/src/main/java/zimu/AppConfig.java index b1e13fc..0ef4ffc 100644 --- a/src/main/java/zimu/AppConfig.java +++ b/src/main/java/zimu/AppConfig.java @@ -7,7 +7,7 @@ public class AppConfig { public static String appName = "SubTitleSearcher"; public static String appTitle = "字幕下载"; //public static String appTitle = "SubTitleSearcher"; - public static String appVer = "2.0.3"; + public static String appVer = "2.0.4"; public static String appPath; public static boolean isExe; diff --git a/src/main/java/zimu/common/sites/ZIMuKuCommon.java b/src/main/java/zimu/common/sites/ZIMuKuCommon.java index a756dd5..ac9853a 100644 --- a/src/main/java/zimu/common/sites/ZIMuKuCommon.java +++ b/src/main/java/zimu/common/sites/ZIMuKuCommon.java @@ -9,12 +9,14 @@ import cn.hutool.core.codec.Base64; import cn.hutool.core.util.CharsetUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.URLUtil; import cn.hutool.http.HttpResponse; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.log.Log; import cn.hutool.log.LogFactory; +import zimu.util.ExeJsUtil; import zimu.util.HtHttpUtil; import zimu.util.StringUtil; import zimu.util.regex.RegexUtil; @@ -33,9 +35,9 @@ public class ZIMuKuCommon { public static void main(String[] args) throws Exception { //System.out.println(DownList("憨豆特工.mkv")); - System.out.println(DownList("downsizing.2017.720p.bluray.x264-geckos.mkv")); - - + //System.out.println(DownList("downsizing.2017.720p.bluray.x264-geckos.mkv")); + System.out.println(DownList("From.Beijing.with.Love.1994.720p.BluRay.x264-WiKi.mkv")); + //System.out.println(getPageList("From.Beijing.with.Love")); //System.out.println(downContent("/detail/101779.html"));; //detail/100250.html @@ -67,13 +69,13 @@ public static JSONArray DownList(String fileName) throws Exception { * @return */ public static JSONObject downContent(String url) { - String result = HtHttpUtil.http.get(baseUrl+url); + String result = httpGet(baseUrl+url); String downUrl = RegexUtil.getMatchStr(result, "(.*?)

", Pattern.DOTALL); @@ -200,4 +202,26 @@ public static JSONArray getPageList(String title) { return resList; } + + public static String httpGet(String url) { + String result = HtHttpUtil.http.get(url); + if(result!=null && StrUtil.count(result, "url")>10 && result.contains("]*>(.*?)"); + jsStr = jsStr.replaceAll("window.location[\\s]*=[\\s]*url", ""); + jsStr = jsStr.replaceAll("location[\\s]*=[\\s]*url", ""); + if(jsStr==null) { + jsStr = ""; + } + String jsVal = null; + try { + jsVal = ExeJsUtil.getJsVal("function getUrl(){"+jsStr+";return url;} getUrl()"); + }catch(Exception e) { + logger.error(e); + } + if(jsVal!=null&&jsVal.length()>0) { + return httpGet(jsVal.contains("://") ? jsVal : baseUrl+jsVal); + } + } + return result; + } } diff --git a/src/main/java/zimu/tests/Test2.java b/src/main/java/zimu/tests/Test2.java new file mode 100644 index 0000000..cfbbdbc --- /dev/null +++ b/src/main/java/zimu/tests/Test2.java @@ -0,0 +1,24 @@ +package zimu.tests; + +import javax.script.Compilable; +import javax.script.CompiledScript; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; + +public class Test2 { + + public static void main(String[] args) { + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine engine = manager.getEngineByName("JavaScript"); + try { + String script = "function getUrl(){var url='adsf';return url;} getUrl()"; + Compilable compilable = (Compilable) engine; + CompiledScript JSFunction = compilable.compile(script); + Object result = JSFunction.eval(); + System.out.println(result); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/zimu/util/ExeJsUtil.java b/src/main/java/zimu/util/ExeJsUtil.java new file mode 100644 index 0000000..83560c1 --- /dev/null +++ b/src/main/java/zimu/util/ExeJsUtil.java @@ -0,0 +1,28 @@ +package zimu.util; + +import javax.script.Compilable; +import javax.script.CompiledScript; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; + +public class ExeJsUtil { + + /** + * 执行js并返回结果 + * @param jsStr + * @return + */ + public static String getJsVal(String jsStr) { + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine engine = manager.getEngineByName("JavaScript"); + try { + Compilable compilable = (Compilable) engine; + CompiledScript JSFunction = compilable.compile(jsStr); + Object result = JSFunction.eval(); + return result != null ? result.toString() : null; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } +}