fix: call YouTube API directly, announce all matched results
YouTube InnerTube is a public API -- no need to route through SOCKS5 proxy, which was causing SSL EOF errors on every poll. Switch to direct urllib.request.urlopen. Remove _MAX_ANNOUNCE cap; all matched results are now announced individually instead of truncating with "... and N more". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -20,7 +20,6 @@ _log = logging.getLogger(__name__)
|
||||
_NAME_RE = re.compile(r"^[a-z0-9][a-z0-9-]{0,19}$")
|
||||
_MAX_KEYWORD_LEN = 100
|
||||
_MAX_SEEN = 200
|
||||
_MAX_ANNOUNCE = 5
|
||||
_DEFAULT_INTERVAL = 300
|
||||
_MAX_INTERVAL = 3600
|
||||
_FETCH_TIMEOUT = 15
|
||||
@@ -181,7 +180,7 @@ def _search_youtube(keyword: str) -> list[dict]:
|
||||
req = urllib.request.Request(_YT_SEARCH_URL, data=payload, method="POST")
|
||||
req.add_header("Content-Type", "application/json")
|
||||
|
||||
resp = _urlopen(req, timeout=_FETCH_TIMEOUT)
|
||||
resp = urllib.request.urlopen(req, timeout=_FETCH_TIMEOUT)
|
||||
raw = resp.read()
|
||||
resp.close()
|
||||
|
||||
@@ -395,8 +394,7 @@ async def _poll_once(bot, key: str, announce: bool = True) -> None:
|
||||
if announce and matched:
|
||||
channel = data["channel"]
|
||||
name = data["name"]
|
||||
shown = matched[:_MAX_ANNOUNCE]
|
||||
for item in shown:
|
||||
for item in matched:
|
||||
title = _truncate(item["title"]) if item["title"] else "(no title)"
|
||||
url = item["url"]
|
||||
date = item.get("date", "")
|
||||
@@ -407,9 +405,6 @@ async def _poll_once(bot, key: str, announce: bool = True) -> None:
|
||||
if url:
|
||||
line += f" -- {url}"
|
||||
await bot.send(channel, line)
|
||||
remaining = len(matched) - len(shown)
|
||||
if remaining > 0:
|
||||
await bot.send(channel, f"[{name}/{tag}] ... and {remaining} more")
|
||||
|
||||
for item in new_items:
|
||||
seen_list.append(item["id"])
|
||||
|
||||
Reference in New Issue
Block a user