Skip to content

Commit

Permalink
增加标题复制功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Andyfoo committed Feb 14, 2019
1 parent 458465b commit 1e63aa0
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 6 deletions.
Binary file modified _release/SubTitleSearcher/SubTitleSearcher.exe
Binary file not shown.
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>1.2.1.1</version>
<version>1.2.5.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jodd-version>3.8.5</jodd-version>
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 @@ -6,7 +6,7 @@
public class AppConfig {
public static String appName = "SubTitleSearcher";
public static String appTitle = "字幕下载";
public static String appVer = "1.2.1.1";
public static String appVer = "1.2.5";

public static String appPath;
public static boolean isExe;
Expand Down
108 changes: 108 additions & 0 deletions src/main/java/zimu/common/ZiMuCommon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package zimu.common;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ZiMuCommon {
/**
* 将字符串复制到剪切板。
*/
public static void copyClipboard(String writeMe) {
Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable tText = new StringSelection(writeMe);
clip.setContents(tText, null);
}

/**
* 获取字符中的汉字部分
* @param title
* @return
*/
public static String getTitleCnStr(String title) {
if(title == null)return "";
title = title.replace(":", ":");
//title = title.replace("_", "—");
//title = title.replace("-", "ˉ");
title = title.replace("[", "【");
title = title.replace("]", "】");
title = title.replace("修正版", "");
String[] arr = title.split("\\.");
if(arr.length > 2) {
title = title.substring(0, title.lastIndexOf("."));
}
if(arr.length > 3) {
title = title.substring(0, title.lastIndexOf("."));
}

String title2 = title.replaceAll("【.*】", "");

//中文+标点组合
Pattern pattern = Pattern.compile("[\u4E00-\u9FA5"
+ "\u3002\uff1f\uff01\uff0c\u3001\uff1b\uff1a\u201c"
+ "\u201d\u2018\u2019\uff08\uff09\u300a\u300b\u3008"
+ "\u3009\u3010\u3011\u300e\u300f\u300c\u300d\ufe43"
+ "\ufe44\u3014\u3015\u2026\u2014\uff5e\ufe4f\uffe5"
+ "\u02c9]+");
Matcher matcher = pattern.matcher(title2);
String resStr = "";
if(matcher.find()) {
resStr = matcher.group(0);
}else {
matcher = pattern.matcher(title);
if(matcher.find()) {
resStr = matcher.group(0);
resStr = resStr.replaceAll("[【】]+", "");
}
}
//中文+英文+标点组合
pattern = Pattern.compile("[\\w\u4E00-\u9FA5"
+ "\u3002\uff1f\uff01\uff0c\u3001\uff1b\uff1a\u201c"
+ "\u201d\u2018\u2019\uff08\uff09\u300a\u300b\u3008"
+ "\u3009\u3010\u3011\u300e\u300f\u300c\u300d\ufe43"
+ "\ufe44\u3014\u3015\u2026\u2014\uff5e\ufe4f\uffe5"
+ "\u02c9]+");
if((resStr == null || resStr.length() == 0) && Pattern.compile("[\u4E00-\u9FA5]+").matcher(title).find()) {
matcher = pattern.matcher(title);
if(matcher.find()) {
resStr = matcher.group(0);
resStr = resStr.replaceAll("[【】]+", "");
}
}


return resStr;
}

public static void main(String[] args) {
// System.out.println("[缩小人生]Downsizing.2017.1080p.Bluray.MKV.x264.AC3修正版.ass [ASS/SSA][双语][下载次数:1709]".
// replaceAll("\\[[^]]*]\\[[^]]*]\\[下载次数.+]", ""));;

//System.out.println(getTitleCnStr("【X战警:逆转未来 导演剪辑版】X-Men.Days.of.Future.Past.THE.ROGUE.CUT.1080p.BluRay.x264-SADPANDA"));
//System.exit(0);
String[] titles = new String[] {
"test.a.b.c",
"我是中文.a.b.c",
"我是中文 a.b.c",
"我是中文a.b.c",
"我是-中文a.b.c",
"我是_中文a.b.c",
"[我是中文]a.b.c",
"【获取】我是中文a.b.c",
"[获wee取]我是中文a.b.c",
"[超人特工队(国粤台英)].The.Incredibles.2004.BluRay.720p.x264.AC3.4Audios-CMCT.完美匹配国语chsc",
"[缩小人生]Downsizing.2017.1080p.Bluray.MKV.x264.AC3修正版",
"X战警:第一战.X-Men.First.Class.2011.2160p.BluRay",
"战X警:第一战.X-Men.First.Class.2011.2160p.BluRay",
"【X战警:逆转未来 导演剪辑版】X-Men.Days.of.Future.Past.THE.ROGUE.CUT.1080p.BluRay.x264-SADPANDA"
};
//System.out.println(getTitleCnStr("[获wee取]我是中文a.b.c"));
for(int i = 0; i < titles.length; i++) {
System.out.println(getTitleCnStr(titles[i]));
}
}

}
2 changes: 1 addition & 1 deletion src/main/java/zimu/down/DownZIMu.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static void searchList() {

JSONArray list = null;
String filenameStr = StringUtil.basename(MainWin.movFilename);
String filenameBase = filenameStr.substring(0, filenameStr.lastIndexOf("."));
String filenameBase = filenameStr.contains(".")?filenameStr.substring(0, filenameStr.lastIndexOf(".")):filenameStr;

//射手
if(MainWin.sheshouCheckBox.isSelected()) {
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/zimu/gui/MainWin.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class MainWin {

public static void init() {
GuiConfig.setUIFont();
frame = new JFrame(String.format("%s %s", AppConfig.appTitle, AppConfig.appVer));
frame = new JFrame(String.format("%s V%s", AppConfig.appTitle, AppConfig.appVer));
frame.setSize(920, 600);
frame.setMinimumSize(new Dimension(800, 500));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Expand Down Expand Up @@ -140,6 +140,10 @@ public void actionPerformed(ActionEvent e) {
File file = jfc.getSelectedFile();
if (file != null && file.isFile()) {
String filepath = file.getAbsolutePath();
if(file.isDirectory()) {
alert("请选择有效的视频文件");
return;
}
setFile(filepath);
startSearch();
}
Expand Down Expand Up @@ -518,7 +522,8 @@ public void run() {

}
public static void setFile(String filepath) {
lastSelPath = (new File(filepath)).getParentFile().getAbsolutePath();
File file = new File(filepath);
lastSelPath = file.getParentFile().getAbsolutePath();
filePathText.setText(filepath);
movFilename = filepath;
logger.info(movFilename);
Expand Down Expand Up @@ -549,7 +554,11 @@ public boolean importData(JComponent comp, Transferable t) {
if (filepath.endsWith("]")) {
filepath = filepath.substring(0, filepath.length() - 1);
}

File file = new File(filepath);
if(file.isDirectory()) {
alert("请选择有效的视频文件");
return false;
}
setFile(filepath);
startSearch();
//JOptionPane.showMessageDialog(frame, filepath);
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/zimu/gui/SubTitlePopupMenu.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package zimu.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -9,15 +10,22 @@
import javax.swing.JPopupMenu;
import javax.swing.JTable;

import zimu.common.ZiMuCommon;

public class SubTitlePopupMenu {
JPopupMenu popupMenu;
Map<String, ActionListener> actionListenerMap = new HashMap<String, ActionListener>();
JTable jTable;
public boolean simplified = false;

String titleStr = "";
String titleCnStr = "";

public SubTitlePopupMenu(JTable jTable) {
popupMenu = new JPopupMenu();
this.jTable = jTable;
setJTable();
addDefaultEvent();
}

public void createPopupMenu() {
Expand All @@ -33,8 +41,34 @@ public void createPopupMenu() {
add("下载字幕(UTF-8 繁转简)", "download_simplified_utf8");
add("下载字幕(GBK 繁转简)", "download_simplified_gbk");
add("下载字幕(Big5 繁转简)", "download_simplified_big5");
popupMenu.addSeparator();
if(titleStr!=null && titleStr.length() > 0) {
add("复制文字:"+titleStr, "copy_title");
}
if(titleCnStr!=null && titleCnStr.length() > 0) {
add("复制文字:"+titleCnStr, "copy_title_cn");
}

//popupMenu.addSeparator();
//add("当前目录改名为xxxx", "rename_title");
//add("当前目录改名为xxxx", "rename_title_cn");

}

public void addDefaultEvent() {
addEvent("copy_title", new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ZiMuCommon.copyClipboard(titleStr);
}
});
addEvent("copy_title_cn", new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ZiMuCommon.copyClipboard(titleCnStr);
}
});
}

public void setJTable() {
jTable.addMouseListener(new java.awt.event.MouseAdapter() {
Expand All @@ -54,6 +88,18 @@ public void mouseClicked(java.awt.event.MouseEvent evt) {
// }
// 将表格所选项设为当前右键点击的行
jTable.setRowSelectionInterval(focusedRowIndex, focusedRowIndex);
int selRow = jTable.getSelectedRow();
if(selRow > -1) {
String title = (String) jTable.getValueAt(selRow, 2);
if(title.contains(".")) {
title = title.substring(0, title.lastIndexOf("."));
}
if(title.contains("下载次数")) {
title = title.replaceAll("\\[[^]]*]\\[[^]]*]\\[下载次数.+]", "");
}
titleStr = title;
titleCnStr = ZiMuCommon.getTitleCnStr(title);
}
popupMenu.removeAll();
createPopupMenu();

Expand Down
1 change: 1 addition & 0 deletions src/main/java/zimu/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public static String extName(File file) {
return extName(file.getName());
}


public static void main(String[] args) {

}
Expand Down

0 comments on commit 1e63aa0

Please sign in to comment.