mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Fix Mediafire downloading
This commit is contained in:
parent
68f801a6c0
commit
ee9b61be12
@ -28,12 +28,13 @@ public class DownloadUrl : IVerb
|
||||
var command = new Command("download-url");
|
||||
command.Add(new Option<Uri>(new[] {"-u", "-url"}, "Url to parse"));
|
||||
command.Add(new Option<AbsolutePath>(new[] {"-o", "-output"}, "Output file"));
|
||||
command.Add(new Option<bool>(new [] {"-p", "--proxy"}, "Use the Wabbajack Proxy (default: true)"));
|
||||
command.Description = "Downloads a file to a given output";
|
||||
command.Handler = CommandHandler.Create(Run);
|
||||
return command;
|
||||
}
|
||||
|
||||
private async Task<int> Run(Uri url, AbsolutePath output)
|
||||
private async Task<int> Run(Uri url, AbsolutePath output, bool proxy = true)
|
||||
{
|
||||
var parsed = _dispatcher.Parse(url);
|
||||
if (parsed == null)
|
||||
@ -44,7 +45,8 @@ public class DownloadUrl : IVerb
|
||||
}
|
||||
|
||||
var archive = new Archive() {State = parsed, Name = output.FileName.ToString()};
|
||||
var hash = await _dispatcher.Download(archive, output, CancellationToken.None); ;
|
||||
|
||||
var hash = await _dispatcher.Download(archive, output, CancellationToken.None, proxy); ;
|
||||
Console.WriteLine($"Download complete: {output.Size().ToFileSizeString()} {hash} {hash.ToHex()} {(long)hash}");
|
||||
return 0;
|
||||
}
|
||||
|
@ -37,11 +37,11 @@ public class DownloadDispatcher
|
||||
_useProxyCache = useProxyCache;
|
||||
}
|
||||
|
||||
public async Task<Hash> Download(Archive a, AbsolutePath dest, CancellationToken token)
|
||||
public async Task<Hash> Download(Archive a, AbsolutePath dest, CancellationToken token, bool? proxy = null)
|
||||
{
|
||||
using var downloadScope = _logger.BeginScope("Downloading {Name}", a.Name);
|
||||
using var job = await _limiter.Begin("Downloading " + a.Name, a.Size, token);
|
||||
return await Download(a, dest, job, token);
|
||||
return await Download(a, dest, job, token, proxy);
|
||||
}
|
||||
|
||||
public async Task<Archive> MaybeProxy(Archive a, CancellationToken token)
|
||||
@ -68,13 +68,13 @@ public class DownloadDispatcher
|
||||
return a;
|
||||
}
|
||||
|
||||
public async Task<Hash> Download(Archive a, AbsolutePath dest, Job<DownloadDispatcher> job, CancellationToken token)
|
||||
public async Task<Hash> Download(Archive a, AbsolutePath dest, Job<DownloadDispatcher> job, CancellationToken token, bool? useProxy = null)
|
||||
{
|
||||
if (!dest.Parent.DirectoryExists())
|
||||
dest.Parent.CreateDirectory();
|
||||
|
||||
var downloader = Downloader(a);
|
||||
if (_useProxyCache && downloader is IProxyable p)
|
||||
if ((useProxy ?? _useProxyCache) && downloader is IProxyable p)
|
||||
{
|
||||
var uri = p.UnParse(a.State);
|
||||
var newUri = await _wjClient.MakeProxyUrl(a, uri);
|
||||
|
@ -115,10 +115,22 @@ public class MediaFireDownloader : ADownloader<DTOs.DownloadStates.MediaFire>, I
|
||||
await job.Report((int) job.Size, (CancellationToken) token);
|
||||
var body = new HtmlDocument();
|
||||
body.LoadHtml(bodyData);
|
||||
var node = body.DocumentNode.DescendantsAndSelf().First(d => d.HasClass("input") && d.HasClass("popsok") &&
|
||||
var node = body.DocumentNode.DescendantsAndSelf().FirstOrDefault(d => d.HasClass("input") && d.HasClass("popsok") &&
|
||||
d.GetAttributeValue("aria-label", "") ==
|
||||
"Download file");
|
||||
if (node != null)
|
||||
return new Uri(node.GetAttributeValue("href", "not-found"));
|
||||
|
||||
var startText = "window.location.href = '";
|
||||
var start = body.DocumentNode.InnerHtml.IndexOf(startText, StringComparison.CurrentCultureIgnoreCase);
|
||||
|
||||
if (start != -1)
|
||||
{
|
||||
var end = body.DocumentNode.InnerHtml.IndexOf("\'", start + startText.Length,
|
||||
StringComparison.CurrentCultureIgnoreCase);
|
||||
var data = body.DocumentNode.InnerHtml[(start + startText.Length)..end];
|
||||
return new Uri(data);
|
||||
}
|
||||
}
|
||||
|
||||
return state.Url;
|
||||
|
Loading…
Reference in New Issue
Block a user