using DownKyi.Core.BiliApi.BiliUtils; using DownKyi.Core.BiliApi.Cheese; using DownKyi.Core.BiliApi.Cheese.Models; using DownKyi.Core.BiliApi.VideoStream; using DownKyi.Core.Storage; using DownKyi.Core.Utils; using DownKyi.Models; using DownKyi.Utils; using System; using System.Collections.Generic; using System.Windows.Media.Imaging; namespace DownKyi.Services { public class CheeseInfoService : IInfoService { private readonly CheeseView cheeseView; public CheeseInfoService(string input) { if (input == null) { return; } if (ParseEntrance.IsCheeseSeasonUrl(input)) { long seasonId = ParseEntrance.GetCheeseSeasonId(input); cheeseView = CheeseInfo.CheeseViewInfo(seasonId); } if (ParseEntrance.IsCheeseEpisodeUrl(input)) { long episodeId = ParseEntrance.GetCheeseEpisodeId(input); cheeseView = CheeseInfo.CheeseViewInfo(-1, episodeId); } } /// /// 获取视频剧集 /// /// public List GetVideoPages() { List pages = new List(); if (cheeseView == null) { return pages; } if (cheeseView.Episodes == null) { return pages; } if (cheeseView.Episodes.Count == 0) { return pages; } int order = 0; foreach (var episode in cheeseView.Episodes) { order++; string name = episode.Title; string duration = Format.FormatDuration(episode.Duration - 1); VideoPage page = new VideoPage { Avid = episode.Aid, Bvid = null, Cid = episode.Cid, EpisodeId = episode.Id, Order = order, Name = name, Duration = "N/A" }; pages.Add(page); } return pages; } /// /// 获取视频章节与剧集 /// /// public List GetVideoSections() { return null; } /// /// 获取视频流的信息,从VideoPage返回 /// /// public void GetVideoStream(VideoPage page) { var playUrl = VideoStream.GetCheesePlayUrl(page.Avid, page.Bvid, page.Cid, page.EpisodeId); Utils.VideoPageInfo(playUrl, page); } /// /// 获取视频信息 /// /// public VideoInfoView GetVideoView() { if (cheeseView == null) { return null; } // 查询、保存封面 // 将SeasonId保存到avid字段中 // 每集封面的cid保存到cid字段,EpisodeId保存到bvid字段中 StorageCover storageCover = new StorageCover(); string coverUrl = cheeseView.Cover; string cover = storageCover.GetCover(cheeseView.SeasonId, "cheese", -1, coverUrl); // 获取用户头像 string upName; string header; if (cheeseView.UpInfo != null) { upName = cheeseView.UpInfo.Name; StorageHeader storageHeader = new StorageHeader(); header = storageHeader.GetHeader(cheeseView.UpInfo.Mid, cheeseView.UpInfo.Name, cheeseView.UpInfo.Avatar); } else { upName = ""; header = null; } // 为videoInfoView赋值 VideoInfoView videoInfoView = new VideoInfoView(); App.PropertyChangeAsync(new Action(() => { videoInfoView.CoverUrl = coverUrl; videoInfoView.Cover = cover == null ? null : new BitmapImage(new Uri(cover)); videoInfoView.Title = cheeseView.Title; videoInfoView.VideoZone = DictionaryResource.GetString("Cheese"); videoInfoView.CreateTime = ""; videoInfoView.PlayNumber = Format.FormatNumber(cheeseView.Stat.Play); videoInfoView.DanmakuNumber = Format.FormatNumber(0); videoInfoView.LikeNumber = Format.FormatNumber(0); videoInfoView.CoinNumber = Format.FormatNumber(0); videoInfoView.FavoriteNumber = Format.FormatNumber(0); videoInfoView.ShareNumber = Format.FormatNumber(0); videoInfoView.ReplyNumber = Format.FormatNumber(0); videoInfoView.Description = cheeseView.Subtitle; videoInfoView.UpName = upName; if (header != null) { StorageHeader storageHeader = new StorageHeader(); videoInfoView.UpHeader = storageHeader.GetHeaderThumbnail(header, 48, 48); videoInfoView.UpperMid = cheeseView.UpInfo.Mid; } else { videoInfoView.UpHeader = null; } })); return videoInfoView; } } }