1
0
mirror of https://git.sr.ht/~cadence/NewLeaf synced 2024-11-22 15:47:30 +00:00

Add searches

This commit is contained in:
Cadence Ember 2020-08-08 02:51:01 +12:00
parent ad018b0a0c
commit 84dd940ac4
No known key found for this signature in database
GPG Key ID: 128B99B1B74A6412

View File

@ -25,11 +25,15 @@ def length_text_to_seconds(text):
class Second(object): class Second(object):
def _cp_dispatch(self, vpath): def _cp_dispatch(self, vpath):
if vpath[:2] == ["api", "v1"] and len(vpath) >= 4: if vpath[:2] == ["api", "v1"]:
endpoints = ["channels", "videos"] endpoints = [
["channels", 1, 2],
["videos", 1, 1],
["search", 0, 0]
]
for e in endpoints: for e in endpoints:
if vpath[2] == e: if vpath[2] == e[0] and len(vpath) >= e[1]+3 and len(vpath) <= e[2]+3:
vpath[:3] = [e] vpath[:3] = [e[0]]
return self return self
return vpath return vpath
@ -266,5 +270,29 @@ class Second(object):
"identifier": "CHANNEL_DOES_NOT_EXIST" "identifier": "CHANNEL_DOES_NOT_EXIST"
} }
@cherrypy.expose
@cherrypy.tools.json_out()
def search(self, *, q, sort_by):
info = ytdl.extract_info("ytsearchall:{}".format(q), download=False)
return list({
"type": "video",
"title": video["title"],
"videoId": video["id"],
"author": None,
"authorId": None,
"authorUrl": None,
"videoThumbnails": [],
"description": None,
"descriptionHtml": None,
"viewCount": None,
"published": None,
"publishedText": None,
"lengthSeconds": None,
"liveNow": None,
"paid": None,
"premium": None,
"isUpcoming": None
} for video in info["entries"] if "title" in video)
cherrypy.config.update({"server.socket_port": 3000}) cherrypy.config.update({"server.socket_port": 3000})
cherrypy.quickstart(Second()) cherrypy.quickstart(Second())