文件命名格式中,时间格式可设置;机器码去掉硬盘信息;修复多线程操作sqlite的异常问题;修复视频标题和分P标题相同时找不到下载文件的问题;150%缩放下的窗口不超出屏幕;

pull/278/head
leiurayer 4 years ago
parent 4fd747d382
commit 0e2058548f

@ -42,8 +42,8 @@ namespace DownKyi.Core.Aria2cNet.Client.Entity
//[JsonProperty("use-head")] //[JsonProperty("use-head")]
//public string UseHead { get; set; } //public string UseHead { get; set; }
//[JsonProperty("user-agent")] [JsonProperty("user-agent")]
//public string UserAgent { get; set; } public string UserAgent { get; set; }
public override string ToString() public override string ToString()
{ {

@ -16,5 +16,6 @@ namespace DownKyi.Core.Settings.Models
public List<string> HistoryVideoRootPaths { get; set; } // 历史视频保存路径 public List<string> HistoryVideoRootPaths { get; set; } // 历史视频保存路径
public AllowStatus IsUseSaveVideoRootPath { get; set; } // 是否使用默认视频保存路径 public AllowStatus IsUseSaveVideoRootPath { get; set; } // 是否使用默认视频保存路径
public List<FileNamePart> FileNameParts { get; set; } // 文件命名格式 public List<FileNamePart> FileNameParts { get; set; } // 文件命名格式
public string FileNamePartTimeFormat { get; set; } // 文件命名中的时间格式
} }
} }

@ -44,6 +44,9 @@ namespace DownKyi.Core.Settings
FileNamePart.VIDEO_CODEC, FileNamePart.VIDEO_CODEC,
}; };
// 文件命名中的时间格式
private readonly string fileNamePartTimeFormat = "yyyy-MM-dd";
/// <summary> /// <summary>
/// 获取优先下载的视频编码 /// 获取优先下载的视频编码
/// </summary> /// </summary>
@ -260,5 +263,32 @@ namespace DownKyi.Core.Settings
return SetSettings(); return SetSettings();
} }
/// <summary>
/// 获取文件命名中的时间格式
/// </summary>
/// <returns></returns>
public string GetFileNamePartTimeFormat()
{
appSettings = GetSettings();
if (appSettings.Video.FileNamePartTimeFormat == null || appSettings.Video.FileNamePartTimeFormat == string.Empty)
{
// 第一次获取,先设置默认值
SetFileNamePartTimeFormat(fileNamePartTimeFormat);
return fileNamePartTimeFormat;
}
return appSettings.Video.FileNamePartTimeFormat;
}
/// <summary>
/// 设置文件命名中的时间格式
/// </summary>
/// <param name="fileNamePartTimeFormat"></param>
/// <returns></returns>
public bool SetFileNamePartTimeFormat(string fileNamePartTimeFormat)
{
appSettings.Video.FileNamePartTimeFormat = fileNamePartTimeFormat;
return SetSettings();
}
} }
} }

@ -1,20 +1,37 @@
using System; using DownKyi.Core.Logging;
using System;
using System.Collections.Generic;
using System.Data.SQLite; using System.Data.SQLite;
namespace DownKyi.Core.Storage.Database namespace DownKyi.Core.Storage.Database
{ {
public class DbHelper public class DbHelper
{ {
private readonly string connStr;
private readonly SQLiteConnection conn; private readonly SQLiteConnection conn;
private static readonly Dictionary<string, SQLiteConnection> database = new Dictionary<string, SQLiteConnection>();
/// <summary> /// <summary>
/// 创建一个数据库 /// 创建一个数据库
/// </summary> /// </summary>
/// <param name="dbPath"></param> /// <param name="dbPath"></param>
public DbHelper(string dbPath) public DbHelper(string dbPath)
{ {
string connStr = $"Data Source={dbPath};Version=3;"; connStr = $"Data Source={dbPath};Version=3;";
if (database.ContainsKey(connStr))
{
conn = database[connStr];
if (conn != null)
{
return;
}
}
conn = new SQLiteConnection(connStr); conn = new SQLiteConnection(connStr);
database.Add(connStr, conn);
} }
/// <summary> /// <summary>
@ -25,8 +42,20 @@ namespace DownKyi.Core.Storage.Database
public DbHelper(string dbPath, string secretKey) public DbHelper(string dbPath, string secretKey)
{ {
string connStr = $"Data Source={dbPath};Version=3;"; string connStr = $"Data Source={dbPath};Version=3;";
if (database.ContainsKey(connStr))
{
conn = database[connStr];
if (conn != null)
{
return;
}
}
conn = new SQLiteConnection(connStr); conn = new SQLiteConnection(connStr);
conn.SetPassword(secretKey); conn.SetPassword(secretKey);
database.Add(connStr, conn);
} }
/// <summary> /// <summary>
@ -57,6 +86,8 @@ namespace DownKyi.Core.Storage.Database
if (IsOpen()) if (IsOpen())
{ {
conn.Close(); conn.Close();
database.Remove(connStr);
} }
} }
@ -65,6 +96,8 @@ namespace DownKyi.Core.Storage.Database
/// </summary> /// </summary>
/// <param name="sql"></param> /// <param name="sql"></param>
public void ExecuteNonQuery(string sql, Action<SQLiteParameterCollection> action = null) public void ExecuteNonQuery(string sql, Action<SQLiteParameterCollection> action = null)
{
try
{ {
lock (conn) lock (conn)
{ {
@ -82,6 +115,12 @@ namespace DownKyi.Core.Storage.Database
} }
} }
} }
catch (SQLiteException e)
{
Utils.Debugging.Console.PrintLine("DbHelper ExecuteNonQuery()发生异常: {0}", e);
LogManager.Error("DbHelper ExecuteNonQuery()", e);
}
}
/// <summary> /// <summary>
/// 执行一条SQL语句并执行提供的操作一般用于查询 /// 执行一条SQL语句并执行提供的操作一般用于查询
@ -89,6 +128,8 @@ namespace DownKyi.Core.Storage.Database
/// <param name="sql"></param> /// <param name="sql"></param>
/// <param name="action"></param> /// <param name="action"></param>
public void ExecuteQuery(string sql, Action<SQLiteDataReader> action) public void ExecuteQuery(string sql, Action<SQLiteDataReader> action)
{
try
{ {
lock (conn) lock (conn)
{ {
@ -101,6 +142,12 @@ namespace DownKyi.Core.Storage.Database
} }
} }
} }
catch (SQLiteException e)
{
Utils.Debugging.Console.PrintLine("DbHelper ExecuteQuery()发生异常: {0}", e);
LogManager.Error("DbHelper ExecuteQuery()", e);
}
}
} }
} }

