1
0
Fork 0
mirror of https://github.com/inexcode/ixizi synced 2024-11-23 23:31:27 +00:00
ixizi/plugins/ytconvert.py

50 lines
2 KiB
Python
Raw Normal View History

2019-02-10 16:58:20 +00:00
from disco.bot import Bot, Plugin
from urllib.parse import urlparse
GREAT_TUNES = 537635615483887667
class YT_Convert(Plugin):
@Plugin.command('ytmusic', '<url:str>')
def on_yt(self, event, url):
try:
scheme, netloc, path, params, query, fragment = urlparse(url)
if netloc.lower().endswith("youtube.com"):
if query.split('&')[0].startswith('v='):
result = "**On YT Music:** https://music.youtube.com/watch?{}".format(query.split('&')[0])
else:
result = "Not a video."
elif netloc.lower().endswith("youtu.be"):
if len(path) > 3:
result = "**On YT Music:** https://music.youtube.com/watch?v={}".format(path[1:])
else:
result = "Uhhh???!"
else:
result = "Not a YT link."
except Exception as e:
event.msg.reply(str(e))
else:
event.msg.reply(result)
@Plugin.listen('MessageCreate')
def on_message(self, event):
if event.message.channel_id == GREAT_TUNES:
try:
scheme, netloc, path, params, query, fragment = urlparse(event.message.content)
if netloc.lower().endswith("youtube.com"):
if query.split('&')[0].startswith('v='):
result = "**On YT Music:** https://music.youtube.com/watch?{}".format(query.split('&')[0])
else:
result = False
elif netloc.lower().endswith("youtu.be"):
if len(path) > 3:
result = "**On YT Music:** https://music.youtube.com/watch?v={}".format(path[1:])
else:
result = False
else:
result = False
except Exception as e:
print(e)
else:
if result:
event.reply(result)