`
liuguihua0823
  • 浏览: 109818 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

JAVA提取优酷等视频网址的视频信息(持续更新中......)

阅读更多

支持以下网址:优酷、土豆、酷6、乐视、腾讯、搜狐、凤凰视频、音悦台MV播放页面的解析,解析出来的属性包括:视频标题、视频缩略图、视频简介、视频时长、视频来源、视频页面地址、视频FLASH地址、页面嵌入HTML代码。

 

版本更新说明:
1、2011-09-12 创建版本,支持优酷、土豆、酷6、6间房、新浪、搜狐、56(我乐)视频播放页面的信息解析
2、2011-09-13 新加对凤凰视频的支持,链接地址不在支持的列表中时返回原链接地址以及链接的页面标题

3、2011-09-23 新加对音悦台MV播放也的解析支持http://www.yinyuetai.com

4、2015-05-25 更新支持,支持视频:优酷、土豆、酷6、乐视、腾讯、搜狐、凤凰视频、音悦台MV

 

使用方法如下:

1、视频对象类com.guihua.video.extract.Video.java

package com.guihua.video.extract;

import java.io.Serializable;

public class Video implements Serializable {

	private static final long serialVersionUID = -6220973207083491817L;

	private String title = "";// 视频标题

	private String thumbnail = "";// 视频缩略图

	private String summary = "";// 视频简介

	private String time = "";// 视频时长

	private String source = "";// 视频来源

	private String pageUrl = "";// 视频页面地址

	private String flashUrl = "";// 视频FLASH地址

	private String htmlCode = "";// 视频HTML代码

	public String getTitle() {
		if (null == title) {
			return "";
		} else {
			return title;
		}
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getThumbnail() {
		if (null == thumbnail) {
			return "";
		} else {
			return thumbnail;
		}
	}

	public void setThumbnail(String thumbnail) {
		this.thumbnail = thumbnail;
	}

	public String getSummary() {
		if (null == summary) {
			return "";
		} else {
			return summary;
		}
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	public String getTime() {
		if (null == time) {
			return "";
		} else {
			return time;
		}
	}

	public void setTime(String time) {
		this.time = time;
	}

	public String getSource() {
		if (null == source) {
			return "";
		} else {
			return source;
		}
	}

	public void setSource(String source) {
		this.source = source;
	}

	public String getPageUrl() {
		if (null == pageUrl) {
			return "";
		} else {
			return pageUrl;
		}
	}

	public void setPageUrl(String pageUrl) {
		this.pageUrl = pageUrl;
	}

	public String getFlashUrl() {
		if (null == flashUrl) {
			return "";
		} else {
			return flashUrl;
		}
	}

	public void setFlashUrl(String flashUrl) {
		this.flashUrl = flashUrl;
	}

	public String getHtmlCode() {
		if (null == htmlCode) {
			return "";
		} else {
			return htmlCode;
		}
	}

	public void setHtmlCode(String htmlCode) {
		this.htmlCode = htmlCode;
	}

}

 

2、测试类代码

 

String url = "http://v.youku.com/v_show/id_XMzAyMjE1Nzgw.html";
// String url = "http://www.tudou.com/programs/view/Zkazx5iaUSQ/";
// String url = "http://v.ku6.com/special/show_4024167/Dwq_4xKT5Go4f4F6.html";
// String url = "http://v.ku6.com/show/bFx2VCEiF15U53E6.html";
// String url = "http://6.cn/watch/14757577.html";
// String url = "http://www.56.com/u37/v_NjE3OTQ4NTg.html";
// String url = "http://video.sina.com.cn/p/news/s/v/2011-09-11/133861482545.html";
// String url = "http://tv.sohu.com/20110912/n319076906.shtml";
// String url = "http://v.ifeng.com/documentary/discovery/201109/ed52d159-a3f4-4969-972d-c9e6d51d00ff.shtml";
// String url = "http://www.yinyuetai.com/video/271439";
// String url = "http://www.baidu.com/";

Video video = VideoUtil.getVideoInfo(url);
System.out.println("视频标题:" + video.getTitle());
System.out.println("视频地址:" + video.getFlashUrl());
System.out.println("视频时长:" + video.getTime());
System.out.println("视频来源:" + video.getSource());
System.out.println("视频简介:" + video.getSummary());
System.out.println("视频缩略图:" + video.getThumbnail());
System.out.println("视频原始地址:" + video.getPageUrl());
System.out.println("视频网页代码:" + video.getHtmlCode());
7
6
分享到:
评论
25 楼 dreamzal 2016-12-28  
不咋样,不能用。
24 楼 dreamzal 2016-12-28  
23 楼 wdmcygah 2016-07-01  
发现有些土豆地址不支持,比如:http://www.tudou.com/programs/view/ZZo6Je9DUvg/
22 楼 sunshine52013 2015-09-07  
提取出来的视频除了优酷能在微信客户端打开  其他的都不行
21 楼 AllureLove2580 2015-04-20  
楼主 空指针怎么解决。。
20 楼 liyuhaoo 2014-12-17  
目前你的这个方法已经不行了啊
19 楼 pan921103 2014-10-30  
根本就没用
18 楼 nash_2012 2014-03-27  
包非常不错,是我需要的,非常感谢
17 楼 jinbaking 2012-06-30  
你好!现在这段代码好像只有6房间和56视频网好使了,其他的都不能用了啊~~有什么新的方法吗?
16 楼 jinbaking 2012-06-30  
韩国特别人体吧人
15 楼 Flyinggg 2012-04-20  
null
Exception in thread "main" java.lang.NullPointerException
at com.hlj.test.Know.main(Know.java:24)


用的你测试的方法。。。

出现video为null。。。这是什么问题。


import org.osm.video.Video;
import org.osm.video.VideoUtil;

public class Know {

public static void main(String[] args) {
    //String url = "http://v.youku.com/v_show/id_XMzAyMjE1Nzgw.html"; 
     String url = "http://www.tudou.com/programs/view/Zkazx5iaUSQ/"; 
    // String url = "http://v.ku6.com/special/show_4024167/Dwq_4xKT5Go4f4F6.html"; 
    // String url = "http://v.ku6.com/show/bFx2VCEiF15U53E6.html"; 
    // String url = "http://6.cn/watch/14757577.html"; 
    // String url = "http://www.56.com/u37/v_NjE3OTQ4NTg.html"; 
    // String url = "http://video.sina.com.cn/p/news/s/v/2011-09-11/133861482545.html"; 
    // String url = "http://tv.sohu.com/20110912/n319076906.shtml"; 
    // String url = "http://v.ifeng.com/documentary/discovery/201109/ed52d159-a3f4-4969-972d-c9e6d51d00ff.shtml"; 
    // String url = "http://www.yinyuetai.com/video/271439"; 
    // String url = "http://www.baidu.com/"; 
     
    Video video = VideoUtil.getVideoInfo(url); 
    System.out.println(video);
    System.out.println("视频标题:" + video.getTitle()); 
    System.out.println("视频地址:" + video.getFlashUrl()); 
    System.out.println("视频时长:" + video.getTime()); 
    System.out.println("视频来源:" + video.getSource()); 
    System.out.println("视频简介:" + video.getSummary()); 
    System.out.println("视频缩略图:" + video.getThumbnail()); 
    System.out.println("视频原始地址:" + video.getPageUrl()); 
    System.out.println("视频网页代码:" + video.getHtmlCode()); 
}
}
14 楼 hy0664 2012-02-03  
hy0664 写道
hy0664 写道
在你原代码上加入网易视频的支持:

public static Video getNetEaseVideo(String url) throws Exception {
		Document doc = getURLContent(url);

		String content = doc.html();
		content = content.substring(content.indexOf("topicid"));
		content = content.substring(0,content.indexOf("</script>"));
		content = content.replaceAll("\"","").replaceAll("\n","").trim();
		String contents[] = content.split(";");
		/**
		 * 视频标题
		 */
		String title = getScriptVarByName("title=",contents);
		String topicid = getScriptVarByName("topicid=",contents);
		String vid = getScriptVarByName("vid=",contents);
		/**
		 * 视频缩略图
		 */
		String imgpath = getScriptVarByName("imgpath=",contents);

		/**
		 * 视频地址
		 */
		String flash = "http://img1.cache.netease.com/flvplayer081128/~false~"+topicid+"_"+vid+"~"+imgpath.substring(7,imgpath.length()-4)+"~.swf";
		Video video = new Video();
		video.setTitle(title);
		video.setThumbnail(imgpath);
		video.setFlashUrl(flash);
		video.setSource("网易视频");
		video.setPageUrl(url);
		// video.setSummary(summary);
		video.setHtmlCode(getHtmlCode(flash));
		return video;
	}

private static String getScriptVarByName(String name,String contents[]) {
		String text = "";
		for(String s:contents){
			if(s.contains(name)){
				text = s.substring(s.indexOf(name)+name.length());
				break;
			}
		}
		return text;
	}




再加腾讯视频支持

public static Video getQQVideo(String url) throws Exception {
		Document doc = getURLContent(url);
		/**
		 * 视频标题
		 */
		String vid = url.substring(url.lastIndexOf("/")+1,url.lastIndexOf("."));
		System.out.println(vid);
		String title = doc.title().split("-")[0].trim();
		/**
		 * 视频地址
		 */
		String flash = "http://imgcache.qq.com/tencentvideo_v1/player/TencentPlayer.swf?vid="+vid;
		Video video = new Video();
		video.setTitle(title);
		video.setSource("腾讯视频");
		video.setFlashUrl(flash);
		return video;
	}


忘了两个参数:
	public final static String VIDEO_DOMAIN_NETEASE = "v.163.com/video";//网易
	
	public final static String VIDEO_DOMAIN_QQ = "v.qq.com/play";//QQ
13 楼 hy0664 2012-02-03  
hy0664 写道
在你原代码上加入网易视频的支持:

public static Video getNetEaseVideo(String url) throws Exception {
		Document doc = getURLContent(url);

		String content = doc.html();
		content = content.substring(content.indexOf("topicid"));
		content = content.substring(0,content.indexOf("</script>"));
		content = content.replaceAll("\"","").replaceAll("\n","").trim();
		String contents[] = content.split(";");
		/**
		 * 视频标题
		 */
		String title = getScriptVarByName("title=",contents);
		String topicid = getScriptVarByName("topicid=",contents);
		String vid = getScriptVarByName("vid=",contents);
		/**
		 * 视频缩略图
		 */
		String imgpath = getScriptVarByName("imgpath=",contents);

		/**
		 * 视频地址
		 */
		String flash = "http://img1.cache.netease.com/flvplayer081128/~false~"+topicid+"_"+vid+"~"+imgpath.substring(7,imgpath.length()-4)+"~.swf";
		Video video = new Video();
		video.setTitle(title);
		video.setThumbnail(imgpath);
		video.setFlashUrl(flash);
		video.setSource("网易视频");
		video.setPageUrl(url);
		// video.setSummary(summary);
		video.setHtmlCode(getHtmlCode(flash));
		return video;
	}

private static String getScriptVarByName(String name,String contents[]) {
		String text = "";
		for(String s:contents){
			if(s.contains(name)){
				text = s.substring(s.indexOf(name)+name.length());
				break;
			}
		}
		return text;
	}




再加腾讯视频支持

public static Video getQQVideo(String url) throws Exception {
		Document doc = getURLContent(url);
		/**
		 * 视频标题
		 */
		String vid = url.substring(url.lastIndexOf("/")+1,url.lastIndexOf("."));
		System.out.println(vid);
		String title = doc.title().split("-")[0].trim();
		/**
		 * 视频地址
		 */
		String flash = "http://imgcache.qq.com/tencentvideo_v1/player/TencentPlayer.swf?vid="+vid;
		Video video = new Video();
		video.setTitle(title);
		video.setSource("腾讯视频");
		video.setFlashUrl(flash);
		return video;
	}
12 楼 hy0664 2012-02-03  
在你原代码上加入网易视频的支持:

public static Video getNetEaseVideo(String url) throws Exception {
		Document doc = getURLContent(url);

		String content = doc.html();
		content = content.substring(content.indexOf("topicid"));
		content = content.substring(0,content.indexOf("</script>"));
		content = content.replaceAll("\"","").replaceAll("\n","").trim();
		String contents[] = content.split(";");
		/**
		 * 视频标题
		 */
		String title = getScriptVarByName("title=",contents);
		String topicid = getScriptVarByName("topicid=",contents);
		String vid = getScriptVarByName("vid=",contents);
		/**
		 * 视频缩略图
		 */
		String imgpath = getScriptVarByName("imgpath=",contents);

		/**
		 * 视频地址
		 */
		String flash = "http://img1.cache.netease.com/flvplayer081128/~false~"+topicid+"_"+vid+"~"+imgpath.substring(7,imgpath.length()-4)+"~.swf";
		Video video = new Video();
		video.setTitle(title);
		video.setThumbnail(imgpath);
		video.setFlashUrl(flash);
		video.setSource("网易视频");
		video.setPageUrl(url);
		// video.setSummary(summary);
		video.setHtmlCode(getHtmlCode(flash));
		return video;
	}

private static String getScriptVarByName(String name,String contents[]) {
		String text = "";
		for(String s:contents){
			if(s.contains(name)){
				text = s.substring(s.indexOf(name)+name.length());
				break;
			}
		}
		return text;
	}

11 楼 Hobo86 2011-12-16  
要是把列表的再加上就完美了
10 楼 nuoheng 2011-11-06  
9 楼 liuguihua0823 2011-09-14  
sxitzmg 写道
?????
Exception in thread "main" java.lang.IllegalArgumentException: usage: supply url to fetch
at org.osm.jsoup.helper.Validate.isTrue(Validate.java:45)
at org.osm.jsoup.examples.ListLinks.main(ListLinks.java:16)

视频地址贴一下
8 楼 sxitzmg 2011-09-13  
?????
Exception in thread "main" java.lang.IllegalArgumentException: usage: supply url to fetch
at org.osm.jsoup.helper.Validate.isTrue(Validate.java:45)
at org.osm.jsoup.examples.ListLinks.main(ListLinks.java:16)
7 楼 sghcel 2011-09-13  
标记一下!!1
6 楼 xingxuan2101 2011-09-13  

相关推荐

Global site tag (gtag.js) - Google Analytics