@ -20,8 +20,8 @@ namespace DownKyi.Core.Utils
string machineCodeString = "PC." + string machineCodeString = "PC." +
machineCode.GetMainBordId() + "." + machineCode.GetMainBordId() + "." +
machineCode.GetCpuInfo() + "." + machineCode.GetCpuInfo();// + "." +
machineCode.GetDiskID();// + "." + //machineCode.GetDiskID();// + "." +
//machineCode.GetMoAddress(); //machineCode.GetMoAddress();
return machineCodeString.Replace(" ", ""); return machineCodeString.Replace(" ", "");
} }

@ -100,6 +100,7 @@
<Compile Include="Services\Download\AddToDownloadService.cs" /> <Compile Include="Services\Download\AddToDownloadService.cs" />
<Compile Include="Services\Download\DownloadStorageService.cs" /> <Compile Include="Services\Download\DownloadStorageService.cs" />
<Compile Include="Services\SearchService.cs" /> <Compile Include="Services\SearchService.cs" />
<Compile Include="Utils\WindowAdaptation.cs" />
<Compile Include="ViewModels\PageViewModels\BangumiFollowMedia.cs" /> <Compile Include="ViewModels\PageViewModels\BangumiFollowMedia.cs" />
<Compile Include="ViewModels\PageViewModels\Favorites.cs" /> <Compile Include="ViewModels\PageViewModels\Favorites.cs" />
<Compile Include="ViewModels\PageViewModels\FavoritesMedia.cs" /> <Compile Include="ViewModels\PageViewModels\FavoritesMedia.cs" />

@ -219,6 +219,7 @@
<system:String x:Key="DisplayUpMid">UP主ID</system:String> <system:String x:Key="DisplayUpMid">UP主ID</system:String>
<system:String x:Key="DisplayUpName">UP主昵称</system:String> <system:String x:Key="DisplayUpName">UP主昵称</system:String>
<system:String x:Key="Reset">恢复默认</system:String> <system:String x:Key="Reset">恢复默认</system:String>
<system:String x:Key="FileNameTimeFormat">时间格式:</system:String>
<system:String x:Key="SettingDanmaku">弹幕</system:String> <system:String x:Key="SettingDanmaku">弹幕</system:String>
<system:String x:Key="FilterType">按类型屏蔽</system:String> <system:String x:Key="FilterType">按类型屏蔽</system:String>

@ -3,6 +3,7 @@ using DownKyi.Core.BiliApi.Bangumi.Models;
using DownKyi.Core.BiliApi.BiliUtils; using DownKyi.Core.BiliApi.BiliUtils;
using DownKyi.Core.BiliApi.VideoStream; using DownKyi.Core.BiliApi.VideoStream;
using DownKyi.Core.BiliApi.VideoStream.Models; using DownKyi.Core.BiliApi.VideoStream.Models;
using DownKyi.Core.Settings;
using DownKyi.Core.Storage; using DownKyi.Core.Storage;
using DownKyi.Core.Utils; using DownKyi.Core.Utils;
using DownKyi.Utils; using DownKyi.Utils;
@ -120,10 +121,12 @@ namespace DownKyi.Services
}; };
} }
// 文件命名中的时间格式
string timeFormat = SettingsManager.GetInstance().GetFileNamePartTimeFormat();
// 视频发布时间 // 视频发布时间
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区 DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区
DateTime dateTime = startTime.AddSeconds(episode.PubTime); DateTime dateTime = startTime.AddSeconds(episode.PubTime);
page.PublishTime = dateTime.ToString("yyyy-MM-dd"); page.PublishTime = dateTime.ToString(timeFormat);
pages.Add(page); pages.Add(page);
} }
@ -194,10 +197,12 @@ namespace DownKyi.Services
}; };
} }
// 文件命名中的时间格式
string timeFormat = SettingsManager.GetInstance().GetFileNamePartTimeFormat();
// 视频发布时间 // 视频发布时间
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区 DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区
DateTime dateTime = startTime.AddSeconds(episode.PubTime); DateTime dateTime = startTime.AddSeconds(episode.PubTime);
page.PublishTime = dateTime.ToString("yyyy-MM-dd"); page.PublishTime = dateTime.ToString(timeFormat);
pages.Add(page); pages.Add(page);
} }

@ -3,6 +3,7 @@ using DownKyi.Core.BiliApi.Cheese;
using DownKyi.Core.BiliApi.Cheese.Models; using DownKyi.Core.BiliApi.Cheese.Models;
using DownKyi.Core.BiliApi.VideoStream; using DownKyi.Core.BiliApi.VideoStream;
using DownKyi.Core.BiliApi.VideoStream.Models; using DownKyi.Core.BiliApi.VideoStream.Models;
using DownKyi.Core.Settings;
using DownKyi.Core.Storage; using DownKyi.Core.Storage;
using DownKyi.Core.Utils; using DownKyi.Core.Utils;
using DownKyi.Utils; using DownKyi.Utils;
@ -88,10 +89,12 @@ namespace DownKyi.Services
}; };
} }
// 文件命名中的时间格式
string timeFormat = SettingsManager.GetInstance().GetFileNamePartTimeFormat();
// 视频发布时间 // 视频发布时间
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区 DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区
DateTime dateTime = startTime.AddSeconds(episode.ReleaseDate); DateTime dateTime = startTime.AddSeconds(episode.ReleaseDate);
page.PublishTime = dateTime.ToString("yyyy-MM-dd"); page.PublishTime = dateTime.ToString(timeFormat);
pages.Add(page); pages.Add(page);
} }

@ -302,7 +302,7 @@ namespace DownKyi.Services.Download
.SetBvid(page.Bvid) .SetBvid(page.Bvid)
.SetCid(page.Cid) .SetCid(page.Cid)
.SetUpMid(page.Owner.Mid) .SetUpMid(page.Owner.Mid)
.SetUpName(page.Owner.Name); .SetUpName(Format.FormatFileName(page.Owner.Name));
string filePath = Path.Combine(directory, fileName.RelativePath()); string filePath = Path.Combine(directory, fileName.RelativePath());
// 视频类别 // 视频类别

@ -138,25 +138,32 @@ namespace DownKyi.Services.Download
// 路径 // 路径
string[] temp = downloading.DownloadBase.FilePath.Split('/'); string[] temp = downloading.DownloadBase.FilePath.Split('/');
string path = downloading.DownloadBase.FilePath.Replace(temp[temp.Length - 1], ""); //string path = downloading.DownloadBase.FilePath.Replace(temp[temp.Length - 1], "");
string path = downloading.DownloadBase.FilePath.TrimEnd(temp[temp.Length - 1].ToCharArray());
// 下载文件名 // 下载文件名
string fileName = Guid.NewGuid().ToString("N"); string fileName = Guid.NewGuid().ToString("N");
string key = $"{downloadVideo.Id}_{downloadVideo.Codecs}"; string key = $"{downloadVideo.Id}_{downloadVideo.Codecs}";
// 老版本数据库没有这一项会变成null // 老版本数据库没有这一项会变成null
if (downloading.Downloading.DownloadedFiles == null) if (downloading.Downloading.DownloadedFiles == null)
{
downloading.Downloading.DownloadedFiles = new List<string>(); downloading.Downloading.DownloadedFiles = new List<string>();
}
if (downloading.Downloading.DownloadFiles.ContainsKey(key)) if (downloading.Downloading.DownloadFiles.ContainsKey(key))
{ {
// 如果存在,表示下载过, // 如果存在,表示下载过,
// 则继续使用上次下载的文件名 // 则继续使用上次下载的文件名
fileName = downloading.Downloading.DownloadFiles[key]; fileName = downloading.Downloading.DownloadFiles[key];
// 还要检查一下文件有没有被人删掉,删掉的话重新下载 // 还要检查一下文件有没有被人删掉,删掉的话重新下载
// 如果下载视频之后音频文件被人删了。此时gid还是视频的会下错文件 // 如果下载视频之后音频文件被人删了。此时gid还是视频的会下错文件
if (downloading.Downloading.DownloadedFiles.Contains(key) && File.Exists(Path.Combine(path, fileName))) if (downloading.Downloading.DownloadedFiles.Contains(key) && File.Exists(Path.Combine(path, fileName)))
{
return Path.Combine(path, fileName); return Path.Combine(path, fileName);
} }
}
else else
{ {
// 记录本次下载的文件 // 记录本次下载的文件
@ -575,7 +582,9 @@ namespace DownKyi.Services.Download
{ {
// 路径 // 路径
string[] temp = downloading.DownloadBase.FilePath.Split('/'); string[] temp = downloading.DownloadBase.FilePath.Split('/');
string path = downloading.DownloadBase.FilePath.Replace(temp[temp.Length - 1], ""); //string path = downloading.DownloadBase.FilePath.Replace(temp[temp.Length - 1], "");
string path = downloading.DownloadBase.FilePath.TrimEnd(temp[temp.Length - 1].ToCharArray());
// 路径不存在则创建 // 路径不存在则创建
if (!Directory.Exists(path)) if (!Directory.Exists(path))
{ {
@ -973,10 +982,10 @@ namespace DownKyi.Services.Download
{ {
//HttpProxy = $"http://{Settings.GetAriaHttpProxy()}:{Settings.GetAriaHttpProxyListenPort()}", //HttpProxy = $"http://{Settings.GetAriaHttpProxy()}:{Settings.GetAriaHttpProxyListenPort()}",
Dir = path, Dir = path,
Out = localFileName Out = localFileName,
//Header = $"cookie: {Login.GetLoginInfoCookiesString()}\nreferer: https://www.bilibili.com", //Header = $"cookie: {LoginHelper.GetLoginInfoCookiesString()}\nreferer: https://www.bilibili.com",
//UseHead = "true", //UseHead = "true",
//UserAgent = Utils.GetUserAgent() UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36",
}; };
// 如果设置了代理则增加HttpProxy // 如果设置了代理则增加HttpProxy

@ -7,6 +7,16 @@ namespace DownKyi.Services.Download
{ {
public class DownloadStorageService public class DownloadStorageService
{ {
~DownloadStorageService()
{
DownloadingDb downloadingDb = new DownloadingDb();
downloadingDb.Close();
DownloadedDb downloadedDb = new DownloadedDb();
downloadedDb.Close();
DownloadBaseDb downloadBaseDb = new DownloadBaseDb();
downloadBaseDb.Close();
}
#region 下载中数据 #region 下载中数据
/// <summary> /// <summary>
@ -25,7 +35,7 @@ namespace DownKyi.Services.Download
{ {
downloadingDb.Insert(downloadingItem.DownloadBase.Uuid, downloadingItem.Downloading); downloadingDb.Insert(downloadingItem.DownloadBase.Uuid, downloadingItem.Downloading);
} }
downloadingDb.Close(); //downloadingDb.Close();
} }
/// <summary> /// <summary>
@ -40,7 +50,7 @@ namespace DownKyi.Services.Download
DownloadingDb downloadingDb = new DownloadingDb(); DownloadingDb downloadingDb = new DownloadingDb();
downloadingDb.Delete(downloadingItem.DownloadBase.Uuid); downloadingDb.Delete(downloadingItem.DownloadBase.Uuid);
downloadingDb.Close(); //downloadingDb.Close();
} }
/// <summary> /// <summary>
@ -52,7 +62,7 @@ namespace DownKyi.Services.Download
// 从数据库获取数据 // 从数据库获取数据
DownloadingDb downloadingDb = new DownloadingDb(); DownloadingDb downloadingDb = new DownloadingDb();
Dictionary<string, object> dic = downloadingDb.QueryAll(); Dictionary<string, object> dic = downloadingDb.QueryAll();
downloadingDb.Close(); //downloadingDb.Close();
// 遍历 // 遍历
List<DownloadingItem> list = new List<DownloadingItem>(); List<DownloadingItem> list = new List<DownloadingItem>();
@ -85,7 +95,7 @@ namespace DownKyi.Services.Download
DownloadingDb downloadingDb = new DownloadingDb(); DownloadingDb downloadingDb = new DownloadingDb();
downloadingDb.Update(downloadingItem.DownloadBase.Uuid, downloadingItem.Downloading); downloadingDb.Update(downloadingItem.DownloadBase.Uuid, downloadingItem.Downloading);
downloadingDb.Close(); //downloadingDb.Close();
} }
#endregion #endregion
@ -108,7 +118,7 @@ namespace DownKyi.Services.Download
{ {
downloadedDb.Insert(downloadedItem.DownloadBase.Uuid, downloadedItem.Downloaded); downloadedDb.Insert(downloadedItem.DownloadBase.Uuid, downloadedItem.Downloaded);
} }
downloadedDb.Close(); //downloadedDb.Close();
} }
/// <summary> /// <summary>
@ -123,7 +133,7 @@ namespace DownKyi.Services.Download
DownloadedDb downloadedDb = new DownloadedDb(); DownloadedDb downloadedDb = new DownloadedDb();
downloadedDb.Delete(downloadedItem.DownloadBase.Uuid); downloadedDb.Delete(downloadedItem.DownloadBase.Uuid);
downloadedDb.Close(); //downloadedDb.Close();
} }
/// <summary> /// <summary>
@ -135,7 +145,7 @@ namespace DownKyi.Services.Download
// 从数据库获取数据 // 从数据库获取数据
DownloadedDb downloadedDb = new DownloadedDb(); DownloadedDb downloadedDb = new DownloadedDb();
Dictionary<string, object> dic = downloadedDb.QueryAll(); Dictionary<string, object> dic = downloadedDb.QueryAll();
downloadedDb.Close(); //downloadedDb.Close();
// 遍历 // 遍历
List<DownloadedItem> list = new List<DownloadedItem>(); List<DownloadedItem> list = new List<DownloadedItem>();
@ -168,7 +178,7 @@ namespace DownKyi.Services.Download
DownloadedDb downloadedDb = new DownloadedDb(); DownloadedDb downloadedDb = new DownloadedDb();
downloadedDb.Update(downloadedItem.DownloadBase.Uuid, downloadedItem.Downloaded); downloadedDb.Update(downloadedItem.DownloadBase.Uuid, downloadedItem.Downloaded);
downloadedDb.Close(); //downloadedDb.Close();
} }
#endregion #endregion
@ -189,7 +199,7 @@ namespace DownKyi.Services.Download
{ {
downloadBaseDb.Insert(downloadBase.Uuid, downloadBase); downloadBaseDb.Insert(downloadBase.Uuid, downloadBase);
} }
downloadBaseDb.Close(); //downloadBaseDb.Close();
} }
/// <summary> /// <summary>
@ -200,7 +210,7 @@ namespace DownKyi.Services.Download
{ {
DownloadBaseDb downloadBaseDb = new DownloadBaseDb(); DownloadBaseDb downloadBaseDb = new DownloadBaseDb();
downloadBaseDb.Delete(uuid); downloadBaseDb.Delete(uuid);
downloadBaseDb.Close(); //downloadBaseDb.Close();
} }
/// <summary> /// <summary>
@ -211,7 +221,7 @@ namespace DownKyi.Services.Download
{ {
DownloadBaseDb downloadBaseDb = new DownloadBaseDb(); DownloadBaseDb downloadBaseDb = new DownloadBaseDb();
object obj = downloadBaseDb.QueryById(uuid); object obj = downloadBaseDb.QueryById(uuid);
downloadBaseDb.Close(); //downloadBaseDb.Close();
return obj is DownloadBase downloadBase ? downloadBase : null; return obj is DownloadBase downloadBase ? downloadBase : null;
} }
@ -226,7 +236,7 @@ namespace DownKyi.Services.Download
DownloadBaseDb downloadBaseDb = new DownloadBaseDb(); DownloadBaseDb downloadBaseDb = new DownloadBaseDb();
downloadBaseDb.Update(downloadBase.Uuid, downloadBase); downloadBaseDb.Update(downloadBase.Uuid, downloadBase);
downloadBaseDb.Close(); //downloadBaseDb.Close();
} }
#endregion #endregion

@ -2,6 +2,7 @@
using DownKyi.Core.BiliApi.Video; using DownKyi.Core.BiliApi.Video;
using DownKyi.Core.BiliApi.Video.Models; using DownKyi.Core.BiliApi.Video.Models;
using DownKyi.Core.BiliApi.VideoStream; using DownKyi.Core.BiliApi.VideoStream;
using DownKyi.Core.Settings;
using DownKyi.Core.Storage; using DownKyi.Core.Storage;
using DownKyi.Core.Utils; using DownKyi.Core.Utils;
using DownKyi.ViewModels.PageViewModels; using DownKyi.ViewModels.PageViewModels;
@ -96,10 +97,12 @@ namespace DownKyi.Services
}; };
} }
// 文件命名中的时间格式
string timeFormat = SettingsManager.GetInstance().GetFileNamePartTimeFormat();
// 视频发布时间 // 视频发布时间
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区 DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区
DateTime dateTime = startTime.AddSeconds(videoView.Pubdate); DateTime dateTime = startTime.AddSeconds(videoView.Pubdate);
videoPage.PublishTime = dateTime.ToString("yyyy-MM-dd"); videoPage.PublishTime = dateTime.ToString(timeFormat);
videoPages.Add(videoPage); videoPages.Add(videoPage);
} }
@ -151,10 +154,12 @@ namespace DownKyi.Services
}; };
} }
// 文件命名中的时间格式
string timeFormat = SettingsManager.GetInstance().GetFileNamePartTimeFormat();
// 视频发布时间 // 视频发布时间
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区 DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区
DateTime dateTime = startTime.AddSeconds(videoView.Pubdate); DateTime dateTime = startTime.AddSeconds(videoView.Pubdate);
page.PublishTime = dateTime.ToString("yyyy-MM-dd"); page.PublishTime = dateTime.ToString(timeFormat);
// 这里的发布时间有问题, // 这里的发布时间有问题,
// 如果是合集,也会执行这里, // 如果是合集,也会执行这里,
// 但是发布时间是入口视频的,不是所有视频的 // 但是发布时间是入口视频的,不是所有视频的

