misc
This commit is contained in:
parent
31d692bfe6
commit
e612f9beec
@ -46,6 +46,7 @@ import xdman.ui.components.NewDownloadWindow;
|
||||
import xdman.ui.components.TrayHandler;
|
||||
import xdman.ui.components.VideoDownloadWindow;
|
||||
import xdman.ui.components.VideoPopup;
|
||||
import xdman.ui.components.VideoPopupItem;
|
||||
import xdman.ui.laf.XDMLookAndFeel;
|
||||
import xdman.ui.res.StringResource;
|
||||
import xdman.util.FFmpegDownloader;
|
||||
@ -85,6 +86,8 @@ public class XDMApp implements DownloadListener, DownloadWindowListener, Compara
|
||||
// notification is stored in this
|
||||
// variable
|
||||
|
||||
private ArrayList<VideoPopupItem> itemList = new ArrayList<>();
|
||||
|
||||
public static void instanceStarted() {
|
||||
Logger.log("instance starting...");
|
||||
final XDMApp app = XDMApp.getInstance();
|
||||
@ -1306,4 +1309,8 @@ public class XDMApp implements DownloadListener, DownloadWindowListener, Compara
|
||||
notifyListeners(id);
|
||||
}
|
||||
|
||||
public ArrayList<VideoPopupItem> getVideoItemsList() {
|
||||
return itemList;
|
||||
}
|
||||
|
||||
}
|
@ -9,6 +9,7 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.net.Socket;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@ -25,6 +26,8 @@ import xdman.network.http.HttpHeader;
|
||||
import xdman.network.http.JavaHttpClient;
|
||||
import xdman.preview.FFmpegStream;
|
||||
import xdman.preview.PreviewStream;
|
||||
import xdman.ui.components.VideoPopupItem;
|
||||
import xdman.util.Base64;
|
||||
import xdman.util.FormatUtilities;
|
||||
import xdman.util.Logger;
|
||||
import xdman.util.StringUtils;
|
||||
@ -79,6 +82,21 @@ public class MonitoringSession implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private void onVideoRetrieve(Request request, Response res) throws UnsupportedEncodingException {
|
||||
try {
|
||||
String id = new String(request.getBody(), "utf-8");
|
||||
for (VideoPopupItem item : XDMApp.getInstance().getVideoItemsList()) {
|
||||
if (id.equals(item.getMetadata().getId())) {
|
||||
HttpMetadata md = item.getMetadata().derive();
|
||||
Logger.log("dash metdata ? " + (md instanceof DashMetadata));
|
||||
XDMApp.getInstance().addVideo(md, item.getFile());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
setResponseOk(res);
|
||||
}
|
||||
}
|
||||
|
||||
private void onLinksReceived(Request request, Response res) throws UnsupportedEncodingException {
|
||||
try {
|
||||
Logger.log(new String(request.getBody()));
|
||||
@ -170,7 +188,19 @@ public class MonitoringSession implements Runnable {
|
||||
setResponseOk(res);
|
||||
}
|
||||
|
||||
private void onSync(Request request, Response res) {
|
||||
private String encode(String str) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int count = 0;
|
||||
for (char ch : str.toCharArray()) {
|
||||
if (count > 0)
|
||||
sb.append(",");
|
||||
sb.append((int) ch);
|
||||
count++;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private void onSync(Request request, Response res) throws UnsupportedEncodingException {
|
||||
StringBuffer json = new StringBuffer();
|
||||
json.append("{\n\"enabled\": ");
|
||||
json.append(Config.getInstance().isBrowserMonitoringEnabled());
|
||||
@ -185,9 +215,26 @@ public class MonitoringSession implements Runnable {
|
||||
json.append("],");
|
||||
json.append("\n\"vidExts\": [");
|
||||
appendArray(Config.getInstance().getVidExts(), json);
|
||||
json.append("],");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int count = 0;
|
||||
for (VideoPopupItem item : XDMApp.getInstance().getVideoItemsList()) {
|
||||
String id = item.getMetadata().getId();
|
||||
String text = encode(item.getFile());
|
||||
String info = item.getInfo();
|
||||
if (count > 0)
|
||||
sb.append(",");
|
||||
sb.append(String.format("{\"id\": \"%s\", \"text\": \"%s\",\"info\":\"%s\"}", id, text,
|
||||
info));
|
||||
count++;
|
||||
}
|
||||
json.append("\n\"vidList\": [");
|
||||
json.append(sb.toString());
|
||||
json.append("]");
|
||||
json.append("\n}");
|
||||
|
||||
//System.out.println(json);
|
||||
|
||||
byte[] b = json.toString().getBytes();
|
||||
|
||||
res.setCode(200);
|
||||
@ -262,11 +309,25 @@ public class MonitoringSession implements Runnable {
|
||||
} else if (verb.startsWith("/links")) {
|
||||
Logger.log("sending 204...");
|
||||
onLinksReceived(request, response);
|
||||
} else if (verb.startsWith("/item")) {
|
||||
Logger.log("sending 204...");
|
||||
onVideoRetrieve(request, response);
|
||||
} else if (verb.startsWith("/clear")) {
|
||||
Logger.log("sending 204...");
|
||||
onVideoClear(request, response);
|
||||
} else {
|
||||
throw new IOException("invalid verb " + verb);
|
||||
}
|
||||
}
|
||||
|
||||
private void onVideoClear(Request request, Response response) {
|
||||
try {
|
||||
XDMApp.getInstance().getVideoItemsList().clear();
|
||||
} finally {
|
||||
setResponseOk(response);
|
||||
}
|
||||
}
|
||||
|
||||
// the url should be /preview/ffmpeg/1/{UUID}/{T1,T2,NULL}
|
||||
private void onPreview(Request request, Response response) throws IOException {
|
||||
PreviewStream ps = null;
|
||||
|
@ -42,6 +42,7 @@ import xdman.ui.res.StringResource;
|
||||
import xdman.util.Logger;
|
||||
import xdman.util.StringUtils;
|
||||
import xdman.util.XDMUtils;
|
||||
|
||||
public class VideoPopup extends JDialog implements ActionListener, Comparator<VideoPopupItem> {
|
||||
|
||||
/**
|
||||
@ -94,7 +95,7 @@ public class VideoPopup extends JDialog implements ActionListener, Comparator<Vi
|
||||
private void arrangeList() {
|
||||
videoItems.clear();
|
||||
ArrayList<VideoPopupItem> itemsCopy = new ArrayList<VideoPopupItem>();
|
||||
itemsCopy.addAll(itemList);
|
||||
itemsCopy.addAll(XDMApp.getInstance().getVideoItemsList());
|
||||
Collections.sort(itemsCopy, this);
|
||||
for (VideoPopupItem item : itemsCopy) {
|
||||
videoItems.addElement(item);
|
||||
@ -102,13 +103,13 @@ public class VideoPopup extends JDialog implements ActionListener, Comparator<Vi
|
||||
}
|
||||
|
||||
private VideoPopup() {
|
||||
itemList = new ArrayList<VideoPopupItem>();
|
||||
videoItems = new DefaultListModel<VideoPopupItem>();
|
||||
init();
|
||||
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
|
||||
Insets scnMax = Toolkit.getDefaultToolkit().getScreenInsets(this.getGraphicsConfiguration());
|
||||
this.setLocation(d.width - getWidth() - getScaledInt(50), d.height - scnMax.bottom - getHeight() - getScaledInt(30));
|
||||
this.setLocation(d.width - getWidth() - getScaledInt(50),
|
||||
d.height - scnMax.bottom - getHeight() - getScaledInt(30));
|
||||
}
|
||||
|
||||
private int initialY;
|
||||
@ -119,7 +120,7 @@ public class VideoPopup extends JDialog implements ActionListener, Comparator<Vi
|
||||
private JPanel itemPanel;
|
||||
private boolean upward = false;
|
||||
private DefaultListModel<VideoPopupItem> videoItems;
|
||||
private ArrayList<VideoPopupItem> itemList;
|
||||
|
||||
private JList<VideoPopupItem> itemListBox;
|
||||
private int mHoveredJListIndex = -1;
|
||||
private Box menuBox;
|
||||
@ -264,7 +265,7 @@ public class VideoPopup extends JDialog implements ActionListener, Comparator<Vi
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String name = ((JComponent) e.getSource()).getName();
|
||||
for (VideoPopupItem item : itemList) {
|
||||
for (VideoPopupItem item : XDMApp.getInstance().getVideoItemsList()) {
|
||||
if (name.equals(item.getMetadata().getId())) {
|
||||
collapse();
|
||||
HttpMetadata md = item.getMetadata().derive();
|
||||
@ -275,7 +276,7 @@ public class VideoPopup extends JDialog implements ActionListener, Comparator<Vi
|
||||
if (name.equals("CLOSE")) {
|
||||
collapse();
|
||||
menuBox.removeAll();
|
||||
itemList.clear();
|
||||
XDMApp.getInstance().getVideoItemsList().clear();
|
||||
dispose();
|
||||
_this = null;
|
||||
} else if (name.equals("COLAPSE")) {
|
||||
@ -363,8 +364,8 @@ public class VideoPopup extends JDialog implements ActionListener, Comparator<Vi
|
||||
if (item.getMetadata() == null) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < itemList.size(); i++) {
|
||||
VideoPopupItem p = itemList.get(i);
|
||||
for (int i = 0; i < XDMApp.getInstance().getVideoItemsList().size(); i++) {
|
||||
VideoPopupItem p = XDMApp.getInstance().getVideoItemsList().get(i);
|
||||
HttpMetadata m1 = item.getMetadata();
|
||||
HttpMetadata m2 = p.getMetadata();
|
||||
if (m1.getType() == m2.getType()) {
|
||||
@ -382,7 +383,7 @@ public class VideoPopup extends JDialog implements ActionListener, Comparator<Vi
|
||||
}
|
||||
}
|
||||
|
||||
itemList.add(item);
|
||||
XDMApp.getInstance().getVideoItemsList().add(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -392,8 +393,8 @@ public class VideoPopup extends JDialog implements ActionListener, Comparator<Vi
|
||||
String[] arr = getIdAndLen(url);
|
||||
String id = arr[0];
|
||||
String len = arr[1];
|
||||
for (int i = 0; i < itemList.size(); i++) {
|
||||
VideoPopupItem p = itemList.get(i);
|
||||
for (int i = 0; i < XDMApp.getInstance().getVideoItemsList().size(); i++) {
|
||||
VideoPopupItem p = XDMApp.getInstance().getVideoItemsList().get(i);
|
||||
HttpMetadata m2 = p.getMetadata();
|
||||
if (m2 instanceof DashMetadata) {
|
||||
DashMetadata dm1 = (DashMetadata) m2;
|
||||
|
Loading…
x
Reference in New Issue
Block a user