基本实现下载功能

croire 3 years ago
parent 7c43873e87
commit 251619a4ba

@ -20,7 +20,7 @@ namespace DownKyi.Core.BiliApi.Zone
return that; return that;
} }
public List<ZoneAttr> GetZone() public List<ZoneAttr> GetZones()
{ {
return zones; return zones;
} }

@ -122,15 +122,15 @@ namespace DownKyi.Core.Utils
} }
else if (speed < 1024) else if (speed < 1024)
{ {
formatSpeed = speed.ToString("#.##") + "B/s"; formatSpeed = string.Format("{0:F2}", speed) + "B/s";
} }
else if (speed < 1024 * 1024) else if (speed < 1024 * 1024)
{ {
formatSpeed = (speed / 1024).ToString("#.##") + "KB/s"; formatSpeed = string.Format("{0:F2}", speed / 1024) + "KB/s";
} }
else else
{ {
formatSpeed = (speed / 1024 / 1024).ToString("#.##") + "MB/s"; formatSpeed = string.Format("{0:F2}", speed / 1024 / 1024) + "MB/s";
} }
return formatSpeed; return formatSpeed;
} }

@ -1,5 +1,4 @@
using DownKyi.Core.Aria2cNet.Client; using DownKyi.Core.BiliApi.VideoStream.Models;
using DownKyi.Core.BiliApi.VideoStream.Models;
using DownKyi.Images; using DownKyi.Images;
using DownKyi.Utils; using DownKyi.Utils;
using Prism.Commands; using Prism.Commands;

