Skip to content

Commit

Permalink
Adding sleep kwarg to YoutubeAPIClient
Browse files Browse the repository at this point in the history
  • Loading branch information
Yomguithereal committed Mar 28, 2024
1 parent fa876a7 commit ed2e408
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion minet/youtube/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
YouTubeExclusiveMemberError,
YouTubeUnknown403Error,
YouTubeAccessNotConfiguredError,
YouTubeAPILimitReached,
)
from minet.youtube.types import (
YouTubeVideo,
Expand Down Expand Up @@ -72,14 +73,15 @@ def get_channel_id(scraper: YouTubeScraper, channel_target: str) -> str:


class YouTubeAPIClient(object):
def __init__(self, key):
def __init__(self, key, sleep: bool = True):
if not isinstance(key, list):
key = [key]

self.keys = {k: True for k in key}
self.current_key = key[0]
self.pool_manager = create_pool_manager()
self.scraper = YouTubeScraper()
self.sleep = sleep

# YouTube's API is known to crash sometimes...
self.retryer = create_request_retryer(
Expand Down Expand Up @@ -113,6 +115,9 @@ def request_json(self, url):
elif reason == "quotaExceeded":
# Current key is exhausted, disabling it and switching to another if there is one
if not self.rotate_key():
if not self.sleep:
raise YouTubeAPILimitReached

# If all keys are exhausted, start waiting until tomorrow and reset keys
sleep_time = seconds_to_midnight_pacific_time() + 10

Expand Down

0 comments on commit ed2e408

Please sign in to comment.