1
0
mirror of https://git.sr.ht/~cadence/NewLeaf synced 2024-11-25 08:57:30 +00:00

Compare commits

..

3 Commits

Author SHA1 Message Date
Cadence Ember
73b4fbabf7
Do not actually write out pages. 2022-01-10 13:23:04 +13:00
Cadence Ember
36ae18c12f
Report errors when an account has been terminated 2022-01-10 13:02:08 +13:00
0a13ab88cb
Stream responses on /vi and /ggpht endpoints
The chunk_size=None parameter to iter_content lets us consume data as
soon as it arrives
https://docs.python-requests.org/en/master/api/#requests.Response.iter_content
2021-12-16 17:11:34 +13:00
2 changed files with 9 additions and 4 deletions

View File

@ -29,6 +29,11 @@ def extract_channel(ucid):
"error": alert_text,
"identifier": "NOT_FOUND"
}
elif alert_text.startswith("This account has been terminated"):
return {
"error": alert_text,
"identifier": "ACCOUNT_TERMINATED"
}
else:
print("Seen alert text '{}'".format(alert_text))

View File

@ -123,17 +123,17 @@ class NewLeaf(object):
@cherrypy.expose
def vi(self, id, file):
with requests.get("https://i.ytimg.com/vi/{}/{}".format(id, file)) as r:
with requests.get("https://i.ytimg.com/vi/{}/{}".format(id, file), stream=True) as r:
r.raise_for_status()
cherrypy.response.headers["content-type"] = r.headers["content-type"]
return r # no idea if this is a good way to do it, but it definitely works! :D
return next(r.iter_content(chunk_size=None))
@cherrypy.expose
def ggpht(self, *path):
with requests.get("https://yt3.ggpht.com/{}".format("/".join(path))) as r:
with requests.get("https://yt3.ggpht.com/{}".format("/".join(path)), stream=True) as r:
r.raise_for_status()
cherrypy.response.headers["content-type"] = r.headers["content-type"]
return r
return next(r.iter_content(chunk_size=None))
bind_port = getattr(configuration, "bind_port", 3000)
bind_host = getattr(configuration, "bind_host", "0.0.0.0")