@ -0,0 +1,146 @@
using System;
using System.Drawing;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Interop;
namespace DownKyi.Utils
{
/// <summary>
/// 为窗口<see cref="Window"/>添加附加属性的辅助类
///
/// https://www.cnblogs.com/kybs0/p/9834023.html
/// </summary>
public class WindowAdaptation
{
#region 窗口宽度比例
/// <summary>
/// 窗口宽度比例 单位:小数(0 - 1.0]
/// <para>窗口实际宽度=使用屏幕可显示区域(屏幕高度-任务栏高度)* 窗口宽度比例</para>
/// </summary>
public static readonly DependencyProperty WidthByScreenRatioProperty = DependencyProperty.RegisterAttached(
"WidthByScreenRatio", typeof(double), typeof(WindowAdaptation), new PropertyMetadata(1.0, OnWidthByScreenRatioPropertyChanged));
private static void OnWidthByScreenRatioPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is Window window && e.NewValue is double widthByScreenRatio)
{
if (widthByScreenRatio <= 0 || widthByScreenRatio > 1)
{
throw new ArgumentException($"屏幕比例不支持{widthByScreenRatio}");
}
var screenDisplayArea = GetScreenSize(window);
var screenRatioWidth = screenDisplayArea.Width * widthByScreenRatio;
//if (!double.IsNaN(window.Width) && screenDisplayArea.Width > window.Width)
//{
// window.Width = window.Width;
//}
//else
//{
// window.Width = screenRatioWidth;
//}
if (!double.IsNaN(window.Width) && screenRatioWidth > window.Width)
{
window.Width = window.Width;
}
else if (!double.IsNaN(window.MinWidth) && screenRatioWidth < window.MinWidth)
{
window.Width = screenDisplayArea.Width;
}
else
{
window.Width = screenRatioWidth;
}
}
}
public static void SetWidthByScreenRatio(DependencyObject element, double value)
{
element.SetValue(WidthByScreenRatioProperty, value);
}
public static double GetWidthByScreenRatio(DependencyObject element)
{
return (double)element.GetValue(WidthByScreenRatioProperty);
}
#endregion
#region 窗口高度比例
/// <summary>
/// 窗口宽度比例 单位:小数(0 - 1.0]
/// <para>窗口实际宽度=使用屏幕可显示区域(屏幕高度-任务栏高度)* 窗口宽度比例</para>
/// </summary>
public static readonly DependencyProperty HeightByScreenRatioProperty = DependencyProperty.RegisterAttached(
"HeightByScreenRatio", typeof(double), typeof(WindowAdaptation), new PropertyMetadata(1.0, OnHeightByScreenRatioPropertyChanged));
private static void OnHeightByScreenRatioPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is Window window && e.NewValue is double heightByScreenRatio)
{
if (heightByScreenRatio <= 0 || heightByScreenRatio > 1)
{
throw new ArgumentException($"屏幕比例不支持{heightByScreenRatio}");
}
var screenDisplayArea = GetScreenSize(window);
var screenRatioHeight = screenDisplayArea.Height * heightByScreenRatio;
if (!double.IsNaN(window.Height) && screenDisplayArea.Height > window.Height)
{
window.Height = window.Height;
}
else
{
window.Height = screenRatioHeight;
}
//if (!double.IsNaN(window.Height) && screenRatioHeight > window.Height)
//{
// window.Height = window.Height;
//}
//else if (!double.IsNaN(window.MinHeight) && screenRatioHeight < window.MinHeight)
//{
// window.Height = screenDisplayArea.Height;
//}
//else
//{
// window.Height = screenRatioHeight;
//}
}
}
public static void SetHeightByScreenRatio(DependencyObject element, double value)
{
element.SetValue(HeightByScreenRatioProperty, value);
}
public static double GetHeightByScreenRatio(DependencyObject element)
{
return (double)element.GetValue(HeightByScreenRatioProperty);
}
#endregion
const int DpiPercent = 96;
private static dynamic GetScreenSize(Window window)
{
var intPtr = new WindowInteropHelper(window).Handle;//获取当前窗口的句柄
var screen = Screen.FromHandle(intPtr);//获取当前屏幕
using (Graphics currentGraphics = Graphics.FromHwnd(intPtr))
{
//分别获取当前屏幕X/Y方向的DPI
double dpiXRatio = currentGraphics.DpiX / DpiPercent;
double dpiYRatio = currentGraphics.DpiY / DpiPercent;
var width = screen.WorkingArea.Width / dpiXRatio;
var height = screen.WorkingArea.Height / dpiYRatio;
return new { Width = width, Height = height };
}
}
}
}

