Compare commits

...

5 commits

Author SHA1 Message Date
08557106b4
Update formatting 2024-01-18 23:02:24 -05:00
dc84305937
Correct typo 2024-01-18 23:01:24 -05:00
21fff236be
Correct typo 2024-01-18 22:39:48 -05:00
e67ac81be3
Correct typo 2024-01-18 22:37:58 -05:00
5c0422fa8d
Improve formatting 2024-01-18 22:35:33 -05:00
3 changed files with 15 additions and 9 deletions

View file

@ -2,8 +2,8 @@ FROM python:3.11.6
WORKDIR /usr/src/units
COPY requiremtns.txt .
RUN pip install -r requirements.com
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY bot.py .

20
bot.py
View file

@ -1,9 +1,10 @@
import os
from urllib.parse import urlparse, parse_qs
import re
from contextlib import suppress
from urllib.parse import urlparse, parse_qs
import discord
from discord.ext import commands
import re
intents = discord.Intents.default()
intents.members = True
@ -36,16 +37,21 @@ async def on_message(message):
async def get_youtube_id(url: str, ignore_playlist=True) -> str:
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 not ignore_playlist:
# use case: get playlist id not current video in playlist
with suppress(KeyError):
return parse_qs(query.query)['list'][0]
if query.path == '/watch': return parse_qs(query.query)['v'][0]
if query.path[:7] == '/watch/': 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]
if query.path == '/watch':
return parse_qs(query.query)['v'][0]
if query.path[:7] == '/watch/':
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)