Commit 9b03fd8efa1efb08ff06668c3d12bbb77179bed6
Merge branch 'zhubo' into 'master'
ugc项目迁移 See merge request !3
Showing
5 changed files
with
208 additions
and
7 deletions
.settings/org.eclipse.wst.common.component
| 1 | -<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | -<project-modules id="moduleCoreId" project-version="1.5.0"> | |
| 1 | +<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> | |
| 3 | 2 | <wb-module deploy-name="cnlive_live_web"> |
| 4 | 3 | <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> |
| 5 | 4 | <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> | ... | ... |
pom.xml
| ... | ... | @@ -53,11 +53,6 @@ |
| 53 | 53 | <artifactId>cnlive_live_model</artifactId> |
| 54 | 54 | <version>0.0.1-SNAPSHOT</version> |
| 55 | 55 | </dependency> |
| 56 | - <dependency> | |
| 57 | - <groupId>com.cnlive</groupId> | |
| 58 | - <artifactId>cnlive_media_tools</artifactId> | |
| 59 | - <version>1.0.0</version> | |
| 60 | - </dependency> | |
| 61 | 56 | </dependencies> |
| 62 | 57 | <packaging>war</packaging> |
| 63 | 58 | </project> | ... | ... |
src/main/java/com/cnlive/mz/live/action/CopyOfIndexAction.java
0 → 100644
| 1 | +/** | |
| 2 | + * Project Name:cnlive_live_web | |
| 3 | + * File Name:IndexAction.java | |
| 4 | + * Package Name:com.cnlive.mz.live.action | |
| 5 | + * Date:2015年8月3日下午3:18:31 | |
| 6 | + * Copyright (c) 2015, cnlive.com All Rights Reserved. | |
| 7 | + * | |
| 8 | + */ | |
| 9 | + | |
| 10 | +package com.cnlive.mz.live.action; | |
| 11 | + | |
| 12 | +import java.io.File; | |
| 13 | +import java.util.HashMap; | |
| 14 | +import java.util.LinkedHashMap; | |
| 15 | +import java.util.Map; | |
| 16 | + | |
| 17 | +import net.sf.json.JSONObject; | |
| 18 | + | |
| 19 | +import org.apache.commons.lang.StringUtils; | |
| 20 | +import org.smart4j.framework.ioc.annotation.Inject; | |
| 21 | +import org.smart4j.framework.mvc.annotation.Action; | |
| 22 | +import org.smart4j.framework.mvc.annotation.Request; | |
| 23 | +import org.smart4j.framework.mvc.bean.Params; | |
| 24 | + | |
| 25 | +import com.cnlive.mz.live.bean.Account; | |
| 26 | +import com.cnlive.ksyun.KsYun; | |
| 27 | +import com.cnlive.mz.commons.CNLiveFFmpeg; | |
| 28 | +import com.cnlive.mz.commons.CnliveUtil; | |
| 29 | +import com.cnlive.mz.commons.DateUtil; | |
| 30 | +import com.cnlive.mz.commons.JsonUtil; | |
| 31 | +import com.cnlive.mz.commons.net.HttpReq; | |
| 32 | +import com.cnlive.mz.commons.sys.Scp; | |
| 33 | +import com.cnlive.mz.live.bean.ResultBean; | |
| 34 | +import com.cnlive.mz.live.entity.TApp; | |
| 35 | +import com.cnlive.mz.live.entity.TDispatchServer; | |
| 36 | +import com.cnlive.mz.live.entity.TUser; | |
| 37 | +import com.cnlive.mz.live.entity.TVideo; | |
| 38 | +import com.cnlive.mz.live.service.TActivityService; | |
| 39 | +import com.cnlive.mz.live.service.TAppService; | |
| 40 | +import com.cnlive.mz.live.service.TChannelService; | |
| 41 | +import com.cnlive.mz.live.service.TDispatchServerService; | |
| 42 | +import com.cnlive.mz.live.service.TUserService; | |
| 43 | +import com.cnlive.mz.live.service.TVideoService; | |
| 44 | +import com.cnlive.mz.live.service.TWowzaService; | |
| 45 | + | |
| 46 | +@Action | |
| 47 | +public class CopyOfIndexAction { | |
| 48 | + @Inject | |
| 49 | + private TChannelService tChannelService; | |
| 50 | + @Inject | |
| 51 | + private TActivityService tActivityService; | |
| 52 | + @Inject | |
| 53 | + private TWowzaService tWowzaService; | |
| 54 | + | |
| 55 | + @Inject | |
| 56 | + private TUserService tUserService; | |
| 57 | + | |
| 58 | + @Request.Post("/api/video/uploadNotify") | |
| 59 | + public void uploadNotify(Params params) { | |
| 60 | + String video_uuid = params.getString("video_uuid"); | |
| 61 | + String upload_type = params.getString("upload_type"); | |
| 62 | + String video_type = params.getString("video_type"); | |
| 63 | + String state = params.getString("state"); | |
| 64 | + notify(video_uuid); | |
| 65 | + // renderJson(new ResultBean(100, "请求成功", null)); | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * sdk 方式上传 | |
| 70 | + */ | |
| 71 | + @Request.Post("/api/video/supload") | |
| 72 | + public void supload(Params params) { | |
| 73 | + ResultBean resultBean = new ResultBean(); | |
| 74 | + try { | |
| 75 | + Map data = new LinkedHashMap(); | |
| 76 | + String app_access_key = params.getString("app_access_key"); | |
| 77 | + String user_access_key = params.getString("user_access_key"); | |
| 78 | + String server_access_key = params.getString("server_access_key"); | |
| 79 | + String uuid = CnliveUtil.getUUID(); | |
| 80 | + String md5 = params.getString("md5"); | |
| 81 | + TVideo tVideo = new TVideo(); | |
| 82 | + tVideo.setCustom_args(params.getString("custom_args")); | |
| 83 | + tVideo.setRelation_id(params.getString("relation_id")); | |
| 84 | + tVideo.setName(params.getString("name")); | |
| 85 | + tVideo.setVideo_type(params.getString("video_type")); | |
| 86 | + tVideo.setPlat(params.getString("plat")); | |
| 87 | + tVideo.setState(207); | |
| 88 | + tVideo.setMd5(md5); | |
| 89 | + tVideo.setVideo_uuid(uuid); | |
| 90 | + tVideo.setTitle(params.getString("title")); | |
| 91 | + tVideo.setVideo_type(params.getString("video_type")); | |
| 92 | + tVideo.setDescription(params.getString("description")); | |
| 93 | + saveSdkVideoSrc(tVideo, server_access_key, user_access_key, app_access_key); | |
| 94 | + resultBean.setCode(100); | |
| 95 | + resultBean.setMessage("请求成功"); | |
| 96 | + data.put("video_uuid", uuid); | |
| 97 | + resultBean.setData(data); | |
| 98 | + } catch (Exception e) { | |
| 99 | + e.printStackTrace(); | |
| 100 | + } | |
| 101 | + // renderJson(resultBean); | |
| 102 | + } | |
| 103 | + | |
| 104 | + TDispatchServerService tDispatchServerService; | |
| 105 | + TAppService tAppService; | |
| 106 | + TVideoService tVideoService; | |
| 107 | + | |
| 108 | + public void saveSdkVideoSrc(TVideo tVideo, String server_access_key, String user_access_key, String app_access_key) { | |
| 109 | + TDispatchServer dispatchServer = tDispatchServerService.getServerByAccessKey(server_access_key); | |
| 110 | + TUser user = tUserService.getUserByAccessKey(user_access_key); | |
| 111 | + TApp app = tAppService.getAppByAccessKey(app_access_key); | |
| 112 | + int video_type = Integer.parseInt(tVideo.getVideo_type()); | |
| 113 | + String name = tVideo.getName(); | |
| 114 | + tVideo.setT_app_id(app.getId()); | |
| 115 | + tVideo.setT_user_id(user.getId()); | |
| 116 | + tVideo.setT_dispatch_server_id(dispatchServer.getId()); | |
| 117 | + tVideo.setState(207); | |
| 118 | + tVideoService.save(tVideo); | |
| 119 | + } | |
| 120 | + | |
| 121 | + public void notify(String video_uuid) { | |
| 122 | + TVideo video = tVideoService.getVideoByUuId(video_uuid); | |
| 123 | + tVideoService.updateState(video.getId(), 302); | |
| 124 | + NotifyThread t = new NotifyThread(video); | |
| 125 | + t.start(); | |
| 126 | + } | |
| 127 | + | |
| 128 | + public String tempPath = "/opt/video/"; | |
| 129 | + | |
| 130 | + class NotifyThread extends Thread { | |
| 131 | + TVideo video; | |
| 132 | + | |
| 133 | + NotifyThread(TVideo video) { | |
| 134 | + this.video = video; | |
| 135 | + } | |
| 136 | + | |
| 137 | + @Override | |
| 138 | + public void run() { | |
| 139 | + TDispatchServer dispatchServer = tDispatchServerService.getDispatchServerById(video | |
| 140 | + .getT_dispatch_server_id()); | |
| 141 | + String floder = "/home/lijielong/video/storage/";// dispatchServer.getStr("floder"); | |
| 142 | + String account = dispatchServer.getAccount(); | |
| 143 | + Account acc = (Account) JsonUtil.getDtoFromJsonObjStr(account, Account.class); | |
| 144 | + String name = video.getName(); | |
| 145 | + String md5 = video.getMd5(); | |
| 146 | + String ip = dispatchServer.getIp(); | |
| 147 | + String remoteFile = floder + md5 + "/" + name; | |
| 148 | + boolean flag = Scp.get(ip, acc.getS_name(), acc.getS_password(), tempPath, remoteFile); | |
| 149 | + if (flag) { | |
| 150 | + String localFilePath = tempPath + name; | |
| 151 | + File localFile = new File(localFilePath); | |
| 152 | + String basePath = tempPath + DateUtil.getDays("yyyy/MM/dd/"); | |
| 153 | + new File(basePath).mkdirs(); | |
| 154 | + String imageKey = DateUtil.getDays("yyyy/MM/dd/") + video.getVideo_uuid() + ".jpg"; | |
| 155 | + String imagePath = tempPath + imageKey; | |
| 156 | + CNLiveFFmpeg ffmpeg = new CNLiveFFmpeg(localFilePath); | |
| 157 | + String w = ffmpeg.getWidth(); | |
| 158 | + String h = ffmpeg.getHeight(); | |
| 159 | + int width = Integer.parseInt(w); | |
| 160 | + int height = Integer.parseInt(h); | |
| 161 | + CNLiveFFmpeg.getPreviewImg(localFilePath, imagePath); | |
| 162 | + | |
| 163 | + File image = new File(imagePath); | |
| 164 | + if (!image.exists()) { | |
| 165 | + image = new File("/usr/local/tomcat/webapps/ROOT/resource/assets/images/336x220.jpg"); | |
| 166 | + } | |
| 167 | + String ks3ImagePath = putToKS3(image, imageKey); | |
| 168 | + String ks3VideoPath = putToKS3(localFile, DateUtil.getDays("yyyy/MM/dd/") + name); | |
| 169 | + Map map = new HashMap(); | |
| 170 | + map.put("file_path", ks3VideoPath); | |
| 171 | + map.put("preview_image", ks3ImagePath); | |
| 172 | + tVideoService.update(video.getId(), map); | |
| 173 | + } else { | |
| 174 | + System.out.println("scp get file fail " + remoteFile); | |
| 175 | + } | |
| 176 | + } | |
| 177 | + } | |
| 178 | + | |
| 179 | + public String putToKS3(File file, String key) { | |
| 180 | + KsYun yun = new KsYun(false); | |
| 181 | + yun.singlePut("cnlive-ugc", key, file); | |
| 182 | + return "http://cnlive-ugc.ks3-cn-beijing.ksyun.com/" + key; | |
| 183 | + } | |
| 184 | + | |
| 185 | + private void pushToCms(TVideo video, String start_time, String endTime) { | |
| 186 | + String url = "http://icms.staff.cnlive.com/icms_service/api/ugcContentSave.do"; | |
| 187 | + JSONObject obj = JSONObject.fromObject(video.getCustom_args()); | |
| 188 | + Map map = new HashMap(); | |
| 189 | + map.put("MAM_UUID", video.getName()); | |
| 190 | + map.put("MAM_USERID", String.valueOf(obj.get("userId"))); | |
| 191 | + map.put("MAM_NickName", obj.get("nickName")); | |
| 192 | + map.put("MAM_Title", video.getTitle()); | |
| 193 | + map.put("MAM_Description", video.getDescription()); | |
| 194 | + map.put("MAM_PublishDate", start_time); | |
| 195 | + map.put("MAM_VideoUrl", video.getFile_path()); | |
| 196 | + map.put("MAM_VideoHUrl", video.getFile_path()); | |
| 197 | + map.put("MAM_VideoUHUrl", video.getFile_path()); | |
| 198 | + map.put("MAM_VideoLUrl", video.getFile_path()); | |
| 199 | + if (StringUtils.isNotEmpty(endTime)) { | |
| 200 | + map.put("MAM_EndTime", endTime); | |
| 201 | + } | |
| 202 | + JSONObject jsonObj = JSONObject.fromObject(map); | |
| 203 | + String str = HttpReq.postRequestWidthResult(url, "json", jsonObj.toString()); | |
| 204 | + System.out.println("测试期间:调用cms" + str); | |
| 205 | + } | |
| 206 | + | |
| 207 | +} | ... | ... |
target/classes/com/cnlive/mz/live/LiveUtils.class deleted
100644 → 0
No preview for this file type
target/test-classes/com/cnlive/live/web/AppTest.class deleted
100644 → 0
No preview for this file type