private async Task <ApiDataModel <DashModel> > GetBiliBiliDash(PlayInfo playInfo, int qn) { try { var api = PlayerAPI.VideoPlayUrl(aid: playInfo.avid, cid: playInfo.cid, qn: qn, true); if (playInfo.play_mode == VideoPlayType.Season) { api = PlayerAPI.SeasonPlayUrl(aid: playInfo.avid, cid: playInfo.cid, qn: qn, season_type: playInfo.season_type, true); } var result = await api.Request(); if (result.status) { DashModel dashModel = null; var obj = result.GetJObject(); if (obj["code"].ToInt32() != 0 || result.results.Contains("8986943")) { return(await GetBiliPlusDash(playInfo, qn)); } if (obj.ContainsKey("data")) { dashModel = JsonConvert.DeserializeObject <DashModel>(obj["data"].ToString()); } if (obj.ContainsKey("result") && obj["result"].ToString() != "suee") { dashModel = JsonConvert.DeserializeObject <DashModel>(obj["result"].ToString()); } if (obj.ContainsKey("dash")) { dashModel = JsonConvert.DeserializeObject <DashModel>(obj.ToString()); } //var data = await result.GetJson<ApiDataModel<DashModel>>(); //if (data.code != 0 || result.results.Contains("8986943")) //{ // return await GetBiliPlusDash(playInfo, qn); //} if (dashModel == null) { dashModel = await result.GetJson <DashModel>(); } if (dashModel.dash == null) { return(new ApiDataModel <DashModel>() { code = -910, message = "需要使用FLV" }); } return(new ApiDataModel <DashModel>() { code = 0, data = dashModel }); } else { if (playInfo.play_mode == VideoPlayType.Season) { return(await GetBiliPlusDash(playInfo, qn)); } return(new ApiDataModel <DashModel>() { code = -998, message = result.message }); } } catch (Exception ex) { var data = HandelError <object>(ex); return(new ApiDataModel <DashModel>() { code = -999, message = data.message }); } }
private async Task <ApiDataModel <DashModel> > GetGrpcDash(PlayInfo playInfo, int qn, int mode) { try { Proto.Reply.PlayViewReply playViewReply = new Proto.Reply.PlayViewReply(); Proto.Request.CodeType codec = (mode == 1) ? Proto.Request.CodeType.Code264 : Proto.Request.CodeType.Code265; if (playInfo.play_mode == VideoPlayType.Season) { playViewReply = await playUrlApi.BangumiPlayView(Convert.ToInt64(playInfo.ep_id), Convert.ToInt64(playInfo.cid), qn, 16, codec, SettingHelper.Account.AccessKey); } else { playViewReply = await playUrlApi.VideoPlayView(Convert.ToInt64(playInfo.avid), Convert.ToInt64(playInfo.cid), qn, 16, codec, SettingHelper.Account.AccessKey); } DashModel dashModel = new DashModel(); if (playViewReply.VideoInfo.DashAudio == null) { return(new ApiDataModel <DashModel>() { code = -910, message = "需要使用FLV" }); } dashModel.accept_description = playViewReply.VideoInfo.StreamList.Select(x => x.StreamInfo.NewDescription).ToList(); dashModel.accept_quality = playViewReply.VideoInfo.StreamList.Select(x => x.StreamInfo.Quality).ToList(); dashModel.format = playViewReply.VideoInfo.Format; dashModel.timelength = playViewReply.VideoInfo.Timelength; dashModel.video_codecid = playViewReply.VideoInfo.VideoCodecid; dashModel.dash = new DashDashModel(); dashModel.dash.video = new List <DashItemModel>(); dashModel.dash.audio = new List <DashItemModel>(); foreach (var item in playViewReply.VideoInfo.StreamList) { dashModel.dash.video.Add(new DashItemModel() { backupUrl = item.DashVideo.BackupUrl.ToList(), backup_url = item.DashVideo.BackupUrl.ToList(), baseUrl = item.DashVideo.BaseUrl, bandwidth = item.DashVideo.Bandwidth, base_url = item.DashVideo.BaseUrl, codecid = item.DashVideo.Codecid, mimeType = "video/mp4", id = item.StreamInfo.Quality, }); } foreach (var item in playViewReply.VideoInfo.DashAudio) { dashModel.dash.audio.Add(new DashItemModel() { backupUrl = item.BackupUrl.ToList(), backup_url = item.BackupUrl.ToList(), baseUrl = item.BaseUrl, bandwidth = item.Bandwidth, base_url = item.BaseUrl, codecid = item.Codecid, mimeType = "video/mp4", id = item.Id, }); } return(new ApiDataModel <DashModel>() { code = 0, data = dashModel }); } catch (Exception ex) { var data = HandelError <object>(ex); if (playInfo.play_mode == VideoPlayType.Season) { return(await GetBiliPlusDash(playInfo, qn)); } return(new ApiDataModel <DashModel>() { code = -999, message = data.message }); } }