@ -153,6 +153,10 @@ namespace DownKyi.Services.Download
// 更新状态显示 // 更新状态显示
downloading.DownloadStatusTitle = DictionaryResource.GetString("WhileDownloading"); downloading.DownloadStatusTitle = DictionaryResource.GetString("WhileDownloading");
downloading.DownloadContent = DictionaryResource.GetString("DownloadingCover"); downloading.DownloadContent = DictionaryResource.GetString("DownloadingCover");
// 下载大小
downloading.DownloadingFileSize = string.Empty;
// 下载速度
downloading.SpeedDisplay = string.Empty;
// 查询、保存封面 // 查询、保存封面
StorageCover storageCover = new StorageCover(); StorageCover storageCover = new StorageCover();
@ -198,6 +202,10 @@ namespace DownKyi.Services.Download
// 更新状态显示 // 更新状态显示
downloading.DownloadStatusTitle = DictionaryResource.GetString("WhileDownloading"); downloading.DownloadStatusTitle = DictionaryResource.GetString("WhileDownloading");
downloading.DownloadContent = DictionaryResource.GetString("DownloadingDanmaku"); downloading.DownloadContent = DictionaryResource.GetString("DownloadingDanmaku");
// 下载大小
downloading.DownloadingFileSize = string.Empty;
// 下载速度
downloading.SpeedDisplay = string.Empty;
string title = $"{downloading.Name}"; string title = $"{downloading.Name}";
string assFile = $"{downloading.FilePath}.ass"; string assFile = $"{downloading.FilePath}.ass";
@ -217,7 +225,7 @@ namespace DownKyi.Services.Download
//} //}
// 字幕配置 // 字幕配置
var subtitleConfig = new Config Config subtitleConfig = new Config
{ {
Title = title, Title = title,
ScreenWidth = screenWidth, ScreenWidth = screenWidth,
@ -250,6 +258,10 @@ namespace DownKyi.Services.Download
// 更新状态显示 // 更新状态显示
downloading.DownloadStatusTitle = DictionaryResource.GetString("WhileDownloading"); downloading.DownloadStatusTitle = DictionaryResource.GetString("WhileDownloading");
downloading.DownloadContent = DictionaryResource.GetString("DownloadingSubtitle"); downloading.DownloadContent = DictionaryResource.GetString("DownloadingSubtitle");
// 下载大小
downloading.DownloadingFileSize = string.Empty;
// 下载速度
downloading.SpeedDisplay = string.Empty;
List<string> srtFiles = new List<string>(); List<string> srtFiles = new List<string>();
@ -293,6 +305,10 @@ namespace DownKyi.Services.Download
// 更新状态显示 // 更新状态显示
downloading.DownloadStatusTitle = DictionaryResource.GetString("MixedFlow"); downloading.DownloadStatusTitle = DictionaryResource.GetString("MixedFlow");
downloading.DownloadContent = DictionaryResource.GetString("DownloadingVideo"); downloading.DownloadContent = DictionaryResource.GetString("DownloadingVideo");
// 下载大小
downloading.DownloadingFileSize = string.Empty;
// 下载速度
downloading.SpeedDisplay = string.Empty;
string finalFile = $"{downloading.FilePath}.mp4"; string finalFile = $"{downloading.FilePath}.mp4";
if (videoUid == null) if (videoUid == null)
@ -326,6 +342,10 @@ namespace DownKyi.Services.Download
// 更新状态显示 // 更新状态显示
downloading.DownloadStatusTitle = DictionaryResource.GetString("Parsing"); downloading.DownloadStatusTitle = DictionaryResource.GetString("Parsing");
downloading.DownloadContent = string.Empty; downloading.DownloadContent = string.Empty;
// 下载大小
downloading.DownloadingFileSize = string.Empty;
// 下载速度
downloading.SpeedDisplay = string.Empty;
if (downloading.PlayUrl != null && downloading.DownloadStatus == DownloadStatus.NOT_STARTED) if (downloading.PlayUrl != null && downloading.DownloadStatus == DownloadStatus.NOT_STARTED)
{ {
@ -654,6 +674,9 @@ namespace DownKyi.Services.Download
/// <returns></returns> /// <returns></returns>
private DownloadResult DownloadByAria(DownloadingItem downloading, List<string> urls, string path, string localFileName) private DownloadResult DownloadByAria(DownloadingItem downloading, List<string> urls, string path, string localFileName)
{ {
// path已斜杠结尾去掉斜杠
path = path.TrimEnd('/').TrimEnd('\\');
AriaSendOption option = new AriaSendOption AriaSendOption option = new AriaSendOption
{ {
//HttpProxy = $"http://{Settings.GetAriaHttpProxy()}:{Settings.GetAriaHttpProxyListenPort()}", //HttpProxy = $"http://{Settings.GetAriaHttpProxy()}:{Settings.GetAriaHttpProxyListenPort()}",
@ -691,6 +714,8 @@ namespace DownKyi.Services.Download
{ {
case DownloadStatus.PAUSE: case DownloadStatus.PAUSE:
Task<AriaPause> ariaPause = AriaClient.PauseAsync(downloading.Gid); Task<AriaPause> ariaPause = AriaClient.PauseAsync(downloading.Gid);
// 通知UI并阻塞当前线程
Pause(downloading);
break; break;
case DownloadStatus.DOWNLOADING: case DownloadStatus.DOWNLOADING:
Task<AriaPause> ariaUnpause = AriaClient.UnpauseAsync(downloading.Gid); Task<AriaPause> ariaUnpause = AriaClient.UnpauseAsync(downloading.Gid);
@ -712,8 +737,7 @@ namespace DownKyi.Services.Download
} }
// 根据进度判断本次是否需要更新UI // 根据进度判断本次是否需要更新UI
// TODO 小于多少需要测试 if (Math.Abs(percent - video.Progress) < 0.01) { return; }
if (percent - video.Progress < 0.01) { return; }
// 下载进度 // 下载进度
video.Progress = percent; video.Progress = percent;
@ -729,7 +753,6 @@ namespace DownKyi.Services.Download
{ {
video.MaxSpeed = speed; video.MaxSpeed = speed;
} }
} }
private void AriaDownloadFinish(bool isSuccess, string downloadPath, string gid, string msg) private void AriaDownloadFinish(bool isSuccess, string downloadPath, string gid, string msg)

@ -162,7 +162,7 @@ namespace DownKyi.Services
// 分区 // 分区
string videoZone = string.Empty; string videoZone = string.Empty;
var zoneList = Core.BiliApi.Zone.VideoZone.Instance().GetZone(); var zoneList = Core.BiliApi.Zone.VideoZone.Instance().GetZones();
var zone = zoneList.Find(it => it.Id == videoView.Tid); var zone = zoneList.Find(it => it.Id == videoView.Tid);
if (zone != null) if (zone != null)
{ {

@ -585,11 +585,31 @@ namespace DownKyi.ViewModels
} }
} }
// 视频分区
int zoneId = -1;
List<ZoneAttr> zoneList = VideoZone.Instance().GetZones();
ZoneAttr zone = zoneList.Find(it => it.Id == VideoInfoView.TypeId);
if (zone != null)
{
ZoneAttr zoneParent = zoneList.Find(it => it.Id == zone.ParentId);
if (zoneParent != null)
{
zoneId = zoneParent.Id;
}
}
// 如果只有一个视频章节,则不在命名中出现
string sectionName = string.Empty;
if (VideoSections.Count > 1)
{
sectionName = section.Title;
}
// 文件路径 // 文件路径
List<FileNamePart> fileNameParts = SettingsManager.GetInstance().GetFileNameParts(); List<FileNamePart> fileNameParts = SettingsManager.GetInstance().GetFileNameParts();
FileName fileName = FileName.Builder(fileNameParts) FileName fileName = FileName.Builder(fileNameParts)
.SetOrder(page.Order) .SetOrder(page.Order)
.SetSection(Format.FormatFileName(section.Title)) .SetSection(Format.FormatFileName(sectionName))
.SetMainTitle(Format.FormatFileName(VideoInfoView.Title)) .SetMainTitle(Format.FormatFileName(VideoInfoView.Title))
.SetPageTitle(Format.FormatFileName(page.Name)) .SetPageTitle(Format.FormatFileName(page.Name))
.SetVideoZone(VideoInfoView.VideoZone.Split('>')[0]) .SetVideoZone(VideoInfoView.VideoZone.Split('>')[0])
@ -644,7 +664,7 @@ namespace DownKyi.ViewModels
EpisodeId = page.EpisodeId, EpisodeId = page.EpisodeId,
CoverUrl = page.FirstFrame, CoverUrl = page.FirstFrame,
ZoneImage = (DrawingImage)Application.Current.Resources[VideoZoneIcon.Instance().GetZoneImageKey(VideoInfoView.TypeId)], ZoneImage = (DrawingImage)Application.Current.Resources[VideoZoneIcon.Instance().GetZoneImageKey(zoneId)],
Order = page.Order, Order = page.Order,
MainTitle = VideoInfoView.Title, MainTitle = VideoInfoView.Title,

@ -15,7 +15,7 @@
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="70" /> <ColumnDefinition Width="70" />
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
<ColumnDefinition Width="300" /> <ColumnDefinition Width="320" />
<ColumnDefinition Width="80" /> <ColumnDefinition Width="80" />
<ColumnDefinition Width="20" /> <ColumnDefinition Width="20" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>

Loading…
Cancel
Save