Spaces:
Running
Running
Commit
•
c4e5ba6
1
Parent(s):
86d1f26
fix headers
Browse files- routes/ytApi/search.py +8 -2
routes/ytApi/search.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
-
import
|
|
|
2 |
import re
|
3 |
from .. import helpers
|
4 |
|
@@ -6,7 +7,12 @@ def search(request):
|
|
6 |
searchQuery = helpers.getFromRequest(request, "query")
|
7 |
if not searchQuery: searchQuery = "rickroll"
|
8 |
try:
|
9 |
-
html =
|
|
|
|
|
|
|
|
|
|
|
10 |
videoList = re.findall(r"watch\?v=(\S{11})", html.read().decode())
|
11 |
return {"status": "pass", "query": searchQuery, "videoIds": videoList}
|
12 |
except Exception as e:
|
|
|
1 |
+
from urllib.request import urlopen, Request
|
2 |
+
from urllib.parse import quote_plus
|
3 |
import re
|
4 |
from .. import helpers
|
5 |
|
|
|
7 |
searchQuery = helpers.getFromRequest(request, "query")
|
8 |
if not searchQuery: searchQuery = "rickroll"
|
9 |
try:
|
10 |
+
html = urlopen(
|
11 |
+
Request(
|
12 |
+
"https://www.youtube.com/results?search_query={}".format(quote_plus(searchQuery)),
|
13 |
+
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"}
|
14 |
+
)
|
15 |
+
)
|
16 |
videoList = re.findall(r"watch\?v=(\S{11})", html.read().decode())
|
17 |
return {"status": "pass", "query": searchQuery, "videoIds": videoList}
|
18 |
except Exception as e:
|