mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
download dispatcher now also accepts urls as input
This commit is contained in:
parent
b59ad6b8fc
commit
e4e307c4fd
@ -37,5 +37,16 @@ namespace Wabbajack.Lib.Downloaders
|
||||
return Downloaders.Select(d => d.GetDownloaderState(ini)).FirstOrDefault(result => result != null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reduced version of Resolve archive that requires less information, but only works
|
||||
/// with a single URL string
|
||||
/// </summary>
|
||||
/// <param name="ini"></param>
|
||||
/// <returns></returns>
|
||||
public static AbstractDownloadState ResolveArchive(string url)
|
||||
{
|
||||
return Downloaders.OfType<IUrlDownloader>().Select(d => d.GetDownloaderState(url)).FirstOrDefault(result => result != null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -7,13 +7,18 @@ using System.Web;
|
||||
|
||||
namespace Wabbajack.Lib.Downloaders
|
||||
{
|
||||
public class DropboxDownloader : IDownloader
|
||||
public class DropboxDownloader : IDownloader, IUrlDownloader
|
||||
{
|
||||
public AbstractDownloadState GetDownloaderState(dynamic archive_ini)
|
||||
{
|
||||
var urlstring = archive_ini?.General?.directURL;
|
||||
if (urlstring == null) return null;
|
||||
var uri = new UriBuilder((string)urlstring);
|
||||
return GetDownloaderState(urlstring);
|
||||
}
|
||||
|
||||
public AbstractDownloadState GetDownloaderState(string url)
|
||||
{
|
||||
if (url == null) return null;
|
||||
var uri = new UriBuilder(url);
|
||||
if (uri.Host != "www.dropbox.com") return null;
|
||||
var query = HttpUtility.ParseQueryString(uri.Query);
|
||||
|
||||
|
@ -11,14 +11,19 @@ using Wabbajack.Lib.Validation;
|
||||
|
||||
namespace Wabbajack.Lib.Downloaders
|
||||
{
|
||||
public class GoogleDriveDownloader : IDownloader
|
||||
public class GoogleDriveDownloader : IDownloader, IUrlDownloader
|
||||
{
|
||||
public AbstractDownloadState GetDownloaderState(dynamic archive_ini)
|
||||
{
|
||||
var url = archive_ini?.General?.directURL;
|
||||
var regex = new Regex("((?<=id=)[a-zA-Z0-9_-]*)|(?<=\\/file\\/d\\/)[a-zA-Z0-9_-]*");
|
||||
return GetDownloaderState(url);
|
||||
}
|
||||
|
||||
public AbstractDownloadState GetDownloaderState(string url)
|
||||
{
|
||||
if (url != null && url.StartsWith("https://drive.google.com"))
|
||||
{
|
||||
var regex = new Regex("((?<=id=)[a-zA-Z0-9_-]*)|(?<=\\/file\\/d\\/)[a-zA-Z0-9_-]*");
|
||||
var match = regex.Match(url);
|
||||
return new State
|
||||
{
|
||||
|
@ -9,13 +9,23 @@ using File = Alphaleonis.Win32.Filesystem.File;
|
||||
|
||||
namespace Wabbajack.Lib.Downloaders
|
||||
{
|
||||
public class HTTPDownloader : IDownloader
|
||||
public class HTTPDownloader : IDownloader, IUrlDownloader
|
||||
{
|
||||
|
||||
public AbstractDownloadState GetDownloaderState(dynamic archive_ini)
|
||||
{
|
||||
var url = archive_ini?.General?.directURL;
|
||||
return GetDownloaderState(url, archive_ini);
|
||||
|
||||
}
|
||||
|
||||
public AbstractDownloadState GetDownloaderState(string uri)
|
||||
{
|
||||
return GetDownloaderState(uri, null);
|
||||
}
|
||||
|
||||
public AbstractDownloadState GetDownloaderState(string url, dynamic archive_ini)
|
||||
{
|
||||
if (url != null)
|
||||
{
|
||||
var tmp = new State
|
||||
|
@ -16,4 +16,5 @@ namespace Wabbajack.Lib.Downloaders
|
||||
/// </summary>
|
||||
void Prepare();
|
||||
}
|
||||
|
||||
}
|
||||
|
13
Wabbajack.Lib/Downloaders/IUrlDownloader.cs
Normal file
13
Wabbajack.Lib/Downloaders/IUrlDownloader.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Wabbajack.Lib.Downloaders
|
||||
{
|
||||
public interface IUrlDownloader : IDownloader
|
||||
{
|
||||
AbstractDownloadState GetDownloaderState(string url);
|
||||
}
|
||||
}
|
@ -13,14 +13,19 @@ using Wabbajack.Lib.Validation;
|
||||
|
||||
namespace Wabbajack.Lib.Downloaders
|
||||
{
|
||||
public class MegaDownloader : IDownloader
|
||||
public class MegaDownloader : IDownloader, IUrlDownloader
|
||||
{
|
||||
|
||||
public AbstractDownloadState GetDownloaderState(dynamic archive_ini)
|
||||
{
|
||||
var url = archive_ini?.General?.directURL;
|
||||
return GetDownloaderState(url);
|
||||
}
|
||||
|
||||
public AbstractDownloadState GetDownloaderState(string url)
|
||||
{
|
||||
if (url != null && url.StartsWith(Consts.MegaPrefix))
|
||||
return new State {Url = url};
|
||||
return new State { Url = url };
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -10,12 +10,16 @@ using Wabbajack.Lib.Validation;
|
||||
|
||||
namespace Wabbajack.Lib.Downloaders
|
||||
{
|
||||
public class ModDBDownloader : IDownloader
|
||||
public class ModDBDownloader : IDownloader, IUrlDownloader
|
||||
{
|
||||
public AbstractDownloadState GetDownloaderState(dynamic archive_ini)
|
||||
{
|
||||
var url = archive_ini?.General?.directURL;
|
||||
return GetDownloaderState(url);
|
||||
}
|
||||
|
||||
public AbstractDownloadState GetDownloaderState(string url)
|
||||
{
|
||||
if (url != null && url.StartsWith("https://www.moddb.com/downloads/start"))
|
||||
{
|
||||
return new State
|
||||
|
@ -115,6 +115,7 @@
|
||||
<Compile Include="Downloaders\GoogleDriveDownloader.cs" />
|
||||
<Compile Include="Downloaders\HTTPDownloader.cs" />
|
||||
<Compile Include="Downloaders\IDownloader.cs" />
|
||||
<Compile Include="Downloaders\IUrlDownloader.cs" />
|
||||
<Compile Include="Downloaders\ManualDownloader.cs" />
|
||||
<Compile Include="Downloaders\MEGADownloader.cs" />
|
||||
<Compile Include="Downloaders\ModDBDownloader.cs" />
|
||||
|
@ -31,6 +31,13 @@ namespace Wabbajack.Test
|
||||
|
||||
Assert.IsNotNull(state);
|
||||
|
||||
var url_state = DownloadDispatcher.ResolveArchive(
|
||||
"https://mega.nz/#!CsMSFaaJ!-uziC4mbJPRy2e4pPk8Gjb3oDT_38Be9fzZ6Ld4NL-k");
|
||||
|
||||
Assert.AreEqual("https://mega.nz/#!CsMSFaaJ!-uziC4mbJPRy2e4pPk8Gjb3oDT_38Be9fzZ6Ld4NL-k",
|
||||
((MegaDownloader.State)url_state).Url);
|
||||
|
||||
|
||||
var converted = state.ViaJSON();
|
||||
Assert.IsTrue(converted.Verify());
|
||||
var filename = Guid.NewGuid().ToString();
|
||||
@ -55,6 +62,12 @@ namespace Wabbajack.Test
|
||||
|
||||
Assert.IsNotNull(state);
|
||||
|
||||
var url_state = DownloadDispatcher.ResolveArchive(
|
||||
"https://www.dropbox.com/s/5hov3m2pboppoc2/WABBAJACK_TEST_FILE.txt?dl=0");
|
||||
|
||||
Assert.AreEqual("https://www.dropbox.com/s/5hov3m2pboppoc2/WABBAJACK_TEST_FILE.txt?dl=1",
|
||||
((HTTPDownloader.State)url_state).Url);
|
||||
|
||||
var converted = state.ViaJSON();
|
||||
Assert.IsTrue(converted.Verify());
|
||||
var filename = Guid.NewGuid().ToString();
|
||||
@ -79,6 +92,12 @@ namespace Wabbajack.Test
|
||||
|
||||
Assert.IsNotNull(state);
|
||||
|
||||
var url_state = DownloadDispatcher.ResolveArchive(
|
||||
"https://drive.google.com/file/d/1grLRTrpHxlg7VPxATTFNfq2OkU_Plvh_/view?usp=sharing");
|
||||
|
||||
Assert.AreEqual("1grLRTrpHxlg7VPxATTFNfq2OkU_Plvh_",
|
||||
((GoogleDriveDownloader.State)url_state).Id);
|
||||
|
||||
var converted = state.ViaJSON();
|
||||
Assert.IsTrue(converted.Verify());
|
||||
var filename = Guid.NewGuid().ToString();
|
||||
@ -103,6 +122,12 @@ namespace Wabbajack.Test
|
||||
|
||||
Assert.IsNotNull(state);
|
||||
|
||||
var url_state = DownloadDispatcher.ResolveArchive(
|
||||
"https://raw.githubusercontent.com/wabbajack-tools/opt-out-lists/master/ServerWhitelist.yml");
|
||||
|
||||
Assert.AreEqual("https://raw.githubusercontent.com/wabbajack-tools/opt-out-lists/master/ServerWhitelist.yml",
|
||||
((HTTPDownloader.State)url_state).Url);
|
||||
|
||||
var converted = state.ViaJSON();
|
||||
Assert.IsTrue(converted.Verify());
|
||||
var filename = Guid.NewGuid().ToString();
|
||||
@ -127,6 +152,7 @@ namespace Wabbajack.Test
|
||||
|
||||
Assert.IsNotNull(state);
|
||||
|
||||
|
||||
var converted = state.ViaJSON();
|
||||
Assert.IsTrue(converted.Verify());
|
||||
// Exercise the cache code
|
||||
@ -150,6 +176,12 @@ namespace Wabbajack.Test
|
||||
|
||||
Assert.IsNotNull(state);
|
||||
|
||||
var url_state = DownloadDispatcher.ResolveArchive(
|
||||
"https://www.moddb.com/downloads/start/124908?referer=https%3A%2F%2Fwww.moddb.com%2Fmods%2Fautopause");
|
||||
|
||||
Assert.AreEqual("https://www.moddb.com/downloads/start/124908?referer=https%3A%2F%2Fwww.moddb.com%2Fmods%2Fautopause",
|
||||
((ModDBDownloader.State)url_state).Url);
|
||||
|
||||
var converted = state.ViaJSON();
|
||||
Assert.IsTrue(converted.Verify());
|
||||
var filename = Guid.NewGuid().ToString();
|
||||
|
Loading…
Reference in New Issue
Block a user