您的位置:首页 > 其它

流媒体开发之-新浪体育NBA视频解析

2013-12-09 00:36 183 查看
当我们去解析新浪体育NBA赛事的时候,有一个项目是视频,它存储的是网页形式,我们需要获取真实地址才能播放,不利用第三方工具,我们也可以去从网页上获取真实地址,首先我们看一下他的一个真实地址http://v.iask.com/v_play_ipad.php?vid=121251907,多个对比可以看到只有vid后面的内容是变化的,所以我们只需要从网页上抓取他的vid内容就可以了,而站点地址的网页里面是有提供这个vid的,有两个地方可以获取,一个是script里面,内容如下:

var $SCOPE = {};
  // 视频
  $SCOPE['video'] = {
    channel:'ty',
    cid:'',
    epgid:'',
    vid:'121242131',
    hd_vid:'0',
    sid:'63230801',
    uid: '6',
    categoryId: '2',
    pid:'6',
    tid:'408',
    pic: 'http://p1.v.iask.com/264/11/121242131_2.jpg',
    actlogActive:1,
    url: window.location.href,
    title:'视频集锦-詹宁斯33分 活塞下半场发力大胜公牛',
    resolution:0,
    isWide:0,
    swfOutsideUrl:'http://you.video.sina.com.cn/api/sinawebApi/outplayrefer.php/vid=121242131_6_bUzmHSE7XWLK+l1lHz2stqkM7KQNt6njnynt71+iJgxaVQSOZorfO4kK4SvXAstA8G9M/s.swf',
    videoData:{
      ipad_vid:'121240242',
      class_code:'1'
    },
    newsid:'6-408-163232',
    ad_state:'1',
    videoStyle:2,
    index:1,
    comment_state:0,
    AllCount:0
  };
  // 其它
  $SCOPE['jsPath'] = 'http://sjs2.sinajs.cn/video/snake_video/js/';
  $SCOPE['cssPath'] = 'http://sjs0.sinajs.cn/video/snake_video/css/';
  $SCOPE['jsVersion'] = '1.0.0.34';
  $SCOPE['cssVersion'] = '1.0.0.14';
  $SCOPE['hotVideoUrl']='http://platform.sina.com.cn/top_news/top?app_key=1841630516&top_channel=video&top_type=day&top_cat=sp_ty_yypdpx&top_time=today&top_show_num=10&top_order=DESC&show_video_info=1&short_title=1';
  // 模块
  var $widget = [];
  // suda 日志
      $SCOPE['sudaData']={
        code:"1420"
      };


里面的vid:'121242131',就是vid后面的内容,但是我们使用jsoup解析不太好用,另一个地方就是他的相关视频 第一个就是当前要解析的视频,里面的标签是video-id="121242131",这个解析比较容易,所以我们解析来解析第二个地方来获取真实地址:

/**
	 * 获取新浪的视频
	 * @param url
	 * @return
	 */
	public VideoDemandModel getVideoDemandModel(String url){
		VideoDemandModel model = new VideoDemandModel();
		try {
			Document doc = Jsoup.connect(url).get();
			Element video_info = doc.getElementById("pl_video_info");
			Element tit = video_info.select("div.tit").first();
			model.setTitle(tit.getElementsByTag("h3").text());
			Element vedioinfo_inner = video_info.select("div.vedioinfo_inner").first();
			model.setDateTime(vedioinfo_inner.select("p.from").first().text());
			Elements ems = vedioinfo_inner.select("em[task=oldinfor]");
			if (ems != null && ems.size() > 0) {
				model.setDescription(ems.first().text().trim());
			}else {
				 ems = vedioinfo_inner.select("em[task=infor]");
				 model.setDescription(ems.first().text().trim());
			}
			Elements videoIds = doc.select("li[video-id]");
			if (videoIds != null) {
				Element li = videoIds.first();
				Element videoLk = li.select("a.videoLk").first();
				String img = videoLk.getElementsByTag("img").first().attr("_src");
				model.setImg(img);
				String time = videoLk.select("span.playTm").first().getElementsByTag("em").first().text();
				model.setDateTime(time);
				model.setUrl_real("http://v.iask.com/v_play_ipad.php?vid="+li.attr("video-id"));
			}
			System.out.println(model.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return model;
	}


解析出的内容如下:

标题:视频信息 图片链接:http://p3.v.iask.com/603/259/121242141_2.jpg站点链接:null上传时间: 视频真实地址:http://v.iask.com/v_play_ipad.php?vid=121242141

使用vlc测试可以播放
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: