Upload files to ''
This commit is contained in:
parent
a775f2de2d
commit
5d90b3bde3
|
@ -0,0 +1,40 @@
|
|||
import os
|
||||
from flask import Flask, request
|
||||
import telebot
|
||||
|
||||
import constants as keys
|
||||
import redirect as r
|
||||
|
||||
TOKEN = keys.API_KEY
|
||||
bot = telebot.TeleBot(TOKEN)
|
||||
server = Flask(__name__)
|
||||
|
||||
|
||||
@bot.message_handler(commands=['start', 'help'])
|
||||
def welcome_msg(message):
|
||||
bot.reply_to(message,
|
||||
"Hi! This bot will redirect you from YouTube to an Invidious instance. Just share me a YouTube link.")
|
||||
|
||||
|
||||
@bot.message_handler(func=lambda message: True)
|
||||
def response_msg(message):
|
||||
bot.reply_to(message, r.redirect(message.text))
|
||||
|
||||
|
||||
@server.route('/' + TOKEN, methods=['POST'])
|
||||
def get_message():
|
||||
json_string = request.get_data().decode('utf-8')
|
||||
update = telebot.types.Update.de_json(json_string)
|
||||
bot.process_new_updates([update])
|
||||
return "!", 200
|
||||
|
||||
|
||||
@server.route('/')
|
||||
def webhook():
|
||||
bot.remove_webhook()
|
||||
bot.set_webhook(url='https://untrackmebot.herokuapp.com/ ' + TOKEN)
|
||||
return "!", 200
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
server.run(host='0.0.0.0', port=int(os.environ.get('PORT', 5000)))
|
|
@ -0,0 +1,29 @@
|
|||
import re
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
def url_extract(text):
|
||||
urls = re.findall(r'\b((?:https?://)?(?:(?:www\.)?(?:[\da-z\.-]+)\.(?:[a-z]{2,6})|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|(?:(?:[0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?:(?::[0-9a-fA-F]{1,4}){1,6})|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(?::[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(?:ffff(?::0{1,4}){0,1}:){0,1}(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])|(?:[0-9a-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])))(?::[0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])?(?:/[\w\.-]*)*/?)\b', text)
|
||||
return urls
|
||||
|
||||
def extract_ytid(url):
|
||||
query = urlparse(url)
|
||||
if query.hostname == 'youtu.be':
|
||||
return query.path[1:]
|
||||
if query.hostname in ('www.youtube.com', 'youtube.com'):
|
||||
if query.path == '/watch':
|
||||
p = urlparse.parse_qs(query.query)
|
||||
return p['v'][0]
|
||||
if query.path[:7] == '/embed':
|
||||
return query.path.split('/')[2]
|
||||
if query.path[:3] == '/v/':
|
||||
return query.path.split('/')[2]
|
||||
return None
|
||||
|
||||
server = 'yewtu.be/watch?v='
|
||||
|
||||
def redirect(text):
|
||||
url = url_extract(text)[0]
|
||||
id = extract_ytid(url)
|
||||
cleaned = server+id
|
||||
return cleaned
|
|
@ -0,0 +1,14 @@
|
|||
certifi==2021.10.8
|
||||
charset-normalizer==2.0.12
|
||||
click==8.1.2
|
||||
Flask==2.1.1
|
||||
idna==3.3
|
||||
importlib-metadata==4.11.3
|
||||
itsdangerous==2.1.2
|
||||
Jinja2==3.1.1
|
||||
MarkupSafe==2.1.1
|
||||
pyTelegramBotAPI==4.4.1
|
||||
requests==2.27.1
|
||||
urllib3==1.26.9
|
||||
Werkzeug==2.1.1
|
||||
zipp==3.8.0
|
Loading…
Reference in New Issue