diff --git a/pom.xml b/pom.xml
index 62c8f68..6d462c2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
SubTitleSearcher
SubTitleSearcher
- 2.0.2.0
+ 2.0.3.0
UTF-8
Copyright 2019 pslib.com
diff --git a/src/main/java/zimu/AppConfig.java b/src/main/java/zimu/AppConfig.java
index 92ccdb2..b1e13fc 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.2";
+ public static String appVer = "2.0.3";
public static String appPath;
public static boolean isExe;
diff --git a/src/main/java/zimu/gui/ExtractDialog.java b/src/main/java/zimu/gui/ExtractDialog.java
index 1e90c49..f998ff6 100644
--- a/src/main/java/zimu/gui/ExtractDialog.java
+++ b/src/main/java/zimu/gui/ExtractDialog.java
@@ -29,9 +29,9 @@
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
-import netscape.javascript.JSObject;
import zimu.AppConfig;
import zimu.gui.parms.DownParm;
+import zimu.server.ServerMain;
import zimu.util.MyFileUtil;
import zimu.util.StringUtil;
import zimu.util.WinRarUtil;
@@ -40,19 +40,21 @@ public class ExtractDialog extends JDialog {
private static final long serialVersionUID = 1L;
static final Log logger = LogFactory.get();
+
+ public static ExtractDialog extractDialog = null;
- String title;
+ public String title;
private JFXPanel bsPanel = new JFXPanel();
WebView webview;
Scene webviewScene;
- byte[] archiveData;
- String archiveExt;
- String subFilename;
+ public byte[] archiveData;
+ public String archiveExt;
+ public String subFilename;
String archivePath;
- List archiveFiles;
+ public List archiveFiles;
DownParm downParm;
int zimuIndex;
@@ -70,8 +72,9 @@ public ExtractDialog(Frame parent, int index, DownParm downParm, String title, S
this.archiveExt = ext;
this.subFilename = filename;
- initData();
+
initComponents();
+ extractDialog = this;
}
@Override
@@ -92,7 +95,19 @@ protected void escapeKeyProc() {
clear();
setVisible(false);
}
+ private void jsAlert(String message) {
+ JOptionPane.showMessageDialog(this, message);
+ }
+ private boolean jsConfirm(String message) {
+ int r = JOptionPane.showConfirmDialog(this, message, "提示信息", JOptionPane.YES_NO_OPTION);
+ if (r == JOptionPane.YES_OPTION) {
+ return true;
+ } else if (r == JOptionPane.NO_OPTION) {
+ return false;
+ }
+ return false;
+ }
public void alert(String str) {
JOptionPane.showMessageDialog(this, str);
}
@@ -192,36 +207,46 @@ private void openUrl(String url) {
com.sun.javafx.webkit.WebConsoleListener.setDefaultListener((webView, message, lineNumber, sourceId) -> {
logger.info("from webview: " + message + " [" + sourceId + " - " + lineNumber + "]");
});
- ExtractDialogJsApp extractDialogJsApp = new ExtractDialogJsApp(this);
Platform.runLater(new Runnable() {
@Override
public void run() {
+
+
webview = new WebView();
// webview.setContextMenuEnabled(false);
WebEngine webEngine = webview.getEngine();
webEngine.setJavaScriptEnabled(true);
+ webEngine.setOnAlert(event -> jsAlert(event.getData()));
+ webEngine.setConfirmHandler(message -> jsConfirm(message));
webEngine.setOnError(event -> {
logger.info(event.getMessage());
});
- ((JSObject) webEngine.executeScript("window")).setMember("javaApp", extractDialogJsApp);
-
- webEngine.load(url);
+// webEngine.getLoadWorker().stateProperty().addListener((ov, oldState, newState) -> {
+//
+// });
+
webviewScene = new Scene(webview);
bsPanel.setScene(webviewScene);
+
+ initData();
+ webEngine.load(url);
+ webview.getEngine().executeScript("window.serverPort="+AppConfig.serverPort+"");
+
}
});
}
public static void main(String args[]) {
+ ServerMain.start();
GuiConfig.setUIFont();
// String filename = "E:/workspace/_me/dev/my_libs/test_lib/data/file/archive/test.7z";
String ext = "rar";
String filename = "H:/_tmp/MOV/[zmk.tw]Downsizing.2017.1080p.BluRay.x264-GECKOS." + ext;
- filename = "E:/workspace/_me/dev/my_tools/SubTitleSearcher/target/test.rar";
+ filename = "E:/workspace/_me/dev/my_tools/SubTitleSearcher/target/_test_data/data.zip";
byte[] data = MyFileUtil.fileReadBin(filename);
diff --git a/src/main/java/zimu/gui/ExtractDialogJsApp.java b/src/main/java/zimu/gui/ExtractDialogJsApp.java
deleted file mode 100644
index d51ca01..0000000
--- a/src/main/java/zimu/gui/ExtractDialogJsApp.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package zimu.gui;
-
-import java.io.File;
-
-import cn.hutool.core.util.ArrayUtil;
-import cn.hutool.json.JSONArray;
-import cn.hutool.json.JSONObject;
-import cn.hutool.json.JSONUtil;
-import cn.hutool.log.Log;
-import cn.hutool.log.LogFactory;
-import zimu.AppConfig;
-import zimu.util.StringUtil;
-
-public class ExtractDialogJsApp {
- static final Log logger = LogFactory.get();
- ExtractDialog extractDialog;
-
- public ExtractDialogJsApp(ExtractDialog extractDialog) {
- this.extractDialog = extractDialog;
- }
-
- /**
- * 获取初始化数据
- */
- public String getInitData() {
- JSONObject resp = new JSONObject();
- JSONArray list = new JSONArray();
- for (int i = 0; i < extractDialog.archiveFiles.size(); i++) {
- File file = extractDialog.archiveFiles.get(i);
- String title = file.getName();
-
- if(!ArrayUtil.contains(AppConfig.subExtNames, StringUtil.extName(file).toLowerCase())){
- continue;
- }
-
- String key = title;
- JSONObject row = new JSONObject();
- row.put("key", key);
- row.put("title", title);
- row.put("size", file.length());
- row.put("sizeF", StringUtil.getPrintSize(file.length()));
-
- list.add(row);
- }
- resp.put("list", list);
- resp.put("title", extractDialog.title);
- resp.put("archiveExt", extractDialog.archiveExt);
- resp.put("archiveSize", extractDialog.archiveData.length);
- resp.put("archiveSizeF", StringUtil.getPrintSize(extractDialog.archiveData.length));
- return resp.toString();
- }
- /**
- * 下载压缩文件中的字幕
- * @param data
- * @return
- */
- public boolean downArchiveFile(String data) {
- //System.out.println(data);
- if(data == null || data.length() < 10) {
- logger.error("data=null");
- return false;
- }
- JSONObject dataJson = JSONUtil.parseObj(data);
- JSONArray items = dataJson.getJSONArray("items");
- if(items == null || items.size() == 0) {
- logger.error("items=null");
- return false;
- }
- return extractDialog.saveSelected(items);
- }
- public void test() {
- System.out.println("test");
- }
-}
\ No newline at end of file
diff --git a/src/main/java/zimu/gui/parms/SearchParm.java b/src/main/java/zimu/gui/parms/SearchParm.java
index df9ae83..d8c23f9 100644
--- a/src/main/java/zimu/gui/parms/SearchParm.java
+++ b/src/main/java/zimu/gui/parms/SearchParm.java
@@ -9,7 +9,11 @@ public class SearchParm {
public boolean from_zimuku = true;
public boolean from_subhd = false;
-
+// public boolean from_sheshou = false;
+// public boolean from_xunlei = false;
+// public boolean from_zimuku = false;
+// public boolean from_subhd = true;
+
public boolean isFrom_sheshou() {
diff --git a/src/main/java/zimu/server/ServerMain.java b/src/main/java/zimu/server/ServerMain.java
index 4b58152..6aba507 100644
--- a/src/main/java/zimu/server/ServerMain.java
+++ b/src/main/java/zimu/server/ServerMain.java
@@ -7,6 +7,7 @@
import cn.hutool.log.LogFactory;
import zimu.AppConfig;
import zimu.server.controllers.ApiController;
+import zimu.server.controllers.ExtractApiController;
import zimu.server.controllers.IndexController;
public class ServerMain {
@@ -20,6 +21,7 @@ public static void start() {
serverConfig.setHttpJsonMessageConverter(new MyHttpJsonMessageConverter());
serverConfig.getRouter().addMapper("", IndexController.class);
serverConfig.getRouter().addMapper("/api", ApiController.class);
+ serverConfig.getRouter().addMapper("/extract_api", ExtractApiController.class);
boolean runResult = new WebServerBuilder.Builder().serverConfig(serverConfig).build().startWithThread();
logger.info("ServerMain start runResult="+runResult);
if(!runResult && tryCount++ < 50) {
diff --git a/src/main/java/zimu/server/controllers/ApiController.java b/src/main/java/zimu/server/controllers/ApiController.java
index f6383df..64fb3c8 100644
--- a/src/main/java/zimu/server/controllers/ApiController.java
+++ b/src/main/java/zimu/server/controllers/ApiController.java
@@ -12,6 +12,11 @@
import zimu.gui.parms.DownParm;
import zimu.gui.parms.SearchParm;
+/**
+ * 列表页面查询接口
+ * @author FH
+ *
+ */
public class ApiController extends Base {
static final Log logger = LogFactory.get();
diff --git a/src/main/java/zimu/server/controllers/ExtractApiController.java b/src/main/java/zimu/server/controllers/ExtractApiController.java
new file mode 100644
index 0000000..5996934
--- /dev/null
+++ b/src/main/java/zimu/server/controllers/ExtractApiController.java
@@ -0,0 +1,85 @@
+package zimu.server.controllers;
+
+import java.io.File;
+
+import com.hibegin.http.server.api.HttpRequest;
+import com.hibegin.http.server.api.HttpResponse;
+
+import cn.hutool.core.util.ArrayUtil;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import cn.hutool.log.Log;
+import cn.hutool.log.LogFactory;
+import zimu.AppConfig;
+import zimu.gui.ExtractDialog;
+import zimu.util.StringUtil;
+/*
+ * 解压文件接口
+ */
+public class ExtractApiController extends Base {
+ static final Log logger = LogFactory.get();
+
+ /**
+ * 获取初始化数据
+ */
+ public void get_init_data() {
+ JSONObject resp = new JSONObject();
+ JSONArray list = new JSONArray();
+ for (int i = 0; i < ExtractDialog.extractDialog.archiveFiles.size(); i++) {
+ File file = ExtractDialog.extractDialog.archiveFiles.get(i);
+ String title = file.getName();
+
+ if(!ArrayUtil.contains(AppConfig.subExtNames, StringUtil.extName(file).toLowerCase())){
+ continue;
+ }
+
+ String key = title;
+ JSONObject row = new JSONObject();
+ row.put("key", key);
+ row.put("title", title);
+ row.put("size", file.length());
+ row.put("sizeF", StringUtil.getPrintSize(file.length()));
+
+ list.add(row);
+ }
+ resp.put("list", list);
+ resp.put("title", ExtractDialog.extractDialog.title);
+ resp.put("archiveExt", ExtractDialog.extractDialog.archiveExt);
+ resp.put("archiveSize", ExtractDialog.extractDialog.archiveData.length);
+ resp.put("archiveSizeF", StringUtil.getPrintSize(ExtractDialog.extractDialog.archiveData.length));
+
+ outJsonpMessage(request,response, 0, "OK", resp);
+ }
+ /**
+ * 下载压缩文件中的字幕
+ * @param data
+ * @return
+ */
+ public void down_archive_file() {
+ HttpRequest request = getRequest();
+ HttpResponse response = getResponse();
+ String data = request.getParaToStr("data");
+ if(data == null) {
+ outJsonpMessage(request,response, 1, "请求数据错误");
+ return;
+ }
+ logger.info("data="+data);
+ if(data == null || data.length() < 10) {
+ logger.error("data=null");
+ outJsonpMessage(request,response, 1, "参数错误");
+ return;
+ }
+ JSONObject dataJson = JSONUtil.parseObj(data);
+ JSONArray items = dataJson.getJSONArray("items");
+ if(items == null || items.size() == 0) {
+ logger.error("items=null");
+ outJsonpMessage(request,response, 1, "参数错误");
+ return;
+ }
+
+ JSONObject resp = new JSONObject();
+ resp.put("saveSelected", ExtractDialog.extractDialog.saveSelected(items));
+ outJsonpMessage(request,response, 0, "OK", resp);
+ }
+}
diff --git a/src/main/resources/html/images/js/extract_dialog.js b/src/main/resources/html/images/js/extract_dialog.js
index a9d724d..a0c807c 100644
--- a/src/main/resources/html/images/js/extract_dialog.js
+++ b/src/main/resources/html/images/js/extract_dialog.js
@@ -67,8 +67,13 @@ $(function(){
window.last_list_table_tr = $(this);
});
$('.list_table').on('click','.download',function(){
+ var btn = this;
+ btn.disabled = true;
var tr = $(this).parents('tr');
down_zimu(tr.find('input[name="item_id"]').val(), tr.find('select[name="item_simplified_charset"]').val());
+ window.setTimeout(function(){
+ btn.disabled = false;
+ }, 300);
});
$('#simplified_select_all').change(function(){
@@ -86,8 +91,8 @@ $(function(){
});
$('#btn_download').on('click', function(){
- var _this = this;
- this.disabled = true;
+ var btn = this;
+ btn.disabled = true;
var items_ids = [];
@@ -106,6 +111,7 @@ $(function(){
}
});
if(items_ids.length == 0){
+ btn.disabled = false;
my_alert('请选择字幕');
return;
}
@@ -113,40 +119,54 @@ $(function(){
var searchData = {
items : items_ids
};
- my_loading_show();
- if(app.downArchiveFile(json_encode(searchData))){
- my_tip('下载成功');
- }else{
- my_tip('下载失败');
- }
- my_loading_hide();
- window.setTimeout(function(){
- _this.disabled = false;
- }, 300);
+ ajax_jsonp('/extract_api/down_archive_file',{
+ data : json_encode(searchData)
+ }, function (data){
+ btn.disabled = false;
+ if(data.result > 0){
+ my_alert(data.message);
+ return;
+ }
+ if(data == null){
+ my_alert('初始化数据失败');
+ return;
+ }
+ if(data.saveSelected){
+ my_tip('下载成功');
+ }else{
+ my_tip('下载失败');
+ }
+ });
});
-
+
+ //window.serverPort = serverPort;
+ window.serverUrl = "http://127.0.0.1:"+serverPort;
laytpl_preload('#rec_list_tpl');
init_data();
});
+
function init_data(){
- my_loading_show();
- var data = app.getInitData();
- if(data == null){
- my_alert('初始化数据失败');
- return;
- }
- data = json_decode(data);
-
- $('#search_box .con').html(data.title + '('+data.archiveExt+', '+data.archiveSizeF+')');
-
- $('#status_label').html('压缩包里共有'+data.list.length+'个字幕文件');
- $('#rec_list').empty();
- laytpl_render('#rec_list_tpl', data, function(html){
- $('#rec_list').append(html);
- $('#batch_from').newforms();
+ ajax_jsonp('/extract_api/get_init_data',{
+
+ }, function (data){
+ if(data.result > 0){
+ my_alert(data.message);
+ return;
+ }
+ if(data == null){
+ my_alert('初始化数据失败');
+ return;
+ }
+
+ $('#search_box .con').html(data.title + '('+data.archiveExt+', '+data.archiveSizeF+')');
+
+ $('#status_label').html('压缩包里共有'+data.list.length+'个字幕文件');
+ $('#rec_list').empty();
+ laytpl_render('#rec_list_tpl', data, function(html){
+ $('#rec_list').append(html);
+ $('#batch_from').newforms();
+ });
});
-
- my_loading_hide();
}
//下载鼠标最后移动到的字幕
function down_last_tr_zimu(charset){
@@ -179,11 +199,21 @@ function down_zimu(id, charset){
var searchData = {
items : items_ids
};
- my_loading_show();
- if(app.downArchiveFile(json_encode(searchData))){
- my_tip('下载成功');
- }else{
- my_tip('下载失败');
- }
- my_loading_hide();
+ ajax_jsonp('/extract_api/down_archive_file',{
+ data : json_encode(searchData)
+ }, function (data){
+ if(data.result > 0){
+ my_alert(data.message);
+ return;
+ }
+ if(data == null){
+ my_alert('初始化数据失败');
+ return;
+ }
+ if(data.saveSelected){
+ my_tip('下载成功');
+ }else{
+ my_tip('下载失败');
+ }
+ });
}
diff --git a/src/main/resources/html/images/js/main.js b/src/main/resources/html/images/js/main.js
index bc4e29b..39f753d 100644
--- a/src/main/resources/html/images/js/main.js
+++ b/src/main/resources/html/images/js/main.js
@@ -28,10 +28,6 @@ window.app = {
if(!this.inApp())return false;
return javaApp.copyClipboard(str);
},
- downArchiveFile : function(data){
- if(!this.inApp())return false;
- return javaApp.downArchiveFile(data);
- },
inApp : function(){
return (typeof(javaApp)=='object' && typeof(javaApp.test) == 'function')
}
@@ -75,13 +71,22 @@ function set_select_all(id, bat_name){
var _this = this;
$('input[name="'+bat_name+'"]').each(function (){
this.checked = _this.checked;
+ if(this.checked){
+ $(this).attr('checked', 'checked');
+ $(this).prop("checked");
+ }else{
+ $(this).removeAttr('checked');
+ $(this).removeProp("checked");
+ }
+
$(this).trigger('nf_change');
})
});
- var bat_list = $('input[name="'+bat_name+'"]');
- bat_list.change(function (){
+ $(document).on('change', 'input[name="'+bat_name+'"]', function (){
var _this = this;
- console.log(bat_list.filter('[checked]').length);
+ var bat_list = $('input[name="'+bat_name+'"]');
+ ///console.log($('.list_table').html())
+ //console.log(bat_list.filter('[checked]').length+","+bat_list.length)
if(bat_list.filter('[checked]').length == bat_list.length){
$(id).get(0).checked = true;
$(id).trigger('nf_change');