调整代码结构

croire 3 years ago
parent 31d82a9309
commit 3c2ef7cf1e

@ -4,25 +4,43 @@ namespace DownKyi.Core.BiliApi.BiliUtils
{
public static class Constant
{
private static readonly List<Quality> resolutions = new List<Quality>
{
new Quality { Name = "HDR 真彩", Id = 125 },
new Quality { Name = "4K 超清", Id = 120 },
new Quality { Name = "1080P 60帧", Id = 116 },
new Quality { Name = "1080P 高码率", Id = 112 },
new Quality { Name = "1080P 高清", Id = 80 },
new Quality { Name = "720P 60帧", Id = 74 },
new Quality { Name = "720P 高清", Id = 64 },
new Quality { Name = "480P 清晰", Id = 32 },
new Quality { Name = "360P 流畅", Id = 16 },
};
private static readonly List<Quality> qualities = new List<Quality>
{
new Quality { Name = "64K", Id = 30216 },
new Quality { Name = "132K", Id = 30232 },
new Quality { Name = "192K", Id = 30280 },
};
/// <summary>
/// 音质id及含义
/// 获取支持的视频画质
/// </summary>
public static Dictionary<int, string> AudioQuality { get; } = new Dictionary<int, string>()
/// <returns></returns>
public static List<Quality> GetResolutions()
{
{ 30216, "64K" },
{ 30232, "132K" },
{ 30280, "192K" }
};
return resolutions;
}
/// <summary>
/// 音质id及含义
/// 获取支持的视频音质
/// </summary>
public static Dictionary<string, int> AudioQualityId { get; } = new Dictionary<string, int>()
/// <returns></returns>
public static List<Quality> GetAudioQualities()
{
{ "64K", 30216 },
{ "132K", 30232 },
{ "192K", 30280 }
};
return qualities;
}
}
}

@ -1,6 +1,6 @@
namespace DownKyi.Models
namespace DownKyi.Core.BiliApi.BiliUtils
{
public class Resolution
public class Quality
{
public string Name { get; set; }
public int Id { get; set; }

@ -129,6 +129,7 @@
<Compile Include="BiliApi\Bangumi\Models\BangumiUpInfo.cs" />
<Compile Include="BiliApi\BiliUtils\Constant.cs" />
<Compile Include="BiliApi\BiliUtils\ParseEntrance.cs" />
<Compile Include="BiliApi\BiliUtils\Quality.cs" />
<Compile Include="BiliApi\Cheese\CheeseInfo.cs" />
<Compile Include="BiliApi\Cheese\Models\CheeseBrief.cs" />
<Compile Include="BiliApi\Cheese\Models\CheeseEpisode.cs" />

@ -96,7 +96,6 @@
<Compile Include="Models\DisplayFileNamePart.cs" />
<Compile Include="Models\ParseScopeDisplay.cs" />
<Compile Include="Models\PlayStreamType.cs" />
<Compile Include="Models\Resolution.cs" />
<Compile Include="Models\TabHeader.cs" />
<Compile Include="Models\VideoQuality.cs" />
<Compile Include="Models\VideoInfoView.cs" />
@ -110,8 +109,6 @@
<Compile Include="Services\Download\IDownloadService.cs" />
<Compile Include="Services\IFavoritesService.cs" />
<Compile Include="Services\IInfoService.cs" />
<Compile Include="Services\IResolutionService.cs" />
<Compile Include="Services\ResolutionService.cs" />
<Compile Include="Services\Utils.cs" />
<Compile Include="Services\VideoInfoService.cs" />
<Compile Include="Utils\ClipboardHooker.cs" />

@ -1,4 +1,5 @@
using Prism.Mvvm;
using DownKyi.Core.BiliApi.BiliUtils;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Windows.Media;
@ -77,15 +78,6 @@ namespace DownKyi.Models
set => SetProperty(ref duration, value);
}
// 音频编码
public int AudioCodecId { get; set; }
private string audioCodecName;
public string AudioCodecName
{
get => audioCodecName;
set => SetProperty(ref audioCodecName, value);
}
// 视频编码
// "hev1.2.4.L156.90"
// "avc1.640034"
@ -100,13 +92,21 @@ namespace DownKyi.Models
}
// 视频画质
private Resolution resolution;
public Resolution Resolution
private Quality resolution;
public Quality Resolution
{
get => resolution;
set => SetProperty(ref resolution, value);
}
// 音频编码
private Quality audioCodec;
public Quality AudioCodec
{
get => audioCodec;
set => SetProperty(ref audioCodec, value);
}
// 文件路径,不包含扩展名,所有内容均以此路径下载
public string FilePath { get; set; }

@ -59,7 +59,7 @@ namespace DownKyi.Services.Download
PlayUrlDashVideo downloadAudio = null;
foreach (PlayUrlDashVideo audio in downloading.PlayUrl.Dash.Audio)
{
if (audio.Id == downloading.AudioCodecId)
if (audio.Id == downloading.AudioCodec.Id)
{
downloadAudio = audio;
break;

@ -1,10 +0,0 @@
using DownKyi.Models;
using System.Collections.Generic;
namespace DownKyi.Services
{
public interface IResolutionService
{
List<Resolution> GetResolution();
}
}

@ -1,26 +0,0 @@
using DownKyi.Models;
using System.Collections.Generic;
namespace DownKyi.Services
{
public class ResolutionService : IResolutionService
{
public List<Resolution> GetResolution()
{
List<Resolution> resolutions = new List<Resolution>
{
new Resolution { Name = "HDR 真彩", Id = 125 },
new Resolution { Name = "4K 超清", Id = 120 },
new Resolution { Name = "1080P 60帧", Id = 116 },
new Resolution { Name = "1080P 高码率", Id = 112 },
new Resolution { Name = "1080P 高清", Id = 80 },
new Resolution { Name = "720P 60帧", Id = 74 },
new Resolution { Name = "720P 高清", Id = 64 },
new Resolution { Name = "480P 清晰", Id = 32 },
new Resolution { Name = "360P 流畅", Id = 16 }
};
return resolutions;
}
}
}

@ -1,4 +1,5 @@
using DownKyi.Core.BiliApi.VideoStream.Models;
using DownKyi.Core.BiliApi.BiliUtils;
using DownKyi.Core.BiliApi.VideoStream.Models;
using DownKyi.Core.Settings;
using DownKyi.Core.Settings.Models;
using DownKyi.Core.Utils;
@ -101,9 +102,10 @@ namespace DownKyi.Services
// 音质id大于设置画质时跳过
if (audio.Id > defaultAudioQuality) { continue; }
if (Core.BiliApi.BiliUtils.Constant.AudioQuality.ContainsKey(audio.Id))
Quality audioQuality = Constant.GetAudioQualities().FirstOrDefault(t => { return t.Id == audio.Id; });
if (audioQuality != null)
{
ListHelper.AddUnique(audioQualityFormatList, Core.BiliApi.BiliUtils.Constant.AudioQuality[audio.Id]);
ListHelper.AddUnique(audioQualityFormatList, audioQuality.Name);
}
}

@ -3,7 +3,6 @@ using DownKyi.Core.FileName;
using DownKyi.Core.Settings;
using DownKyi.Events;
using DownKyi.Models;
using DownKyi.Services;
using DownKyi.Utils;
using Prism.Commands;
using Prism.Events;
@ -37,29 +36,29 @@ namespace DownKyi.ViewModels.Settings
set => SetProperty(ref selectedVideoCodec, value);
}
private List<Resolution> videoQualityList;
public List<Resolution> VideoQualityList
private List<Quality> videoQualityList;
public List<Quality> VideoQualityList
{
get => videoQualityList;
set => SetProperty(ref videoQualityList, value);
}
private Resolution selectedVideoQuality;
public Resolution SelectedVideoQuality
private Quality selectedVideoQuality;
public Quality SelectedVideoQuality
{
get => selectedVideoQuality;
set => SetProperty(ref selectedVideoQuality, value);
}
private List<string> audioQualityList;
public List<string> AudioQualityList
private List<Quality> audioQualityList;
public List<Quality> AudioQualityList
{
get => audioQualityList;
set => SetProperty(ref audioQualityList, value);
}
private string selectedAudioQuality;
public string SelectedAudioQuality
private Quality selectedAudioQuality;
public Quality SelectedAudioQuality
{
get => selectedAudioQuality;
set => SetProperty(ref selectedAudioQuality, value);
@ -123,15 +122,10 @@ namespace DownKyi.ViewModels.Settings
};
// 优先下载画质
VideoQualityList = new ResolutionService().GetResolution();
VideoQualityList = Constant.GetResolutions();
// 优先下载音质
AudioQualityList = new List<string>
{
"64K",
"132K",
"192K",
};
AudioQualityList = Constant.GetAudioQualities();
// 文件命名格式
SelectedFileName = new ObservableCollection<DisplayFileNamePart>();
@ -168,7 +162,7 @@ namespace DownKyi.ViewModels.Settings
// 优先下载音质
int audioQuality = SettingsManager.GetInstance().GetAudioQuality();
SelectedAudioQuality = Constant.AudioQuality[audioQuality];
SelectedAudioQuality = AudioQualityList.FirstOrDefault(t => { return t.Id == audioQuality; });
// 是否下载flv视频后转码为mp4
AllowStatus isTranscodingFlvToMp4 = SettingsManager.GetInstance().IsTranscodingFlvToMp4();
@ -221,23 +215,25 @@ namespace DownKyi.ViewModels.Settings
/// <param name="parameter"></param>
private void ExecuteVideoQualityCommand(object parameter)
{
if (!(parameter is Resolution resolution)) { return; }
if (!(parameter is Quality resolution)) { return; }
bool isSucceed = SettingsManager.GetInstance().SetQuality(resolution.Id);
PublishTip(isSucceed);
}
// 优先下载音质事件
private DelegateCommand<string> audioQualityCommand;
public DelegateCommand<string> AudioQualityCommand => audioQualityCommand ?? (audioQualityCommand = new DelegateCommand<string>(ExecuteAudioQualityCommand));
private DelegateCommand<object> audioQualityCommand;
public DelegateCommand<object> AudioQualityCommand => audioQualityCommand ?? (audioQualityCommand = new DelegateCommand<object>(ExecuteAudioQualityCommand));
/// <summary>
/// 优先下载音质事件
/// </summary>
/// <param name="parameter"></param>
private void ExecuteAudioQualityCommand(string parameter)
private void ExecuteAudioQualityCommand(object parameter)
{
bool isSucceed = SettingsManager.GetInstance().SetAudioQuality(Constant.AudioQualityId[parameter]);
if (!(parameter is Quality quality)) { return; }
bool isSucceed = SettingsManager.GetInstance().SetAudioQuality(quality.Id);
PublishTip(isSucceed);
}

