This commit is contained in:
2024-06-17 10:53:33 +03:00
commit a1da810c2d
22 changed files with 1253 additions and 0 deletions

79
downinstagram(01).py Normal file
View File

@@ -0,0 +1,79 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import logging
import os
import asyncio
from aiogram import Bot, Dispatcher, types
from aiogram.utils import executor
import instaloader
# Ваш токен от BotFather
API_TOKEN = '5285575539:AAGu_qK23xq98fta1fJmV9oyDYoq9yhzeHM'
# Настройка прокси
PROXY_URL = 'http://185.250.148.233:8899'
PROXY_AUTH = ('bots_man', 'Ax123456')
# Настройка логирования с записью в файл
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler('bot_instagram_logs.log'),
logging.StreamHandler()
]
)
logger = logging.getLogger(__name__)
# Инициализация бота и диспетчера с использованием прокси
async def create_bot():
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)
return dp, bot
# Функция для скачивания видео с Instagram с использованием cookies
def download_instagram_video(url):
L = instaloader.Instaloader()
# Загрузка cookies
L.load_session_from_file('bdg9840', 'session-bdg9840')
try:
post = instaloader.Post.from_shortcode(L.context, url.split("/")[-2])
if post.is_video:
L.download_post(post, target="downloads")
video_filename = next((f for f in os.listdir("downloads") if f.endswith('.mp4')), None)
if video_filename:
video_path = os.path.join("downloads", video_filename)
return video_path, post.title
return None, None
except Exception as e:
logger.error(f"Ошибка при скачивании видео: {e}")
return None, None
async def on_startup(dp):
logger.info('Start polling.')
# Обработчик команды /start
async def send_welcome(message: types.Message):
await message.reply("Привет! Я бот для скачивания видео с Instagram. Отправьте ссылку на видео чтобы начать.")
# Обработчик получения ссылки на Instagram
async def handle_instagram_link(message: types.Message):
link = message.text
await message.reply("Видео скачивается, пожалуйста подождите...")
video_file, video_title = download_instagram_video(link)
if video_file:
caption = f"Вот ваше видео с Instagram: {video_title}" if video_title else "Вот ваше видео с Instagram"
with open(video_file, 'rb') as video:
await bot.send_video(message.chat.id, video, caption=caption)
os.remove(video_file)
else:
await message.reply("Произошла ошибка при скачивании видео. Пожалуйста, попробуйте ещё раз.")
if __name__ == '__main__':
dp, bot = asyncio.run(create_bot())
dp.register_message_handler(send_welcome, commands=['start'])
dp.register_message_handler(handle_instagram_link)
executor.start_polling(dp, skip_updates=True, on_startup=on_startup)