Skip to content

Commit

Permalink
- Add support for all versions of HFS
Browse files Browse the repository at this point in the history
  • Loading branch information
KoalaBear84 committed Dec 31, 2024
1 parent e912eda commit ee44678
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Open Directory Downloader

Indexes open directories listings in 130+ supported formats, including FTP(S), Google Drive, Bhadoo, GoIndex, Go2Index (alternatives), Dropbox, Mediafire, GoFile, GitHub.
Indexes open directories listings in 130+ supported formats, including FTP(S), Google Drive, Directory Lister, HFS, Bhadoo, GoIndex, Go2Index (alternatives), Mediafire, GoFile, GitHub.

![](assets/Screenshot01.png)

Expand Down
1 change: 1 addition & 0 deletions src/OpenDirectoryDownloader/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class Constants
public const string PixeldrainDomain = "pixeldrain.com";

public const string Parameters_GdIndex_RootId = "GDINDEX_ROOTID";
public const string Parameters_HttpHeader_Server = "HttpHeader_Server";
public const string Parameters_GoFileIOAccountToken = "GOFILE_ACCOUNTTOKEN";

public const string DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
Expand Down
5 changes: 3 additions & 2 deletions src/OpenDirectoryDownloader/DirectoryParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ public static async Task<WebDirectory> ParseHtml(WebDirectory webDirectory, stri
return await PixeldrainParser.ParseIndex(httpClient, webDirectory, html);
}

if (httpResponseMessage?.Headers.Server?.ToString()?.ToLowerInvariant().StartsWith("hfs") == true)
if (httpResponseMessage?.Headers.Server?.ToString()?.StartsWith("hfs", StringComparison.InvariantCultureIgnoreCase) == true)
{
return await HfsParser.ParseIndex(httpClient, webDirectory, html);
string httpHeaderServer = httpResponseMessage?.Headers.Server?.ToString();
return await HfsParser.ParseIndex(httpClient, webDirectory, html, httpHeaderServer);
}

IHtmlDocument htmlDocument = await HtmlParser.ParseDocumentAsync(html);
Expand Down
2 changes: 1 addition & 1 deletion src/OpenDirectoryDownloader/OpenDirectoryIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ private async Task ProcessWebDirectoryAsync(string threadName, WebDirectory webD

if (webDirectory.Parser == Site.HFS.HfsParser.Parser)
{
WebDirectory parsedWebDirectory = await Site.HFS.HfsParser.ParseIndex(HttpClient, webDirectory, null);
WebDirectory parsedWebDirectory = await Site.HFS.HfsParser.ScanAsync(HttpClient, webDirectory, null);
AddProcessedWebDirectory(webDirectory, parsedWebDirectory);
return;
}
Expand Down
26 changes: 22 additions & 4 deletions src/OpenDirectoryDownloader/Site/HFS/HfsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ public static class HfsParser
{
public const string Parser = "HFS";

public static async Task<WebDirectory> ParseIndex(HttpClient httpClient, WebDirectory webDirectory, string html)
public static async Task<WebDirectory> ParseIndex(HttpClient httpClient, WebDirectory webDirectory, string html, string httpHeaderServer)
{
try
{
if (!string.IsNullOrWhiteSpace(httpHeaderServer))
{
OpenDirectoryIndexer.Session.Parameters[Constants.Parameters_HttpHeader_Server] = httpHeaderServer;
}

webDirectory = await ScanAsync(httpClient, webDirectory, html);
}
catch (Exception ex)
Expand All @@ -31,14 +36,27 @@ public static async Task<WebDirectory> ParseIndex(HttpClient httpClient, WebDire
return webDirectory;
}

private static async Task<WebDirectory> ScanAsync(HttpClient httpClient, WebDirectory webDirectory, string html)
public static async Task<WebDirectory> ScanAsync(HttpClient httpClient, WebDirectory webDirectory, string html)
{
Program.Logger.Debug("Retrieving listings for {url}", webDirectory.Url);
webDirectory.Parser = Parser;

try
{
HttpResponseMessage httpResponseMessage = await httpClient.GetAsync($"{webDirectory.Uri.Scheme}://{webDirectory.Uri.Host}{(webDirectory.Uri.IsDefaultPort ? string.Empty : $":{webDirectory.Uri.Port}")}/~/api/file_list?csrf=&path={WebUtility.UrlEncode(webDirectory.Uri.AbsolutePath)}&omit=c");
bool useGetFileList = true;

if (OpenDirectoryIndexer.Session.Parameters.TryGetValue(Constants.Parameters_HttpHeader_Server, out string httpHeaderServerSession))
{
useGetFileList =
httpHeaderServerSession.StartsWith("HFS 2023", StringComparison.InvariantCultureIgnoreCase) ||
httpHeaderServerSession.StartsWith("HFS 0.", StringComparison.InvariantCultureIgnoreCase);
}

string url = useGetFileList ?
$"{webDirectory.Uri.Scheme}://{webDirectory.Uri.Host}{(webDirectory.Uri.IsDefaultPort ? string.Empty : $":{webDirectory.Uri.Port}")}/~/api/get_file_list?csrf=&uri={WebUtility.UrlEncode(webDirectory.Uri.AbsolutePath)}&omit=c" :
$"{webDirectory.Uri.Scheme}://{webDirectory.Uri.Host}{(webDirectory.Uri.IsDefaultPort ? string.Empty : $":{webDirectory.Uri.Port}")}/~/api/file_list?csrf=&path={WebUtility.UrlEncode(webDirectory.Uri.AbsolutePath)}&omit=c";

HttpResponseMessage httpResponseMessage = await httpClient.GetAsync(url);
string content = await httpResponseMessage.Content.ReadAsStringAsync();

HfsListing hfsListing = HfsListing.FromJson(content);
Expand Down Expand Up @@ -66,7 +84,7 @@ private static async Task<WebDirectory> ScanAsync(HttpClient httpClient, WebDire
{
Url = new Uri(baseUri, hfsItem.N).ToString(),
FileName = hfsItem.N,
FileSize = hfsItem.S ?? -1
FileSize = hfsItem.S
});
}
}
Expand Down

0 comments on commit ee44678

Please sign in to comment.