Skip to content

Commit

Permalink
Merge pull request #128 from 9001/improve-copyparty-parser
Browse files Browse the repository at this point in the history
Improve copyparty parser
  • Loading branch information
KoalaBear84 authored Jan 15, 2023
2 parents b5edcc8 + 5963325 commit 1dafe03
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/OpenDirectoryDownloader/DirectoryParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public static async Task<WebDirectory> ParseHtml(WebDirectory webDirectory, stri
}

// copyparty
if (htmlDocument.QuerySelector("div#ops") is not null)
if (htmlDocument.QuerySelector("#op_bup #u2err") is not null)
{
return ParseCopypartyListing(baseUrl, parsedWebDirectory, htmlDocument);
}
Expand Down Expand Up @@ -455,9 +455,8 @@ private static WebDirectory ParseCopypartyListing(string baseUrl, WebDirectory p
{
IHtmlAnchorElement link = entry.QuerySelector("td:nth-child(2) a") as IHtmlAnchorElement;
IHtmlTableCellElement fileSize = entry.QuerySelector("td:nth-child(3)") as IHtmlTableCellElement;
IHtmlTableCellElement fileType = entry.QuerySelector("td:nth-child(4)") as IHtmlTableCellElement;

bool isDirectory = fileType.TextContent == "---";
bool isDirectory = link.TextContent.EndsWith("/");

if (link is not null)
{
Expand All @@ -479,7 +478,7 @@ private static WebDirectory ParseCopypartyListing(string baseUrl, WebDirectory p
parsedWebDirectory.Files.Add(new WebFile
{
Url = fullUrl,
FileName = Path.GetFileName(WebUtility.UrlDecode(fullUrl)),
FileName = Path.GetFileName(WebUtility.UrlDecode(fullUrl.Split('?')[0])),
FileSize = FileSizeHelper.ParseFileSize(fileSize.TextContent)
});
}
Expand Down

0 comments on commit 1dafe03

Please sign in to comment.