Hentai-Downloader/source/inputhandler.d

69 lines
1.7 KiB
D
Raw Normal View History

2020-04-13 13:19:14 -04:00
import std.stdio;
import std.string;
import std.array;
import core.stdc.stdlib : exit, EXIT_FAILURE;
import config.downloaderconfig;
import sites.basesite;
import sites.hentaicafe;
import sites.nhentai;
/++
+ This function parses the url and creates the appropriate site object
+ and then downloads the images
+/
void siteFactory(string url)
{
immutable string hentaicafe_indicator = "/hc.fyi/";
immutable string nhentai_indicator = "/g/";
// Load the config file
Config config = DownloaderConfig.loadConfig();
// Placeholder for down casted object
BaseSite mangaSite;
if(indexOf(url, hentaicafe_indicator) != -1) // The supplied url is a hentaicafe url
{
// Create `HentaiCafe` object
HentaiCafe hentaicafe = new HentaiCafe(config);
// Implicit downcast to `BaseSite`
mangaSite = hentaicafe;
}
else if(indexOf(url, nhentai_indicator) != -1) // The supplied url is a nhentai url
{
// Create `NHentai` object
NHentai nhentai = new NHentai(config);
// Implicit downcast to `BaseSite`
mangaSite = nhentai;
}
else
{
writeln("[!] The url you supplied isn't supported :(");
writeln(url);
// FIXME:
// Dont exit with a failure
exit(EXIT_FAILURE);
}
// Download the manga
mangaSite.downloadDoujin(url);
}
/++
+ This function parses each url in a list
+ and creates the appropriate site object to
+ download the managa
+/
void siteFactory(string[] urls)
{
// Call the site factory for each url that way you can have a list
// of mixed manag links
foreach(string url; urls)
siteFactory(url);
}