mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2025-07-25 21:04:01 +00:00
Fix GoogleDriveDownloader not working properly
This commit is contained in:
@ -165,11 +165,13 @@ public class DownloadDispatcher
|
||||
|
||||
try
|
||||
{
|
||||
_logger.LogWarning("Initial download of {archive} failed, trying mirror", archive.Name);
|
||||
downloadedHash = await DownloadFromMirror(archive, destination, token);
|
||||
if (downloadedHash != default) return (DownloadResult.Mirror, downloadedHash);
|
||||
}
|
||||
catch (NotSupportedException)
|
||||
{
|
||||
_logger.LogInformation("Could not find archive {archive} on mirror", archive.Name);
|
||||
// Thrown if downloading from mirror is not supported for archive, keep original hash
|
||||
}
|
||||
|
||||
|
@ -3,12 +3,14 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using HtmlAgilityPack;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Downloaders.Interfaces;
|
||||
@ -111,6 +113,10 @@ public class GoogleDriveDownloader : ADownloader<DTOs.DownloadStates.GoogleDrive
|
||||
if (download)
|
||||
{
|
||||
var initialUrl = $"https://drive.google.com/uc?id={state.Id}&export=download";
|
||||
string url = string.Empty;
|
||||
var qb = new QueryBuilder();
|
||||
var parameters = new Dictionary<string, string>();
|
||||
|
||||
var msg = new HttpRequestMessage(HttpMethod.Get, initialUrl);
|
||||
msg.AddChromeAgent();
|
||||
|
||||
@ -127,24 +133,27 @@ public class GoogleDriveDownloader : ADownloader<DTOs.DownloadStates.GoogleDrive
|
||||
|
||||
doc.LoadHtml(txt);
|
||||
|
||||
var action = doc.DocumentNode.DescendantsAndSelf()
|
||||
.Where(d => d.Name == "form" && d.Id == "downloadForm" &&
|
||||
d.GetAttributeValue("method", "") == "post")
|
||||
.Select(d => d.GetAttributeValue("action", ""))
|
||||
.FirstOrDefault();
|
||||
var form = doc.DocumentNode.DescendantsAndSelf()
|
||||
.FirstOrDefault(d => d.Name == "form" && d.Id.Contains("download", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (action != null)
|
||||
warning = ("download_warning_", "t");
|
||||
if (form == null)
|
||||
return new HttpRequestMessage(HttpMethod.Get, initialUrl);
|
||||
|
||||
url = form.GetAttributeValue("action", "https://drive.usercontent.google.com/download");
|
||||
foreach(var element in form.Descendants())
|
||||
{
|
||||
if (element.Name != "input") continue;
|
||||
var name = element.GetAttributeValue("name", "");
|
||||
var value = element.GetAttributeValue("value", "");
|
||||
if(!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(value))
|
||||
{
|
||||
qb.Add(name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
response.Dispose();
|
||||
if (warning == default)
|
||||
{
|
||||
return new HttpRequestMessage(HttpMethod.Get, initialUrl);
|
||||
}
|
||||
|
||||
var url = $"https://drive.google.com/uc?export=download&confirm={warning.Value}&id={state.Id}";
|
||||
var httpState = new HttpRequestMessage(HttpMethod.Get, url);
|
||||
var httpState = new HttpRequestMessage(HttpMethod.Get, url + qb.ToString());
|
||||
httpState.AddChromeAgent();
|
||||
return httpState;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.72" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.1" />
|
||||
|
@ -122,7 +122,7 @@ public class WabbajackCDNDownloader : ADownloader<WabbajackCDN>, IUrlDownloader,
|
||||
|
||||
private async Task<FileDefinition?> GetDefinition(WabbajackCDN state, CancellationToken token)
|
||||
{
|
||||
_logger.LogInformation("Getting file definition for CDN download {primaryKeyString}, {url}", state.PrimaryKeyString, state.Url);
|
||||
_logger.LogInformation("Getting file definition for CDN download {primaryKeyString}", state.PrimaryKeyString);
|
||||
var msg = MakeMessage(new Uri(state.Url + "/definition.json.gz"));
|
||||
using var data = await _client.SendAsync(msg, token);
|
||||
if (!data.IsSuccessStatusCode) return null;
|
||||
|
@ -525,7 +525,7 @@ public class Client
|
||||
|
||||
public async ValueTask<Uri?> MakeProxyUrl(Archive archive, Uri uri)
|
||||
{
|
||||
if (archive.State is Manual && !await ProxyHas(uri))
|
||||
if (!await ProxyHas(uri))
|
||||
return null;
|
||||
|
||||
return new Uri(
|
||||
|
Reference in New Issue
Block a user