Skip to content

Commit

Permalink
Move validation of the channel ids from _register() to _subscribe()
Browse files Browse the repository at this point in the history
  • Loading branch information
SeoulSKY committed Aug 25, 2024
1 parent 486bb1f commit 0bcdb3d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions ytnoti/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,13 @@ async def _subscribe(self, channel_ids: str | Iterable[str]) -> None:
if isinstance(channel_ids, str):
channel_ids = [channel_ids]

async with AsyncClient() as client:
for channel_id in channel_ids:
response = await client.head(f"https://www.youtube.com/channel/{channel_id}")

if response.status_code != HTTPStatus.OK.value:
raise ValueError(f"Invalid channel ID: {channel_id}")

if not self.is_ready:
self._subscribed_ids.update(channel_ids)
return
Expand All @@ -388,13 +395,6 @@ async def _register(self,
:raises HTTPError: If failed to subscribe or unsubscribe due to an HTTP error.
"""

async with AsyncClient() as client:
for channel_id in channel_ids:
response = await client.head(f"https://www.youtube.com/channel/{channel_id}")

if response.status_code != HTTPStatus.OK.value:
raise ValueError(f"Invalid channel ID: {channel_id}")

for channel_id in channel_ids:
async with AsyncClient() as client:
self.__logger.debug("Sending %s request for channel: %s", mode, channel_id)
Expand Down

0 comments on commit 0bcdb3d

Please sign in to comment.