Hentai-Downloader/source/inputhandler.d

70 lines
1.7 KiB
D

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)
{
// if url is empty just return
if(url == "") return;
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
{
writefln("[!] The url (%s) you supplied isn't supported :(", 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);
}