Skip to content

Commit

Permalink
pan precommit porzadku pilnuje
Browse files Browse the repository at this point in the history
  • Loading branch information
skelly37 committed Mar 2, 2025
1 parent a948276 commit 6da7f79
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 60 deletions.
2 changes: 1 addition & 1 deletion bot/handlers/bot_message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
get_video_sent_log_message,
)
from bot.settings import settings
from bot.utils.resolution import Resolution
from bot.utils.log import (
log_system_message,
log_user_activity,
)
from bot.utils.resolution import Resolution

ValidatorFunctions = List[Callable[[Message], Awaitable[bool]]]
class BotMessageHandler(ABC):
Expand Down
1 change: 0 additions & 1 deletion bot/utils/functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from dataclasses import dataclass
import json
import logging
from typing import (
Expand Down
119 changes: 69 additions & 50 deletions preprocessor/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,87 @@

from transciption_generator import TranscriptionGenerator
from video_transcoder import VideoTranscoder
from preprocessor.utils.args import(
parse_multi_mode_args,

from bot.utils.resolution import Resolution
from preprocessor.utils.args import (
ParserModes,
parse_multi_mode_args,
)
from bot.utils.resolution import Resolution


def generate_parser_modes() -> ParserModes:
parser_modes = {
"transcribe": [
("videos", {
"type": Path,
"help": "Path to input videos for preprocessing"}
(
"videos", {
"type": Path,
"help": "Path to input videos for preprocessing",
},
),

("--transcription_jsons_dir", {
"type": Path,
"default": "", # todo
"help": "Path for output transcriptions JSONs"
}),
(
"--transcription_jsons_dir", {
"type": Path,
"default": "", # todo
"help": "Path for output transcriptions JSONs",
},
),

# todo

],

"transcode": [
("videos", {
"type": Path,
"help": "Path to input videos for preprocessing"
}),

("--transcoded_videos_dir", {
"type": Path,
"default": VideoTranscoder.DEFAULT_OUTPUT_DIR,
"help": "Path for output videos after transcoding"}
),
("--resolution", {
"type": lambda x: Resolution[x.upper()],
"choices": list(Resolution),
"default": Resolution.R1080P,
"help": "Target resolution for all videos."
}),
("--codec", {
"type": str,
"default": VideoTranscoder.DEFAULT_CODEC,
"help": "Video codec."
}),
("--preset", {
"type": str,
"default": VideoTranscoder.DEFAULT_PRESET,
"help": "FFmpeg preset."
}),
("--crf", {
"type": int,
"default": VideoTranscoder.DEFAULT_CRF,
"help": "Quality (lower = better)."
}),
("--gop-size", {
"type": float,
"default": VideoTranscoder.DEFAULT_GOP_SIZE,
"help": "Keyframe interval in seconds."
}),
(
"videos", {
"type": Path,
"help": "Path to input videos for preprocessing",
},
),

(
"--transcoded_videos_dir", {
"type": Path,
"default": VideoTranscoder.DEFAULT_OUTPUT_DIR,
"help": "Path for output videos after transcoding",
},
),
(
"--resolution", {
"type": lambda x: Resolution[x.upper()],
"choices": list(Resolution),
"default": Resolution.R1080P,
"help": "Target resolution for all videos.",
},
),
(
"--codec", {
"type": str,
"default": VideoTranscoder.DEFAULT_CODEC,
"help": "Video codec.",
},
),
(
"--preset", {
"type": str,
"default": VideoTranscoder.DEFAULT_PRESET,
"help": "FFmpeg preset.",
},
),
(
"--crf", {
"type": int,
"default": VideoTranscoder.DEFAULT_CRF,
"help": "Quality (lower = better).",
},
),
(
"--gop-size", {
"type": float,
"default": VideoTranscoder.DEFAULT_GOP_SIZE,
"help": "Keyframe interval in seconds.",
},
),
],
}

Expand All @@ -87,14 +106,14 @@ def generate_parser_modes() -> ParserModes:

args = parse_multi_mode_args(
description="Generate JSON audio transcriptions or transcode videos to an acceptable resolution.",
modes = generate_parser_modes()
modes = generate_parser_modes(),
)


mode_workers = {
"all": [
VideoTranscoder,
TranscriptionGenerator
TranscriptionGenerator,
],

"transcode": [
Expand All @@ -103,7 +122,7 @@ def generate_parser_modes() -> ParserModes:

"transcribe": [
TranscriptionGenerator,
]
],
}

print(args)
Expand Down
1 change: 1 addition & 0 deletions preprocessor/transciption_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path


class TranscriptionGenerator:
def __init__(self, input_videos: Path, output_jsons: Path):
self.__input_videos = input_videos
Expand Down
4 changes: 1 addition & 3 deletions preprocessor/utils/args.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import argparse
import json
from typing import (
Dict,
List,
Tuple,
)

import json


Argument = Tuple[str, Dict[str, str]]
ParserModes = Dict[str, List[Argument]]
def parse_multi_mode_args(description: str, modes: ParserModes) -> json:
Expand Down
3 changes: 2 additions & 1 deletion preprocessor/utils/error_handling_logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from typing import List


class ErrorHandlingLogger:
class LoggerNotFinalizedException(Exception):
def __init__(self):
Expand Down Expand Up @@ -47,4 +48,4 @@ def finalize(self) -> int:
self.__logger.error(f"- {error}")
return self.__error_exit_code
self.__logger.info(f"Processing for '{self.__class_name}' completed successfully.")
return 0
return 0
8 changes: 4 additions & 4 deletions preprocessor/video_transcoder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
import subprocess
import json
import logging
from pathlib import Path
import subprocess

from bot.utils.resolution import Resolution
from preprocessor.utils.error_handling_logger import ErrorHandlingLogger
Expand All @@ -25,7 +25,7 @@ def __init__(self, args: json):
self.__preset: str = str(args["preset"])
self.__crf: int = int(args["crf"])
self.__gop_size: float = float(args["gop_size"])

if not self.__input_videos.is_dir():
raise NotADirectoryError(f"Input videos is not a directory: '{self.__input_videos}'")

Expand Down Expand Up @@ -97,4 +97,4 @@ def __get_framerate(video: Path) -> float:
raise ValueError(f"Frame rate not found in {video}")

num, denom = (int(x) for x in r_frame_rate.split('/'))
return num / denom
return num / denom

0 comments on commit 6da7f79

Please sign in to comment.