From 8de9c2195a8384871a83a591fbf76c26b27b957b Mon Sep 17 00:00:00 2001 From: Lev Plyusnin Date: Sat, 14 Jun 2025 20:30:21 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=BD=D0=BE=D0=B5=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2=20?= =?UTF-8?q?=D1=81=20=D0=B4=D0=BB=D0=B8=D0=BD=D0=BD=D1=8B=D0=BC=D0=B8=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- ymd/core.py | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c845a9e..422594b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta" [project] name = "yandex-music-downloader" -version = "3.4.7" +version = "3.4.8" description = "Загрузчик музыки с сервиса Яндекс.Музыка" requires-python = ">=3.9" readme = "README.md" diff --git a/ymd/core.py b/ymd/core.py index f92093f..1275bfe 100644 --- a/ymd/core.py +++ b/ymd/core.py @@ -1,4 +1,5 @@ import datetime as dt +import hashlib import re import typing from collections.abc import Callable @@ -52,6 +53,9 @@ MAX_COMPATIBILITY_LEVEL = 1 AUDIO_FILE_SUFFIXES = {".mp3", ".flac", ".m4a"} TEMPORARY_FILE_NAME_TEMPLATE = ".yandex-music-downloader.{}.tmp" +MAX_FILE_NAME_LENGTH_WITHOUT_SUFFIX = 255 - max( + len(suffix) for suffix in AUDIO_FILE_SUFFIXES +) class CoreTrackQuality(IntEnum): @@ -137,7 +141,14 @@ def prepare_base_path( clear_re = UNSAFE_PATH_CLEAR_RE replacement = clear_re.sub("_", replacement) path_str = path_str.replace(placeholder, replacement) - return Path(path_str) + path = Path(path_str) + trimmed_parts = [ + part + if len(part) <= MAX_FILE_NAME_LENGTH_WITHOUT_SUFFIX + else part[:MAX_FILE_NAME_LENGTH_WITHOUT_SUFFIX] + for part in path.parts + ] + return Path(*trimmed_parts) def set_tags( @@ -371,8 +382,9 @@ def write_via_temporary_file( target_path: Path, temporary_file_hook: Optional[Callable[[Path], None]] = None, ) -> Path: + target_name = hashlib.sha256(target_path.name.encode()).hexdigest() temporary_file = target_path.parent / ( - TEMPORARY_FILE_NAME_TEMPLATE.format(target_path.name) + TEMPORARY_FILE_NAME_TEMPLATE.format(target_name) ) try: temporary_file.write_bytes(data)