From 2961b87c1aa76e460ef48f024db795e28af5c4ed Mon Sep 17 00:00:00 2001 From: Vincent Wang <376787823@qq.com> Date: Mon, 14 Oct 2024 14:11:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8B=E8=BD=BDbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WeiboAlbumDownloader/Helpers/HttpHelper.cs | 11 ++++++++++- WeiboAlbumDownloader/MainWindow.xaml.cs | 12 ++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/WeiboAlbumDownloader/Helpers/HttpHelper.cs b/WeiboAlbumDownloader/Helpers/HttpHelper.cs index 8ec2b3b..7f7578d 100644 --- a/WeiboAlbumDownloader/Helpers/HttpHelper.cs +++ b/WeiboAlbumDownloader/Helpers/HttpHelper.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using System; using System.IO; +using System.Linq; using System.Net; using System.Threading.Tasks; using System.Windows; @@ -54,7 +55,15 @@ public static async Task GetAsync(string url, WeiboDataSource dataSource, if (!string.IsNullOrEmpty(fileName)) { - FileStream lxFS = File.Create(fileName); + var invalidChar = Path.GetInvalidFileNameChars(); + var newFileName = invalidChar.Aggregate(Path.GetFileName(fileName), (o, r) => (o.Replace(r.ToString(), string.Empty))); + + if (newFileName.Length > 240) + newFileName = GetUniqueFileName(newFileName.Substring(0, 240) + Path.GetExtension(newFileName)); + else + newFileName = GetUniqueFileName(fileName); + + FileStream lxFS = File.Create(newFileName); await stream.CopyToAsync(lxFS); lxFS.Close(); lxFS.Dispose(); diff --git a/WeiboAlbumDownloader/MainWindow.xaml.cs b/WeiboAlbumDownloader/MainWindow.xaml.cs index 9f1769d..0413f63 100644 --- a/WeiboAlbumDownloader/MainWindow.xaml.cs +++ b/WeiboAlbumDownloader/MainWindow.xaml.cs @@ -33,7 +33,7 @@ public partial class MainWindow : MicaWindow //①此处升级一下版本号 //②Github release新建一个新版本Tag //③上传压缩包删除Settings.json以及uidList.txt - double currentVersion = 3.1; + double currentVersion = 3.2; /// /// com1是根据uid获取相册id,https://photo.weibo.com/albums/get_all?uid=10000000000&page=1;根据uid和相册id以及相册type获取图片列表,https://photo.weibo.com/photos/get_all?uid=10000000000&album_id=3959362334782071&page=1&type=3 @@ -745,6 +745,7 @@ await Task.Run(async () => + timestamp.ToString("yyyy-MM-dd HH_mm_ss") + newCaption; Debug.WriteLine(fileName); + int id = 1; //下载获取图片列表中的图片原图 foreach (var item in originalPics) { @@ -753,7 +754,7 @@ await Task.Run(async () => if (string.IsNullOrEmpty(item)) continue; - var fileNamee = fileName + ".jpg"; + var fileNamee = fileName + $"_{id}.jpg"; //已存在的文件超过设置值,判定该用户下载过了 if (settings!.CountDownloadedSkipToNextUser > 0 && countDownloadedSkipToNextUser > settings.CountDownloadedSkipToNextUser) { @@ -786,6 +787,7 @@ await Task.Run(async () => { AppendLog($"文件下载失败,原始url:{item},下载路径{fileNamee}", MessageEnum.Error); } + id++; } foreach (var item in originalVideos) { @@ -794,7 +796,7 @@ await Task.Run(async () => if (string.IsNullOrEmpty(item)) continue; - var fileNamee = fileName + ".mp4"; + var fileNamee = fileName + $"_{id}.mp4"; //已存在的文件超过设置值,判定该用户下载过了 if (settings!.CountDownloadedSkipToNextUser > 0 && countDownloadedSkipToNextUser > settings.CountDownloadedSkipToNextUser) { @@ -827,6 +829,7 @@ await Task.Run(async () => { AppendLog($"文件下载失败,原始url:{item},下载路径{fileNamee}", MessageEnum.Error); } + id++; } foreach (var item in originalLivePhotos) { @@ -835,7 +838,7 @@ await Task.Run(async () => if (string.IsNullOrEmpty(item)) continue; - var fileNamee = fileName + ".mov"; + var fileNamee = fileName + $"_{id}.mov"; //已存在的文件超过设置值,判定该用户下载过了 if (settings!.CountDownloadedSkipToNextUser > 0 && countDownloadedSkipToNextUser > settings.CountDownloadedSkipToNextUser) { @@ -868,6 +871,7 @@ await Task.Run(async () => { AppendLog($"文件下载失败,原始url:{item},下载路径{fileNamee}", MessageEnum.Error); } + id++; } }