wrolpi/modules/videos/video/api.py
lrnselfreliance cafc6514cb
Restore the censored-video search filter (#499)
* Restore the censored-video search filter

Censored videos (no longer publicly available — detected when a channel
refresh drops them from the channel list, or when comment downloads fail
with "video unavailable/private/removed") are already flagged on
FileGroup.censored, but there was no way to find them since the search
rework dropped the old filter.

Add a "Censored" toggle to the reworked search filter modal, shown only on
the Videos page (showCensored).  When enabled the video search returns only
videos with FileGroup.censored = TRUE, tracked via a ?censored=true query
param (useSearchCensored).
* Move Availability filter below the Tags/Results row

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-27 09:48:36 -06:00

74 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,
body.censored,
)
ret = {'file_groups': list(file_groups), 'totals': {'file_groups': videos_total}}
return json_response(ret)