23 lines
831 B
Python
23 lines
831 B
Python
import abc
|
|
import os
|
|
import re
|
|
from typing import Optional, Tuple
|
|
|
|
|
|
class Downloader(abc.ABC):
|
|
"""Базовый класс для загрузчиков"""
|
|
|
|
@abc.abstractmethod
|
|
def is_supported_url(self, url: str) -> bool:
|
|
"""Проверяет, поддерживается ли URL"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
async def download_audio(self, url: str, config: dict) -> Tuple[Optional[str], Optional[str], Optional[int]]:
|
|
"""Скачивает аудио и возвращает (путь к файлу, название, длительность)"""
|
|
pass
|
|
|
|
@staticmethod
|
|
def sanitize_filename(name: str) -> str:
|
|
"""Очищает название файла от недопустимых символов"""
|
|
return re.sub(r'[^\w\-_\. ]', '', name)[:100] |