Skip to content

Commit

Permalink
change video ID handling
Browse files Browse the repository at this point in the history
Update the way we grab a video ID from a url to account for links being used that don't have the watchv in it. Could potentially solve #2341?
  • Loading branch information
BabyBoySnow committed Sep 28, 2023
1 parent 8b316d2 commit 3eacf3f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions musicbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,16 @@ async def on_player_play(self, player, entry):
return

if self.config.embeds:
url = player.current_entry.url
# Attempt to grab video ID from possible link names
match = re.search(r'(?:youtu\.be/|youtube\.com/watch\?v=|youtube\.com/embed/)([\w-]+)', url)

if match:
videoID = match.group(1)
else:
log.error("Unkknown link or unable to get video ID.")
content = self._gen_embed()
content.title = newmsg
url = player.current_entry.url
videoID = url.split("watch?v=")[1].split("&")[0]
content.set_image(url=f"https://i1.ytimg.com/vi/{videoID}/hqdefault.jpg")

# send it in specified channel
Expand Down Expand Up @@ -2893,7 +2899,14 @@ async def cmd_np(self, player, channel, guild, message):
)
if self.config.embeds:
url = player.current_entry.url
videoID = url.split("watch?v=")[1].split("&")[0]
# Attempt to grab video ID from possible link names
match = re.search(r'(?:youtu\.be/|youtube\.com/watch\?v=|youtube\.com/embed/)([\w-]+)', url)

if match:
videoID = match.group(1)
else:
log.error("Unkknown link or unable to get video ID.")

np_text = (
np_text.replace("Now ", "")
.replace(action_text, "")
Expand Down

0 comments on commit 3eacf3f

Please sign in to comment.