def download(downloader, args, file, download_file): with nsfw_dl.NSFWDL() as dl: img = dl.download(downloader, args=args) if callable(file): file = file(img) if download_file: with open(file, "wb") as f: f.write(dl.get(img)) print(file) else: print(img)
def main(argv=sys.argv[1:]): # pylint: disable=dangerous-default-value """ Main entrypoint to nsfw_dl commandline. """ image = argparse.ArgumentParser() image.add_argument('-d', '--download', help='Download the result to a file.', default=False) image.add_argument('-f', '--file', help="Filename to download to.", default=lambda x: x.split("/")[-1]) image.add_argument('-s', '--source', help='Image source to use.', default='') image.add_argument('query', help='Tags to use during search.', default='', nargs="*") args = image.parse_args(argv) if (args.source == ''): print("Usage: " + os.path.basename(sys.argv[0]) + " [-d/--download]" " [-f/--file ...] [-s/--source ...] [query]") print("Where first ... is the file name you want, second ... " "is the source where source can be:") sources = "\n".join("\n".join(v for v in source) for source in nsfw_dl.SOURCES.values()) print(sources) print("And query is what you want to search for.") else: download_file = args.download file = args.file with nsfw_dl.NSFWDL() as dl: img = dl.download(args.source, args=" ".join(args.query)) if callable(file): file = file(img) if download_file: with open(file, "wb") as f: f.write(dl.get(img)) print(file) else: print(img)
def test_fake_loader(): """tests the NSFWDL class.""" with pytest.raises(nsfw_dl.errors.NoLoader): with nsfw_dl.NSFWDL() as dl: dl.download("fake_loader", args="1girl")
def test_e621_search(): with nsfw_dl.NSFWDL() as dl: img = dl.download("E621Search", args="1girl") assert img
def test_e621_random(): with nsfw_dl.NSFWDL() as dl: img = dl.download("E621Random") assert img
def test_drunkenpumken_random(): with nsfw_dl.NSFWDL() as dl: img = dl.download("DrunkenpumkenRandom") assert img
def test_lolibooru_random(): with nsfw_dl.NSFWDL() as dl: img = dl.download("LolibooruRandom") assert img
def test_konachan_random(): with nsfw_dl.NSFWDL() as dl: img = dl.download("KonachanRandom") assert img
def test_tsumino_random(): with nsfw_dl.NSFWDL() as dl: img = dl.download("TsuminoRandom") assert img
def test_tbib_search(): with nsfw_dl.NSFWDL() as dl: img = dl.download("TbibSearch", args="1girl") assert img
def test_tbib_random(): with nsfw_dl.NSFWDL() as dl: img = dl.download("TbibRandom") assert img
def test_danbooru_random(): """tests danbooru's random.""" with nsfw_dl.NSFWDL() as dl: img = dl.download("DanbooruRandom") assert img
def test_rule34_search(): with nsfw_dl.NSFWDL() as dl: img = dl.download("Rule34Search", args="1girl") assert img
def test_rule34_random(): with nsfw_dl.NSFWDL() as dl: img = dl.download("Rule34Random") assert img
def test_furrybooru_random(): with nsfw_dl.NSFWDL() as dl: img = dl.download("FurrybooruRandom") assert img
def test_yandere_random(): with nsfw_dl.NSFWDL() as dl: img = dl.download("YandereRandom") assert img
def test_hbrowse_random(): with nsfw_dl.NSFWDL() as dl: img = dl.download("HbrowseRandom") assert img
def test_yandere_search(): with nsfw_dl.NSFWDL() as dl: img = dl.download("YandereSearch", args="1girl") assert img
def test_konachan_search(): with nsfw_dl.NSFWDL() as dl: img = dl.download("KonachanSearch", args="2girls") assert img
async def test_danbooru_async(): """ ONLY ASYNC TEST """ async with nsfw_dl.NSFWDL() as dl: img = await dl.download("DanbooruRandom") assert img
def test_lolibooru_search(): with nsfw_dl.NSFWDL() as dl: img = dl.download("LolibooruSearch", args="1girl") assert img
def __init__(self, bot): self.client = nsfw_dl.NSFWDL(session=bot.session, loop=bot.loop)