mirror of
https://gitlab.com/MisterBiggs/telegram-video-download-bot.git
synced 2025-06-15 22:56:43 +00:00
added start/help and video chat action
This commit is contained in:
parent
49777095ad
commit
2f41e846e2
13
bot.py
13
bot.py
@ -6,7 +6,7 @@ import requests as r
|
|||||||
import youtube_dl
|
import youtube_dl
|
||||||
from requests_toolbelt.downloadutils import stream
|
from requests_toolbelt.downloadutils import stream
|
||||||
|
|
||||||
|
import telegram
|
||||||
from telegram import Update
|
from telegram import Update
|
||||||
from telegram.ext import (
|
from telegram.ext import (
|
||||||
CallbackContext,
|
CallbackContext,
|
||||||
@ -19,6 +19,12 @@ from telegram.ext import (
|
|||||||
URL_REGEX = r"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)"
|
URL_REGEX = r"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)"
|
||||||
|
|
||||||
|
|
||||||
|
def start(update: Update, context: CallbackContext):
|
||||||
|
update.message.reply(
|
||||||
|
"This bot downloads the video from any link sent to it. @MisterBiggs for more help."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def url_search(update: Update, context: CallbackContext) -> None:
|
def url_search(update: Update, context: CallbackContext) -> None:
|
||||||
msg = update.message.text.strip()
|
msg = update.message.text.strip()
|
||||||
print(msg)
|
print(msg)
|
||||||
@ -26,6 +32,9 @@ def url_search(update: Update, context: CallbackContext) -> None:
|
|||||||
ydl_opts = {}
|
ydl_opts = {}
|
||||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
vid = ydl.extract_info(msg)
|
vid = ydl.extract_info(msg)
|
||||||
|
context.bot.send_chat_action(
|
||||||
|
chat_id=update.message.chat_id, action=telegram.ChatAction.UPLOAD_VIDEO
|
||||||
|
)
|
||||||
print(vid.keys())
|
print(vid.keys())
|
||||||
b = io.BytesIO()
|
b = io.BytesIO()
|
||||||
resp = r.get(vid["url"], stream=True)
|
resp = r.get(vid["url"], stream=True)
|
||||||
@ -39,6 +48,8 @@ def url_search(update: Update, context: CallbackContext) -> None:
|
|||||||
|
|
||||||
updater = Updater(os.environ["TELEGRAM"])
|
updater = Updater(os.environ["TELEGRAM"])
|
||||||
|
|
||||||
|
updater.dispatcher.add_handler(CommandHandler("start", start))
|
||||||
|
updater.dispatcher.add_handler(CommandHandler("help", start))
|
||||||
updater.dispatcher.add_handler(CommandHandler("dl", url_search))
|
updater.dispatcher.add_handler(CommandHandler("dl", url_search))
|
||||||
updater.dispatcher.add_handler(MessageHandler(Filters.text, url_search))
|
updater.dispatcher.add_handler(MessageHandler(Filters.text, url_search))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user