Skip to content

Commit

Permalink
title: use non-greedy search that allows for quotes in title
Browse files Browse the repository at this point in the history
Fixes issue where video titles may have quotes:

    https://www.youtube.com/watch?v=zwqBbK6UuuU

Thanks @tfaughnan
  • Loading branch information
pbui committed Jul 13, 2024
1 parent 904a2c8 commit 9f723fd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/bobbit/modules/title.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ async def youtube_title(bot, url, text):
video_name = re.findall(r'<title[^>]*>([^<]+) - YouTube[\s]*</title>', text)[0] # get title, removing "- YouTube" from the end
except IndexError:
# XXX: 2024-06-08 - Alternative means of extracting video name (Google sending back different JSON)
video_name = re.findall(r'videoPrimaryInfoRenderer.*?"text":"([^"]+)"', text)[0]
video_name = re.findall(r'videoPrimaryInfoRenderer.*?"text":"(.*?)"}', text)[0]

# XXX: Escape backslashed strings, https://stackoverflow.com/a/57192592
video_name = video_name.encode('latin-1', 'backslashreplace')\
.decode('unicode-escape')

return bot.client.format_text(
'{color}{green}Video{color}: {bold}{video_name}{bold} {color}{green}Channel{color}: {bold}{channel_name}{bold}',
Expand Down

0 comments on commit 9f723fd

Please sign in to comment.