From 580705652f008a8d3a88f947c97496763e02b407 Mon Sep 17 00:00:00 2001
From: croire <1432593898@qq.com>
Date: Thu, 23 Dec 2021 00:01:13 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B0=81=E9=9D=A2=E4=B8=8B?=
=?UTF-8?q?=E8=BD=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
DownKyi/Models/DownloadBaseItem.cs | 3 +
.../Services/Download/AriaDownloadService.cs | 55 ++++++++++++++-----
DownKyi/Services/Download/IDownloadService.cs | 2 +-
.../ViewModels/ViewVideoDetailViewModel.cs | 3 +-
4 files changed, 48 insertions(+), 15 deletions(-)
diff --git a/DownKyi/Models/DownloadBaseItem.cs b/DownKyi/Models/DownloadBaseItem.cs
index 52a84b0..488f572 100644
--- a/DownKyi/Models/DownloadBaseItem.cs
+++ b/DownKyi/Models/DownloadBaseItem.cs
@@ -39,6 +39,9 @@ namespace DownKyi.Models
// 视频封面的url
public string CoverUrl { get; set; }
+ // 视频page的封面的url
+ public string PageCoverUrl { get; set; }
+
private DrawingImage zoneImage;
public DrawingImage ZoneImage
{
diff --git a/DownKyi/Services/Download/AriaDownloadService.cs b/DownKyi/Services/Download/AriaDownloadService.cs
index f538484..d972c38 100644
--- a/DownKyi/Services/Download/AriaDownloadService.cs
+++ b/DownKyi/Services/Download/AriaDownloadService.cs
@@ -148,7 +148,7 @@ namespace DownKyi.Services.Download
/// 下载封面
///
///
- public string DownloadCover(DownloadingItem downloading)
+ public string DownloadCover(DownloadingItem downloading, string coverUrl, string fileName)
{
// 更新状态显示
downloading.DownloadStatusTitle = DictionaryResource.GetString("WhileDownloading");
@@ -160,24 +160,16 @@ namespace DownKyi.Services.Download
// 查询、保存封面
StorageCover storageCover = new StorageCover();
- string cover = storageCover.GetCover(downloading.Avid, downloading.Bvid, downloading.Cid, downloading.CoverUrl);
+ string cover = storageCover.GetCover(downloading.Avid, downloading.Bvid, downloading.Cid, coverUrl);
if (cover == null)
{
return null;
}
- // 图片的扩展名
- string[] temp = downloading.CoverUrl.Split('.');
- string fileExtension = temp[temp.Length - 1];
-
- // 图片的地址
- string coverPath = $"{StorageManager.GetCover()}/{cover}";
-
// 复制图片到指定位置
try
{
- string fileName = $"{downloading.FilePath}.{fileExtension}";
- File.Copy(coverPath, fileName);
+ File.Copy(cover, fileName, true);
// 记录本次下载的文件
downloading.DownloadFiles.Add(fileName);
@@ -448,6 +440,15 @@ namespace DownKyi.Services.Download
///
private async void SingleDownload(DownloadingItem downloading)
{
+ // 路径
+ string[] temp = downloading.FilePath.Split('/');
+ string path = downloading.FilePath.Replace(temp[temp.Length - 1], "");
+ // 路径不存在则创建
+ if (!Directory.Exists(path))
+ {
+ Directory.CreateDirectory(path);
+ }
+
await Task.Run(new Action(() =>
{
downloading.DownloadStatus = DownloadStatus.DOWNLOADING;
@@ -507,14 +508,24 @@ namespace DownKyi.Services.Download
// 如果需要下载封面
if (downloading.NeedDownloadContent["downloadCover"])
{
- outputCover = DownloadCover(downloading);
+
+ string fileName = $"{downloading.FilePath}.{GetImageExtension(downloading.PageCoverUrl)}";
+
+ // page的封面
+ outputCover = DownloadCover(downloading, downloading.PageCoverUrl, fileName);
+ // 封面
+ DownloadCover(downloading, downloading.CoverUrl, $"{path}/Cover.{GetImageExtension(downloading.CoverUrl)}");
}
// 暂停
Pause(downloading);
// 混流
- string outputMedia = MixedFlow(downloading, audioUid, videoUid);
+ string outputMedia = string.Empty;
+ if (downloading.NeedDownloadContent["downloadAudio"] || downloading.NeedDownloadContent["downloadVideo"])
+ {
+ outputMedia = MixedFlow(downloading, audioUid, videoUid);
+ }
// 暂停
Pause(downloading);
@@ -570,6 +581,24 @@ namespace DownKyi.Services.Download
}));
}
+ ///
+ /// 获取图片的扩展名
+ ///
+ ///
+ ///
+ private string GetImageExtension(string coverUrl)
+ {
+ if (coverUrl == null)
+ {
+ return string.Empty;
+ }
+
+ // 图片的扩展名
+ string[] temp = coverUrl.Split('.');
+ string fileExtension = temp[temp.Length - 1];
+ return fileExtension;
+ }
+
///
/// 强制暂停
///
diff --git a/DownKyi/Services/Download/IDownloadService.cs b/DownKyi/Services/Download/IDownloadService.cs
index 8facfb4..3621dad 100644
--- a/DownKyi/Services/Download/IDownloadService.cs
+++ b/DownKyi/Services/Download/IDownloadService.cs
@@ -10,7 +10,7 @@ namespace DownKyi.Services.Download
string DownloadVideo(DownloadingItem downloading);
string DownloadDanmaku(DownloadingItem downloading);
List DownloadSubtitle(DownloadingItem downloading);
- string DownloadCover(DownloadingItem downloading);
+ string DownloadCover(DownloadingItem downloading, string coverUrl, string fileName);
string MixedFlow(DownloadingItem downloading, string audioUid, string videoUid);
void Start();
diff --git a/DownKyi/ViewModels/ViewVideoDetailViewModel.cs b/DownKyi/ViewModels/ViewVideoDetailViewModel.cs
index 2f297e3..f1bab8d 100644
--- a/DownKyi/ViewModels/ViewVideoDetailViewModel.cs
+++ b/DownKyi/ViewModels/ViewVideoDetailViewModel.cs
@@ -663,7 +663,8 @@ namespace DownKyi.ViewModels
Cid = page.Cid,
EpisodeId = page.EpisodeId,
- CoverUrl = page.FirstFrame,
+ CoverUrl = VideoInfoView.CoverUrl,
+ PageCoverUrl = page.FirstFrame,
ZoneImage = (DrawingImage)Application.Current.Resources[VideoZoneIcon.Instance().GetZoneImageKey(zoneId)],
Order = page.Order,