Skip to content

Commit

Permalink
更改多分片文件下载逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
kengwang committed Feb 8, 2021
1 parent 24f28d6 commit 5485925
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions BiliDuang/DownloadObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,24 @@ public void LinkStart()
status = 5;
if (!single)
{
Directory.CreateDirectory(saveto + "/" + avname);
Directory.CreateDirectory(saveto + "/" + avname + ".biliduang");
message = "开始下载";
//当前暂不支持断点续传,于是我们便把之前的文件删掉吧
if (File.Exists(saveto + "/" + avname + "/" + blocknum.ToString() + "." + urls[blocknum].type))
if (File.Exists(saveto + "/" + avname + ".biliduang" + "/" + blocknum.ToString() + "." + urls[blocknum].type))
{
FileInfo fi = new FileInfo(saveto + "/" + avname + "/" + blocknum.ToString() + "." + urls[blocknum].type);
FileInfo fi = new FileInfo(saveto + "/" + avname + ".biliduang" + "/" + blocknum.ToString() + "." + urls[blocknum].type);
if (fi.Length == urls[blocknum].size)
{
Completed(true, "文件已经存在且大小正确");
return;
}
File.Delete(saveto + "/" + avname + "/" + blocknum.ToString() + "." + urls[blocknum].type);
File.Delete(saveto + "/" + avname + ".biliduang" + "/" + blocknum.ToString() + "." + urls[blocknum].type);

}
Console.WriteLine("Creating Download url: " + urls[blocknum].url + " to " + saveto + "/" + avname + "/" + blocknum.ToString() + "." + urls[blocknum].type);
Console.WriteLine("Creating Download url: " + urls[blocknum].url + " to " + saveto + "/" + avname + ".biliduang" + "/" + blocknum.ToString() + "." + urls[blocknum].type);
sw.Start();
wcusing = true;
wc.DownloadFileAsync(uri, saveto + "/" + avname + "/" + blocknum.ToString() + "." + urls[blocknum].type);
wc.DownloadFileAsync(uri, saveto + "/" + avname + ".biliduang" + "/" + blocknum.ToString() + "." + urls[blocknum].type);
}
else
{
Expand Down Expand Up @@ -213,18 +213,18 @@ public void LinkStart()
status = 5;
if (!single)
{
Directory.CreateDirectory(saveto + "/" + avname);
Directory.CreateDirectory(saveto + "/" + avname + ".biliduang");
message = "开始下载";
//aria2c可能支持断点续传
if (File.Exists(saveto + "/" + avname + "/" + blocknum.ToString() + "." + urls[blocknum].type))
if (File.Exists(saveto + "/" + avname + ".biliduang" + "/" + blocknum.ToString() + "." + urls[blocknum].type))
{
FileInfo fi = new FileInfo(saveto + "/" + avname + "/" + blocknum.ToString() + "." + urls[blocknum].type);
FileInfo fi = new FileInfo(saveto + "/" + avname + ".biliduang" + "/" + blocknum.ToString() + "." + urls[blocknum].type);
if (fi.Length == urls[blocknum].size)
{
Completed(true, "文件已经存在且大小正确");
return;
}
//File.Delete(saveto + "/" + avname + "/" + blocknum.ToString() + "." + urls[blocknum].type);
//File.Delete(saveto + "/" + avname + ".biliduang" + "/" + blocknum.ToString() + "." + urls[blocknum].type);
}
Console.WriteLine("Creating Download url by aria2c: " + urls[blocknum].url + " to " + saveto + "/" + avname + "/" + blocknum.ToString() + "." + urls[blocknum].type);

Expand All @@ -243,7 +243,6 @@ public void LinkStart()
}
File.Delete(saveto + "/" + avname + "." + urls[blocknum].type);
}
File.Delete(saveto + "/" + avname + " - " + name + "_" + blocknum.ToString() + "." + urls[blocknum].type);
Console.WriteLine("Creating Download url: " + urls[blocknum].url + " to " + saveto + "/" + avname + " - " + name + "_" + blocknum.ToString() + "." + urls[blocknum].type);
DownloadFileByAria2(urls[blocknum].url, saveto, avname + "." + urls[blocknum].type);
}
Expand Down Expand Up @@ -355,7 +354,7 @@ private void Completed(bool complete, string msg)
}
else
{
FileInfo fi = new FileInfo(saveto + "/" + avname + "/" + blocknum.ToString() + "." + urls[blocknum].type);
FileInfo fi = new FileInfo(saveto + "/" + avname + ".biliduang" + "/" + blocknum.ToString() + "." + urls[blocknum].type);
Console.WriteLine("Download Complete! Downloaded Size: " + fi.Length.ToString() + " Server Size: " + urls[blocknum].size.ToString());
if (urls[blocknum].size != -1 && fi.Length != urls[blocknum].size)
{
Expand All @@ -372,7 +371,7 @@ private void Completed(bool complete, string msg)
else if (!single)
{

FileInfo fi = new FileInfo(saveto + "/" + avname + "/" + blocknum.ToString() + "." + urls[blocknum].type);
FileInfo fi = new FileInfo(saveto + "/" + avname + ".biliduang" + "/" + blocknum.ToString() + "." + urls[blocknum].type);
if (fi.Exists && (urls[blocknum].size != -1 && fi.Length != urls[blocknum].size))
{
Console.WriteLine("Size Error, Try Download Again");
Expand Down Expand Up @@ -482,7 +481,7 @@ private void MergeVideo()
List<string> filenames = new List<string>();
for (int i = 0; i < urls.Count; i++)
{
filenames.Add(saveto + "/" + avname + "/" + i + "." + urls[i].type);
filenames.Add(saveto + "/" + avname + ".biliduang" + "/" + i + "." + urls[i].type);
}

foreach (string file in filenames)
Expand Down Expand Up @@ -510,7 +509,7 @@ private void MergeVideo()
{
try
{
Directory.Delete(saveto + "/" + avname, true);
Directory.Delete(saveto + "/" + avname + ".biliduang", true);
}
catch (Exception) { }
status = 66;
Expand All @@ -528,13 +527,13 @@ private void MergeVideo()
List<string> filenames = new List<string>();
for (int i = 0; i < urls.Count; i++)
{
filenames.Add(saveto + "/" + avname + "/" + i + "." + urls[i].type);
filenames.Add(saveto + "/" + avname + ".biliduang" + "/" + i + "." + urls[i].type);
}
if (FlvMerger.StartMerge(filenames, (saveto + "/" + avname + "." + urls[0].type)))
{
if (File.Exists(saveto + "/" + avname + "." + urls[0].type))
{
Directory.Delete(saveto + "/" + avname, true);
Directory.Delete(saveto + "/" + avname + ".biliduang", true);
status = 66;
message = "下载完成!";
}
Expand Down

1 comment on commit 5485925

@kengwang
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个BUG可以追溯到很早以前有人说文件被误删的事情了,我也没想到B站居然允许这玩意儿为空! 之前测试的时候疏忽了,再次道歉.

Please sign in to comment.