Skip to content

Commit

Permalink
修复下载bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hupo376787 committed Oct 14, 2024
1 parent 5f9254e commit 2961b87
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 10 additions & 1 deletion WeiboAlbumDownloader/Helpers/HttpHelper.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -54,7 +55,15 @@ public static async Task<T> GetAsync<T>(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();
Expand Down
12 changes: 8 additions & 4 deletions WeiboAlbumDownloader/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public partial class MainWindow : MicaWindow
//①此处升级一下版本号
//②Github release新建一个新版本Tag
//③上传压缩包删除Settings.json以及uidList.txt
double currentVersion = 3.1;
double currentVersion = 3.2;

/// <summary>
/// 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
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -786,6 +787,7 @@ await Task.Run(async () =>
{
AppendLog($"文件下载失败,原始url:{item},下载路径{fileNamee}", MessageEnum.Error);
}
id++;
}
foreach (var item in originalVideos)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -827,6 +829,7 @@ await Task.Run(async () =>
{
AppendLog($"文件下载失败,原始url:{item},下载路径{fileNamee}", MessageEnum.Error);
}
id++;
}
foreach (var item in originalLivePhotos)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -868,6 +871,7 @@ await Task.Run(async () =>
{
AppendLog($"文件下载失败,原始url:{item},下载路径{fileNamee}", MessageEnum.Error);
}
id++;
}
}
Expand Down

0 comments on commit 2961b87

Please sign in to comment.