private static async Task <SingleVideoDialogViewModel> InitializeVideoModel(BiliVideoInfo videoInfo)
        {
            var model = new SingleVideoDialogViewModel();

            model.VideoName = videoInfo.Name;
            model.Bv        = videoInfo.Bv;
            model.Cid       = videoInfo.Cid;

            //var stream = await NetHelper.HttpGetStreamAsync(videoInfo.CoverUrl, null, null);
            //var file = await ApplicationData.Current.LocalCacheFolder.CreateFileAsync("videocovercache", CreationCollisionOption.GenerateUniqueName);
            //var fileStream = await file.OpenStreamForWriteAsync();
            //await stream.CopyToAsync(fileStream);
            //stream.Close();
            //fileStream.Close();
            //var img = new BitmapImage();
            //await img.SetSourceAsync((await file.OpenStreamForReadAsync()).AsRandomAccessStream());
            var img = new BitmapImage(new Uri(videoInfo.CoverUrl));

            model.VideoCover = img;

            model.VideoQualityList = new List <SingleVideoDialogViewModel.VideoQuality>();
            foreach (var item in videoInfo.QualityCodeList)
            {
                var key   = item;
                var value = QualityDictionary[item];
                model.VideoQualityList.Add(new SingleVideoDialogViewModel.VideoQuality(key, value));
            }

            return(model);
        }
Beispiel #2
0
        public static async Task <BiliVideoInfo> GetSingleVideoInfoAsync(string bv, long cid, int quality, string sESSDATA)
        {
            var master = await GetVideoMasterInfoAsync(bv, sESSDATA);

            List <(string, string)> cookies = null;

            if (!string.IsNullOrWhiteSpace(sESSDATA))
            {
                cookies = new List <(string, string)>();
                cookies.Add(("SESSDATA", sESSDATA));
            }
            var json = JsonConvert.DeserializeObject <VideoStreamJson>
                           (await NetHelper.HttpGet("http://api.bilibili.com/x/player/playurl",
                                                    cookies, $"bvid={bv}", $"cid={cid}", $"qn={quality}", "fnval=16"));

            if (json.data == null)
            {
                throw new ParsingVideoException("视频解析失败,请检查是否缺少大会员权限");
            }

            var info = new BiliVideoInfo()
            {
                Bv              = master.Bv,
                Cid             = cid,
                Name            = master.Title + " " + master.VideoList.Where(v => v.Cid == cid)?.FirstOrDefault().Name,
                CoverUrl        = master.VideoList.Where(v => v.Cid == cid)?.FirstOrDefault().Cover ?? master.Picture,
                QualityCodeList = json.data.accept_quality
            };

            return(info);
        }
        public static async Task <SingleVideoDialog> CreateAsync(BiliVideoInfo videoInfo, XamlRoot xamlRoot)
        {
            var vm = await InitializeVideoModel(videoInfo);

            var model = new SingleVideoDialog(vm, xamlRoot);

            return(model);
        }