Torrent file name sanitizing (#390)

Hi, I've added file names sanitization when saving the torrent file, as
previously the import was failing on torrents with special characters in
names. This fixes #367
This commit is contained in:
Sergey Khruschak
2026-02-03 18:09:36 +02:00
committed by GitHub
parent d5994a9037
commit 24fcba6bee
3 changed files with 14 additions and 1 deletions

View File

@@ -9,6 +9,7 @@ import bencoder
import libtorrent
import patoolib
import requests
from pathvalidate import sanitize_filename
from requests.exceptions import InvalidSchema
from media_manager.config import MediaManagerConfig
@@ -132,7 +133,7 @@ def get_torrent_hash(torrent: IndexerQueryResult) -> str:
:return: The hash of the torrent.
"""
torrent_filepath = (
MediaManagerConfig().misc.torrent_directory / f"{torrent.title}.torrent"
MediaManagerConfig().misc.torrent_directory / f"{sanitize_filename(torrent.title)}.torrent"
)
if torrent_filepath.exists():
log.warning(f"Torrent file already exists at: {torrent_filepath}")

View File

@@ -33,6 +33,7 @@ dependencies = [
"sabnzbd-api>=0.1.2",
"transmission-rpc>=7.0.11",
"libtorrent>=2.0.11",
"pathvalidate>=3.3.1",
]
[dependency-groups]

11
uv.lock generated
View File

@@ -864,6 +864,7 @@ dependencies = [
{ name = "httpx-oauth" },
{ name = "jsonschema" },
{ name = "libtorrent" },
{ name = "pathvalidate" },
{ name = "patool" },
{ name = "pillow" },
{ name = "psycopg", extra = ["binary"] },
@@ -903,6 +904,7 @@ requires-dist = [
{ name = "httpx-oauth", specifier = ">=0.16.1" },
{ name = "jsonschema", specifier = ">=4.24.0" },
{ name = "libtorrent", specifier = ">=2.0.11" },
{ name = "pathvalidate", specifier = ">=3.3.1" },
{ name = "patool", specifier = ">=4.0.1" },
{ name = "pillow", specifier = ">=11.3.0" },
{ name = "psycopg", extras = ["binary"], specifier = ">=3.2.9" },
@@ -946,6 +948,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/20/12/38679034af332785aac8774540895e234f4d07f7545804097de4b666afd8/packaging-25.0-py3-none-any.whl", hash = "sha256:29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484", size = 66469, upload-time = "2025-04-19T11:48:57.875Z" },
]
[[package]]
name = "pathvalidate"
version = "3.3.1"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/fa/2a/52a8da6fe965dea6192eb716b357558e103aea0a1e9a8352ad575a8406ca/pathvalidate-3.3.1.tar.gz", hash = "sha256:b18c07212bfead624345bb8e1d6141cdcf15a39736994ea0b94035ad2b1ba177", size = 63262, upload-time = "2025-06-15T09:07:20.736Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/9a/70/875f4a23bfc4731703a5835487d0d2fb999031bd415e7d17c0ae615c18b7/pathvalidate-3.3.1-py3-none-any.whl", hash = "sha256:5263baab691f8e1af96092fa5137ee17df5bdfbd6cff1fcac4d6ef4bc2e1735f", size = 24305, upload-time = "2025-06-15T09:07:19.117Z" },
]
[[package]]
name = "patool"
version = "4.0.3"