Last active
June 29, 2023 10:52
-
-
Save AlgorithmAlchemy/efc137c881ab947c498a83534977ccb8 to your computer and use it in GitHub Desktop.
YouTube Dll donwload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
format = video_format_id_1 | |
link_mess = video_url_1 | |
print(link_mess) | |
chat_id = call.message.chat.id # автор сообщения | |
limit = 0 | |
# код для проверки лимита на скачивание у пользователя | |
cursor = connect.execute(f'''SELECT day_limit | |
FROM users | |
WHERE chat_id = {chat_id}''') | |
for row in cursor: | |
limit = int(row[0]) | |
user_id = call.message.chat.id | |
await call.answer('Скачиваем епт.') | |
msg = await bot.send_message(chat_id=call.message.chat.id, text='⏳') | |
limit -= 1 | |
connect.execute(f'''UPDATE users | |
SET day_limit = {limit} | |
WHERE chat_id = {chat_id}''') | |
db.commit() | |
try: | |
ydl = youtube_dl.YoutubeDL({'outtmpl': '%(id)s.%(ext)s'}) | |
with ydl: | |
result = ydl.extract_info( | |
call.message.text.replace("clip", "video"), | |
download=True | |
) | |
video = open(f"{result['id']}.{result['ext']}", "rb") | |
await bot.send_video(call.message.chat.id, video=video, caption=f"{str(link_mess)} " | |
f" \n@{me}") | |
await bot.delete_message(chat_id=call.message.from_user.id, message_id=msg.message_id) | |
os.remove(f"{result['id']}.{result['ext']}") | |
# except youtube_dl.utils.DownloadError: | |
except TypeError: | |
await send_messages(chat_id, "Link Error") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment