JMTNTBANG / Bitey-Frank

The official mascot of the unofficial Discord server of the Garbage Stream.
MIT License
1 stars 3 forks source link

yt_checker.py needs to be fixed #16

Closed JMTNTBANG closed 9 months ago

JMTNTBANG commented 1 year ago

The problem appears to be from too many requests being sent at once, looking for a fix for that, also accepting redesigns of the system entirely

2023-09-17 19:54:49 ERROR    discord.client Ignoring exception in on_ready
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.10/site-packages/discord/client.py", line 409, in _run_event
    await coro(*args, **kwargs)
  File "/home/ubuntu/Garbage_Bot/Bitey-Frank/yt_checker.py", line 62, in on_ready
    await yt_check()
  File "/home/ubuntu/Garbage_Bot/Bitey-Frank/yt_checker.py", line 45, in yt_check
    await checker('Dankmus')
  File "/home/ubuntu/Garbage_Bot/Bitey-Frank/yt_checker.py", line 30, in checker
    a = get_latest_video(f'@{ytchannel}')
  File "/home/ubuntu/Garbage_Bot/Bitey-Frank/youtube_tools.py", line 26, in get_latest_video
    response = get_info.execute()
  File "/home/ubuntu/.local/lib/python3.10/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/googleapiclient/http.py", line 938, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://youtube.googleapis.com/youtube/v3/videos?part=snippet&id=iMmxSEiqtdQ&key=AIzaSyBP-99NKZanXgXFhymYq-5unmmXTNJ94Yk&alt=json returned "The request cannot be completed because you have exceeded your <a href="/youtube/v3/getting-started#quota">quota</a>.". Details: "[{'message': 'The request cannot be completed because you have exceeded your <a href="/youtube/v3/getting-started#quota">quota</a>.', 'domain': 'youtube.quota', 'reason': 'quotaExceeded'}]">
BobVonBob commented 1 year ago

Google has a 10000 "unit" quota on their API, and scanning videos uses one unit. Quick and dirty solution is scan for the latest video once every 86400 / (10000 * (num of channels)) seconds, about once every 70 seconds with the current 8 channels.

That might actually be the most reasonable solution, since as far as I can see Google doesn't provide a way of checking the quota outside the developer dashboard.

Persistent tracking of quota usage would technically be the "right way", but there's only one API consumer in the bot, so eeeehhhhh.

BobVonBob commented 1 year ago

And perhaps make the developer key a separate config thing like the Discord token, since anyone else using this bot (or web scrapers looking for open developer keys, probably a good idea to delete that one and create a new one if you change this) will consume your quota.

JMTNTBANG commented 1 year ago

Google has a 10000 "unit" quota on their API, and scanning videos uses one unit. Quick and dirty solution is scan for the latest video once every 86400 / (10000 * (num of channels)) seconds, about once every 70 seconds with the current 8 channels.

That might actually be the most reasonable solution, since as far as I can see Google doesn't provide a way of checking the quota outside the developer dashboard.

Persistent tracking of quota usage would technically be the "right way", but there's only one API consumer in the bot, so eeeehhhhh.

lol yeah now that i think about it that does makes sense, thanks for implementing this

JMTNTBANG commented 11 months ago

This did not fix the issue apperently, so the quest is still on for a fix/rewrite for those who are up to the challenge

BobVonBob commented 11 months ago

Does the API key page on the YT developer portal show the API key quota? Perhaps try making a new key to rule out usage by a third party since it was public for months?

JMTNTBANG commented 11 months ago

I doubt it, maybe we can try just decreasing the check interval, since checking to barely hit the limit might not be great

JMTNTBANG commented 9 months ago

65ef56f6d990fa1a1d75b79bb62c48b2ee504fa5