2021-11-01 16:42:52 -06:00
|
|
|
from http import HTTPStatus
|
|
|
|
|
|
|
|
|
|
from sanic import Blueprint, response
|
|
|
|
|
from sanic.request import Request
|
2022-01-13 09:29:58 -07:00
|
|
|
from sanic_ext import validate
|
|
|
|
|
from sanic_ext.extensions.openapi import openapi
|
2021-11-01 16:42:52 -06:00
|
|
|
|
|
|
|
|
from wrolpi.common import logger
|
2022-08-06 05:22:07 +00:00
|
|
|
from wrolpi.common import wrol_mode_check
|
2021-11-01 16:42:52 -06:00
|
|
|
from wrolpi.root_api import add_blueprint, json_response
|
2022-01-13 09:29:58 -07:00
|
|
|
from wrolpi.schema import JSONErrorResponse
|
2022-02-16 21:57:27 -07:00
|
|
|
from . import lib, schema
|
2021-12-23 09:38:12 -07:00
|
|
|
from .channel import lib as channel_lib
|
2021-11-01 16:42:52 -06:00
|
|
|
from .channel.api import channel_bp
|
2021-12-23 09:38:12 -07:00
|
|
|
from .video import lib as video_lib
|
2021-11-01 16:42:52 -06:00
|
|
|
from .video.api import video_bp
|
|
|
|
|
|
2021-12-20 16:08:13 -07:00
|
|
|
content_bp = Blueprint('VideoContent', '/api/videos')
|
2021-11-01 16:42:52 -06:00
|
|
|
bp = Blueprint('Videos', '/api/videos').group(
|
|
|
|
|
content_bp, # view and manage video content and settings
|
|
|
|
|
channel_bp, # view and manage channels
|
|
|
|
|
video_bp, # view videos
|
|
|
|
|
)
|
|
|
|
|
add_blueprint(bp)
|
|
|
|
|
|
|
|
|
|
logger = logger.getChild(__name__)
|
|
|
|
|
|
|
|
|
|
|
2022-04-08 09:57:04 -06:00
|
|
|
@content_bp.post('/download/<channel_id:int>')
|
|
|
|
|
@openapi.description('Update a channel catalog, download any missing videos')
|
2022-02-03 12:39:14 -07:00
|
|
|
@openapi.response(HTTPStatus.OK, schema.StreamResponse)
|
2022-01-13 09:29:58 -07:00
|
|
|
@openapi.response(HTTPStatus.BAD_REQUEST, JSONErrorResponse)
|
2021-11-01 16:42:52 -06:00
|
|
|
@wrol_mode_check
|
2022-04-08 09:57:04 -06:00
|
|
|
def download(_, channel_id: int = None):
|
|
|
|
|
channel_lib.download_channel(channel_id)
|
|
|
|
|
return response.empty()
|
2021-11-01 16:42:52 -06:00
|
|
|
|
|
|
|
|
|
2021-12-20 16:08:13 -07:00
|
|
|
@content_bp.post('/favorite')
|
2022-02-03 11:36:26 -07:00
|
|
|
@openapi.definition(
|
|
|
|
|
description='Toggle the favorite flag on a video',
|
2022-02-03 12:39:14 -07:00
|
|
|
body=schema.FavoriteRequest,
|
2022-02-03 11:36:26 -07:00
|
|
|
)
|
2022-02-03 12:39:14 -07:00
|
|
|
@validate(schema.FavoriteRequest)
|
|
|
|
|
@openapi.response(HTTPStatus.OK, schema.FavoriteResponse)
|
2022-01-13 09:29:58 -07:00
|
|
|
@openapi.response(HTTPStatus.BAD_REQUEST, JSONErrorResponse)
|
2022-02-03 12:39:14 -07:00
|
|
|
async def favorite(_: Request, body: schema.FavoriteRequest):
|
2022-01-31 21:18:49 -07:00
|
|
|
_favorite = video_lib.set_video_favorite(body.video_id, body.favorite)
|
|
|
|
|
ret = {'video_id': body.video_id, 'favorite': _favorite}
|
2021-11-01 16:42:52 -06:00
|
|
|
return json_response(ret, HTTPStatus.OK)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@content_bp.get('/statistics')
|
2022-02-03 12:39:14 -07:00
|
|
|
@openapi.response(HTTPStatus.OK, schema.VideosStatisticsResponse)
|
2021-11-01 16:42:52 -06:00
|
|
|
async def statistics(_: Request):
|
2022-02-03 12:39:14 -07:00
|
|
|
ret = await lib.get_statistics()
|
2021-11-01 16:42:52 -06:00
|
|
|
return json_response(ret, HTTPStatus.OK)
|