mirror of
https://github.com/Viren070/MediaFusion.git
synced 2025-12-01 23:21:11 +01:00
#109 : Add adult content filtering functionality
This commit is contained in:
@@ -19,6 +19,9 @@ class Settings(BaseSettings):
|
||||
prowlarr_api_key: str | None = None
|
||||
prowlarr_search_interval_hour: int = 24
|
||||
prowlarr_immediate_max_process: int = 10
|
||||
adult_content_regex_keywords: str = (
|
||||
r"\b(18\+|adult|porn|sex|xxx|nude|naked|erotic|sexy|18\s*plus|18\s*\+)\b"
|
||||
)
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
|
||||
@@ -18,6 +18,7 @@ from scrapers.helpers import (
|
||||
UA_HEADER,
|
||||
)
|
||||
from utils.network import CircuitBreaker, batch_process_with_circuit_breaker
|
||||
from utils.parser import is_contain_18_plus_keywords
|
||||
from utils.torrent import extract_torrent_metadata
|
||||
|
||||
|
||||
@@ -216,6 +217,12 @@ async def get_torrent_data_from_prowlarr(download_url: str) -> tuple[dict, bool]
|
||||
|
||||
async def prowlarr_data_parser(meta_data: dict) -> tuple[dict, bool]:
|
||||
"""Parse prowlarr data."""
|
||||
if is_contain_18_plus_keywords(meta_data.get("title")):
|
||||
logging.warning(
|
||||
f"Skipping {meta_data.get('title')} due to adult content keywords."
|
||||
)
|
||||
return {}, False
|
||||
|
||||
if meta_data.get("indexer") in [
|
||||
"Torlock",
|
||||
"YourBittorrent",
|
||||
|
||||
@@ -15,7 +15,7 @@ from scrapers.helpers import (
|
||||
update_torrent_series_streams_metadata,
|
||||
update_torrent_movie_streams_metadata,
|
||||
)
|
||||
from utils.parser import convert_size_to_bytes
|
||||
from utils.parser import convert_size_to_bytes, is_contain_18_plus_keywords
|
||||
from utils.validation_helper import is_video_file
|
||||
|
||||
|
||||
@@ -123,6 +123,10 @@ async def store_and_parse_movie_stream_data(
|
||||
streams = []
|
||||
info_hashes = []
|
||||
for stream in stream_data:
|
||||
if is_contain_18_plus_keywords(stream["title"]):
|
||||
logging.warning(f"Stream contains 18+ keywords: {stream['title']}")
|
||||
continue
|
||||
|
||||
parsed_data = parse_stream_title(stream)
|
||||
if not parsed_data["seeders"]:
|
||||
continue
|
||||
@@ -176,6 +180,10 @@ async def store_and_parse_series_stream_data(
|
||||
streams = []
|
||||
info_hashes = []
|
||||
for stream in stream_data:
|
||||
if is_contain_18_plus_keywords(stream["title"]):
|
||||
logging.warning(f"Stream contains 18+ keywords: {stream['title']}")
|
||||
continue
|
||||
|
||||
parsed_data = parse_stream_title(stream)
|
||||
if not parsed_data["seeders"]:
|
||||
continue
|
||||
|
||||
@@ -42,6 +42,10 @@ from streaming_providers.torbox.utils import (
|
||||
)
|
||||
|
||||
ia = Cinemagoer()
|
||||
ADULT_CONTENT_KEYWORDS = re.compile(
|
||||
settings.adult_content_regex_keywords,
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
|
||||
async def filter_and_sort_streams(
|
||||
@@ -325,3 +329,10 @@ def generate_manifest(manifest: dict, user_data: UserData) -> dict:
|
||||
|
||||
manifest["resources"] = resources
|
||||
return manifest
|
||||
|
||||
|
||||
def is_contain_18_plus_keywords(title: str) -> bool:
|
||||
"""
|
||||
Check if the title contains 18+ keywords to filter out adult content.
|
||||
"""
|
||||
return ADULT_CONTENT_KEYWORDS.search(title) is not None
|
||||
|
||||
@@ -17,6 +17,8 @@ from anyio.streams.memory import MemoryObjectSendStream
|
||||
from demagnetize.core import Demagnetizer
|
||||
from torf import Magnet
|
||||
|
||||
from utils.parser import is_contain_18_plus_keywords
|
||||
|
||||
# remove logging from demagnetize
|
||||
logging.getLogger("demagnetize").setLevel(logging.CRITICAL)
|
||||
|
||||
@@ -71,6 +73,12 @@ def extract_torrent_metadata(content: bytes) -> dict:
|
||||
tracker[0].decode() for tracker in torrent_data.get(b"announce-list", [])
|
||||
]
|
||||
torrent_name = info.get(b"name", b"").decode() or file_data[0]["filename"]
|
||||
if is_contain_18_plus_keywords(torrent_name):
|
||||
logging.warning(
|
||||
f"Torrent name contains 18+ keywords: {torrent_name}. Skipping"
|
||||
)
|
||||
return {}
|
||||
|
||||
largest_file = max(file_data, key=lambda x: x["size"])
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user