diff --git a/__init__.py b/__init__.py index 177bcd3..b3cf29b 100644 --- a/__init__.py +++ b/__init__.py @@ -10,7 +10,8 @@ NODE_CLASS_MAPPINGS = { "Simple Wildcards": SimpleWildcards, "Simple Wildcards (Dir.)": SimpleWildcardsDir, "Wildcards": Wildcards, -} + "Get From Danbooru": GetFromDanbooru, + } __all__ = ['NODE_CLASS_MAPPINGS'] diff --git a/gtsuya_nodes.py b/gtsuya_nodes.py index 404a9c1..8d01575 100644 --- a/gtsuya_nodes.py +++ b/gtsuya_nodes.py @@ -4,6 +4,9 @@ import shutil import glob import re import random +from urllib.request import urlopen +import json +import time """ @@ -37,7 +40,7 @@ class SimpleWildcards: RETURN_TYPES = ("STRING",) RETURN_NAMES = ("text",) FUNCTION = "get_text" - CATEGORY = "gtsuya/wildcards" + CATEGORY = "GtsuyaStudio/Wildcards" def get_text(self, text, seed): wildcards_path = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))+'\\wildcards' @@ -71,7 +74,7 @@ class SimpleWildcardsDir: RETURN_TYPES = ("STRING",) RETURN_NAMES = ("text",) FUNCTION = "get_text" - CATEGORY = "gtsuya/wildcards" + CATEGORY = "GtsuyaStudio/Wildcards" def get_text(self, text, directory, seed): wildcards = re.findall('__(.*?)__', text) @@ -109,7 +112,7 @@ class Wildcards: RETURN_TYPES = ("STRING",) RETURN_NAMES = ("text",) FUNCTION = "get_value" - CATEGORY = "gtsuya/wildcards" + CATEGORY = "GtsuyaStudio/Wildcards" def get_value(self, text, str1=None, str2=None, str3=None, str4=None, str5=None): @@ -128,9 +131,44 @@ class Wildcards: #---------------------------------------------------------------------------------------------------------------------------------------------------# +class GetFromDanbooru: + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "query_tag": ("STRING", {"default": ""}), + "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}), + }, + } + + RETURN_TYPES = ("STRING","STRING",) + RETURN_NAMES = ("tags","img_url",) + FUNCTION = "get_value" + CATEGORY = "GtsuyaStudio/Get From" + + def get_value(self, seed, query_tag): + tags = None + img_url = None + login = "Gtsuya_Studio" + api_key = "orhE6jtQE2mBNPUZeSNki2Dp" + url = "https://danbooru.donmai.us/posts/random.json?login="+login+"&api_key="+api_key + if query_tag != '': + url = url+"&tags="+query_tag + img_url = None + with urlopen(url) as response: + body = response.read() + items = json.loads(body) + tags = items['tag_string'] + img_url = items['file_url'] + + return (tags,img_url) + +#---------------------------------------------------------------------------------------------------------------------------------------------------# + # A dictionary that contains the friendly/humanly readable titles for the nodes NODE_DISPLAY_NAME_MAPPINGS = { "SimpleWildcards": "Simple Wildcards", "SimpleWildcardsDir": "Simple Wildcards (Dir.)", "Wildcards": "Wildcards", + "GetFromDanbooru": "Get From Danbooru", }