public VideoAnalyseResponse Analyse([FromBody] VideoAnalyseRequest request) { var response = new VideoAnalyseResponse(); try { if (string.IsNullOrEmpty(request.Url)) { response.ErrCode = -1; response.ErrMsg = "url不存在"; } else { //response = new Core2.Extension.QQ().Analyse(request.Url, LoginMonitor.QQCookies); response = AnalysisFactory.GetResponse(request.Url, LoginMonitor.QQCookies); } } catch (Exception ex) { response.ErrCode = -1; response.ErrMsg = "出现异常,请求失败"; Logger.Fatal($"{ex.Message}\r\n{ex.StackTrace}"); } response.Version = this.Version; Logger.Info($"--->request\r\n{JsonConvert.SerializeObject(request)}\r\n--->response\r\n{JsonConvert.SerializeObject(response)}"); return(response); }
public VideoAnalyseResponse Analyse(string url, string cookie = null) { var response = new VideoAnalyseResponse(); var vids = GetVid(url); //同一个页面,嵌套多个视频,会有多个vid 如微信公众号文章 if (vids.Count > 0) { var info = new List <VideoInfo>(); var errorMsg = string.Empty; //这里只取第一个视频 var vid = vids.FirstOrDefault(); if (GetInfos(vid, cookie, out info, out errorMsg)) { response.Data.AddRange(info); } else { response.ErrCode = -1; response.ErrMsg = errorMsg; } return(response); } else { return(new VideoAnalyseResponse() { ErrCode = -1, ErrMsg = $"[{url}]没有找到vid" }); } }
public IActionResult AnalyseCore([FromQuery] string rk) { var ckplayerJson = new CKPlayerJsonViewModel() { autoplay = true }; var url = string.Empty; var gkey = string.Empty; var timestamp = string.Empty; var sign = string.Empty; if (!DecodeRequestKey(rk, out url, out gkey, out timestamp, out sign)) { return(Json(new { errorCode = -9998, msg = "参数错误,请求非法!" })); } //url解码 验证签名需要 url = FormatHelper.UrlDecode(url); if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(gkey) | string.IsNullOrEmpty(timestamp) | string.IsNullOrEmpty(sign)) { return(Json(new { errorCode = -9999, msg = "参数错误,请求非法!" })); } long.TryParse(timestamp, out long timestampl); var time = FormatHelper.ConvertToDateTime(timestampl); //不得超过2分钟 if (DateTime.Compare(time.AddMinutes(2), DateTime.Now) < 0) { return(Json(new { errorCode = -10000, msg = "请求已过期" })); } //gkey需要与会话一致 var server_gkey = HttpContext.Session.GetString("gkey"); if (gkey != server_gkey) { return(Json(new { errorCode = -10001, msg = "会话超时,请求非法!" })); } //校验签名 if (!ValidateSign(url, gkey, timestamp, sign)) { return(Json(new { errorCode = -10002, msg = "签名错误,请求非法!" })); } var cacheKey = $"analyse_{url}"; var response = new VideoAnalyseResponse(); if (!_memoryCache.TryGetValue(cacheKey, out response)) { response = AnalyseService.Analyse(_configInfos["ConfigInfos:AnalyseServiceAddress"], url); if (response != null && response.ErrCode == 0 && response.Data.Count > 0) { _memoryCache.Set(cacheKey, response, new DateTimeOffset(DateTime.Now.AddHours(1))); } } //处理数据 var result = new List <string>(); var name = string.Empty; if (response == null || response.ErrCode != 0) { //result.Add("http://movie.ks.js.cn/flv/other/1_0.mp4"); //解析失败 //应该返回错误 todo 这里返回null } else { //可能会有多个视频 这里只取第一个 var video = response.Data.FirstOrDefault(); if (video != null) { var ckvideo = new CKVideo() { type = "mp4", weight = 0, definition = video.Definition }; foreach (var item in video.Part) { if (!string.IsNullOrEmpty(item.Url)) { ckvideo.video.Add(new CKVideoInfo() { file = item.Url, duration = item.Duration }); } } ckplayerJson.video.Add(ckvideo); } } return(Json(ckplayerJson)); }