时间:2020-11-17 00:59:37 | 栏目:JAVA代码 | 点击:次
想要php版的朋友可以到这里下载测试 https://www.jb51.net/codes/83179.html
public class test1 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
//设定视频地址
String url = "http://v.youku.com/v_show/id_XMjU0MjI2NzY0.html";
//获取id后面的字符串,也就是"XMjU0MjI2NzY0.html"
int no = url.indexOf("id_");
//获取id值,也就是"XMjU0MjI2NzY0"
String videoId = url.substring(no+3, url.indexOf(".html"));
//获取视频信息数据的URL对象
URL myurl = new URL("http://v.youku.com/player/getPlayList/VideoIDS/"+videoId+"/timezone/+08/version/5/source/out?password=&ran=2513&n=3");
//从URL对象中获取输入流
InputStreamReader isr = new InputStreamReader(myurl.openStream());
//封装
BufferedReader br = new BufferedReader(isr);
//readLine获取文本,然后以"\/"切割文本中的信息
String[] urls = br.readLine().split("\\/");
isr.close();
br.close();
//因为信息数据是固定格式的,所以直接第四个元素肯定是我们所需要的。
String target = urls[3];
//对上面结果继续以"切割
String imgid = target.substring(0,target.indexOf("\""));
//拼凑一下,就是我们需要的地址了
String img = "http://g2.ykimg.com/" + imgid;
System.out.println(img);
/*
结果为:http://g2.ykimg.com/1100641F464D8FBF5FA3D90209C8DF96B67E2C-567E-AB53-C132-D7787FC966AB
*/
}
}