diff --git a/src/CyberdropDownloader.Avalonia/CyberdropDownloader.Avalonia.csproj b/src/CyberdropDownloader.Avalonia/CyberdropDownloader.Avalonia.csproj
index 6498888..cd02bb4 100644
--- a/src/CyberdropDownloader.Avalonia/CyberdropDownloader.Avalonia.csproj
+++ b/src/CyberdropDownloader.Avalonia/CyberdropDownloader.Avalonia.csproj
@@ -6,15 +6,15 @@
Cyberdrop Downloader
Copyright © 2022
Cyberdrop Downloader
- 2.2.5.0
- 2.2.4.0
+ 2.2.6.0
+ 2.2.6.0
en
Assets\duck.ico
- 2.2.5
+ 2.2.6
https://github.com/izqalan/cy-client
diff --git a/src/CyberdropDownloader.Avalonia/ViewModels/MainWindowViewModel.cs b/src/CyberdropDownloader.Avalonia/ViewModels/MainWindowViewModel.cs
index af9f092..ffc6b46 100644
--- a/src/CyberdropDownloader.Avalonia/ViewModels/MainWindowViewModel.cs
+++ b/src/CyberdropDownloader.Avalonia/ViewModels/MainWindowViewModel.cs
@@ -120,9 +120,9 @@ await Task.Run(async () =>
{
await _webScraper.LoadAlbumAsync(url);
}
- catch(Exception exception)
+ catch(Exception ex)
{
- switch(exception)
+ switch(ex)
{
case NullAlbumTitleException:
Log("Failed to fetch album title.");
@@ -136,19 +136,16 @@ await Task.Run(async () =>
Log("Failed to fetch album files.");
break;
+ case UriFormatException:
+ Log("Invalid URL format.");
+ continue;
+
default:
- Log("Unknown webscraper error. Please report this to the github repository.");
+ Log($"Unknown webscraper error. Please report this to the github repository. {ex.Message}");
continue;
}
}
- // If the album url is invalid, then log and skip over it
- if(!_webScraper.Successful)
- {
- Log($"Invalid Url: {url}");
- continue;
- }
-
// Update album title
UpdateAlbumTitle(_webScraper.Album.Title);
@@ -174,9 +171,9 @@ await Task.Run(async () =>
continue;
}
}
- catch(Exception exception)
+ catch(Exception ex)
{
- switch(exception)
+ switch(ex)
{
// Drive letter doesn't exist or path doesn't exist
case ArgumentException:
@@ -194,7 +191,7 @@ await Task.Run(async () =>
break;
default:
- Log("Unknown error. Please report this to the github repository.");
+ Log($"Unknown error. Please report this to the github repository. {ex.Message}");
break;
}
}
diff --git a/src/CyberdropDownloader.Core/WebScraper.cs b/src/CyberdropDownloader.Core/WebScraper.cs
index 56e8aac..2dd32c0 100644
--- a/src/CyberdropDownloader.Core/WebScraper.cs
+++ b/src/CyberdropDownloader.Core/WebScraper.cs
@@ -11,10 +11,8 @@ namespace CyberdropDownloader.Core
public class WebScraper
{
private Album _album;
- private bool _successful;
public Album Album => _album;
- public bool Successful => _successful;
public async Task LoadAlbumAsync(string url)
{
@@ -28,7 +26,6 @@ await Task.Run(async () =>
(string title, string size, Queue files) albumData = FetchAlbumData(htmlDocument);
_album = new Album(albumData.title, albumData.size, albumData.files);
- _successful = true;
}
});
}
@@ -41,36 +38,77 @@ await Task.Run(async () =>
private string FetchAlbumTitle(HtmlDocument htmlDocument)
{
- string title = htmlDocument.DocumentNode.SelectNodes("//div/h1[@id='title']").First().Attributes["title"].Value;
+ string title;
- return title ?? throw new NullAlbumTitleException();
+ try
+ {
+ title = htmlDocument.DocumentNode.SelectNodes("//div/h1[@id='title']").First().Attributes["title"].Value;
+ }
+ catch(Exception ex)
+ {
+ switch(ex)
+ {
+ case ArgumentNullException or NullReferenceException:
+ throw new NullAlbumTitleException();
+
+ default:
+ throw new Exception(ex.Message);
+ }
+ }
+
+ return title;
}
private string FetchAlbumSize(HtmlDocument htmlDocument)
{
- string size = htmlDocument.DocumentNode.SelectNodes("//div/p[@class='title']")[1].InnerHtml;
+ string size;
+
+ try
+ {
+ size = htmlDocument.DocumentNode.SelectNodes("//div/p[@class='title']")[1].InnerHtml;
+ }
+ catch(Exception ex)
+ {
+ switch(ex)
+ {
+ case ArgumentNullException or NullReferenceException:
+ throw new NullAlbumSizeException();
+
+ default:
+ throw new Exception(ex.Message);
+ }
+ }
- return size ?? throw new NullAlbumFilesException();
+ return size;
}
private Queue FetchAlbumFiles(HtmlDocument htmlDocument)
{
Queue urls = new Queue();
- HtmlNodeCollection files = htmlDocument.DocumentNode.SelectNodes("//a[@class='image'][@href]");
-
- if(files == null)
+ try
{
- throw new NullAlbumFilesException();
+ HtmlNodeCollection files = htmlDocument.DocumentNode.SelectNodes("//a[@class='image'][@href]");
+
+ foreach(HtmlNode link in files)
+ {
+ urls.Enqueue(new AlbumFile()
+ {
+ Name = link.Attributes["title"].Value,
+ Url = link.Attributes["href"].Value
+ });
+ }
}
-
- foreach(HtmlNode link in files)
+ catch(Exception ex)
{
- urls.Enqueue(new AlbumFile()
+ switch(ex)
{
- Name = link.Attributes["title"].Value,
- Url = link.Attributes["href"].Value
- });
+ case ArgumentNullException or NullReferenceException:
+ throw new NullAlbumFilesException();
+
+ default:
+ throw new Exception(ex.Message);
+ }
}
return urls;