Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bralbral committed Sep 26, 2024
1 parent 1240017 commit caf0936
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 21 deletions.
2 changes: 0 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Simple LiveStreams notifier in telegram based on [aiogram](https://github.com/ai
|-----------------|-------------------------------------------------|----------------------------------------------------------------------|
| Youtube | [youtube-dlp](https://github.com/yt-dlp/yt-dlp) ||
| Twitch | [twitch-api](https://github.com/Teekeks/pyTwitchAPI) ||
| Kick |||


Use this bot to receive periodic reports on live broadcasts on stream platforms and generate and send the report to telegram.

Expand Down
1 change: 0 additions & 1 deletion src/bot/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
def superuser_commands() -> list[BotCommand]:
commands = [
BotCommand(command="add_user", description="Add user to bot."),
BotCommand(command="add_channels", description="Add channels from file."),
BotCommand(command="scheduler_start", description="Start scheduler."),
BotCommand(command="scheduler_pause", description="Stop scheduler."),
]
Expand Down
2 changes: 1 addition & 1 deletion src/bot/dialogs/user/channel/add/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

url_examples: dict = {
ChannelType.YOUTUBE: "https://www.youtube.com/@username",
ChannelType.TWITCH: "empty",
ChannelType.TWITCH: "https://www.twitch.tv/username",
ChannelType.KICK: "empty",
}

Expand Down
12 changes: 1 addition & 11 deletions src/bot/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@
from aiogram.fsm.state import StatesGroup


class ChannelsSG(StatesGroup):
input_url = State()
input_label = State()
scrolling = State()
delete = State()
turn_on = State()
turn_off = State()
bulk_channels = State()


class ChannelsListSG(StatesGroup):
scrolling = State()
delete = State()
Expand All @@ -29,4 +19,4 @@ class UsersSG(StatesGroup):
promote = State()


__all__ = ["ChannelCreateSG", "ChannelsListSG", "ChannelsSG", "UsersSG"]
__all__ = ["ChannelCreateSG", "ChannelsListSG", "UsersSG"]
3 changes: 2 additions & 1 deletion src/bot/utils/setup_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from aiogram.types import BotCommandScopeChat
from sulguk import AiogramSulgukMiddleware

from ...constants import VERSION
from ..commands import superuser_commands
from ..commands import user_commands
from src.config import BotConfig
Expand Down Expand Up @@ -35,7 +36,7 @@ async def setup_bot(
user_commands() + superuser_commands(),
scope=BotCommandScopeChat(chat_id=_id),
)
await bot.send_message(chat_id=_id, text="Bot started.")
await bot.send_message(chat_id=_id, text=f"Starting bot, version: {VERSION}")

await bot.delete_webhook()
return bot
Expand Down
2 changes: 1 addition & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
SQLITE_DATABASE_FILE_PATH: str = os.environ.get(
"SQLITE_DATABASE_FILE_PATH", os.path.join(ROOT_DIR, "youtube-notifier-bot.db")
)
VERSION: str = "2024-09-26.04"
VERSION: str = "2024-09-26.06"

__all__ = [
"CONFIG_FILE_PATH",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from src.scheduler.jobs.telegram_notify_job.data_fetcher.utils import make_time_readable
from src.scheduler.jobs.telegram_notify_job.dto import ErrorVideoInfo
from src.scheduler.jobs.telegram_notify_job.dto import VideoInfo
from src.utils import extract_twitch_username


async def async_fetch_livestream(
Expand All @@ -27,8 +28,12 @@ async def async_fetch_livestream(

live_stream = None
try:

username = extract_twitch_username(channel.url)
if not username:
raise Exception(f"Cannot extract username for {channel.url}")
data: Optional[Stream] = await first(
twitch.get_streams(user_login=[channel.url], first=1, stream_type="live")
twitch.get_streams(user_login=[username], first=1, stream_type="live")
)

if data:
Expand Down
2 changes: 0 additions & 2 deletions src/scheduler/jobs/telegram_notify_job/notifier/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
from src.db import DataAccessLayer
from src.db.models import MessageLogModel
from src.logger import logger
from src.scheduler.jobs.telegram_notify_job.dto.videoinfo import ErrorVideoInfo
from src.scheduler.jobs.telegram_notify_job.dto.videoinfo import VideoInfo


async def notify(
Expand Down
16 changes: 15 additions & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
import re
from typing import Optional

YOUTUBE_USERNAME_CHANNEL_LINK_PATTERN = re.compile(
r"^https?://(?:www\.)?youtube\.com/@[\w-]+/?$"
)

TWITCH_USERNAME_CHANNEL_LINK_PATTERN = re.compile(
r"^https?://(?:www\.)?twitch\.tv/([\w-]+)/?$"
)


def youtube_channel_url_validator(link: str) -> bool:
match = re.match(YOUTUBE_USERNAME_CHANNEL_LINK_PATTERN, link)
return bool(match)


def twitch_channel_url_validator(link: str) -> bool:
return False
match = re.match(TWITCH_USERNAME_CHANNEL_LINK_PATTERN, link)
return bool(match)


def extract_twitch_username(link: str) -> Optional[str]:
match = re.match(TWITCH_USERNAME_CHANNEL_LINK_PATTERN, link)
if match:
return match.group(1)
return None


def kick_channel_url_validator(link: str) -> bool:
return False


__all__ = [
"extract_twitch_username",
"kick_channel_url_validator",
"twitch_channel_url_validator",
"youtube_channel_url_validator",
Expand Down

0 comments on commit caf0936

Please sign in to comment.