mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-04 05:39:57 -05:00
Adding links next to video captions to allow scrubbing of video by the captions, adding filter to make finding quick.
This commit is contained in:
parent
2bae99c6ef
commit
282b0f63e8
10 changed files with 224 additions and 46 deletions
|
|
@ -8,7 +8,7 @@ from sqlalchemy.orm import relationship, Session, deferred
|
|||
from sqlalchemy.orm.collections import InstrumentedList
|
||||
|
||||
from modules.videos.errors import UnknownVideo, UnknownChannel
|
||||
from wrolpi.captions import read_captions
|
||||
from wrolpi.captions import read_captions, read_captions_with_timestamps
|
||||
from wrolpi.common import Base, ModelHelper, logger, get_media_directory, get_relative_to_media_directory, \
|
||||
background_task
|
||||
from wrolpi.db import get_db_curs, get_db_session
|
||||
|
|
@ -336,6 +336,20 @@ class Video(ModelHelper, Base):
|
|||
|
||||
return caption_text
|
||||
|
||||
def get_caption_chunks(self) -> Optional[List[dict]]:
|
||||
"""Search the FileGroup's files for a caption file. Return captions with timestamps."""
|
||||
caption_paths = self.caption_paths
|
||||
caption_chunks = None
|
||||
if english_vtt := [i for i in caption_paths if i.name.endswith('.en.vtt')]:
|
||||
caption_chunks = read_captions_with_timestamps(english_vtt[0])
|
||||
elif vtt := [i for i in caption_paths if i.name.endswith('.vtt')]:
|
||||
caption_chunks = read_captions_with_timestamps(vtt[0])
|
||||
elif english_srt := [i for i in caption_paths if i.name.endswith('.en.srt')]:
|
||||
caption_chunks = read_captions_with_timestamps(english_srt[0])
|
||||
elif srt := [i for i in caption_paths if i.name.endswith('.srt')]:
|
||||
caption_chunks = read_captions_with_timestamps(srt[0])
|
||||
return caption_chunks
|
||||
|
||||
@staticmethod
|
||||
def get_by_path(session: Session, path) -> Optional['Video']:
|
||||
video = session.query(Video) \
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ class VideoCommentsResponse:
|
|||
|
||||
@dataclass
|
||||
class VideoCaptionsResponse:
|
||||
captions: str
|
||||
captions: list
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ def video_get_comments(_: Request, file_group_id: int):
|
|||
@openapi.response(HTTPStatus.NOT_FOUND, JSONErrorResponse)
|
||||
def video_get_captions(_: Request, file_group_id: int):
|
||||
video = lib.get_video(file_group_id)
|
||||
return json_response({'captions': video.file_group.d_text})
|
||||
return json_response({'captions': video.get_caption_chunks()})
|
||||
|
||||
|
||||
@video_bp.post('/search')
|
||||
|
|
|
|||
|
|
@ -197,7 +197,11 @@ async def test_api_video_extras(async_client, simple_channel, video_factory):
|
|||
|
||||
request, response = await async_client.get(f'/api/videos/{video.file_group_id}/captions')
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
assert response.json.get('captions')
|
||||
captions = response.json.get('captions')
|
||||
assert isinstance(captions, list)
|
||||
assert len(captions) > 0
|
||||
assert 'start_seconds' in captions[0]
|
||||
assert 'text' in captions[0]
|
||||
|
||||
request, response = await async_client.get(f'/api/videos/{video.file_group_id}/comments')
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue