Browse Source

YT Music link convert

master
Inex Code 4 years ago
parent
commit
daee7dcd7e
  1. 3
      config.json
  2. 49
      plugins/ytconvert.py

3
config.json

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

49
plugins/ytconvert.py

@ -0,0 +1,49 @@ @@ -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)
Loading…
Cancel
Save