Skip to content

Commit

Permalink
- Add support for another variation of Google Drive Index
Browse files Browse the repository at this point in the history
- Cache GoogleDriveIndexType
  • Loading branch information
KoalaBear84 committed May 30, 2022
1 parent 4ab19b1 commit 6777bca
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/OpenDirectoryDownloader/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class Constants
public const string DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
public const string Parameters_Password = "PASSWORD";
public const string Parameters_FtpEncryptionMode = "FtpEncryptionMode";

public const string GoogleDriveIndexType = "GOOGLEDRIVEINDEXTYPE";

public const long NoFileSize = 0;
public const string Root = "ROOT";
Expand Down
57 changes: 42 additions & 15 deletions src/OpenDirectoryDownloader/DirectoryParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using AngleSharp.Dom;
using AngleSharp.Html.Dom;
using AngleSharp.Html.Parser;
using Esprima;
using Esprima.Ast;
using Newtonsoft.Json;
using NLog;
using OpenDirectoryDownloader.Helpers;
Expand Down Expand Up @@ -90,11 +92,13 @@ public static async Task<WebDirectory> ParseHtml(WebDirectory webDirectory, stri
return await MediafireParser.ParseIndex(httpClient, webDirectory);
}

if (httpClient is not null)
if (httpClient is not null && !OpenDirectoryIndexer.Session.Parameters.ContainsKey(Constants.GoogleDriveIndexType))
{
string googleDriveIndexType = null;

foreach (IHtmlScriptElement script in htmlDocument.Scripts.Where(s => s.Source is not null))
{
string googleDriveIndexType = GoogleDriveIndexMapping.GetGoogleDriveIndexType(script.Source);
googleDriveIndexType = GoogleDriveIndexMapping.GetGoogleDriveIndexType(script.Source);

if (googleDriveIndexType is null && script.Source.ToLower().Contains("app.min.js"))
{
Expand All @@ -120,29 +124,52 @@ public static async Task<WebDirectory> ParseHtml(WebDirectory webDirectory, stri
}
}

if (googleDriveIndexType is not null)
if (googleDriveIndexType is null && script.Source.ToLower().Contains("app.js"))
{
if (OpenDirectoryIndexer.Session.MaxThreads != 1)
string appJsSource = await httpClient.GetStringAsync(script.Source);

JavaScriptParser javaScriptParser = new JavaScriptParser(appJsSource);
Script program = javaScriptParser.ParseScript();
IEnumerable<FunctionDeclaration> javaScriptFunctions = program.ChildNodes.OfType<FunctionDeclaration>();
FunctionDeclaration gdidecodeFunctionDeclaration = javaScriptFunctions.FirstOrDefault(f => f.ChildNodes.OfType<Identifier>().Any(i => i.Name == "gdidecode"));

if (gdidecodeFunctionDeclaration is not null)
{
OpenDirectoryIndexer.Session.MaxThreads = 1;
Logger.Warn($"Reduce threads to 1 because of Google Drive index");
googleDriveIndexType = GoogleDriveIndexMapping.BhadooIndex;
break;
}
}
}

switch (googleDriveIndexType)
if (googleDriveIndexType is not null)
{
OpenDirectoryIndexer.Session.Parameters[Constants.GoogleDriveIndexType] = googleDriveIndexType;

if (OpenDirectoryIndexer.Session.MaxThreads != 1)
{
case GoogleDriveIndexMapping.BhadooIndex:
return await BhadooIndexParser.ParseIndex(htmlDocument, httpClient, webDirectory);
case GoogleDriveIndexMapping.GoIndex:
return await GoIndexParser.ParseIndex(httpClient, webDirectory);
case GoogleDriveIndexMapping.Go2Index:
return await Go2IndexParser.ParseIndex(httpClient, webDirectory);
case GoogleDriveIndexMapping.GdIndex:
return await GdIndexParser.ParseIndex(httpClient, webDirectory, html);
OpenDirectoryIndexer.Session.MaxThreads = 1;
Logger.Warn($"Reduce threads to 1 because of Google Drive index");
}
}
}

if (OpenDirectoryIndexer.Session.Parameters.ContainsKey(Constants.GoogleDriveIndexType))
{
string googleDriveIndexType = OpenDirectoryIndexer.Session.Parameters[Constants.GoogleDriveIndexType];

switch (googleDriveIndexType)
{
case GoogleDriveIndexMapping.BhadooIndex:
return await BhadooIndexParser.ParseIndex(htmlDocument, httpClient, webDirectory);
case GoogleDriveIndexMapping.GoIndex:
return await GoIndexParser.ParseIndex(httpClient, webDirectory);
case GoogleDriveIndexMapping.Go2Index:
return await Go2IndexParser.ParseIndex(httpClient, webDirectory);
case GoogleDriveIndexMapping.GdIndex:
return await GdIndexParser.ParseIndex(httpClient, webDirectory, html);
}
}

htmlDocument.QuerySelectorAll("#sidebar").ToList().ForEach(e => e.Remove());
htmlDocument.QuerySelectorAll("nav").ToList().ForEach(e => e.Remove());

Expand Down

0 comments on commit 6777bca

Please sign in to comment.