コード例 #1
0
ファイル: __main__.py プロジェクト: oxy/nsfw_dl
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)
コード例 #2
0
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)
コード例 #3
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
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")
コード例 #4
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
def test_e621_search():
    with nsfw_dl.NSFWDL() as dl:
        img = dl.download("E621Search", args="1girl")
        assert img
コード例 #5
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
def test_e621_random():
    with nsfw_dl.NSFWDL() as dl:
        img = dl.download("E621Random")
        assert img
コード例 #6
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
def test_drunkenpumken_random():
    with nsfw_dl.NSFWDL() as dl:
        img = dl.download("DrunkenpumkenRandom")
        assert img
コード例 #7
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
def test_lolibooru_random():
    with nsfw_dl.NSFWDL() as dl:
        img = dl.download("LolibooruRandom")
        assert img
コード例 #8
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
def test_konachan_random():
    with nsfw_dl.NSFWDL() as dl:
        img = dl.download("KonachanRandom")
        assert img
コード例 #9
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
def test_tsumino_random():
    with nsfw_dl.NSFWDL() as dl:
        img = dl.download("TsuminoRandom")
        assert img
コード例 #10
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
def test_tbib_search():
    with nsfw_dl.NSFWDL() as dl:
        img = dl.download("TbibSearch", args="1girl")
        assert img
コード例 #11
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
def test_tbib_random():
    with nsfw_dl.NSFWDL() as dl:
        img = dl.download("TbibRandom")
        assert img
コード例 #12
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
def test_danbooru_random():
    """tests danbooru's random."""
    with nsfw_dl.NSFWDL() as dl:
        img = dl.download("DanbooruRandom")
    assert img
コード例 #13
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
def test_rule34_search():
    with nsfw_dl.NSFWDL() as dl:
        img = dl.download("Rule34Search", args="1girl")
        assert img
コード例 #14
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
def test_rule34_random():
    with nsfw_dl.NSFWDL() as dl:
        img = dl.download("Rule34Random")
        assert img
コード例 #15
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
def test_furrybooru_random():
    with nsfw_dl.NSFWDL() as dl:
        img = dl.download("FurrybooruRandom")
        assert img
コード例 #16
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
def test_yandere_random():
    with nsfw_dl.NSFWDL() as dl:
        img = dl.download("YandereRandom")
        assert img
コード例 #17
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
def test_hbrowse_random():
    with nsfw_dl.NSFWDL() as dl:
        img = dl.download("HbrowseRandom")
        assert img
コード例 #18
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
def test_yandere_search():
    with nsfw_dl.NSFWDL() as dl:
        img = dl.download("YandereSearch", args="1girl")
        assert img
コード例 #19
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
def test_konachan_search():
    with nsfw_dl.NSFWDL() as dl:
        img = dl.download("KonachanSearch", args="2girls")
        assert img
コード例 #20
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
async def test_danbooru_async():
    """ ONLY ASYNC TEST """
    async with nsfw_dl.NSFWDL() as dl:
        img = await dl.download("DanbooruRandom")
    assert img
コード例 #21
0
ファイル: test_nsfw_dl.py プロジェクト: oxy/nsfw_dl
def test_lolibooru_search():
    with nsfw_dl.NSFWDL() as dl:
        img = dl.download("LolibooruSearch", args="1girl")
        assert img
コード例 #22
0
 def __init__(self, bot):
     self.client = nsfw_dl.NSFWDL(session=bot.session, loop=bot.loop)