@ -105,8 +105,21 @@ namespace DownKyi.ViewModels.Settings
set => SetProperty(ref selectedOptionalField, value); set => SetProperty(ref selectedOptionalField, value);
} }
#endregion private List<string> fileNamePartTimeFormatList;
public List<string> FileNamePartTimeFormatList
{
get => fileNamePartTimeFormatList;
set => SetProperty(ref fileNamePartTimeFormatList, value);
}
private string selectedFileNamePartTimeFormat;
public string SelectedFileNamePartTimeFormat
{
get => selectedFileNamePartTimeFormat;
set => SetProperty(ref selectedFileNamePartTimeFormat, value);
}
#endregion
public ViewVideoViewModel(IEventAggregator eventAggregator) : base(eventAggregator) public ViewVideoViewModel(IEventAggregator eventAggregator) : base(eventAggregator)
{ {
@ -138,6 +151,13 @@ namespace DownKyi.ViewModels.Settings
SelectedOptionalField = -1; SelectedOptionalField = -1;
// 文件命名中的时间格式
FileNamePartTimeFormatList = new List<string>
{
"yyyy-MM-dd",
"yyyy.MM.dd",
};
#endregion #endregion
} }
@ -184,6 +204,9 @@ namespace DownKyi.ViewModels.Settings
SelectedFileName.Add(new DisplayFileNamePart { Id = item, Title = display }); SelectedFileName.Add(new DisplayFileNamePart { Id = item, Title = display });
} }
// 文件命名中的时间格式
SelectedFileNamePartTimeFormat = SettingsManager.GetInstance().GetFileNamePartTimeFormat();
isOnNavigatedTo = false; isOnNavigatedTo = false;
} }
@ -313,6 +336,8 @@ namespace DownKyi.ViewModels.Settings
isSucceed = SettingsManager.GetInstance().SetFileNameParts(fileName); isSucceed = SettingsManager.GetInstance().SetFileNameParts(fileName);
PublishTip(isSucceed); PublishTip(isSucceed);
SelectedOptionalField = -1;
} }
// 可选文件名字段点击事件 // 可选文件名字段点击事件
@ -363,8 +388,25 @@ namespace DownKyi.ViewModels.Settings
string display = DisplayFileNamePart(item); string display = DisplayFileNamePart(item);
SelectedFileName.Add(new DisplayFileNamePart { Id = item, Title = display }); SelectedFileName.Add(new DisplayFileNamePart { Id = item, Title = display });
} }
SelectedOptionalField = -1;
} }
// 文件命名中的时间格式事件
private DelegateCommand<object> fileNamePartTimeFormatCommand;
public DelegateCommand<object> FileNamePartTimeFormatCommand => fileNamePartTimeFormatCommand ?? (fileNamePartTimeFormatCommand = new DelegateCommand<object>(ExecuteFileNamePartTimeFormatCommand));
/// <summary>
/// 文件命名中的时间格式事件
/// </summary>
/// <param name="parameter"></param>
private void ExecuteFileNamePartTimeFormatCommand(object parameter)
{
if (!(parameter is string timeFormat)) { return; }
bool isSucceed = SettingsManager.GetInstance().SetFileNamePartTimeFormat(timeFormat);
PublishTip(isSucceed);
}
#endregion #endregion

@ -3,12 +3,15 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:local="clr-namespace:DownKyi.Utils"
xmlns:prism="http://prismlibrary.com/" xmlns:prism="http://prismlibrary.com/"
Title="{DynamicResource AppName}" Title="{DynamicResource AppName}"
Width="1100" Width="1100"
Height="750" Height="750"
MinWidth="1100" MinWidth="800"
MinHeight="750" MinHeight="550"
local:WindowAdaptation.HeightByScreenRatio="0.75"
local:WindowAdaptation.WidthByScreenRatio="0.8"
prism:ViewModelLocator.AutoWireViewModel="True" prism:ViewModelLocator.AutoWireViewModel="True"
ResizeMode="CanResize" ResizeMode="CanResize"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen"
@ -200,4 +203,5 @@
</Border> </Border>
</Grid> </Grid>
</Border> </Border>
</Window> </Window>

@ -403,6 +403,7 @@
TextWrapping="WrapWithOverflow" /> TextWrapping="WrapWithOverflow" />
</StackPanel> </StackPanel>
<StackPanel Margin="10" />
</StackPanel> </StackPanel>
</ScrollViewer> </ScrollViewer>
</UserControl> </UserControl>

@ -105,6 +105,7 @@
</ComboBox> </ComboBox>
</StackPanel> </StackPanel>
<StackPanel Margin="10" />
</StackPanel> </StackPanel>
</ScrollViewer> </ScrollViewer>
</UserControl> </UserControl>

