Spaces:
Sleeping
Sleeping
File size: 635 Bytes
66ca64a 367be45 66ca64a 367be45 a0a2b50 367be45 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import urllib
import re
from .. import helpers
def search(request):
searchQuery = helpers.getFromRequest(request, "query")
if not searchQuery: searchQuery = "rickroll"
try:
html = urllib.request.urlopen("https://www.youtube.com/results?search_query={}".format(urllib.parse.quote_plus(searchQuery)))
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 |