package com.newvideo.sohu; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map; import javax.annotation.Resource; import org.apache.log4j.Logger; import org.hibernate.HibernateException; import org.hibernate.Session; import org.springframework.orm.hibernate4.HibernateCallback; import org.springframework.stereotype.Component; import com.newvideo.dao.VideoResourceDao; import com.newvideo.dao.juhe.SoHuVideoDao; import com.newvideo.domain.AdminInfo; import com.newvideo.domain.VideoInfo; import com.newvideo.domain.VideoResource; import com.newvideo.domain.VideoType; import com.newvideo.domain.entity.PlayUrl; import com.newvideo.service.imp.juhe.SoHuService; import com.newvideo.sohu.entity.RootCategory; import com.newvideo.sohu.entity.SecondCategory; import com.newvideo.sohu.entity.SoHuAlbum; import com.newvideo.sohu.entity.SoHuVideo; import com.newvideo.sohu.entity.SohuVideoContent; import com.newvideo.util.JuheVideoUtil; import com.newvideo.util.StringUtil; import com.newvideo.util.TimeUtil; import net.sf.json.JSONObject; @Component public class SoHuUtil { static Logger logger = Logger.getLogger(SoHuUtil.class); @Resource private SoHuService soHuService; @Resource private SoHuVideoDao soHuVideoDao; @Resource private VideoResourceDao videoResourceDao; public SoHuVideoDao getSoHuVideoDao() { return soHuVideoDao; } public void setSoHuVideoDao(SoHuVideoDao soHuVideoDao) { this.soHuVideoDao = soHuVideoDao; } public SoHuService getSoHuService() { return soHuService; } public void setSoHuService(SoHuService soHuService) { this.soHuService = soHuService; } public static List getCategory() { List list = SoHuApi.rootCategoryList(); RootCategory rcg = new RootCategory(); rcg.setCateId(9004); rcg.setCateName("搜狐出品"); list.add(rcg); for (RootCategory rc : list) { System.out.println( "主分类:break;//" + rc.getCateId() + ":break;//" + ":break;//" + rc.getCateCode() + rc.getCateName()); List sList = SoHuApi.secondCategoryList(rc.getCateId()); if (sList != null) for (SecondCategory sc : sList) System.out.println(" case " + sc.getSecondCateCode() + ":break;//" + sc.getSecondCateName()); rc.setScList(sList); } return list; } public static List getSecondCategory(int scode) { List list = new ArrayList(); switch (scode) { // 电视剧 case 101100: // type=; // 偶像剧 case 101101: // 家庭剧 case 101102: // 历史剧 case 101103: // 年代剧 case 101104: // 言情剧 case 101105: // 武侠剧 case 101106: // 古装剧 case 101107: // 都市剧 case 101108: // 农村剧 case 101109: // 军旅剧 case 101110: // 刑侦剧 case 101111: // 喜剧 case 101112: // 悬疑剧 case 101113: // 情景剧 case 101114: // 传记剧 case 101115: // 科幻剧 case 101116: // 动画片 case 101117: // 动作剧 case 101118: // 真人秀 case 101119: // 栏目剧 case 101120: // 谍战剧 case 101121: // 伦理剧 case 101122: // 战争剧 case 101123: // 神话剧 case 101124: // 惊悚剧 case 101127: list.add(150); break;// 剧情片 // 电影 case 100100: // 爱情片 case 100101: // 战争片 case 100102: // 喜剧片 case 100103: // 科幻片 case 100104: // 恐怖片 case 100105: // 动画片 case 100106: // 动作片 case 100107: // 风月片 case 100108: // 剧情片 case 100109: // 歌舞片 case 100110: // 纪录片 case 100111: // 魔幻片 case 100112: // 灾难片 case 100113: // 悬疑片 case 100114: // 传记片 case 100116: // 警匪片 case 100117: // 伦理片 case 100118: // 惊悚片 case 100119: // 谍战片 case 100120: // 历史片 case 100121: // 武侠片 case 100122: // 青春片 case 100123: // 文艺片 case 100135: case 100136: list.add(151); break;// 微电影 // 综艺 case 106100: break;// 访谈 case 106116: break;// 综艺综合 case 106127: break;// 脱口秀 case 106126: break;// 其他 // 动漫 // 游戏 case 128103: list.add(212); break;// 电子竞技 case 128100: list.add(272); break;// 游戏头条 case 128105: break;// 手游 case 128108: list.add(272); break;// 集锦TOP case 128109: list.add(212); break;// 现场赛事 case 128110: list.add(272); break;// 宣传片CG case 128111: list.add(272); break;// 真人秀 case 128112: list.add(212); break;// DOTA/DOTA2 case 128113: list.add(212); break;// 英雄联盟 case 128114: list.add(212); break;// 我的世界 case 128115: break;// 网络游戏 case 128116: break;// 单机游戏 case 128020: break;// 其他 // 搞笑 case 133100: // 疯狂恶搞 case 133102: // 激萌动物 case 133104: // 原创综合 case 133107: // 搞笑综合 case 133108: // 囧人糗事 case 133109: // 逗乐熊娃 case 133110: // 国外搞笑 case 133113: // 恶搞吐槽 case 133122: // 熊娃萌宠 case 133126: // 混剪配音/穿帮 case 133112: // 原创短剧 case 133123: // 奇闻趣事 case 133125: // 搞笑动画 case 133121: // 其他 case 133128: list.add(216); // 音乐歪唱 break; case 133124: list.add(216); list.add(217); break;// 相声小品 case 133129: list.add(216); list.add(220); break;// 萌宠 // 娱乐八卦 case 202101: // 娱乐大事件 case 202100: list.add(219); break;// 影视赏析 // 科技 case 127100: // 随身数码 case 127102: // 智能手机 case 127103: // PC/PAD case 127115: // 智能家居 case 127119: // 科技评测 case 127116: // IT业界 case 127120: // 软件应用 case 127106: // 科技资讯 case 127117: // 科技广告 case 127118: // 其他 case 127109: // 新奇酷玩 case 127121: list.add(221); break;// 航拍 // 汽车 case 126100: // 车讯 case 126101: // 新车 case 126102: // 试车 case 126107: // 赛车 case 126120: // 用车常识 case 126109: // 用车 case 126111: // 玩车 case 126116: // 摩托 case 126117: // 试驾 case 126118: // 评测 case 126124: // 试驾评测 case 126108: // 香车美女 case 126125: // 新车资讯 case 126121: // 玩车改装 case 126122: // 交通警示 case 126123: // 其他 case 126126: // 业界动态 case 126119: list.add(226); break;// 赛事 // 公开课 case 204100: // 社会人文 case 204101: // 名师在线 case 204102: // 纪实纪录 case 204103: // 国内大学 case 204104: list.add(225); break;// 职业考试 // 做饭 case 208100: // 家常菜 case 208101: // 日韩料理 case 208102: // 西餐 case 208103: list.add(228); break;// 甜品烘焙 // 旅游 case 131120: // 城市 case 131128: // 国内游 case 131130: // 东南亚 case 131129: // 旅游综合 case 131107: // 人文 case 131131: // 欧洲 case 131132: // 澳洲 case 131133: // 奇闻探险 case 131113: // 旅游攻略 case 131126: // 旅游资讯 case 131114: // 风俗趣闻 case 131117: list.add(229); break;// 其他 // 健康养身 case 209100: // 医学常识 case 209101: list.add(230); break;// 养生 // 时尚 case 190100: // 服装饰品 case 190107: // 时尚街拍 case 190104: // 服饰搭配 case 190108: // 明星名模 case 190106: list.add(232); break;// 其他 // 母婴 case 132119: // 少儿卡通 case 132120: // 母婴宝典 case 132121: // 萌娃秀 case 132123: // 孕产知识 case 132124: // 育儿健康 case 132125: list.add(233); break;// 早教 // 运动健身 case 125100: list.add(273); break;// 体育资讯 case 125103: list.add(236); break;// 足球 case 125111: list.add(273); break;// 体育综合 case 125104: list.add(234); break;// 极限运动 case 125116: list.add(292); break;// 球类 case 125117: list.add(273); break;// 运动装备 case 125118: list.add(273); break;// 舞蹈 case 125119: list.add(273); break;// 跑步 case 125120: list.add(273); break;// 运动常识 case 125121: list.add(235); break;// 健身塑形 // 音乐 case 121114: list.add(304); break;// 原创 case 121115: break;// 音乐综合 case 121121: list.add(304); break;// 原创MV case 121122: break;// 音乐现场 case 121120: break;// 其他 case 121123: break;// 好歌曲 case 121124: list.add(304); break;// 翻唱 case 121125: list.add(280); break;// 音乐策划 case 121126: list.add(280); break;// 花絮 // 千里眼 case 212109: list.add(291); break;// 镜头故事 } return list; } @SuppressWarnings("unchecked") public void parseAll() { List list =new ArrayList(); //SoHuApi.rootCategoryList(); RootCategory rc = new RootCategory(); rc.setCateId(9004); list.add(rc); Collections.reverse(list); // 获取内容列表 for (RootCategory rcy : list) { final RootCategory fcy = rcy; new Thread(new Runnable() { public void run() { Map map = SoHuApi.getContentList(fcy.getCateId(), 0, 1, 20); if (map.get("count") != null) { int count = Integer.parseInt(map.get("count") + ""); if (count > 1000) count = 1000; for (int i = 1; i < count / 50 + 2; i++) { System.out.println("分类--" + fcy.getCateName()); map = SoHuApi.getContentList(fcy.getCateId(), 0, i, 50); List slist = (List) map.get("data"); if (slist != null && slist.size() > 0) { for (SohuVideoContent svc : slist) { final String name = svc.getVideo_name(); if (!(Boolean) videoResourceDao.excute(new HibernateCallback() { public Boolean doInHibernate(Session session) throws HibernateException { return JuheVideoUtil.isNeedAdd(session, name); } })) continue; System.out.println("分类--" + fcy.getCateName() + " 页码:" + i); SoHuAlbum sa = SoHuApi.getAlbumDetail(svc.getAid()); if (sa != null) {// 有专辑详情 sa.setArea(svc.getArea()); if (!StringUtil.isNullOrEmpty(sa.getArea())) { if (sa.getArea().contains("内地")) sa.setArea("内地"); if (sa.getArea().contains("韩")) sa.setArea("韩国"); if (sa.getArea().contains("日")) sa.setArea("日本"); if (sa.getArea().contains("港")) sa.setArea("香港"); if (sa.getArea().contains("台")) sa.setArea("台湾"); } sa.setTip(svc.getTip()); String c = SoHuApi.getVideoList(sa.getAid(), 1, 20).get("count") + ""; if (!StringUtil.isNullOrEmpty(c)) { List vlist = new ArrayList(); for (int p = 1; p < Integer.parseInt(c) / 50 + 2; p++) { List videoList = (List) SoHuApi .getVideoList(sa.getAid(), p, 50).get("data"); if (videoList != null && videoList.size() > 0) { vlist.addAll(videoList); } } sa.setVideoList(vlist); } Collections.sort(sa.getVideoList(), new Comparator() { public int compare(SoHuVideo o1, SoHuVideo o2) { return o2.getVideo_order() - o1.getVideo_order(); } }); boolean isUpdate = false; try { if (sa.getVideoList().size() > 1) { if (sa.getVideoList().get(0).getVideo_order() > soHuService .getLatestSoHuVideo(sa.getAid()).getVideo_order()) isUpdate = true; } } catch (Exception e) { } String id = soHuService.addAlbum(sa); sa.setId(id); // 添加到视频 String vid = soHuService.addToVideoInfo(sa, isUpdate); // 添加到分类视频 List li = soHuService.getVideoTypeList(sa); for (VideoType vt : li) { soHuService.addToCategoryVideo(vid, vt.getId()); } } } } } } } }).start(); } } private static VideoType getVideoType(String catCode) { if (StringUtil.isNullOrEmpty(catCode)) return null; String mainCode = catCode.split(";")[0]; int id = 1; if (Integer.parseInt(mainCode) < 1000) { switch (Integer.parseInt(mainCode)) { case 100: id = 151; break; case 101: id = 150; break; case 106: id = 152; break; case 107: break; case 115: id = 153; break; case 119: break; case 121: break; case 124: break; case 125: break; case 126: break; case 127: break; case 128: break; case 129: break; case 130: break; case 131: break; case 132: break; case 133: break; case 190: break; case 192: break; case 194: break; case 204: break; } } else { int code = Integer.parseInt(mainCode); if (code >= 101100 && code <= 101127) id = 150; else if (code >= 100100 && code <= 100135) id = 151; else if (code >= 115100 && code <= 115140) id = 153; else if (code >= 106100 && code <= 106140)// 106100 id = 152; } return new VideoType(id); } private static String getTag(SoHuAlbum sa) { VideoType vt = getVideoType(sa.getCate_code()); String tag = ""; if (vt.getId() != 0) { if (vt.getId() == 151) {// 电影 tag = "评分:" + sa.getScore(); } else if (vt.getId() == 150) {// 电视剧 if ("1".equalsIgnoreCase(sa.getOver()))// 完结 tag = sa.getLatest_video_count() + "集全"; else tag = "更新至" + sa.getLatest_video_count() + "集"; } else if (vt.getId() == 152) {// 综艺 if (sa.getVideoList() != null && sa.getVideoList().size() > 0) { SoHuVideo sv = sa.getVideoList().get(0); String date = StringUtil.isNullOrEmpty(sv.getShow_date()) ? sv.getCreate_date() : sv.getShow_date(); tag = "更新至" + date; } } else if (vt.getId() == 153) {// 动漫 if ("1".equalsIgnoreCase(sa.getOver()))// 完结 tag = sa.getLatest_video_count() + "集全"; else tag = "更新至" + sa.getLatest_video_count() + "集"; } else { if (sa.getVideoList() != null && sa.getVideoList().size() > 0) { SoHuVideo sv = sa.getVideoList().get(0); String date = StringUtil.isNullOrEmpty(sv.getShow_date()) ? sv.getCreate_date() : sv.getShow_date(); tag = date; } } } return tag; } public static VideoInfo convertAlBumToVideoInfo(SoHuAlbum sa) { String date = ""; int year = 2016; int month = 1; int day = 1; VideoInfo vi = new VideoInfo(); if (sa.getVideoList() != null && sa.getVideoList().size() > 0) { SoHuVideo sv = sa.getVideoList().get(0); date = StringUtil.isNullOrEmpty(sv.getShow_date()) ? sv.getCreate_date() : sv.getShow_date(); long time = TimeUtil.convertGernalTime(date, "yyyy-MM-dd"); Calendar ca = Calendar.getInstance(); ca.setTimeInMillis(time); day = ca.get(Calendar.DAY_OF_MONTH); month = ca.get(Calendar.MONTH) + 1; year = ca.get(Calendar.YEAR); vi.setUpdatetime(time + ""); vi.setLatestHpicture(sv.getHor_high_pic()); vi.setLatestVpicture(sv.getVer_high_pic()); } vi.setAdmin(new AdminInfo("1")); vi.setArea(""); vi.setBaseurl(""); vi.setBeizhu(""); vi.setCanSave(false); vi.setCommentCount(0); if ("0".equalsIgnoreCase(sa.getTrailer())) vi.setContentType(1);// 正片 else vi.setContentType(2);// 片花 vi.setCreatetime(System.currentTimeMillis() ); vi.setCommentCount(0); vi.setDay(day + ""); vi.setDirector(sa.getDirector()); vi.setDuration("0"); vi.setFinish("1"); vi.setFocus(""); vi.setIntroduction(sa.getAlbum_desc()); vi.setKeyword(""); vi.setLeafctgs(""); vi.setMainActor(sa.getModerator()); vi.setMonth(month + ""); vi.setName(sa.getAlbum_name()); vi.setNowNumber("0"); vi.setOrderby(20 + ""); vi.setPicture(""); vi.setPlayPicture(""); vi.setQulity(""); vi.setScore(sa.getScore()); vi.setShare("0"); vi.setShow("1"); vi.setShowType(1); vi.setTag(sa.getTip()); vi.setThirdType("1"); vi.setTotalNumber("0"); vi.setType(""); vi.setVideoType(getVideoType(sa.getCate_code())); vi.setWatchCount(0 + ""); vi.setYear(year + ""); vi.setVpicture(sa.getVer_high_pic()); vi.setHpicture(sa.getHor_high_pic()); vi.setPicture(sa.getVer_high_pic()); vi.setVideocount(sa.getVideoList() != null ? sa.getVideoList().size() : 1); vi.setArea(sa.getArea()); return vi; } @SuppressWarnings("unchecked") public int getShowType(final String vid) { return (Integer) soHuVideoDao.excute(new HibernateCallback() { public Integer doInHibernate(Session session) throws HibernateException { try { List list = session.createQuery("select vs.album From VideoSoHu vs where vs.video.id=?") .setParameter(0, vid).list(); if (list != null && list.size() > 0) { String cate = list.get(0).getCate_code(); if (!StringUtil.isNullOrEmpty(cate)) { cate = cate.split(";")[0]; if (getVideoType(cate).getId() == 150 || getVideoType(cate).getId() == 153)// 电视剧和动漫 return 2; } } } catch (Exception e) { e.printStackTrace(); } return 1; } }); } public PlayUrl getPlayUrl(String detailSystemId, String resourceId, String type, String id) { logger.info(String.format("%s#%s#%s#%s", detailSystemId, resourceId, type, id)); PlayUrl playUrl = new PlayUrl(); playUrl.setPlayType(2); try { List list = videoResourceDao.list("from VideoResource vr where vr.id=" + resourceId); if (list != null && list.size() > 0) playUrl.setResource(list.get(0)); playUrl.setPlayType(2); List svList = soHuVideoDao.list("from SoHuVideo sv where sv.id=" + id); if (svList != null && svList.size() > 0) { JSONObject object = new JSONObject(); SoHuVideo sv = svList.get(0); if (sv != null) {// 添加 soHuService.addPlayStatistics(detailSystemId, sv); } object.put("aid", sv.getAid()); object.put("site", sv.getSite() + ""); object.put("vid", sv.getVid()); // playUrl.setUrl(sv.getUrl_html5()); playUrl.setUrl( String.format("http://video.yeshitv.com:8089/BuWan/sohuplay.jsp?vid=%s&width=%s&height=%s", sv.getVid(), 640 + "", 480 + "")); playUrl.setParams(object.toString()); } else return null; } catch (Exception e) { e.printStackTrace(); } return playUrl; } }