@ -188,6 +188,7 @@
ToolTip="{DynamicResource LayoutAlgorithmAsyncTip}" /> ToolTip="{DynamicResource LayoutAlgorithmAsyncTip}" />
</StackPanel> </StackPanel>
<StackPanel Margin="10" />
</StackPanel> </StackPanel>
</ScrollViewer> </ScrollViewer>
</UserControl> </UserControl>

@ -256,6 +256,7 @@
</ComboBox> </ComboBox>
</StackPanel> </StackPanel>
<StackPanel Margin="10" />
</StackPanel> </StackPanel>
</ScrollViewer> </ScrollViewer>
</UserControl> </UserControl>

@ -178,20 +178,20 @@
Grid.Column="0" Grid.Column="0"
FontSize="12" FontSize="12"
Foreground="{DynamicResource BrushTextDark}" Foreground="{DynamicResource BrushTextDark}"
Text="{DynamicResource FileName}" /> Text="{DynamicResource OptionalFields}" />
<ListBox <ListBox
x:Name="nameSelectedFileName" Name="nameOptionalFields"
Grid.Row="0" Grid.Row="0"
Grid.Column="1" Grid.Column="1"
MinHeight="30"
Margin="0,0,0,20" Margin="0,0,0,20"
ItemContainerStyle="{StaticResource TagItem2Style}" ItemContainerStyle="{StaticResource TagItem2Style}"
ItemsSource="{Binding SelectedFileName, Mode=TwoWay}" ItemsSource="{Binding OptionalFields, Mode=TwoWay}"
SelectedIndex="{Binding SelectedOptionalField}"
SelectionMode="Single" SelectionMode="Single"
Style="{StaticResource Tag2Style}"> Style="{StaticResource Tag2Style}">
<i:Interaction.Triggers> <i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged"> <i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SelectedFileNameCommand}" CommandParameter="{Binding ElementName=nameSelectedFileName, Path=SelectedItem}" /> <i:InvokeCommandAction Command="{Binding OptionalFieldsCommand}" CommandParameter="{Binding ElementName=nameOptionalFields, Path=SelectedItem}" />
</i:EventTrigger> </i:EventTrigger>
</i:Interaction.Triggers> </i:Interaction.Triggers>
</ListBox> </ListBox>
@ -201,23 +201,49 @@
Grid.Column="0" Grid.Column="0"
FontSize="12" FontSize="12"
Foreground="{DynamicResource BrushTextDark}" Foreground="{DynamicResource BrushTextDark}"
Text="{DynamicResource OptionalFields}" /> Text="{DynamicResource FileName}" />
<ListBox <ListBox
Name="nameOptionalFields" x:Name="nameSelectedFileName"
Grid.Row="1" Grid.Row="1"
Grid.Column="1" Grid.Column="1"
MinHeight="30"
ItemContainerStyle="{StaticResource TagItem2Style}" ItemContainerStyle="{StaticResource TagItem2Style}"
ItemsSource="{Binding OptionalFields, Mode=TwoWay}" ItemsSource="{Binding SelectedFileName, Mode=TwoWay}"
SelectedIndex="{Binding SelectedOptionalField}"
SelectionMode="Single" SelectionMode="Single"
Style="{StaticResource Tag2Style}"> Style="{StaticResource Tag2Style}">
<i:Interaction.Triggers> <i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged"> <i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding OptionalFieldsCommand}" CommandParameter="{Binding ElementName=nameOptionalFields, Path=SelectedItem}" /> <i:InvokeCommandAction Command="{Binding SelectedFileNameCommand}" CommandParameter="{Binding ElementName=nameSelectedFileName, Path=SelectedItem}" />
</i:EventTrigger> </i:EventTrigger>
</i:Interaction.Triggers> </i:Interaction.Triggers>
</ListBox> </ListBox>
<StackPanel
Grid.Row="2"
Grid.Column="1"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Orientation="Horizontal">
<TextBlock
VerticalAlignment="Center"
FontSize="12"
Foreground="{DynamicResource BrushTextDark}"
Text="{DynamicResource FileNameTimeFormat}" />
<ComboBox
Name="nameFileNamePartTimeFormat"
Width="120"
VerticalAlignment="Center"
VerticalContentAlignment="Center"
ItemsSource="{Binding FileNamePartTimeFormatList}"
SelectedItem="{Binding SelectedFileNamePartTimeFormat}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding FileNamePartTimeFormatCommand}" CommandParameter="{Binding ElementName=nameFileNamePartTimeFormat, Path=SelectedItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</StackPanel>
<Button <Button
Grid.Row="2" Grid.Row="2"
Grid.Column="1" Grid.Column="1"
@ -232,6 +258,7 @@
</Grid> </Grid>
</GroupBox> </GroupBox>
<StackPanel Margin="10" />
</StackPanel> </StackPanel>
</ScrollViewer> </ScrollViewer>
</UserControl> </UserControl>

Loading…
Cancel
Save