Skip to content

Commit df3291a

Browse files
author
Meyn
committed
Change download API and remove unused parameter
1 parent 83b544c commit df3291a

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

UnitTest/DownloadTest.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using DownloadAssistant.Request;
22
using Requests;
3-
using System.Diagnostics;
43
using WebsiteScraper.Downloadable.Books;
54
using WebsiteScraper.WebsiteUtilities;
65

@@ -9,7 +8,7 @@ namespace UnitTest
98
[TestClass]
109
public class DownloadTest
1110
{
12-
private string _pathToWebsite = @$"{Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName}\Websites\mangaread.org.wsf";
11+
private string _pathToWebsite = @$"{Directory.GetParent(Directory.GetCurrentDirectory())!.Parent!.Parent!.Parent!.FullName}\Websites\mangaread.org.wsf";
1312

1413
private Website _mangaread = null!;
1514

@@ -80,7 +79,7 @@ public async Task DownloadTestAsync()
8079
await _mangaread.GetStatusTask();
8180
Comic onePunch = new("https://www.mangaread.org/manga/one-punch-man-onepunchman/", "One Punch Man", _mangaread);
8281
await onePunch.UpdateAsync();
83-
ProgressableContainer<LoadRequest> container = await onePunch.Chapter.First().DownloadAsync(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\One Punch Man\1\");
82+
ProgressableContainer<GetRequest> container = await onePunch.Chapter.First().DownloadAsync(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\One Punch Man\1\");
8483
container.StateChanged += (s, e) => Console.WriteLine("State: " + e);
8584
await container.Task;
8685
Console.WriteLine("Downloaded");

WebsiteScraper/Downloadable/Books/Chapter.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ public void SetOrder(int i)
3232

3333
public Chapter(Comic holdingComic) => HoldingComic = holdingComic;
3434

35-
public Task<ProgressableContainer<LoadRequest>> DownloadAsync(string destination, string? tempDestination = null, CancellationToken? token = null, Action? finished = null)
35+
public Task<ProgressableContainer<GetRequest>> DownloadAsync(string destination, CancellationToken? token = null)
3636
{
3737
if (!string.IsNullOrWhiteSpace(DownloadURL))
3838
return DownloadImageFromFileAsync(token);
3939
if (GetValue("AddToListUrl") != null)
40-
return DownloadImageListAsync(destination, tempDestination, token, finished);
40+
return DownloadImageListAsync(destination, token);
4141
else if (GetValue("AddToPagedUrl") != null)
42-
return DownloadImagePageAsync(destination, tempDestination, token, finished);
42+
return DownloadImagePageAsync(destination, token);
4343
else throw new Exception("Can not donwload this object");
4444
}
4545

46-
private async Task<ProgressableContainer<LoadRequest>> DownloadImageListAsync(string destination, string? tempDestination, CancellationToken? token, Action? finished = null)
46+
private async Task<ProgressableContainer<GetRequest>> DownloadImageListAsync(string destination, CancellationToken? token)
4747
{
48-
ProgressableContainer<LoadRequest> container = new();
48+
ProgressableContainer<GetRequest> container = new();
4949
await new OwnRequest(async DToken =>
5050
{
5151
string? selector = GetValue("ListImageQuery");
@@ -63,11 +63,10 @@ private async Task<ProgressableContainer<LoadRequest>> DownloadImageListAsync(st
6363
string[] imageLinks = selector.ParseAll(html);
6464

6565
for (int i = 0; i < imageLinks.Length; i++)
66-
container.Add(new LoadRequest(imageLinks[i], new()
66+
container.Add(new GetRequest(imageLinks[i], new()
6767
{
6868
IsDownload = true,
69-
DestinationPath = destination,
70-
TempDestination = tempDestination ?? string.Empty,
69+
DirectoryPath = destination,
7170
CancellationToken = token,
7271
Filename = $"{Order}_{i}.*",
7372
Priority = RequestPriority.High,
@@ -83,9 +82,9 @@ private async Task<ProgressableContainer<LoadRequest>> DownloadImageListAsync(st
8382
return container;
8483
}
8584

86-
private async Task<ProgressableContainer<LoadRequest>> DownloadImagePageAsync(string destination, string? tempDestination, CancellationToken? token, Action? finished = null)
85+
private async Task<ProgressableContainer<GetRequest>> DownloadImagePageAsync(string destination, CancellationToken? token)
8786
{
88-
ProgressableContainer<LoadRequest> container = new();
87+
ProgressableContainer<GetRequest> container = new();
8988
await new OwnRequest(async DToken =>
9089
{
9190
bool stop = false;
@@ -106,12 +105,11 @@ private async Task<ProgressableContainer<LoadRequest>> DownloadImagePageAsync(st
106105
res.Dispose();
107106
if (string.IsNullOrWhiteSpace(imageLink))
108107
break;
109-
container.Add(new LoadRequest(imageLink, new()
108+
container.Add(new GetRequest(imageLink, new()
110109
{
111110
IsDownload = true,
112111
Priority = RequestPriority.High,
113-
DestinationPath = destination,
114-
TempDestination = tempDestination ?? string.Empty,
112+
DirectoryPath = destination,
115113
CancellationToken = token,
116114
Filename = $"{Order}_{i}.*",
117115
RequestFailed = (request, path) => { Debug.WriteLine("Failed: " + path); }
@@ -129,7 +127,7 @@ private async Task<ProgressableContainer<LoadRequest>> DownloadImagePageAsync(st
129127
return container;
130128
}
131129

132-
private Task<ProgressableContainer<LoadRequest>> DownloadImageFromFileAsync(CancellationToken? token)
130+
private Task<ProgressableContainer<GetRequest>> DownloadImageFromFileAsync(CancellationToken? token)
133131
{
134132
throw new NotImplementedException();
135133
}

WebsiteScraper/Downloadable/Books/Comic.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public static Comic CreateSearch(IElement html, Website website)
5555
_isSearchObject = true,
5656
HoldingWebsite = website
5757
};
58-
comic.Chapter = new Chapter[] { new(comic) { Url = GetParsed(html, searchId?.GetValueOrDefault("LastChapter")) } };
58+
string url = GetParsed(html, searchId?.GetValueOrDefault("LastChapter"));
59+
if (!string.IsNullOrEmpty(url))
60+
comic.Chapter = new Chapter[] { new(comic) { Url = url } };
5961
return comic;
6062
}
6163

WebsiteScraper/WebsiteScraper.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<Title>WebsiteScraper</Title>
99
<Authors>Meyn</Authors>
1010
<Company>Shard</Company>
11-
<Version>1.0.0</Version>
11+
<Version>1.1.0</Version>
1212
<Description>WebsiteScraper is a powerful tool that allows you to effortlessly download your favorite comics and manga from various websites.
1313
You can easily provide a JSON file containing the website links, and the scraper will do the rest.
1414
Using the advanced parsing capabilities of Angelsharp and Regex, the tool efficiently extracts the desired content from the website and saves it onto your device for offline reading.
@@ -22,6 +22,7 @@ With WebsiteScraper, you can enjoy your favorite comics and manga anytime, anywh
2222
<PackageTags>WebsiteScraper; Shard; Manga; Comic; JSON; Parser</PackageTags>
2323
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
2424
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
25+
<PackageReleaseNotes>Change download API and remove unused parameter</PackageReleaseNotes>
2526
</PropertyGroup>
2627

2728
<ItemGroup>

0 commit comments

Comments
 (0)