Add download video by link
This commit is contained in:
@@ -535,6 +535,9 @@ async def url_handler(client: Client, message: Message):
|
||||
from bot.modules.access_control.auth import is_authorized
|
||||
from bot.modules.task_scheduler.queue import task_queue, Task, TaskStatus
|
||||
from bot.modules.task_scheduler.executor import task_executor, set_app_client
|
||||
from bot.modules.message_handler.filters import is_youtube_url, is_instagram_url
|
||||
from bot.modules.media_loader.ytdlp import get_videos_list
|
||||
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
||||
import time
|
||||
|
||||
# Check authorization
|
||||
@@ -554,6 +557,68 @@ async def url_handler(client: Client, message: Message):
|
||||
)
|
||||
return
|
||||
|
||||
# Check if URL is YouTube or Instagram (direct download)
|
||||
is_youtube = is_youtube_url(url)
|
||||
is_instagram = is_instagram_url(url)
|
||||
|
||||
# For non-YouTube/Instagram URLs, check if there are multiple videos
|
||||
if not is_youtube and not is_instagram:
|
||||
# Check if URL contains video selection callback data
|
||||
if url.startswith('video_select:'):
|
||||
# This is a callback from video selection - extract actual URL
|
||||
actual_url = url.replace('video_select:', '', 1)
|
||||
url = actual_url
|
||||
else:
|
||||
# Try to get list of videos from webpage
|
||||
try:
|
||||
status_msg = await message.reply("🔍 Анализирую страницу...")
|
||||
from shared.config import settings
|
||||
videos_info = await get_videos_list(url, cookies_file=settings.COOKIES_FILE)
|
||||
|
||||
if videos_info and videos_info.get('videos'):
|
||||
videos = videos_info['videos']
|
||||
|
||||
if len(videos) > 1:
|
||||
# Multiple videos found - show selection menu
|
||||
await status_msg.delete()
|
||||
|
||||
playlist_title = videos_info.get('playlist_title', 'Найдено видео')
|
||||
text = f"📹 **{playlist_title}**\n\n"
|
||||
text += f"Найдено видео: **{len(videos)}**\n\n"
|
||||
text += "Выберите видео для загрузки:\n\n"
|
||||
|
||||
# Create inline keyboard with video selection buttons
|
||||
buttons = []
|
||||
for idx, video in enumerate(videos[:10], 1): # Limit to 10 videos
|
||||
title = video.get('title', f'Видео {idx}')[:50] # Limit title length
|
||||
duration = video.get('duration')
|
||||
if duration:
|
||||
from bot.utils.helpers import format_duration
|
||||
duration_str = format_duration(duration)
|
||||
title += f" ({duration_str})"
|
||||
|
||||
# Use callback data format: video_select:<video_url>
|
||||
callback_data = f"video_select:{video['url']}"
|
||||
buttons.append([InlineKeyboardButton(f"{idx}. {title}", callback_data=callback_data)])
|
||||
|
||||
keyboard = InlineKeyboardMarkup(buttons)
|
||||
await message.reply(text, reply_markup=keyboard)
|
||||
return
|
||||
elif len(videos) == 1:
|
||||
# Single video found - use its URL
|
||||
url = videos[0]['url']
|
||||
await status_msg.delete()
|
||||
else:
|
||||
# No videos found, but continue with original URL (might be direct video link)
|
||||
await status_msg.delete()
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting videos list: {e}", exc_info=True)
|
||||
# Continue with original URL if error occurs
|
||||
try:
|
||||
await status_msg.delete()
|
||||
except:
|
||||
pass
|
||||
|
||||
# Check concurrent tasks count
|
||||
from bot.config import settings
|
||||
active_tasks_count = await task_queue.get_user_active_tasks_count(user_id)
|
||||
|
||||
Reference in New Issue
Block a user