Skip to content

Commit

Permalink
Video converter part done
Browse files Browse the repository at this point in the history
  • Loading branch information
skelly37 committed Mar 2, 2025
1 parent 781e06a commit a948276
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 272 deletions.
57 changes: 0 additions & 57 deletions Preprocessing/ErrorHandlingLogger.py

This file was deleted.

152 changes: 0 additions & 152 deletions Preprocessing/VideoConverter.py

This file was deleted.

4 changes: 2 additions & 2 deletions bot/handlers/bot_message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
get_video_sent_log_message,
)
from bot.settings import settings
from bot.utils.functions import RESOLUTIONS
from bot.utils.resolution import Resolution
from bot.utils.log import (
log_system_message,
log_user_activity,
Expand Down Expand Up @@ -126,7 +126,7 @@ async def _answer_video(self, message: Message, file_path: Path) -> None:
)
await self._answer(message, await self.get_response(RK.CLIP_SIZE_EXCEEDED, as_parent=True))
else:
resolution = RESOLUTIONS.get(settings.DEFAULT_RESOLUTION_KEY)
resolution = Resolution.from_str(settings.DEFAULT_RESOLUTION_KEY)

await message.answer_video(
FSInputFile(file_path),
Expand Down
47 changes: 18 additions & 29 deletions bot/utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@

logger = logging.getLogger(__name__)

@dataclass
class Resolution:
width: int
height: int

RESOLUTIONS: Dict[str, Resolution] = {
"1080p": Resolution(1920, 1080),
"720p": Resolution(1280, 720),
"480p": Resolution(854, 480),


NUMBER_TO_EMOJI: Dict[str, str] = {
"0": "0️⃣",
"1": "1️⃣",
"2": "2️⃣",
"3": "3️⃣",
"4": "4️⃣",
"5": "5️⃣",
"6": "6️⃣",
"7": "7️⃣",
"8": "8️⃣",
"9": "9️⃣",
}


def convert_number_to_emoji(number: int) -> str:
return "".join(NUMBER_TO_EMOJI.get(digit, digit) for digit in str(number))

class InvalidTimeStringException(Exception):
def __init__(self, time: str) -> None:
self.message = f"Invalid time string: '{time}'. Upewnij się, że używasz formatu MM:SS\u200B.ms, np. 20:30.11"
Expand Down Expand Up @@ -102,25 +110,6 @@ def format_segment(segment: json, season_info: Dict[str, int]) -> FormattedSegme
)



number_to_emoji: Dict[str, str] = {
"0": "0️⃣",
"1": "1️⃣",
"2": "2️⃣",
"3": "3️⃣",
"4": "4️⃣",
"5": "5️⃣",
"6": "6️⃣",
"7": "7️⃣",
"8": "8️⃣",
"9": "9️⃣",
}


def convert_number_to_emoji(number: int) -> str:
return "".join(number_to_emoji.get(digit, digit) for digit in str(number))


def format_user_list(users: List[UserProfile], title: str) -> str:
user_lines = []

Expand All @@ -137,7 +126,7 @@ def format_user_list(users: List[UserProfile], title: str) -> str:
response += "```\n" + "\n\n".join(user_lines) + "\n```"
return response

def remove_diacritics_and_lowercase(text):
def remove_diacritics_and_lowercase(text: str) -> str:
normalized_text = unicodedata.normalize('NFKD', text)
cleaned_text = ''.join([char for char in normalized_text if not unicodedata.combining(char)])
return cleaned_text.lower()
18 changes: 18 additions & 0 deletions bot/utils/resolution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from enum import Enum


class Resolution(Enum):
R1080P = (1920, 1080)
R720P = (1280, 720)
R480P = (854, 480)

def __init__(self, width: int, height: int):
self.width = width
self.height = height

def __str__(self):
return f"{self.height}p"

@staticmethod
def from_str(init: str) -> "Resolution":
return Resolution(Resolution["R" + init.upper()])
Loading

0 comments on commit a948276

Please sign in to comment.