Fix: actually import YoutubeSearch and fix self-variable access

doesn't actually fix the issue where youtube is blocking requests behind a signin requirement but eh
This commit is contained in:
a 2024-10-21 21:40:57 +00:00
parent 81e4db9c4f
commit 9decd6552b

View file

@ -9,6 +9,7 @@ import random # for shuffling the queue
import math # for ceiling function in queue pages import math # for ceiling function in queue pages
from functools import partial from functools import partial
import logging import logging
from youtube_search import YoutubeSearch
if not path.exists('.logs'): if not path.exists('.logs'):
makedirs('.logs') makedirs('.logs')
@ -339,7 +340,7 @@ class Music(Cog):
logger.debug(f"search_youtube() called for query: {query}") logger.debug(f"search_youtube() called for query: {query}")
try: try:
self.query = query self.query = query
self.search_results = YoutubeSearch(query, max_results=MAX_RESULTS).to_dict() self.search_results = YoutubeSearch(query, max_results=self.MAX_RESULTS).to_dict() # this returns a list, funnily enough
except Exception as e: except Exception as e:
logger.error("Exception thrown!") logger.error("Exception thrown!")
logger.error(f"{e=}") logger.error(f"{e=}")
@ -366,12 +367,12 @@ class Music(Cog):
embeds = [] embeds = []
formatted_results = ( formatted_results = (
f"Performed a search for `{self.search_results['id']}`.\n" f"Performed a search for `{self.query}`.\n"
"Which track would you like to play?\n" "Which track would you like to play?\n"
"Make your choice using the `play` command, e.g. `.play 1`.\n\n" "Make your choice using the `play` command, e.g. `.play 1`.\n\n"
) )
for i, result in enumerate(self.search_results['entries']): for i, result in enumerate(self.search_results):
result: dict result: dict