예제 #1
0
        private async Task <ApiDataModel <FlvModel> > GetGrpcFlv(PlayInfo playInfo, int qn)
        {
            try
            {
                Proto.Reply.PlayViewReply playViewReply = new Proto.Reply.PlayViewReply();
                Proto.Request.CodeType    codec         = Proto.Request.CodeType.Code264;
                if (playInfo.play_mode == VideoPlayType.Season)
                {
                    playViewReply = await playUrlApi.BangumiPlayView(Convert.ToInt64(playInfo.ep_id), Convert.ToInt64(playInfo.cid), qn, 0, codec, SettingHelper.Account.AccessKey);
                }
                else
                {
                    playViewReply = await playUrlApi.VideoPlayView(Convert.ToInt64(playInfo.avid), Convert.ToInt64(playInfo.cid), qn, 0, codec, SettingHelper.Account.AccessKey);
                }

                FlvModel flvModel = new FlvModel();
                flvModel.accept_description = playViewReply.VideoInfo.StreamList.Select(x => x.StreamInfo.NewDescription).ToList();
                flvModel.accept_quality     = playViewReply.VideoInfo.StreamList.Select(x => x.StreamInfo.Quality).ToList();
                flvModel.code          = 0;
                flvModel.message       = "";
                flvModel.quality       = playViewReply.VideoInfo.Quality;
                flvModel.timelength    = playViewReply.VideoInfo.Timelength;
                flvModel.video_codecid = playViewReply.VideoInfo.VideoCodecid;
                flvModel.durl          = new List <FlvDurlModel>();
                var video = playViewReply.VideoInfo.StreamList.FirstOrDefault(x => x.SegmentVideo != null);
                foreach (var item in video.SegmentVideo.Segment)
                {
                    flvModel.durl.Add(new FlvDurlModel()
                    {
                        backup_url = item.BackupUrl.ToList(),
                        length     = item.Length,
                        order      = item.Order,
                        size       = item.Size,
                        url        = item.Url
                    });
                }
                return(new ApiDataModel <FlvModel>()
                {
                    code = 0,
                    data = flvModel
                });
            }
            catch (Exception ex)
            {
                var data = HandelError <object>(ex);
                if (playInfo.play_mode == VideoPlayType.Season)
                {
                    return(await GetBiliPlusFlv(playInfo, qn));
                }
                return(new ApiDataModel <FlvModel>()
                {
                    code = -999,
                    message = data.message
                });
            }
        }
예제 #2
0
        private async Task <ApiDataModel <FlvModel> > GetBiliBiliFlv(PlayInfo playInfo, int qn)
        {
            try
            {
                var api = PlayerAPI.VideoPlayUrl(aid: playInfo.avid, cid: playInfo.cid, qn: qn, false);
                if (playInfo.play_mode == VideoPlayType.Season)
                {
                    api = PlayerAPI.SeasonPlayUrl(aid: playInfo.avid, cid: playInfo.cid, qn: qn, season_type: playInfo.season_type, false);
                }
                var result = await api.Request();

                if (result.status)
                {
                    var      obj     = result.GetJObject();
                    FlvModel flvData = null;
                    if (obj["code"].ToInt32() != 0 || result.results.Contains("8986943"))
                    {
                        var bp = await GetBiliPlusFlv(playInfo, qn);

                        return(new ApiDataModel <FlvModel>()
                        {
                            code = bp.code,
                            message = bp.message,
                            data = bp.data
                        });
                    }
                    if (obj["data"] != null)
                    {
                        flvData = JsonConvert.DeserializeObject <FlvModel>(obj["data"].ToString());
                    }
                    if (obj["result"] != null && obj["result"].ToString() != "suee")
                    {
                        flvData = JsonConvert.DeserializeObject <FlvModel>(obj["result"].ToString());
                    }
                    if (obj["durl"] != null)
                    {
                        flvData = JsonConvert.DeserializeObject <FlvModel>(obj.ToString());
                    }
                    return(new ApiDataModel <FlvModel>()
                    {
                        code = 0,
                        message = "",
                        data = flvData
                    });
                    //var data = await result.GetJson<ApiDataModel<FlvModel>>();
                    //if (data.code != 0|| result.results.Contains("8986943"))
                    //{

                    //    //return await GetBiliPlusFlv(playInfo, qn);
                    //}
                    //if (data.data == null)
                    //{
                    //    data.data = await result.GetJson<FlvModel>();
                    //}
                    //return data;
                }
                else
                {
                    if (playInfo.play_mode == VideoPlayType.Season)
                    {
                        var bp = await GetBiliPlusFlv(playInfo, qn);

                        return(new ApiDataModel <FlvModel>()
                        {
                            code = bp.code,
                            message = bp.message,
                            data = bp.data
                        });
                    }
                    return(new ApiDataModel <FlvModel>()
                    {
                        code = -998,
                        message = result.message
                    });
                }
            }
            catch (Exception ex)
            {
                var data = HandelError <object>(ex);
                return(new ApiDataModel <FlvModel>()
                {
                    code = -999,
                    message = data.message
                });
            }
        }