Spaces:
Runtime error
Runtime error
File size: 909 Bytes
c4e5ba6 66ca64a 367be45 66ca64a c4e5ba6 367be45 a0a2b50 367be45 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
from urllib.request import urlopen, Request
from urllib.parse import quote_plus
import re
from .. import helpers
def search(request):
searchQuery = helpers.getFromRequest(request, "query")
if not searchQuery: searchQuery = "rickroll"
try:
html = urlopen(
Request(
"https://www.youtube.com/results?search_query={}".format(quote_plus(searchQuery)),
headers={"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0"}
)
)
videoList = re.findall(r"watch\?v=(\S{11})", html.read().decode())
return {"status": "pass", "query": searchQuery, "videoIds": videoList}
except Exception as e:
print(e)
return {"status": "error", "details": { "error_code": 666, "error_details": "Something went wrong..." }}, 500 |