mirror of
https://github.com/ethanrusz/youtube-url-corrector.git
synced 2025-04-20 15:06:32 -04:00
Compare commits
No commits in common. "08557106b47cec1bd07b242d62134e22035af89d" and "d88d344e4e773607a6823608575cf845284896dc" have entirely different histories.
08557106b4
...
d88d344e4e
3 changed files with 9 additions and 15 deletions
|
@ -2,8 +2,8 @@ FROM python:3.11.6
|
|||
|
||||
WORKDIR /usr/src/units
|
||||
|
||||
COPY requirements.txt .
|
||||
RUN pip install -r requirements.txt
|
||||
COPY requiremtns.txt .
|
||||
RUN pip install -r requirements.com
|
||||
|
||||
COPY bot.py .
|
||||
|
||||
|
|
20
bot.py
20
bot.py
|
@ -1,10 +1,9 @@
|
|||
import os
|
||||
import re
|
||||
from contextlib import suppress
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
|
||||
from contextlib import suppress
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import re
|
||||
|
||||
intents = discord.Intents.default()
|
||||
intents.members = True
|
||||
|
@ -37,21 +36,16 @@ 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)
|
||||
|
|
Loading…
Add table
Reference in a new issue