mirror of
https://github.com/ethanrusz/youtube-url-corrector.git
synced 2024-11-25 13:07:46 -05:00
Improve formatting
This commit is contained in:
parent
d88d344e4e
commit
5c0422fa8d
1 changed files with 13 additions and 7 deletions
20
bot.py
20
bot.py
|
@ -1,9 +1,10 @@
|
||||||
import os
|
import os
|
||||||
from urllib.parse import urlparse, parse_qs
|
import re
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
|
from urllib.parse import urlparse, parse_qs
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
import re
|
|
||||||
|
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
intents.members = True
|
intents.members = True
|
||||||
|
@ -36,16 +37,21 @@ async def on_message(message):
|
||||||
|
|
||||||
async def get_youtube_id(url: str, ignore_playlist=True) -> str:
|
async def get_youtube_id(url: str, ignore_playlist=True) -> str:
|
||||||
query = urlparse(url)
|
query = urlparse(url)
|
||||||
if query.hostname == 'youtu.be': return query.path[1:]
|
if query.hostname == 'youtu.be':
|
||||||
|
return query.path[1:]
|
||||||
if query.hostname in {'www.youtube.com', 'youtube.com', 'music.youtube.com'}:
|
if query.hostname in {'www.youtube.com', 'youtube.com', 'music.youtube.com'}:
|
||||||
if not ignore_playlist:
|
if not ignore_playlist:
|
||||||
# use case: get playlist id not current video in playlist
|
# use case: get playlist id not current video in playlist
|
||||||
with suppress(KeyError):
|
with suppress(KeyError):
|
||||||
return parse_qs(query.query)['list'][0]
|
return parse_qs(query.query)['list'][0]
|
||||||
if query.path == '/watch': return parse_qs(query.query)['v'][0]
|
if query.path == '/watch':
|
||||||
if query.path[:7] == '/watch/': return query.path.split('/')[1]
|
return parse_qs(query.query)['v'][0]
|
||||||
if query.path[:7] == '/embed/': return query.path.split('/')[2]
|
if query.path[:7] == '/watch/':
|
||||||
if query.path[:3] == '/v/': return query.path.split('/')[2]
|
return query.path.split('/')[1]
|
||||||
|
if query.path[:7] == '/embed/':
|
||||||
|
return query.path.split('/')[2]
|
||||||
|
if query.path[:3] == '/v/':
|
||||||
|
return query.path.split('/')[2]
|
||||||
|
|
||||||
|
|
||||||
bot.run(DISCORD_TOKEN)
|
bot.run(DISCORD_TOKEN)
|
||||||
|
|
Loading…
Reference in a new issue