stream-fusion-better/stream_fusion/services/postgresql/models/language_rule_model.py
LimeDrive fa68cb2c6b feat: Implement title matching and language rules management
- Refactored title filtering logic in `filter_results.py` to utilize a new title matching module.
- Introduced normalization functions for search queries in `jackett_service.py` and `yggflix_service.py`.
- Added new endpoints for managing title and language normalization rules in the admin views.
- Implemented loading and reloading of title matching and language rules in the application lifecycle.
- Enhanced release group extraction and language detection in `parser_utils.py` using the new title matching module.
2026-04-01 11:04:04 +02:00

47 lines
1.8 KiB
Python

import time
from typing import Optional
from sqlalchemy import BigInteger, Boolean, String, Text
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import Mapped, mapped_column
from stream_fusion.services.postgresql.base import Base
class LanguageRuleModel(Base):
"""Configurable rules for language detection, priority and release group matching."""
__tablename__ = "language_rules"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
rule_type: Mapped[str] = mapped_column(
String(20), nullable=False, index=True
) # 'french_pattern' | 'release_group' | 'code_mapping' | 'priority_group'
key: Mapped[str] = mapped_column(String(100), nullable=False)
value: Mapped[str] = mapped_column(Text, nullable=False)
extra: Mapped[Optional[dict]] = mapped_column(JSONB, nullable=True)
description: Mapped[Optional[str]] = mapped_column(String(500), nullable=True)
is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
created_at: Mapped[int] = mapped_column(BigInteger, nullable=False)
updated_at: Mapped[int] = mapped_column(BigInteger, nullable=False)
def __init__(self, **kwargs):
now = int(time.time())
if "created_at" not in kwargs:
kwargs["created_at"] = now
if "updated_at" not in kwargs:
kwargs["updated_at"] = now
super().__init__(**kwargs)
def to_dict(self) -> dict:
return {
"id": self.id,
"rule_type": self.rule_type,
"key": self.key,
"value": self.value,
"extra": self.extra,
"description": self.description,
"is_active": self.is_active,
"created_at": self.created_at,
"updated_at": self.updated_at,
}