-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
85 lines (67 loc) · 2.83 KB
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os
from io import BytesIO
from queue import Queue
import requests
from flask import Flask, request
from telegram import Bot, Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import CommandHandler, MessageHandler, Filters, CallbackQueryHandler, Dispatcher
from movies_scraper import search_movies, get_movie
TOKEN = os.getenv("TOKEN")
URL = os.getenv("https://movies-download-bot.onrender.com")
bot = Bot(TOKEN)
def welcome(update, context) -> None:
update.message.reply_text(f"Hello {update.message.from_user.first_name}, Welcome to SB Movies.\n"
f"🔥 Download Your Favourite Movies For 💯 Free And 🍿 Enjoy it.")
update.message.reply_text("👇 Enter Movie Name 👇")
def find_movie(update, context):
search_results = update.message.reply_text("Processing...")
query = update.message.text
movies_list = search_movies(query)
if movies_list:
keyboards = []
for movie in movies_list:
keyboard = InlineKeyboardButton(movie["title"], callback_data=movie["id"])
keyboards.append([keyboard])
reply_markup = InlineKeyboardMarkup(keyboards)
search_results.edit_text('Search Results...', reply_markup=reply_markup)
else:
search_results.edit_text('Sorry 🙏, No Result Found!\nCheck If You Have Misspelled The Movie Name.')
def movie_result(update, context) -> None:
query = update.callback_query
s = get_movie(query.data)
response = requests.get(s["img"])
img = BytesIO(response.content)
query.message.reply_photo(photo=img, caption=f"🎥 {s['title']}")
link = ""
links = s["links"]
for i in links:
link += "🎬" + i + "\n" + links[i] + "\n\n"
caption = f"⚡ Fast Download Links :-\n\n{link}"
if len(caption) > 4095:
for x in range(0, len(caption), 4095):
query.message.reply_text(text=caption[x:x+4095])
else:
query.message.reply_text(text=caption)
def setup():
update_queue = Queue()
dispatcher = Dispatcher(bot, update_queue, use_context=True)
dispatcher.add_handler(CommandHandler('start', welcome))
dispatcher.add_handler(MessageHandler(Filters.text, find_movie))
dispatcher.add_handler(CallbackQueryHandler(movie_result))
return dispatcher
app = Flask(__name__)
@app.route('/')
def index():
return 'Hello World!'
@app.route('/{}'.format(TOKEN), methods=['GET', 'POST'])
def respond():
update = Update.de_json(request.get_json(force=True), bot)
setup().process_update(update)
return 'ok'
@app.route('/setwebhook', methods=['GET', 'POST'])
def set_webhook():
s = bot.setWebhook('{URL}/{HOOK}'.format(URL=URL, HOOK=TOKEN))
if s:
return "webhook setup ok"
else:
return "webhook setup failed"