using DownKyi.Core.FileName; using DownKyi.Core.Settings.Models; using System; using System.Collections.Generic; using System.IO; namespace DownKyi.Core.Settings { public partial class SettingsManager { // 设置优先下载的视频编码 private readonly VideoCodecs videoCodecs = VideoCodecs.AVC; // 设置优先下载画质 private readonly int quality = 120; // 设置优先下载音质 private readonly int audioQuality = 30280; // 是否下载flv视频后转码为mp4 private readonly AllowStatus isTranscodingFlvToMp4 = AllowStatus.YES; // 默认下载目录 private readonly string saveVideoRootPath = Path.Combine(Environment.CurrentDirectory, "Media"); // 历史下载目录 private readonly List historyVideoRootPaths = new List(); // 是否使用默认下载目录,如果是,则每次点击下载选中项时不再询问下载目录 private readonly AllowStatus isUseSaveVideoRootPath = AllowStatus.NO; // 下载内容 private readonly VideoContentSettings videoContent = new VideoContentSettings(); // 文件命名格式 private readonly List fileNameParts = new List { FileNamePart.MAIN_TITLE, FileNamePart.SLASH, FileNamePart.SECTION, FileNamePart.SLASH, FileNamePart.ORDER, FileNamePart.HYPHEN, FileNamePart.PAGE_TITLE, FileNamePart.HYPHEN, FileNamePart.VIDEO_QUALITY, FileNamePart.HYPHEN, FileNamePart.VIDEO_CODEC, }; // 文件命名中的时间格式 private readonly string fileNamePartTimeFormat = "yyyy-MM-dd"; // 文件命名中的序号格式 private readonly OrderFormat orderFormat = OrderFormat.NATURAL; /// /// 获取优先下载的视频编码 /// /// public VideoCodecs GetVideoCodecs() { appSettings = GetSettings(); if (appSettings.Video.VideoCodecs == VideoCodecs.NONE) { // 第一次获取,先设置默认值 SetVideoCodecs(videoCodecs); return videoCodecs; } return appSettings.Video.VideoCodecs; } /// /// 设置优先下载的视频编码 /// /// /// public bool SetVideoCodecs(VideoCodecs videoCodecs) { appSettings.Video.VideoCodecs = videoCodecs; return SetSettings(); } /// /// 获取优先下载画质 /// /// public int GetQuality() { appSettings = GetSettings(); if (appSettings.Video.Quality == -1) { // 第一次获取,先设置默认值 SetQuality(quality); return quality; } return appSettings.Video.Quality; } /// /// 设置优先下载画质 /// /// /// public bool SetQuality(int quality) { appSettings.Video.Quality = quality; return SetSettings(); } /// /// 获取优先下载音质 /// /// public int GetAudioQuality() { appSettings = GetSettings(); if (appSettings.Video.AudioQuality == -1) { // 第一次获取,先设置默认值 SetAudioQuality(audioQuality); return audioQuality; } return appSettings.Video.AudioQuality; } /// /// 设置优先下载音质 /// /// /// public bool SetAudioQuality(int quality) { appSettings.Video.AudioQuality = quality; return SetSettings(); } /// /// 获取是否下载flv视频后转码为mp4 /// /// public AllowStatus IsTranscodingFlvToMp4() { appSettings = GetSettings(); if (appSettings.Video.IsTranscodingFlvToMp4 == AllowStatus.NONE) { // 第一次获取,先设置默认值 IsTranscodingFlvToMp4(isTranscodingFlvToMp4); return isTranscodingFlvToMp4; } return appSettings.Video.IsTranscodingFlvToMp4; } /// /// 设置是否下载flv视频后转码为mp4 /// /// /// public bool IsTranscodingFlvToMp4(AllowStatus isTranscodingFlvToMp4) { appSettings.Video.IsTranscodingFlvToMp4 = isTranscodingFlvToMp4; return SetSettings(); } /// /// 获取下载目录 /// /// public string GetSaveVideoRootPath() { appSettings = GetSettings(); if (appSettings.Video.SaveVideoRootPath == null) { // 第一次获取,先设置默认值 SetSaveVideoRootPath(saveVideoRootPath); return saveVideoRootPath; } return appSettings.Video.SaveVideoRootPath; } /// /// 设置下载目录 /// /// /// public bool SetSaveVideoRootPath(string path) { appSettings.Video.SaveVideoRootPath = path; return SetSettings(); } /// /// 获取历史下载目录 /// /// public List GetHistoryVideoRootPaths() { appSettings = GetSettings(); if (appSettings.Video.HistoryVideoRootPaths == null) { // 第一次获取,先设置默认值 SetHistoryVideoRootPaths(historyVideoRootPaths); return historyVideoRootPaths; } return appSettings.Video.HistoryVideoRootPaths; } /// /// 设置历史下载目录 /// /// /// public bool SetHistoryVideoRootPaths(List historyPaths) { appSettings.Video.HistoryVideoRootPaths = historyPaths; return SetSettings(); } /// /// 获取是否使用默认下载目录 /// /// public AllowStatus IsUseSaveVideoRootPath() { appSettings = GetSettings(); if (appSettings.Video.IsUseSaveVideoRootPath == AllowStatus.NONE) { // 第一次获取,先设置默认值 IsUseSaveVideoRootPath(isUseSaveVideoRootPath); return isUseSaveVideoRootPath; } return appSettings.Video.IsUseSaveVideoRootPath; } /// /// 设置是否使用默认下载目录 /// /// /// public bool IsUseSaveVideoRootPath(AllowStatus isUseSaveVideoRootPath) { appSettings.Video.IsUseSaveVideoRootPath = isUseSaveVideoRootPath; return SetSettings(); } /// /// 获取下载内容 /// /// public VideoContentSettings GetVideoContent() { appSettings = GetSettings(); if (appSettings.Video.VideoContent == null) { // 第一次获取,先设置默认值 SetVideoContent(videoContent); return videoContent; } return appSettings.Video.VideoContent; } /// /// 设置下载内容 /// /// /// public bool SetVideoContent(VideoContentSettings videoContent) { appSettings.Video.VideoContent = videoContent; return SetSettings(); } /// /// 获取文件命名格式 /// /// public List GetFileNameParts() { appSettings = GetSettings(); if (appSettings.Video.FileNameParts == null || appSettings.Video.FileNameParts.Count == 0) { // 第一次获取,先设置默认值 SetFileNameParts(fileNameParts); return fileNameParts; } return appSettings.Video.FileNameParts; } /// /// 设置文件命名格式 /// /// /// public bool SetFileNameParts(List fileNameParts) { appSettings.Video.FileNameParts = fileNameParts; return SetSettings(); } /// /// 获取文件命名中的时间格式 /// /// public string GetFileNamePartTimeFormat() { appSettings = GetSettings(); if (appSettings.Video.FileNamePartTimeFormat == null || appSettings.Video.FileNamePartTimeFormat == string.Empty) { // 第一次获取,先设置默认值 SetFileNamePartTimeFormat(fileNamePartTimeFormat); return fileNamePartTimeFormat; } return appSettings.Video.FileNamePartTimeFormat; } /// /// 设置文件命名中的时间格式 /// /// /// public bool SetFileNamePartTimeFormat(string fileNamePartTimeFormat) { appSettings.Video.FileNamePartTimeFormat = fileNamePartTimeFormat; return SetSettings(); } /// /// 获取文件命名中的序号格式 /// /// public OrderFormat GetOrderFormat() { appSettings = GetSettings(); if (appSettings.Video.OrderFormat == OrderFormat.NOT_SET) { // 第一次获取,先设置默认值 SetOrderFormat(orderFormat); return orderFormat; } return appSettings.Video.OrderFormat; } /// /// 设置文件命名中的序号格式 /// /// /// public bool SetOrderFormat(OrderFormat orderFormat) { appSettings.Video.OrderFormat = orderFormat; return SetSettings(); } } }