Skip to content

Commit

Permalink
add options for md5 search and twitter artist as tag
Browse files Browse the repository at this point in the history
  • Loading branch information
reluce committed Jun 23, 2023
1 parent 8fa1f09 commit 21919d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
8 changes: 2 additions & 6 deletions config_sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public = false # Is your szurubooru reachable over the internet?
[auto_tagger]
saucenao_api_token = "my_saucenao_api_token" # In case you want to increase your daily query limit
saucenao_enabled = true # Set this to false and deepbooru_enabled to true if you only want to tag with DeepBooru
md5_search_enabled = true # Search file with their MD5 hash on Boorus
deepbooru_enabled = false
deepbooru_model = "./misc/deepbooru/model-resnet_custom_v3.h5"
deepbooru_threshold = "0.7" # Define how accurate the matched tag from DeepBooru has to be
Expand Down Expand Up @@ -36,12 +37,6 @@ password = "None"
user = "None"
password = "None"
token = "None"
[twitter]
user_id = "None" # The user id which should be queried.
consumer_key = "None" # See https://developer.twitter.com/en/docs/authentication/oauth-1-0a
consumer_secret = "None" # See https://developer.twitter.com/en/docs/authentication/oauth-1-0a
access_token = "None" # See https://developer.twitter.com/en/docs/authentication/oauth-1-0a
access_token_secret = "None" # See https://developer.twitter.com/en/docs/authentication/oauth-1-0a

[upload_media]
src_path = "/local/path/to/upload/dir" # Every valid media file under this dir (recursively) will get uploaded
Expand Down Expand Up @@ -74,6 +69,7 @@ hide_progress = false # Set this to true to hide the progress bar
deepbooru_enabled = true # Apply Deepbooru tagging additionally besides fetched tags from URL
tmp_path = './tmp/gallery_dl'
hide_progress = false # Set this to true to hide the progress bar
use_twitter_artist = false # Set this to true to create the Twitter username + nickname as tags. Tries to query Danbooru first for these names (if they're aliases).
# Following settings apply from upload_media as well:
# max_similarity
# convert_to_jpg
Expand Down
13 changes: 6 additions & 7 deletions src/szurubooru_toolkit/config.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import re
import tomllib
import urllib
from pathlib import Path

import validators
from loguru import logger
from tomlkit import parse
from validators import ValidationFailure


class Config:
"""Holds the options set in config.toml as attributes."""

def __init__(self) -> None:
def __init__(self, config_file: str = 'config.toml') -> None:
"""Parse the user config (config.toml) and set this objects attributes accordingly."""

try:
with open('config.toml') as f:
content = f.read()

with open(config_file, 'rb') as f:
try:
self.config = parse(content)
self.config = tomllib.load(f)
except Exception as e:
logger.critical(e)
exit(1)
Expand Down Expand Up @@ -54,6 +52,7 @@ def check_attr_set(self) -> None:
'auto_tagger': [
'saucenao_api_token',
'saucenao_enabled',
'md5_search_enabled',
'deepbooru_enabled',
'deepbooru_model',
'deepbooru_threshold',
Expand All @@ -80,7 +79,7 @@ def check_attr_set(self) -> None:
],
'import_from_booru': ['deepbooru_enabled', 'hide_progress'],
'import_from_twitter': ['saucenao_enabled', 'deepbooru_enabled', 'hide_progress'],
'import_from_url': ['deepbooru_enabled', 'hide_progress', 'tmp_path'],
'import_from_url': ['deepbooru_enabled', 'hide_progress', 'tmp_path', 'use_twitter_artist'],
'tag_posts': ['hide_progress'],
'delete_posts': ['hide_progress'],
'reset_posts': ['hide_progress'],
Expand Down

0 comments on commit 21919d6

Please sign in to comment.