Skip to content

Commit

Permalink
修改subHD下载的压缩文件保存出错问题。(javafx的webview的js绑定不稳定,去掉一部分)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andyfoo committed Jul 17, 2019
1 parent 9f89888 commit a3e4578
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 133 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>SubTitleSearcher</groupId>
<artifactId>SubTitleSearcher</artifactId>
<version>2.0.2.0</version>
<version>2.0.3.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<copyright>Copyright 2019 pslib.com</copyright>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/zimu/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
49 changes: 37 additions & 12 deletions src/main/java/zimu/gui/ExtractDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<File> archiveFiles;
public List<File> archiveFiles;

DownParm downParm;
int zimuIndex;
Expand All @@ -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
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);

Expand Down
74 changes: 0 additions & 74 deletions src/main/java/zimu/gui/ExtractDialogJsApp.java

This file was deleted.

6 changes: 5 additions & 1 deletion src/main/java/zimu/gui/parms/SearchParm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/zimu/server/ServerMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/zimu/server/controllers/ApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
85 changes: 85 additions & 0 deletions src/main/java/zimu/server/controllers/ExtractApiController.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading

0 comments on commit a3e4578

Please sign in to comment.