summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/Dockerfile10
-rw-r--r--server/requirements.txt4
-rw-r--r--server/szurubooru/func/net.py2
-rw-r--r--server/szurubooru/search/configs/post_search_config.py29
-rw-r--r--server/szurubooru/tests/search/configs/test_post_search_config.py52
5 files changed, 89 insertions, 8 deletions
diff --git a/server/Dockerfile b/server/Dockerfile
index 487f192..3e4dadf 100644
--- a/server/Dockerfile
+++ b/server/Dockerfile
@@ -23,15 +23,15 @@ RUN apk --no-cache add \
py3-pillow \
py3-pynacl \
py3-tz \
- py3-pyrfc3339 \
- && pip3 install --no-cache-dir --disable-pip-version-check \
+ py3-pyrfc3339
+RUN pip3 install --no-cache-dir --disable-pip-version-check \
"alembic>=0.8.5" \
"coloredlogs==5.0" \
"pyheif==0.6.1" \
"heif-image-plugin>=0.3.2" \
- youtube_dl \
- "pillow-avif-plugin>=1.1.0" \
- && apk --no-cache del py3-pip
+ yt-dlp \
+ "pillow-avif-plugin~=1.1.0"
+RUN apk --no-cache del py3-pip
COPY ./ /opt/app/
RUN rm -rf /opt/app/szurubooru/tests
diff --git a/server/requirements.txt b/server/requirements.txt
index 16b29ff..ffe18f0 100644
--- a/server/requirements.txt
+++ b/server/requirements.txt
@@ -3,7 +3,7 @@ certifi>=2017.11.5
coloredlogs==5.0
heif-image-plugin==0.3.2
numpy>=1.8.2
-pillow-avif-plugin>=1.1.0
+pillow-avif-plugin~=1.1.0
pillow>=4.3.0
psycopg2-binary>=2.6.1
pyheif==0.6.1
@@ -12,4 +12,4 @@ pyRFC3339>=1.0
pytz>=2018.3
pyyaml>=3.11
SQLAlchemy>=1.0.12, <1.4
-youtube_dl
+yt-dlp
diff --git a/server/szurubooru/func/net.py b/server/szurubooru/func/net.py
index c53a62e..d6aa95e 100644
--- a/server/szurubooru/func/net.py
+++ b/server/szurubooru/func/net.py
@@ -64,7 +64,7 @@ def download(url: str, use_video_downloader: bool = False) -> bytes:
def _get_youtube_dl_content_url(url: str) -> str:
- cmd = ["youtube-dl", "--format", "best", "--no-playlist"]
+ cmd = ["yt-dlp", "--format", "best", "--no-playlist"]
if config.config["user_agent"]:
cmd.extend(["--user-agent", config.config["user_agent"]])
cmd.extend(["--get-url", url])
diff --git a/server/szurubooru/search/configs/post_search_config.py b/server/szurubooru/search/configs/post_search_config.py
index ddc003b..8d4672d 100644
--- a/server/szurubooru/search/configs/post_search_config.py
+++ b/server/szurubooru/search/configs/post_search_config.py
@@ -122,6 +122,34 @@ def _pool_filter(
)(query, criterion, negated)
+def _category_filter(
+ query: SaQuery, criterion: Optional[criteria.BaseCriterion], negated: bool
+) -> SaQuery:
+ assert criterion
+
+ # Step 1. find the id for the category
+ q1 = db.session.query(model.TagCategory.tag_category_id).filter(
+ model.TagCategory.name == criterion.value
+ )
+
+ # Step 2. find the tags with that category
+ q2 = db.session.query(model.Tag.tag_id).filter(
+ model.Tag.category_id.in_(q1)
+ )
+
+ # Step 3. find all posts that have at least one of those tags
+ q3 = db.session.query(model.PostTag.post_id).filter(
+ model.PostTag.tag_id.in_(q2)
+ )
+
+ # Step 4. profit
+ expr = model.Post.post_id.in_(q3)
+ if negated:
+ expr = ~expr
+
+ return query.filter(expr)
+
+
class PostSearchConfig(BaseSearchConfig):
def __init__(self) -> None:
self.user = None # type: Optional[model.User]
@@ -349,6 +377,7 @@ class PostSearchConfig(BaseSearchConfig):
),
),
(["pool"], _pool_filter),
+ (["category"], _category_filter),
]
)
diff --git a/server/szurubooru/tests/search/configs/test_post_search_config.py b/server/szurubooru/tests/search/configs/test_post_search_config.py
index 4fb8191..b86fa27 100644
--- a/server/szurubooru/tests/search/configs/test_post_search_config.py
+++ b/server/szurubooru/tests/search/configs/test_post_search_config.py
@@ -863,3 +863,55 @@ def test_tumbleweed(
db.session.flush()
verify_unpaged("special:tumbleweed", [4])
verify_unpaged("-special:tumbleweed", [1, 2, 3])
+
+
+@pytest.mark.parametrize(
+ "input,expected_post_ids",
+ [
+ ("category:cat1", [1, 2, 3]),
+ ("category:cat2", [3, 4]),
+ ],
+)
+def test_search_by_tag_category(
+ verify_unpaged,
+ post_factory,
+ tag_factory,
+ tag_category_factory,
+ input,
+ expected_post_ids,
+):
+ cat1 = tag_category_factory(name="cat1")
+ cat2 = tag_category_factory(name="cat2")
+ tag1 = tag_factory(names=["t1"], category=cat1)
+ tag2 = tag_factory(names=["t2"], category=cat1)
+ tag3 = tag_factory(names=["t3"], category=cat2)
+
+ post1 = post_factory(id=1)
+ post1.tags.append(tag1)
+
+ post2 = post_factory(id=2)
+ post2.tags.append(tag2)
+
+ post3 = post_factory(id=3)
+ post3.tags.append(tag1)
+ post3.tags.append(tag3)
+
+ post4 = post_factory(id=4)
+ post4.tags.append(tag3)
+
+ post5 = post_factory(id=5)
+
+ db.session.add_all(
+ [
+ tag1,
+ tag2,
+ tag3,
+ post1,
+ post2,
+ post3,
+ post4,
+ post5,
+ ]
+ )
+ db.session.flush()
+ verify_unpaged(input, expected_post_ids)