Skip to content

Fix slice_segments #36 #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions webvtt/segmenter.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
import typing
import os
import pathlib
from math import ceil, floor
from math import floor

from .webvtt import WebVTT, Caption

@@ -49,7 +49,7 @@ def slice_segments(
total_segments = (
0
if not captions else
int(ceil(captions[-1].end_in_seconds / seconds))
floor(captions[-1].end_in_seconds / seconds) + 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

math.floor returns a float, you should still cast this as an int. Tested on my local and this PR resolves the issue.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reikoshea
Thank you for your feedback. I believe that a cast is unnecessary since the value returned by math.floor is already of integer type. Please see the following example from the Python interpreter:

Python 3.10.16 (main, Apr  8 2025, 14:31:23) [GCC 11.4.0] on linux
>>> import math
>>> math.floor(12.345)
12
>>> type(math.floor(12.345))
<class 'int'>

)

segments: typing.List[typing.List[Caption]] = [