mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
from http import HTTPStatus
|
|
|
|
from sanic import Blueprint
|
|
from sanic.request import Request
|
|
from sanic_ext import validate
|
|
from sanic_ext.extensions.openapi import openapi
|
|
|
|
from wrolpi.api_utils import json_response
|
|
from wrolpi.common import logger
|
|
from wrolpi.errors import InvalidOrderBy
|
|
from wrolpi.schema import JSONErrorResponse
|
|
from . import lib
|
|
from .. import schema
|
|
|
|
video_bp = Blueprint('Video', '/api/videos')
|
|
|
|
logger = logger.getChild(__name__)
|
|
|
|
|
|
@video_bp.get('/<file_group_id:int>')
|
|
@openapi.description('Get Video information')
|
|
@openapi.response(HTTPStatus.OK, schema.VideoResponse)
|
|
@openapi.response(HTTPStatus.NOT_FOUND, JSONErrorResponse)
|
|
def video_get(request: Request, file_group_id: int):
|
|
skip_viewed = request.args.get('skip_viewed', '').lower() == 'true'
|
|
video, previous_video, next_video = lib.get_video_for_app(file_group_id, skip_viewed=skip_viewed)
|
|
return json_response({'file_group': video, 'prev': previous_video, 'next': next_video})
|
|
|
|
|
|
@video_bp.get('/<file_group_id:int>/comments')
|
|
@openapi.description('Get Video comments')
|
|
@openapi.response(HTTPStatus.OK, schema.VideoCommentsResponse)
|
|
@openapi.response(HTTPStatus.NOT_FOUND, JSONErrorResponse)
|
|
def video_get_comments(_: Request, file_group_id: int):
|
|
video = lib.get_video(file_group_id)
|
|
return json_response({'comments': video.get_comments()})
|
|
|
|
|
|
@video_bp.get('/<file_group_id:int>/captions')
|
|
@openapi.description('Get Video captions')
|
|
@openapi.response(HTTPStatus.OK, schema.VideoCaptionsResponse)
|
|
@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.get_caption_chunks()})
|
|
|
|
|
|
@video_bp.post('/search')
|
|
@openapi.definition(
|
|
summary='Search Video titles and captions',
|
|
body=schema.VideoSearchRequest,
|
|
)
|
|
@openapi.response(HTTPStatus.OK, schema.VideoSearchResponse)
|
|
@openapi.response(HTTPStatus.NOT_FOUND, JSONErrorResponse)
|
|
@validate(schema.VideoSearchRequest)
|
|
async def search_videos(_: Request, body: schema.VideoSearchRequest):
|
|
if body.order_by not in lib.VIDEO_ORDERS:
|
|
raise InvalidOrderBy('Invalid order by')
|
|
|
|
file_groups, videos_total = lib.search_videos(
|
|
body.search_str,
|
|
body.offset,
|
|
body.limit,
|
|
body.channel_id,
|
|
body.order_by,
|
|
body.tag_names,
|
|
body.headline,
|
|
)
|
|
|
|
ret = {'file_groups': list(file_groups), 'totals': {'file_groups': videos_total}}
|
|
return json_response(ret)
|
|
|
|
|