diff --git a/app/integrations/youtube.py b/app/integrations/youtube.py new file mode 100644 index 0000000..9325cfb --- /dev/null +++ b/app/integrations/youtube.py @@ -0,0 +1,41 @@ +import time + + +class YoutubeClient: + def __init__(self, bot): + from app import DiscordBot + self.bot: DiscordBot = bot + self.token = None + self.token_expiration_time = None + self.webhook_url = f"{self.bot.config.WEBHOOK_URL}/youtube" + + def check_auth_token(func): + def wrapper(self, *args, **kwargs): + current_time = time.time() + if not self.token_expiration_time or current_time >= self.token_expiration_time: + self.authenticate() + return func(self, *args, **kwargs) + + return wrapper + + def authenticate(self): + pass + + def get_channel_by_username(self, username: str) -> dict: + pass + + @check_auth_token + def subscribe_to_new_video_event(self, user_id: str) -> None: + pass + + @check_auth_token + def unsubscribe_from_new_video_event(self, subscription_id: str) -> None: + pass + + @check_auth_token + def get_subscriptions(self) -> dict: + pass + + @check_auth_token + def get_subscription_by_user_id(self, user_id: str) -> dict: + pass diff --git a/app/webhooks/youtube.py b/app/webhooks/youtube.py new file mode 100644 index 0000000..0b2e0c6 --- /dev/null +++ b/app/webhooks/youtube.py @@ -0,0 +1,19 @@ +from flask import request + +from app import logger +from app.constants import LogTypes as logconstants +from app.webhooks import webhooks + + +@webhooks.route('/youtube', methods=['GET', 'POST']) +def twitch_webhook(): + # from app import bot + + challenge = request.args.get('hub.challenge') + + if (challenge): + return challenge + + logger.info(f'Received Youtube webhook: {request.data}', log_type=logconstants.COMMAND_INFO_TYPE) + + return 'Processed', 204