Skip to content

Commit

Permalink
manual_clip_fix (#37)
Browse files Browse the repository at this point in the history
* fix

* Update manual_clip_handler.py
  • Loading branch information
dam2452 authored Dec 26, 2024
1 parent 07d7298 commit a9f763f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 41 deletions.
21 changes: 17 additions & 4 deletions bot/handlers/sending_videos/manual_clip_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,24 @@ def get_commands(self) -> List[str]:
def _get_validator_functions(self) -> ValidatorFunctions:
return [
self.__check_argument_count,
self.__check_end_time_after_start_time,
]

async def __check_end_time_after_start_time(self, message: Message) -> bool:
content = message.text.split()

try:
start_seconds = minutes_str_to_seconds(content[2])
end_seconds = minutes_str_to_seconds(content[3])
except (InvalidSeasonEpisodeStringException, InvalidTimeStringException):
return True

if end_seconds <= start_seconds:
await self.__reply_end_time_earlier_than_start(message)
return False

return True

async def __check_argument_count(self, message: Message) -> bool:
return await self._validate_argument_count(message, 4, get_invalid_args_count_message())

Expand All @@ -60,9 +76,6 @@ async def _do_handle(self, message: Message) -> None:
except InvalidTimeStringException:
return await self.__reply_incorrect_time_format(message)

if end_seconds <= start_seconds:
return await self.__reply_end_time_earlier_than_start(message)

clip_duration = end_seconds - start_seconds
if await self._handle_clip_duration_limit_exceeded(message, clip_duration):
return
Expand Down Expand Up @@ -129,5 +142,5 @@ async def __reply_incorrect_time_format(self, message: Message) -> None:
await self._log_system_message(logging.INFO, get_log_incorrect_time_format_message())

async def __reply_end_time_earlier_than_start(self, message: Message) -> None:
await self._answer_markdown(message, get_end_time_earlier_than_start_message())
await self._answer(message, get_end_time_earlier_than_start_message())
await self._log_system_message(logging.INFO, get_log_end_time_earlier_than_start_message())
6 changes: 3 additions & 3 deletions bot/responses/sending_videos/manual_clip_handler_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def get_incorrect_time_format_message() -> str:

def get_end_time_earlier_than_start_message() -> str:
return (
"❌ **Czas zakończenia musi być późniejszy niż czas rozpoczęcia!**\n"
"Upewnij się, że **czas_start** jest wcześniejszy niż **czas_koniec**.\n"
"Przykład: **20:30.11** (czas_start) powinno być wcześniejsze niż **21:32.50** (czas_koniec)."
"❌ Czas zakończenia musi być późniejszy niż czas rozpoczęcia!\n"
"Upewnij się, że czas_start jest wcześniejszy niż czas_koniec.\n"
"Przykład: 20:30.11 (czas_start) powinno być wcześniejsze niż 21:32.50 (czas_koniec)."
)


Expand Down
20 changes: 10 additions & 10 deletions bot/tests/expected_file_hashes.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"adjusted_geniusz_-5.5 1.5.mp4": "c92b62c69406b6628c9a131142e4f087b70721d1af899f6c639f2cc56d23e3ad",
"adjusted_kozio\u0142_clip1_10.0 -3.mp4": "c99d8d5c8d9f14037848308e41d5189c4336f714b2c0f0df96c69622e3a6b17e",
"clip_geniusz.mp4": "2f58b4fc4e8be8998627b84382bae352ef5b8793f504adfdf6eb64b7120a824d",
"clip_geniusz_saved.mp4": "2f58b4fc4e8be8998627b84382bae352ef5b8793f504adfdf6eb64b7120a824d",
"clip_kozio\u0142_clip1.mp4": "8820e73ef0a5fdc273bb23f96875b2ef18d6101cde903bddb4ac773cdb786e68",
"clip_kozio\u0142_saved.mp4": "8820e73ef0a5fdc273bb23f96875b2ef18d6101cde903bddb4ac773cdb786e68",
"clip_uczniowie_saved.mp4": "99c888b6ab558c05b2a8be2da1d9b70e43c8675e57636586d6999d55ae44ac65",
"compile_anglii_all.mp4": "27fe069203aa3071fe899e96899aa13f5b4c4ef0a481101b5bd4576222473bfc",
"compile_kozio\u0142_1-4.mp4": "e8a34df42cb6c8338328ee4178209b1370c8ef0dcc287fb01fbf2a2e351466d7",
"compile_kozio\u0142_1_3_5.mp4": "3d142cb7b68f876420707e036ea7006221e99bc8b2927b6bd50f56566423bf81",
"cut_S07E06_36:47.50_36:49.00.mp4": "ca96eb9950da913f9bc1e4b684d2f96e78517c6b5e8b52cf14b45234df37378b",
"cut_S07E06_40:00.00_41:00.00.mp4": "c4a0d5a66614a5fceaf4f5abab7123afbec33b0d9aab39847f4b6d3e335902ea",
"clip_geniusz.mp4": "d9654aab6535df07c965f414642a5900c50d03e589b2ff1311d451fd9a838741",
"clip_geniusz_saved.mp4": "d9654aab6535df07c965f414642a5900c50d03e589b2ff1311d451fd9a838741",
"clip_kozio\u0142_clip1.mp4": "1f08ce5fcc3d309703e4f3aee3382b20081dba760afc6fb31bb7120f47ea0f9e",
"clip_kozio\u0142_saved.mp4": "1f08ce5fcc3d309703e4f3aee3382b20081dba760afc6fb31bb7120f47ea0f9e",
"clip_uczniowie_saved.mp4": "21773127ff9edcee014106697b357009a469e728e435757d7cc99d4c25c3f4c5",
"compile_anglii_all.mp4": "fce653853283293962717131cdea399f8cdd5742ca817699fc5d4452e36b01ad",
"compile_kozio\u0142_1-4.mp4": "f6fa8df42a9366cc3f6aea56c55edef1c2d8178166d7c1b5befd1287fed33e88",
"compile_kozio\u0142_1_3_5.mp4": "7cfe775775d4f935693d21b38fd5e82209b10b58636ea95ceacb92f9187da606",
"cut_S07E06_36:47.50_36:49.00.mp4": "3b9814529dfd91a91beacb33167cbe4a07adf764adbbc7e89800ef8478adbf22",
"cut_S07E06_40:00.00_41:00.00.mp4": "d8248402825d1b1e5c9aba36d5aa7d34baf1fc0bde94e5135c26e3db8597a167",
"episode_list_season_3_long.message": "55c796e5a47048b63a8bff288606d1609e684bc708f4394fe13838c2dc382039",
"episode_list_season_4.message": "1338592dec17e307056d3de302c3ddf68eb916c186d9034a67fe1b2fe5393822",
"kozio\u0142_klip2_from_send.mp4": "8820e73ef0a5fdc273bb23f96875b2ef18d6101cde903bddb4ac773cdb786e68 send_clip_kozio\u0142_klip2.mp4",
Expand Down
49 changes: 25 additions & 24 deletions bot/tests/sending_videos/test_manual_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,28 @@ async def test_cut_clip_large_time_range(self):
response = await self.send_command(command, timeout=timeout)
await self.assert_command_result_file_matches(response, expected_file)

# @pytest.mark.asyncio
# async def test_cut_clip_end_time_before_start_time(self):
# episode = "S07E06"
# start_time = "36:49.00"
# end_time = "36:47.50"
#
# expected_message = msg.get_end_time_earlier_than_start_message()
#
# command = f"/wytnij {episode} {start_time} {end_time}"
# response = await self.send_command(command)
# self.assert_response_contains(response, [expected_message])

# @pytest.mark.asyncio
# async def test_cut_clip_exact_episode_length(self):
# episode = "S07E06"
# start_time = "00:00.00"
# end_time = "45:00.00"
#
# expected_message = msg.get_limit_exceeded_clip_duration_message()
# timeout = 30
#
# command = f"/wytnij {episode} {start_time} {end_time}"
# response = await self.send_command(command, timeout=timeout)
# self.assert_response_contains(response, [expected_message])
@pytest.mark.asyncio
async def test_cut_clip_end_time_before_start_time(self):
episode = "S07E06"
start_time = "36:49.00"
end_time = "36:47.50"

expected_message = msg.get_end_time_earlier_than_start_message()

command = f"/wytnij {episode} {start_time} {end_time}"
response = await self.send_command(command)
self.assert_response_contains(response, [expected_message])

@pytest.mark.asyncio
async def test_cut_clip_exact_episode_length(self):
await self.switch_to_normal_user()
episode = "S07E06"
start_time = "00:00.00"
end_time = "45:00.00"

expected_message = msg.get_limit_exceeded_clip_duration_message()
timeout = 30

command = f"/wytnij {episode} {start_time} {end_time}"
response = await self.send_command(command, timeout=timeout)
self.assert_response_contains(response, [expected_message])

0 comments on commit a9f763f

Please sign in to comment.