Skip to content
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

Ankit/add transcript params #25

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion videodb/__about__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" About information for videodb sdk"""


__version__ = "0.2.3"
__version__ = "0.2.4"
__title__ = "videodb"
__author__ = "videodb"
__email__ = "contact@videodb.io"
Expand Down
2 changes: 2 additions & 0 deletions videodb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
SceneExtractionType,
MediaType,
SearchType,
Segmenter,
SubtitleAlignment,
SubtitleBorderStyle,
SubtitleStyle,
Expand Down Expand Up @@ -41,6 +42,7 @@
"SubtitleStyle",
"TextStyle",
"SceneExtractionType",
"Segmenter",
]


Expand Down
6 changes: 6 additions & 0 deletions videodb/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class SemanticSearchDefaultValues:
score_threshold = 0.2


class Segmenter:
time = "time"
word = "word"
sentence = "sentence"


class ApiPath:
collection = "collection"
upload = "upload"
Expand Down
53 changes: 46 additions & 7 deletions videodb/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
IndexType,
SceneExtractionType,
SearchType,
Segmenter,
SubtitleStyle,
Workflows,
)
Expand Down Expand Up @@ -124,23 +125,61 @@ def get_thumbnails(self) -> List[Image]:
)
return [Image(self._connection, **thumbnail) for thumbnail in thumbnails_data]

def _fetch_transcript(self, force: bool = False) -> None:
if self.transcript and not force:
def _fetch_transcript(
self,
start: int = None,
end: int = None,
segmenter: str = Segmenter.word,
length: int = 1,
force: bool = None,
) -> None:
if (
self.transcript
and not start
and not end
and not segmenter
and not length
and not force
):
return
transcript_data = self._connection.get(
path=f"{ApiPath.video}/{self.id}/{ApiPath.transcription}",
params={"force": "true" if force else "false"},
params={
"start": start,
"end": end,
"segmenter": segmenter,
"length": length,
"force": "true" if force else "false",
},
show_progress=True,
)
self.transcript = transcript_data.get("word_timestamps", [])
self.transcript_text = transcript_data.get("text", "")

def get_transcript(self, force: bool = False) -> List[Dict]:
self._fetch_transcript(force)
def get_transcript(
self,
start: int = None,
end: int = None,
segmenter: str = Segmenter.word,
length: int = 1,
force: bool = None,
) -> List[Dict]:
self._fetch_transcript(
start=start, end=end, segmenter=segmenter, length=length, force=force
)
return self.transcript

def get_transcript_text(self, force: bool = False) -> str:
self._fetch_transcript(force)
def get_transcript_text(
self,
start: int = None,
end: int = None,
segmenter: str = Segmenter.word,
length: int = 1,
force: bool = None,
) -> str:
self._fetch_transcript(
start=start, end=end, segmenter=segmenter, length=length, force=force
)
return self.transcript_text

def index_spoken_words(
Expand Down
Loading