mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-02-01 07:39:10 +00:00
fix: multiple macro errors (#612)
* port fixes from json branch * fix: correctly pass grid_idx in autofill macro * fix(BUILD_URL macro): only add url if url was successfully built * fix(AUTOFILL macro): error when trying to add tag with name that already exists * fix: test was wrongly renaming sidecar file
This commit is contained in:
@@ -998,6 +998,15 @@ class Library:
|
||||
|
||||
return tag
|
||||
|
||||
def get_tag_by_name(self, tag_name: str) -> Tag | None:
|
||||
with Session(self.engine) as session:
|
||||
statement = (
|
||||
select(Tag)
|
||||
.outerjoin(TagAlias)
|
||||
.where(or_(Tag.name == tag_name, TagAlias.name == tag_name))
|
||||
)
|
||||
return session.scalar(statement)
|
||||
|
||||
def get_alias(self, tag_id: int, alias_id: int) -> TagAlias:
|
||||
with Session(self.engine) as session:
|
||||
alias_query = select(TagAlias).where(TagAlias.id == alias_id, TagAlias.tag_id == tag_id)
|
||||
|
||||
@@ -24,7 +24,7 @@ class TagStudioCore:
|
||||
Return a formatted object with notable values or an empty object if none is found.
|
||||
"""
|
||||
info = {}
|
||||
_filepath = filepath.parent / (filepath.stem + ".json")
|
||||
_filepath = filepath.parent / (filepath.name + ".json")
|
||||
|
||||
# NOTE: This fixes an unknown (recent?) bug in Gallery-DL where Instagram sidecar
|
||||
# files may be downloaded with indices starting at 1 rather than 0, unlike the posts.
|
||||
|
||||
@@ -72,7 +72,7 @@ from src.core.library.alchemy.enums import (
|
||||
SearchMode,
|
||||
)
|
||||
from src.core.library.alchemy.fields import _FieldID
|
||||
from src.core.library.alchemy.library import LibraryStatus
|
||||
from src.core.library.alchemy.library import Entry, Library, LibraryStatus
|
||||
from src.core.media_types import MediaCategories
|
||||
from src.core.ts_core import TagStudioCore
|
||||
from src.core.utils.refresh_dir import RefreshDirTracker
|
||||
@@ -130,6 +130,7 @@ class QtDriver(DriverMixin, QObject):
|
||||
SIGTERM = Signal()
|
||||
|
||||
preview_panel: PreviewPanel
|
||||
lib: Library
|
||||
|
||||
def __init__(self, backend, args):
|
||||
super().__init__()
|
||||
@@ -788,9 +789,9 @@ class QtDriver(DriverMixin, QObject):
|
||||
|
||||
def run_macro(self, name: MacroID, grid_idx: int):
|
||||
"""Run a specific Macro on an Entry given a Macro name."""
|
||||
entry = self.frame_content[grid_idx]
|
||||
ful_path = self.lib.library_dir / entry.path
|
||||
source = entry.path.parts[0]
|
||||
entry: Entry = self.frame_content[grid_idx]
|
||||
full_path = self.lib.library_dir / entry.path
|
||||
source = "" if entry.path.parent == Path(".") else entry.path.parts[0].lower()
|
||||
|
||||
logger.info(
|
||||
"running macro",
|
||||
@@ -804,10 +805,10 @@ class QtDriver(DriverMixin, QObject):
|
||||
for macro_id in MacroID:
|
||||
if macro_id == MacroID.AUTOFILL:
|
||||
continue
|
||||
self.run_macro(macro_id, entry.id)
|
||||
self.run_macro(macro_id, grid_idx)
|
||||
|
||||
elif name == MacroID.SIDECAR:
|
||||
parsed_items = TagStudioCore.get_gdl_sidecar(ful_path, source)
|
||||
parsed_items = TagStudioCore.get_gdl_sidecar(full_path, source)
|
||||
for field_id, value in parsed_items.items():
|
||||
if isinstance(value, list) and len(value) > 0 and isinstance(value[0], str):
|
||||
value = self.lib.tag_from_strings(value)
|
||||
@@ -818,8 +819,9 @@ class QtDriver(DriverMixin, QObject):
|
||||
)
|
||||
|
||||
elif name == MacroID.BUILD_URL:
|
||||
url = TagStudioCore.build_url(entry.id, source)
|
||||
self.lib.add_entry_field_type(entry.id, field_id=_FieldID.SOURCE, value=url)
|
||||
url = TagStudioCore.build_url(entry, source)
|
||||
if url is not None:
|
||||
self.lib.add_entry_field_type(entry.id, field_id=_FieldID.SOURCE, value=url)
|
||||
elif name == MacroID.MATCH:
|
||||
TagStudioCore.match_conditions(self.lib, entry.id)
|
||||
elif name == MacroID.CLEAN_URL:
|
||||
|
||||
@@ -12,7 +12,7 @@ def test_sidecar_macro(qt_driver, library, cwd, entry_full):
|
||||
entry_full.path = Path("newgrounds/foo.txt")
|
||||
|
||||
fixture = cwd / "fixtures/sidecar_newgrounds.json"
|
||||
dst = library.library_dir / "newgrounds" / (entry_full.path.stem + ".json")
|
||||
dst = library.library_dir / "newgrounds" / (entry_full.path.name + ".json")
|
||||
dst.parent.mkdir()
|
||||
shutil.copy(fixture, dst)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user