@ -568,7 +568,7 @@ namespace DownKyi.ViewModels
// 如果存在正在下载列表,则跳过,并提示
foreach (DownloadingItem item in App.DownloadingList)
{
if (item.Cid == page.Cid && item.Resolution.Id == page.VideoQuality.Quality && item.AudioCodecName == page.AudioQualityFormat && item.VideoCodecName == page.VideoQuality.SelectedVideoCodec)
if (item.Cid == page.Cid && item.Resolution.Id == page.VideoQuality.Quality && item.AudioCodec.Name == page.AudioQualityFormat && item.VideoCodecName == page.VideoQuality.SelectedVideoCodec)
{
eventAggregator.GetEvent<MessageEvent>().Publish($"{page.Name}{DictionaryResource.GetString("TipAlreadyToAddDownloading")}");
continue;
@ -578,7 +578,7 @@ namespace DownKyi.ViewModels
// 如果存在下载完成列表,弹出选择框是否再次下载
foreach (DownloadedItem item in App.DownloadedList)
{
if (item.Cid == page.Cid && item.Resolution.Id == page.VideoQuality.Quality && item.AudioCodecName == page.AudioQualityFormat && item.VideoCodecName == page.VideoQuality.SelectedVideoCodec)
if (item.Cid == page.Cid && item.Resolution.Id == page.VideoQuality.Quality && item.AudioCodec.Name == page.AudioQualityFormat && item.VideoCodecName == page.VideoQuality.SelectedVideoCodec)
{
eventAggregator.GetEvent<MessageEvent>().Publish($"{page.Name}{DictionaryResource.GetString("TipAlreadyToAddDownloaded")}");
continue;
@ -670,15 +670,15 @@ namespace DownKyi.ViewModels
MainTitle = VideoInfoView.Title,
Name = page.Name,
Duration = page.Duration,
AudioCodecId = Constant.AudioQualityId[page.AudioQualityFormat],
AudioCodecName = page.AudioQualityFormat,
VideoCodecName = page.VideoQuality.SelectedVideoCodec,
Resolution = new Resolution { Name = page.VideoQuality.QualityFormat, Id = page.VideoQuality.Quality },
Resolution = new Quality { Name = page.VideoQuality.QualityFormat, Id = page.VideoQuality.Quality },
AudioCodec = Constant.GetAudioQualities().FirstOrDefault(t => { return t.Name == page.AudioQualityFormat; }),
FilePath = filePath,
PlayStreamType = playStreamType,
DownloadStatus = DownloadStatus.NOT_STARTED,
};
// 需要下载的内容
downloading.NeedDownloadContent["downloadAudio"] = downloadAudio;
downloading.NeedDownloadContent["downloadVideo"] = downloadVideo;

@ -60,7 +60,7 @@
<Binding Path="Duration" />
<Binding Path="Resolution.Name" />
<Binding Path="VideoCodecName" />
<Binding Path="AudioCodecName" />
<Binding Path="AudioCodec.Name" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>

@ -65,6 +65,7 @@
Name="nameAudioQualityList"
Width="120"
VerticalContentAlignment="Center"
DisplayMemberPath="Name"
ItemsSource="{Binding AudioQualityList}"
SelectedItem="{Binding SelectedAudioQuality}">
<i:Interaction.Triggers>

Loading…
Cancel
Save