package com.newvideo.util.video; import java.util.List; import org.apache.log4j.Logger; import com.newvideo.dao.BaseDao; import com.newvideo.domain.YouKuVideoUrl; import net.sf.json.JSONArray; import net.sf.json.JSONObject; public class UCVideoParser { static Logger logger = Logger.getLogger(UCVideoParser.class); public static String parseData(String result) { JSONObject object =JSONObject.fromObject(result); JSONObject data = object.optJSONObject("data"); JSONArray array = data.optJSONArray("videoList"); if (array != null && array.size() > 0) { JSONObject obj = array.optJSONObject(0); JSONArray fa = obj.optJSONArray("fragment"); if (fa.size() > 1) logger.info(result); return fa.optJSONObject(0).optString("url"); } logger.error(result); return ""; } public static String getRequestUrl(String url) { return "http://m.uczzd.cn/iflow/api/v1/article/video/parse?pageUrl=" + (url.contains("?") ? url.split("\\?")[0] : url); } public static YouKuVideoUrl getYouKuVideo(String url) { BaseDao dao = new BaseDao(); List list = dao.list( "from YouKuVideoUrl yk where yk.url=?", new String[] { url.contains("?") ? url.split("\\?")[0] : url }); if (list != null && list.size() > 0) return list.get(0); else return null; } public static void updateYouKuVideo(String url, String realUrl) { BaseDao dao = new BaseDao(); List list = dao.list( "from YouKuVideoUrl yk where yk.url=?", new String[] { url.contains("?") ? url.split("\\?")[0] : url }); if (list != null && list.size() > 0) { list.get(0).setRealurl(realUrl); list.get(0).setUpdatetime(System.currentTimeMillis() + ""); dao.update(list.get(0)); } else { YouKuVideoUrl yv = new YouKuVideoUrl(); yv.setRealurl(realUrl); yv.setUpdatetime(System.currentTimeMillis() + ""); yv.setUrl(url.contains("?") ? url.split("\\?")[0] : url); dao.create(yv); } } }