MCPcopy Create free account
hub / github.com/Roy3838/Observer / live_status

Function live_status

api/api.py:175–203  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

173
174@app.get("/live")
175async def live_status():
176 import time
177 now = time.monotonic()
178 if now - _live_cache["last_checked"] < LIVE_CACHE_TTL:
179 return {"live": _live_cache["live"], "videoId": _live_cache["videoId"]}
180
181 api_key = os.environ.get("YOUTUBE_API_KEY")
182 if not api_key:
183 return {"live": False, "videoId": None}
184
185 url = "https://www.googleapis.com/youtube/v3/search"
186 params = {
187 "part": "id",
188 "channelId": YOUTUBE_CHANNEL_ID,
189 "eventType": "live",
190 "type": "video",
191 "key": api_key,
192 }
193 async with httpx.AsyncClient() as client:
194 resp = await client.get(url, params=params, timeout=10)
195
196 if resp.status_code != 200:
197 _live_cache["last_checked"] = now
198 return {"live": False, "videoId": None}
199
200 items = resp.json().get("items", [])
201 result = {"live": bool(items), "videoId": items[0]["id"]["videoId"] if items else None}
202 _live_cache.update({**result, "last_checked": now})
203 return result
204
205
206# Root path to check if service is running

Callers

nothing calls this directly

Calls 1

updateMethod · 0.80

Tested by

no test coverage detected