mirror of
https://github.com/ethanrusz/youtube-url-corrector.git
synced 2025-04-12 05:26:33 -04:00
Compare commits
4 commits
2096898fd1
...
9121816fc6
Author | SHA1 | Date | |
---|---|---|---|
9121816fc6 | |||
cace08bd84 | |||
bc7049dcf2 | |||
dd04c8d45b |
3 changed files with 52 additions and 19 deletions
30
.github/workflows/build-and-push.yml
vendored
Normal file
30
.github/workflows/build-and-push.yml
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
name: Build and Push on Release
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
update-registry:
|
||||
name: Update Registry Image
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Login to git.beans.team
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.beans.team
|
||||
username: em
|
||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
|
||||
- name: Build and Push Image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
push: true
|
||||
tags: |
|
||||
git.beans.team/em/yuc:latest
|
||||
git.beans.team/em/yuc:${{ github.event.release.tag_name }}
|
|
@ -10,6 +10,6 @@ services:
|
|||
image: git.beans.team/em/yuc:latest
|
||||
environment:
|
||||
- DISCORD_TOKEN=your_discord_bot_token
|
||||
- PIPED_URL=https://your.piped.url/watch?v=
|
||||
- PIPED_URL=https://your.piped.url # Do not append /watch?v=
|
||||
restart: unless-stopped
|
||||
```
|
||||
|
|
39
bot.py
39
bot.py
|
@ -10,10 +10,10 @@ intents = discord.Intents.default()
|
|||
intents.members = True
|
||||
intents.message_content = True
|
||||
|
||||
bot = commands.Bot(command_prefix='?', intents=intents)
|
||||
bot = commands.Bot(command_prefix="?", intents=intents)
|
||||
|
||||
PIPED_URL = os.getenv('PIPED_URL')
|
||||
DISCORD_TOKEN = os.getenv('DISCORD_TOKEN')
|
||||
PIPED_URL = os.getenv("PIPED_URL") + "/watch?v="
|
||||
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
||||
|
||||
|
||||
@bot.event
|
||||
|
@ -24,7 +24,8 @@ async def on_ready():
|
|||
@bot.event
|
||||
async def on_message(message):
|
||||
regex = re.compile(
|
||||
r'https://(music\.)?(www\.)?youtu(be)?\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)')
|
||||
r"https://(music\.)?(www\.)?youtu(be)?\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)"
|
||||
)
|
||||
|
||||
result = regex.search(message.content)
|
||||
if result is not None:
|
||||
|
@ -32,28 +33,30 @@ async def on_message(message):
|
|||
video_id = await get_youtube_id(youtube_url)
|
||||
|
||||
if video_id is not None:
|
||||
await message.reply(f"I think you meant {PIPED_URL}{video_id}.", mention_author=False)
|
||||
await message.reply(
|
||||
f"I think you meant {PIPED_URL}{video_id}.", mention_author=False
|
||||
)
|
||||
|
||||
|
||||
async def get_youtube_id(url: str, ignore_playlist=True) -> str:
|
||||
query = urlparse(url)
|
||||
if query.hostname == 'youtu.be':
|
||||
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:
|
||||
# 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[:8] == '/shorts/':
|
||||
return query.path.split('/')[1]
|
||||
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[:8] == "/shorts/":
|
||||
return query.path.split("/")[1]
|
||||
|
||||
|
||||
bot.run(DISCORD_TOKEN)
|
||||
|
|
Loading…
Add table
Reference in a new issue