You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
downkyi/DownKyi/Services/CheeseInfoService.cs

161 lines
5.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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);
}
}
/// <summary>
/// 获取视频剧集
/// </summary>
/// <returns></returns>
public List<VideoPage> GetVideoPages()
{
List<VideoPage> pages = new List<VideoPage>();
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;
}
/// <summary>
/// 获取视频章节与剧集
/// </summary>
/// <returns></returns>
public List<VideoSection> GetVideoSections()
{
return null;
}
/// <summary>
/// 获取视频流的信息从VideoPage返回
/// </summary>
/// <param name="page"></param>
public void GetVideoStream(VideoPage page)
{
var playUrl = VideoStream.GetCheesePlayUrl(page.Avid, page.Bvid, page.Cid, page.EpisodeId);
Utils.VideoPageInfo(playUrl, page);
}
/// <summary>
/// 获取视频信息
/// </summary>
/// <returns></returns>
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, "", -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 = 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);
}
else
{
videoInfoView.UpHeader = null;
}
}));
return videoInfoView;
}
}
}