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
最新资源
- 基于51单片机的智能家居.7z
- 基于STM32F103单片机的智能灌溉系统.7z
- 基于STM32单片机和无线网络技术设计和开发的一款智能空气监测系统.7z
- 52单片机的智能风扇系统~.7z
- 51单片机控制的智能小车.7z
- 家具智能化----------利用Android设备和单片机通讯来控制家电的开关.7z
- 基于STC单片机的智能垃圾箱.7z
- 基于STM32单片机的智能晾衣架.7z
- 51单片机程序,智能电风扇的实现,附有protues8.6仿真图.7z
- 51单片机:避障寻迹测距遥控智能小车.7z
- 单片机课程实践——智能家居系统(安卓端).7z
- 基于51单片机的智能门禁系统.7z
- 基于51单片机Y33 4轮智能小车例程.7z
- 汽车卡车检测5-YOLO(v5至v9)、COCO、CreateML、Darknet、Paligemma、TFRecord数据集合集.rar
- 基于单片机智能可控洗衣机设计.7z
- Delphi 12 控件之Winsoft WinRT for FireMonkey v1.5.7z
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
- 6
前往页