Skip to content

Commit

Permalink
支持记录已下载aid到本地文件 #727
Browse files Browse the repository at this point in the history
  • Loading branch information
nilaoda committed Nov 11, 2023
1 parent f0a99b8 commit 1a2acde
Show file tree
Hide file tree
Showing 5 changed files with 394 additions and 344 deletions.
2 changes: 1 addition & 1 deletion BBDown/BBDownApiServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private async Task AddDownloadTaskAsync(MyOption option)
task.Title = vInfo.Title;
task.Pic = vInfo.Pic;
task.VideoPubTime = vInfo.PubTime;
await Program.DownloadPageAsync(option, vInfo, encodingPriority, dfnPriority, firstEncoding, downloadDanmaku,
await Program.DownloadPagesAsync(option, vInfo, encodingPriority, dfnPriority, firstEncoding, downloadDanmaku,
input, savePathFormat, lang, fetchedAid, delay, apiType, task);
task.IsSuccessful = true;
}
Expand Down
3 changes: 3 additions & 0 deletions BBDown/CommandLineInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ internal class CommandLineInvoker
private readonly static Option<string> Aria2cPath = new(new string[] { "--aria2c-path" }, "设置aria2c的路径");
private readonly static Option<string> UposHost = new(new string[] { "--upos-host" }, "自定义upos服务器");
private readonly static Option<bool> ForceReplaceHost = new(new string[] { "--force-replace-host" }, "强制替换下载服务器host(默认开启)");
private readonly static Option<bool> SaveArchivesToFile = new(new string[] { "--save-archives-to-file" }, "将下载过的视频记录到本地文件中, 用于后续跳过下载同个视频");
private readonly static Option<string> DelayPerPage = new(new string[] { "--delay-per-page" }, "设置下载合集分P之间的下载间隔时间(单位: 秒, 默认无间隔)");
private readonly static Option<string> FilePattern = new(new string[] { "--file-pattern", "-F" },
$"使用内置变量自定义单P存储文件名:\r\n\r\n" +
Expand Down Expand Up @@ -140,6 +141,7 @@ protected override MyOption GetBoundValue(BindingContext bindingContext)
if (bindingContext.ParseResult.HasOption(Aria2cPath)) option.Aria2cPath = bindingContext.ParseResult.GetValueForOption(Aria2cPath)!;
if (bindingContext.ParseResult.HasOption(UposHost)) option.UposHost = bindingContext.ParseResult.GetValueForOption(UposHost)!;
if (bindingContext.ParseResult.HasOption(ForceReplaceHost)) option.ForceReplaceHost = bindingContext.ParseResult.GetValueForOption(ForceReplaceHost)!;
if (bindingContext.ParseResult.HasOption(SaveArchivesToFile)) option.SaveArchivesToFile = bindingContext.ParseResult.GetValueForOption(SaveArchivesToFile)!;
if (bindingContext.ParseResult.HasOption(DelayPerPage)) option.DelayPerPage = bindingContext.ParseResult.GetValueForOption(DelayPerPage)!;
if (bindingContext.ParseResult.HasOption(Host)) option.Host = bindingContext.ParseResult.GetValueForOption(Host)!;
if (bindingContext.ParseResult.HasOption(EpHost)) option.EpHost = bindingContext.ParseResult.GetValueForOption(EpHost)!;
Expand Down Expand Up @@ -202,6 +204,7 @@ public static RootCommand GetRootCommand(Func<MyOption, Task> action)
Aria2cPath,
UposHost,
ForceReplaceHost,
SaveArchivesToFile,
DelayPerPage,
Host,
EpHost,
Expand Down
1 change: 1 addition & 0 deletions BBDown/MyOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal class MyOption
public bool AudioAscending { get; set; } = false;
public bool AllowPcdn { get; set; } = false;
public bool ForceReplaceHost { get; set; } = true;
public bool SaveArchivesToFile { get; set; } = false;
public string FilePattern { get; set; } = "";
public string MultiFilePattern { get; set; } = "";
public string SelectPage { get; set; } = "";
Expand Down
23 changes: 23 additions & 0 deletions BBDown/Program.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,29 @@ private static void LoadCredentials(MyOption myOption)
}
}

private static object fileLock = new object();
public static void SaveAidToFile(string aid)
{
lock (fileLock)
{
string filePath = Path.Combine(APP_DIR, "BBDown.archives");
LogDebug("文件路径:{0}", filePath);
File.AppendAllText(filePath, $"{aid}|");
}
}

public static bool CheckAidFromFile(string aid)
{
lock (fileLock)
{
string filePath = Path.Combine(APP_DIR, "BBDown.archives");
if (!File.Exists(filePath)) return false;
LogDebug("文件路径:{0}", filePath);
var text = File.ReadAllText(filePath);
return text.Split('|').Any(item => item == aid);
}
}

/// <summary>
/// 获取选中的分P列表
/// </summary>
Expand Down
Loading

0 comments on commit 1a2acde

Please sign in to comment.