package com.duapp.main;
import java.awt.BorderLayout;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import chrriis.common.UIUtils;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
public class OnlinePlayer {
private final static String TITLE_TUDOU = "土豆网:每个人都是生活的导演。";
private final static String TITLE_YOUKU = "优酷网:世界都在看。";
private static String url = null;
private static Loading loading;
public OnlinePlayer(String realUrl, String title) {
JDialog dialog = new JDialog();
dialog.setTitle(title);
dialog.setResizable(false);
dialog.setBounds(30, 30, 608, 522);
JWebBrowser webBrowser = new JWebBrowser();
webBrowser.setBarsVisible(false);
webBrowser.setButtonBarVisible(false);
webBrowser.setDefaultPopupMenuRegistered(false);
webBrowser.navigate(realUrl);
dialog.add(webBrowser, BorderLayout.CENTER);
loading.dispose();
dialog.setVisible(true);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
}
public static void main(String[] args) {
try {
UIManager
.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception e) {
e.printStackTrace();
}
boolean isOk = false;
//http://v.youku.com/v_show/id_XNDM4OTI5NDg0.html
while(!isOk){
url =JOptionPane.showInputDialog(null, "输入优酷或者土豆视频的地址");
if(url == null){
return;
}
if (url == "" || url.length() == 0) {
JOptionPane.showMessageDialog(null, "地址不能为空!", "错误", JOptionPane.ERROR_MESSAGE);
continue;
}
if (url != null && url.indexOf(WriteToHtml.YOUKU) == -1
&& url.indexOf(WriteToHtml.TUDOU) == -1) {
JOptionPane.showMessageDialog(null, "必须是优酷或者土豆的地址!", "错误", JOptionPane.ERROR_MESSAGE);
continue;
}
isOk = true;
}
loading = new Loading("images/loading.png");
File directory = new File("");// 参数为空
String courseFile = null;
try {
courseFile = directory.getCanonicalPath();
} catch (IOException e) {
e.printStackTrace();
}
final String realUrl = ("file:///" + courseFile + "/temp/temp.html");
NativeInterface.open();
UIUtils.setPreferredLookAndFeel();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
String type = "";
String id = "";
if (url.indexOf(WriteToHtml.YOUKU) != -1) {
id = url.substring(url.indexOf("id_") + 3, url
.indexOf(".html"));
type = WriteToHtml.YOUKU;
new WriteToHtml().writeFile(type, id);
new OnlinePlayer(realUrl, TITLE_YOUKU);
} else {
id = getIdOfTodou(url);
type = WriteToHtml.TUDOU;
new WriteToHtml().writeFile(type, id);
new OnlinePlayer(realUrl,TITLE_TUDOU);
}
}
});
NativeInterface.runEventPump();
}
private static String getIdOfTodou(String urlStr) {
// icode:"3n29ZRnSq2U"
String icode = "icode:\""
+ urlStr.substring(urlStr.lastIndexOf("/") + 1, urlStr
.indexOf(".html")) + "\"";
try {
URL url = new URL(urlStr); // 将urlstr字符串网址实例化为URL定位地址s
URLConnection urlConn = url.openConnection(); // 打开网站链接s
BufferedReader reader = new BufferedReader(new InputStreamReader(
urlConn.getInputStream())); // 实例化输入流,并获取网页代码
String s; // 依次循环,至到读的值为空
StringBuilder sb = new StringBuilder();
while ((s = reader.readLine()) != null) {
sb.append(s);
// sb.append("\n");
}
int icodeEnd = sb.indexOf(icode);
String temp = null;
int iidStart = 0, iidEnd = 0;
if (icodeEnd == -1) {// 找不到符合的icode:""
temp = sb.toString();
iidStart = temp.indexOf("iid:") + 4;
iidEnd = temp.indexOf(",", iidStart);
} else {// 找得到
temp = sb.substring(0, icodeEnd);
iidStart = temp.lastIndexOf("iid:") + 4;
iidEnd = temp.indexOf(",", iidStart);
}
return temp.substring(iidStart, iidEnd).toString();
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}
Cannel_2020
- 粉丝: 313
- 资源: 12
最新资源
- (源码)基于ESP8266和Arduino的HomeMatic水表读数系统.zip
- (源码)基于Django和OpenCV的智能车视频处理系统.zip
- (源码)基于ESP8266的WebDAV服务器与3D打印机管理系统.zip
- (源码)基于Nio实现的Mycat 2.0数据库代理系统.zip
- (源码)基于Java的高校学生就业管理系统.zip
- (源码)基于Spring Boot框架的博客系统.zip
- (源码)基于Spring Boot框架的博客管理系统.zip
- (源码)基于ESP8266和Blynk的IR设备控制系统.zip
- (源码)基于Java和JSP的校园论坛系统.zip
- (源码)基于ROS Kinetic框架的AGV激光雷达导航与SLAM系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
- 6
前往页