YT Music link convert

This commit is contained in:
Inex Code 2019-02-10 19:58:20 +03:00
parent 6e131e9999
commit daee7dcd7e
2 changed files with 51 additions and 1 deletions

View File

@ -4,7 +4,8 @@
"plugins": [
"plugins.dicer",
"plugins.references",
"plugins.coffee"
"plugins.coffee",
"plugins.ytconvert"
]
}
}

49
plugins/ytconvert.py Normal file
View File

@ -0,0 +1,49 @@
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)