update_0.2 #1

Merged
smolkik_adm merged 6 commits from update_0.2 into main 2026-02-19 03:22:57 +00:00
2 changed files with 13 additions and 13 deletions
Showing only changes of commit 817819c382 - Show all commits

View File

@@ -1,7 +1,13 @@
# cache.py
import hashlib
import os
def cache_key(url: str, quality: str, audio: bool = False) -> str:
key_str = f"{url}_{quality}_{audio}"
return hashlib.sha256(key_str.encode()).hexdigest()
def cache_path(cache_dir: str, key: str, extension: str) -> str:
subdir = key[:2]
full_dir = os.path.join(cache_dir, subdir)
os.makedirs(full_dir, exist_ok=True) # ← ОБЯЗАТЕЛЬНО
os.makedirs(full_dir, exist_ok=True)
return os.path.join(full_dir, f"{key}.{extension}")

View File

@@ -1,10 +1,9 @@
# main.py
# main.py — ИСПРАВЛЕНО: добавлен import cache_key
import os
import asyncio
import threading
import logging
import time
from datetime import datetime
from typing import Optional
from aiogram import Bot, Dispatcher, F
@@ -33,7 +32,7 @@ from downloader import (
from middleware import PrivateMiddleware
from rate_limit import check_rate_limit
from info import extract_info, is_playlist, get_platform_info
from cache import cache_path
from cache import cache_key, cache_path # ← ИСПРАВЛЕНО: добавлен cache_key
from cleanup import cleanup_tmp
logging.basicConfig(level=logging.INFO)
@@ -56,7 +55,6 @@ USER_URLS: dict[int, str] = {}
USER_DATA: dict[int, dict] = {}
ACTIVE_DOWNLOADS: dict[int, dict] = {}
# Вспомогательные функции
def render_bar(percent: float, size: int = 10) -> str:
filled = int(size * percent / 100)
return "" * filled + "" * (size - filled)
@@ -89,7 +87,7 @@ def make_progress_cb(loop, message):
asyncio.run_coroutine_threadsafe(update(d), loop)
return cb
# ---------------------- AUTO DOWNLOADS (TikTok/Instagram) ----------------------
# ---------------------- AUTO DOWNLOADS (TikTok/Instagram) ------------------
async def process_tiktok_auto(message: Message, user_id: int, url: str):
status = await message.answer("🎵 <b>Загружаю TikTok (видео + аудио)...</b>", parse_mode="HTML")
@@ -97,7 +95,6 @@ async def process_tiktok_auto(message: Message, user_id: int, url: str):
key_video = cache_key(url, "tiktok_video", audio=False)
key_audio = cache_key(url, "tiktok_audio", audio=True)
# ✅ ИСПРАВЛЕНО: создаём подкаталоги в TMP
video_cache = cache_path(CACHE_DIR, key_video, "mp4")
tmp_video = cache_path(TMP_DIR, key_video, "mp4")
os.makedirs(os.path.dirname(tmp_video), exist_ok=True)
@@ -224,7 +221,7 @@ async def process_instagram_auto(message: Message, user_id: int, url: str):
ACTIVE_DOWNLOADS.pop(user_id, None)
cleanup_tmp(TMP_DIR)
# ---------------------- HANDLERS ----------------------
# ---------------------- HANDLERS ------------------
@dp.message(F.text == "/start")
async def start(message: Message):
@@ -275,8 +272,6 @@ async def handle_link(message: Message):
parse_mode="HTML"
)
# ---------------------- YOUTUBE/VK HANDLERS ----------------------
@dp.callback_query(F.data.startswith("q:"))
async def handle_video(callback: CallbackQuery):
await callback.answer()
@@ -329,7 +324,6 @@ async def handle_video(callback: CallbackQuery):
await status.edit_text("⛔ Загрузка отменена")
return
# ✅ ИСПРАВЛЕНО: просто перемещаем без оптимизации
if os.path.exists(final_path): os.remove(final_path)
os.makedirs(os.path.dirname(final_path), exist_ok=True)
os.rename(tmp_path, final_path)
@@ -439,7 +433,7 @@ async def handle_audio(callback: CallbackQuery):
logger.error(f"Error sending audio: {e}")
await status.edit_text("❌ Ошибка при отправке аудио")
# ---------------------- PLAYLIST HANDLERS ----------------------
# ---------------------- PLAYLIST HANDLERS ------------------
@dp.callback_query(F.data == "playlist_all")
async def handle_playlist_all(callback: CallbackQuery):
await callback.answer()
@@ -602,7 +596,7 @@ async def cancel_download(callback: CallbackQuery):
else:
await callback.answer("❌ Нет активной загрузки", show_alert=True)
# ---------------------- ENTRYPOINT ----------------------
# ---------------------- ENTRYPOINT ------------------
async def main():
cleanup_tmp(TMP_DIR)
try: