Commit 3d04b98258d46826adccc5b2f5cce5b156f5eaaa

Authored by 刘基城
1 parent 61bf205c

添加点播云

src/main/java/com/cnlive/mz/live/action/UgcLiveAction.java
@@ -11,7 +11,6 @@ package com.cnlive.mz.live.action; @@ -11,7 +11,6 @@ package com.cnlive.mz.live.action;
11 11
12 import java.util.ArrayList; 12 import java.util.ArrayList;
13 import java.util.HashMap; 13 import java.util.HashMap;
14 -import java.util.List;  
15 import java.util.Map; 14 import java.util.Map;
16 15
17 import org.apache.commons.lang.StringUtils; 16 import org.apache.commons.lang.StringUtils;
@@ -103,9 +102,9 @@ public class UgcLiveAction { @@ -103,9 +102,9 @@ public class UgcLiveAction {
103 log.error("创建活动失败,活动ID已存在"); 102 log.error("创建活动失败,活动ID已存在");
104 return rb; 103 return rb;
105 } else { 104 } else {
106 - boolean flag = ugcLiveService.create(params);  
107 - if (flag) {  
108 - map.put("location", com.cnlive.mz.live.common.Constants.KS_HOST_UP_RTMP + channelID + "?vdoid=" + activityId); 105 + TLive tLiv = ugcLiveService.create(params);
  106 + if (tLiv!=null) {
  107 + map.put("location", tLiv.getPush_url());
109 rb.setData(map); 108 rb.setData(map);
110 rb.setErrorCode("0"); 109 rb.setErrorCode("0");
111 rb.setErrorMessage("创建活动成功"); 110 rb.setErrorMessage("创建活动成功");
src/main/java/com/cnlive/mz/live/action/VodIpsAction.java
1 package com.cnlive.mz.live.action; 1 package com.cnlive.mz.live.action;
2 2
  3 +import java.io.File;
  4 +import java.io.IOException;
3 import java.util.HashMap; 5 import java.util.HashMap;
  6 +import java.util.Iterator;
4 import java.util.Map; 7 import java.util.Map;
5 8
  9 +import net.sf.json.JSONArray;
  10 +import net.sf.json.JSONObject;
  11 +
  12 +import org.apache.commons.io.FileUtils;
  13 +import org.apache.commons.lang.StringUtils;
6 import org.apache.log4j.Logger; 14 import org.apache.log4j.Logger;
7 import org.smart4j.framework.ioc.annotation.Inject; 15 import org.smart4j.framework.ioc.annotation.Inject;
8 import org.smart4j.framework.mvc.annotation.Action; 16 import org.smart4j.framework.mvc.annotation.Action;
@@ -11,6 +19,10 @@ import org.smart4j.framework.mvc.bean.Params; @@ -11,6 +19,10 @@ import org.smart4j.framework.mvc.bean.Params;
11 import org.smart4j.framework.mvc.bean.Redirect; 19 import org.smart4j.framework.mvc.bean.Redirect;
12 import org.smart4j.framework.mvc.bean.ResultBean; 20 import org.smart4j.framework.mvc.bean.ResultBean;
13 21
  22 +import com.cnlive.mz.live.bean.RedisBean;
  23 +import com.cnlive.mz.live.common.JedisUtil;
  24 +import com.cnlive.mz.live.common.JedisUtil.Strings;
  25 +import com.cnlive.mz.live.common.SerializeUtil;
14 import com.cnlive.mz.live.service.VodIpsServer; 26 import com.cnlive.mz.live.service.VodIpsServer;
15 27
16 /** 28 /**
@@ -29,10 +41,10 @@ public class VodIpsAction { @@ -29,10 +41,10 @@ public class VodIpsAction {
29 @Request.Get("/vodips/h5") 41 @Request.Get("/vodips/h5")
30 public Redirect h5(Params params) { 42 public Redirect h5(Params params) {
31 System.out.println(params); 43 System.out.println(params);
32 - String vId=params.getString("vId");  
33 - int rate=params.getInt("rate"); 44 + String vId = params.getString("vId");
  45 + int rate = params.getInt("rate");
34 Redirect r = new Redirect(); 46 Redirect r = new Redirect();
35 - String url=vodIpsServer.getH5PlayUrl(vId, rate); 47 + String url = vodIpsServer.getH5PlayUrl(vId, rate);
36 r.setRedirectUrl(url); 48 r.setRedirectUrl(url);
37 return r; 49 return r;
38 } 50 }
@@ -40,9 +52,9 @@ public class VodIpsAction { @@ -40,9 +52,9 @@ public class VodIpsAction {
40 @Request.Get("/vodips/app") 52 @Request.Get("/vodips/app")
41 public Redirect app(Params params) { 53 public Redirect app(Params params) {
42 System.out.println(params); 54 System.out.println(params);
43 - String vId=params.getString("vId");  
44 - int rate=params.getInt("rate");  
45 - String url=vodIpsServer.getAppPlayUrl(vId, rate); 55 + String vId = params.getString("vId");
  56 + int rate = params.getInt("rate");
  57 + String url = vodIpsServer.getAppPlayUrl(vId, rate);
46 Redirect r = new Redirect(); 58 Redirect r = new Redirect();
47 r.setRedirectUrl(url); 59 r.setRedirectUrl(url);
48 return r; 60 return r;
@@ -51,15 +63,116 @@ public class VodIpsAction { @@ -51,15 +63,116 @@ public class VodIpsAction {
51 @Request.Get("/vodips/swf") 63 @Request.Get("/vodips/swf")
52 public ResultBean flash(Params params) { 64 public ResultBean flash(Params params) {
53 System.out.println(params); 65 System.out.println(params);
54 - String vId=params.getString("vId");  
55 - int rate=params.getInt("rate");  
56 - String url=vodIpsServer.getFlashPlayUrl(vId, rate); 66 + String vId = params.getString("vId");
  67 + int rate = params.getInt("rate");
  68 + String url = vodIpsServer.getFlashPlayUrl(vId, rate);
57 ResultBean rb = new ResultBean(); 69 ResultBean rb = new ResultBean();
58 Map map = new HashMap(); 70 Map map = new HashMap();
59 - map.put("videoUrl",url); 71 + map.put("videoUrl", url);
60 rb.setData(map); 72 rb.setData(map);
61 rb.setErrorCode("0"); 73 rb.setErrorCode("0");
62 rb.setErrorMessage("成功"); 74 rb.setErrorMessage("成功");
63 return rb; 75 return rb;
64 } 76 }
  77 +
  78 + @Request.Get("/vodips/init")
  79 + public ResultBean init() {
  80 + JedisUtil jedisUtil = JedisUtil.getInstance();
  81 + JedisUtil.Strings strings = jedisUtil.new Strings();
  82 + File files[] = new File("/root/json").listFiles();
  83 + for (int i = 0; i < files.length; i++) {
  84 + File f = files[i];
  85 + System.out.println(f.getName());
  86 + String jsob = "";
  87 + try {
  88 + jsob = FileUtils.readFileToString(f,"utf-8");
  89 + } catch (IOException e) {
  90 + e.printStackTrace();
  91 + }
  92 + JSONObject obj=null;
  93 + boolean succ=true;
  94 + try {
  95 + obj = JSONObject.fromObject(jsob);
  96 + } catch (Exception e) {
  97 + //e.printStackTrace();
  98 + succ=false;
  99 + System.out.println("cuo wu");
  100 + }
  101 + if (succ) {
  102 + f.delete();
  103 + RedisBean rb = new RedisBean();
  104 + rb.setColumn(obj.getString("column"));
  105 + rb.setColumn_id(obj.getString("column_id"));
  106 + rb.setCreate_time(obj.getString("create_time"));
  107 + rb.setDescribe(obj.getString("describe"));
  108 + rb.setDuration(obj.getString("duration"));
  109 + rb.setIcms_url(obj.getString("icms_url"));
  110 + rb.setPrg_type(obj.getString("prg_type"));
  111 + String state = obj.getString("state");
  112 + if (StringUtils.isEmpty(state)) {
  113 + rb.setState("同步完成");
  114 + } else {
  115 + rb.setState(state);
  116 + }
  117 + rb.setSub_title(obj.getString("sub_title"));
  118 + rb.setTitle(obj.getString("title"));
  119 + rb.setUuid(obj.getString("uuid"));
  120 +
  121 + JSONArray fiarr = obj.getJSONArray("files");
  122 + for (Iterator iterator = fiarr.iterator(); iterator.hasNext();) {
  123 + Object object = (Object) iterator.next();
  124 + String url = object.toString();
  125 + if (url.contains("_101.jpg")) {
  126 + rb.setImage2(url);
  127 + }
  128 + if (url.contains("_100.jpg")) {
  129 + rb.setImage1(url);
  130 + }
  131 + // 视频
  132 + if (url.contains("_301.m3u8")) {
  133 + rb.setM3u8_1500(url);
  134 + }
  135 + if (url.contains("_300.m3u8")) {
  136 + rb.setM3u8_800(url);
  137 + }
  138 + if (url.contains("_200.mp4")) {
  139 + rb.setMp4_800(url);
  140 + }
  141 + if (url.contains("_201.mp4")) {
  142 + rb.setMp4_1500(url);
  143 + }
  144 + //
  145 + if (url.contains("_800.m3u8")) {
  146 + rb.setM3u8_800(url);
  147 + }
  148 + if (url.contains("_400.m3u8")) {
  149 + rb.setM3u8_400(url);
  150 + }
  151 + if (url.contains("_1500.m3u8")) {
  152 + rb.setM3u8_1500(url);
  153 + }
  154 + if (url.contains("_400.mp4")) {
  155 + rb.setMp4_400(url);
  156 + }
  157 + if (url.contains("_1500.mp4")) {
  158 + rb.setMp4_1500(url);
  159 + }
  160 + if (url.contains("_800.mp4")) {
  161 + rb.setMp4_800(url);
  162 + }
  163 + if (url.contains("_3000.mp4")) {
  164 + rb.setMp4_3000(url);
  165 + }
  166 + if (url.contains("_3000.m3u8")) {
  167 + rb.setM3u8_3000(url);
  168 + }
  169 + }
  170 + //SerializeUtil.serialize(rb);
  171 + strings.set(obj.getString("uuid"), SerializeUtil.serialize(rb));
  172 + }
  173 +
  174 + }
  175 + ResultBean rb = new ResultBean();
  176 + return rb;
  177 + }
65 } 178 }
src/main/java/com/cnlive/socket/SocketServer.java
@@ -58,7 +58,7 @@ public class SocketServer { @@ -58,7 +58,7 @@ public class SocketServer {
58 try { 58 try {
59 ServerSocket ss = new ServerSocket(port, 5); 59 ServerSocket ss = new ServerSocket(port, 5);
60 while (running) { 60 while (running) {
61 - System.out.println("等待客服端 请求。。。"); 61 + //System.out.println("等待客服端 请求。。。");
62 Socket s = ss.accept(); 62 Socket s = ss.accept();
63 new Thread(new SocketAction(s)).start(); 63 new Thread(new SocketAction(s)).start();
64 } 64 }
@@ -90,7 +90,7 @@ public class SocketServer { @@ -90,7 +90,7 @@ public class SocketServer {
90 } 90 }
91 91
92 if (System.currentTimeMillis() - lastReceiveTime > receiveTimeDelay) { 92 if (System.currentTimeMillis() - lastReceiveTime > receiveTimeDelay) {
93 - System.out.println("socket连接超过30s....."); 93 + //System.out.println("socket连接超过30s.....");
94 } else { 94 } else {
95 try { 95 try {
96 InputStream in = s.getInputStream(); 96 InputStream in = s.getInputStream();
src/main/java/com/cnlive/socket/TE.java
1 package com.cnlive.socket; 1 package com.cnlive.socket;
2 2
3 import java.io.BufferedReader; 3 import java.io.BufferedReader;
  4 +import java.io.File;
4 import java.io.IOException; 5 import java.io.IOException;
5 import java.io.InputStream; 6 import java.io.InputStream;
6 import java.io.InputStreamReader; 7 import java.io.InputStreamReader;
  8 +import java.io.UnsupportedEncodingException;
  9 +
  10 +import net.sf.json.JSONObject;
7 11
8 import org.apache.commons.httpclient.Header; 12 import org.apache.commons.httpclient.Header;
9 import org.apache.commons.httpclient.HttpClient; 13 import org.apache.commons.httpclient.HttpClient;
@@ -11,72 +15,132 @@ import org.apache.commons.httpclient.HttpException; @@ -11,72 +15,132 @@ import org.apache.commons.httpclient.HttpException;
11 import org.apache.commons.httpclient.HttpMethod; 15 import org.apache.commons.httpclient.HttpMethod;
12 import org.apache.commons.httpclient.StatusLine; 16 import org.apache.commons.httpclient.StatusLine;
13 import org.apache.commons.httpclient.methods.GetMethod; 17 import org.apache.commons.httpclient.methods.GetMethod;
  18 +import org.apache.commons.io.FileUtils;
14 19
15 -public class TE {  
16 -public static void main(String[] args) {  
17 - new TE().doGet("http://localhost:8080/cnlive_live_web/live/epg/play/app?channelId=xinyingshi&appId=82_irej0pbo53&timestamp=1472440205&sp_id=82_irej0pbo53&spId=82_irej0pbo53");  
18 -} 20 +import com.cnlive.mz.commons.net.HttpReq;
  21 +import com.cnlive.mz.live.common.BaseUtil;
19 22
20 -private HttpClient getHttpClient() {  
21 - HttpClient client = new HttpClient();  
22 - client.getHttpConnectionManager().getParams().setConnectionTimeout(2200);  
23 - client.getHttpConnectionManager().getParams().setSoTimeout(2200);  
24 - return client;  
25 -}  
26 -public void doGet(String url) {  
27 - BufferedReader in = null;  
28 - HttpClient client = this.getHttpClient();  
29 - HttpMethod method = new GetMethod(url);  
30 - method.setFollowRedirects(false);  
31 - InputStream stream = null;  
32 - try {  
33 - int exeCode = client.executeMethod(method);  
34 - StatusLine status = method.getStatusLine();  
35 - int statusCode = status.getStatusCode();  
36 - StringBuffer buf = new StringBuffer();  
37 - if (statusCode == 301 || statusCode == 302) {  
38 - Header[] hs = method.getResponseHeaders("Location");  
39 - for (Header h : hs) {  
40 - System.out.println(h.getName() + "--" + h.getValue());  
41 - String playUrl = h.getValue();  
42 -  
43 - }  
44 - Header[] hss = method.getResponseHeaders("message");  
45 - for (Header h : hss) {  
46 - System.out.println(h.getName() + "--" + h.getValue());  
47 - String playUrl = h.getValue();  
48 -  
49 - }  
50 - } else {  
51 - stream = method.getResponseBodyAsStream();  
52 - in = new BufferedReader(new InputStreamReader(stream, "UTF-8"));  
53 - String line;  
54 - while (null != (line = in.readLine())) {  
55 - buf.append(line).append("\n");  
56 - }  
57 - System.out.println(buf.toString());  
58 - }  
59 - } catch (HttpException e) {  
60 - e.printStackTrace();  
61 - } catch (IOException e) {  
62 - e.printStackTrace();  
63 - } finally {  
64 - if (in != null) { 23 +public class TE {
  24 +
  25 +
  26 + public static void main(String[] args) {
  27 + // new
  28 + // TE().doGet("http://bc.cnlive.com/live/epg/play/swf?appId=82_irej0pbo53&channelId=7a817495-cc2a-4ab2-85b8-25c7b0a312e3");
  29 + //new TE().aa("test1");
  30 +
  31 + File files[] = new File("e:/json").listFiles();
  32 + for (int i = 0; i < files.length; i++) {
  33 + File f = files[i];
  34 + System.out.println(f.getName());
  35 + String jsob = "";
65 try { 36 try {
66 - in.close();  
67 - } catch (Exception e) { 37 + jsob = FileUtils.readFileToString(f,"utf-8");
  38 + FileUtils.writeStringToFile(f,jsob,"utf-8");
  39 + } catch (IOException e) {
68 e.printStackTrace(); 40 e.printStackTrace();
69 } 41 }
70 } 42 }
71 - if (stream != null) {  
72 - try {  
73 - stream.close();  
74 - } catch (Exception e) {  
75 - e.printStackTrace(); 43 + }
  44 +
  45 + public void res(String streamName) {
  46 + try {
  47 + String accesskey = BaseUtil.getAccessKey();
  48 + accesskey = java.net.URLEncoder.encode(accesskey, "utf-8");
  49 + String signature = BaseUtil.signature(streamName);
  50 + String del = "del";
  51 + String delsignature = BaseUtil.signature(del, streamName);
  52 + String expire = BaseUtil.getTimestamp();
  53 + String url = "http://cnlive.dashboard.ks-cdn.com/blacklist?signature=" + signature + "&accesskey=" + accesskey + "&expire=" + expire
  54 + + "&app=live&method=del&name=" + streamName;
  55 + String jsonArrStr = HttpReq.getRequestWidthResult(url);
  56 + System.out.println("..jsonArrStr.." + jsonArrStr);
  57 + } catch (Exception e) {
  58 + e.printStackTrace();
  59 + }
  60 +
  61 + }
  62 +
  63 + public void aa(String streamName) {
  64 + try {
  65 + String accesskey = BaseUtil.getAccessKey();
  66 + accesskey = java.net.URLEncoder.encode(accesskey, "utf-8");
  67 + String signature = BaseUtil.signature(streamName);
  68 + String add = "add";
  69 + String addsignature = BaseUtil.signature(add, streamName);
  70 + String expire = BaseUtil.getTimestamp();
  71 + System.out.println(expire + "---expire---");
  72 + String url = "http://cnlive.dashboard.ks-cdn.com/blacklist?signature=" + signature + "&accesskey=" + accesskey + "&expire=" + expire
  73 + + "&app=live&method=del&name=" + streamName;
  74 + System.out.println(url);
  75 + String jsonArrStr = HttpReq.getRequestWidthResult(url);
  76 + int status = HttpReq.getRequest(url);
  77 + System.out.println(status + "......and......" + jsonArrStr);
  78 + } catch (UnsupportedEncodingException e) {
  79 + e.printStackTrace();
  80 + }
  81 + }
  82 +
  83 + private HttpClient getHttpClient() {
  84 + HttpClient client = new HttpClient();
  85 + client.getHttpConnectionManager().getParams().setConnectionTimeout(2200);
  86 + client.getHttpConnectionManager().getParams().setSoTimeout(2200);
  87 + return client;
  88 + }
  89 +
  90 + public void doGet(String url) {
  91 + BufferedReader in = null;
  92 + HttpClient client = this.getHttpClient();
  93 + HttpMethod method = new GetMethod(url);
  94 + method.setFollowRedirects(false);
  95 + InputStream stream = null;
  96 + try {
  97 + int exeCode = client.executeMethod(method);
  98 + StatusLine status = method.getStatusLine();
  99 + int statusCode = status.getStatusCode();
  100 + StringBuffer buf = new StringBuffer();
  101 + if (statusCode == 301 || statusCode == 302) {
  102 + Header[] hs = method.getResponseHeaders("Location");
  103 + for (Header h : hs) {
  104 + System.out.println(h.getName() + "--" + h.getValue());
  105 + String playUrl = h.getValue();
  106 +
  107 + }
  108 + Header[] hss = method.getResponseHeaders("message");
  109 + for (Header h : hss) {
  110 + System.out.println(h.getName() + "--" + h.getValue());
  111 + String playUrl = h.getValue();
  112 +
  113 + }
  114 + } else {
  115 + stream = method.getResponseBodyAsStream();
  116 + in = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
  117 + String line;
  118 + while (null != (line = in.readLine())) {
  119 + buf.append(line).append("\n");
  120 + }
  121 + System.out.println(buf.toString());
76 } 122 }
  123 + } catch (HttpException e) {
  124 + e.printStackTrace();
  125 + } catch (IOException e) {
  126 + e.printStackTrace();
  127 + } finally {
  128 + if (in != null) {
  129 + try {
  130 + in.close();
  131 + } catch (Exception e) {
  132 + e.printStackTrace();
  133 + }
  134 + }
  135 + if (stream != null) {
  136 + try {
  137 + stream.close();
  138 + } catch (Exception e) {
  139 + e.printStackTrace();
  140 + }
  141 + }
  142 + method.releaseConnection();
77 } 143 }
78 - method.releaseConnection();  
79 } 144 }
80 -}  
81 145
82 } 146 }