mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 02:48:38 -04:00
Adding skip_viewed to archive and video fetching endpoints.
This commit is contained in:
parent
00cfdc14c6
commit
1c4f57226f
4 changed files with 14 additions and 9 deletions
|
|
@ -36,7 +36,8 @@ async def statistics(_: Request):
|
|||
@openapi.response(HTTPStatus.NOT_FOUND, JSONErrorResponse)
|
||||
async def get_archive(request: Request, file_group_id: int):
|
||||
session = request.ctx.session
|
||||
archive = lib.get_archive_by_file_group_id(session, file_group_id)
|
||||
skip_viewed = request.args.get('skip_viewed', '').lower() == 'true'
|
||||
archive = lib.get_archive_by_file_group_id(session, file_group_id, skip_viewed=skip_viewed)
|
||||
archive_file_group = archive.file_group.__json__()
|
||||
history = [i.file_group.__json__() for i in archive.history]
|
||||
return json_response({'file_group': archive_file_group, 'history': history})
|
||||
|
|
|
|||
|
|
@ -1103,19 +1103,21 @@ def parse_article_html_metadata(html: Union[bytes, str], assume_utc: bool = True
|
|||
return metadata
|
||||
|
||||
|
||||
def get_archive(session: Session, archive_id: int) -> Archive:
|
||||
def get_archive(session: Session, archive_id: int, skip_viewed: bool = False) -> Archive:
|
||||
"""Get an Archive."""
|
||||
archive = Archive.find_by_id(session, archive_id)
|
||||
archive.file_group.set_viewed()
|
||||
if not skip_viewed:
|
||||
archive.file_group.set_viewed()
|
||||
return archive
|
||||
|
||||
|
||||
def get_archive_by_file_group_id(session: Session, file_group_id: int) -> Archive:
|
||||
def get_archive_by_file_group_id(session: Session, file_group_id: int, skip_viewed: bool = False) -> Archive:
|
||||
"""Get an Archive by its FileGroup ID."""
|
||||
archive = session.query(Archive).filter_by(file_group_id=file_group_id).one_or_none()
|
||||
if not archive:
|
||||
raise UnknownArchive(f'Unknown Archive with FileGroup ID: {file_group_id}')
|
||||
archive.file_group.set_viewed()
|
||||
if not skip_viewed:
|
||||
archive.file_group.set_viewed()
|
||||
return archive
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -23,8 +23,9 @@ logger = logger.getChild(__name__)
|
|||
@openapi.description('Get Video information')
|
||||
@openapi.response(HTTPStatus.OK, schema.VideoResponse)
|
||||
@openapi.response(HTTPStatus.NOT_FOUND, JSONErrorResponse)
|
||||
def video_get(_: Request, file_group_id: int):
|
||||
video, previous_video, next_video = lib.get_video_for_app(file_group_id)
|
||||
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})
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -23,13 +23,14 @@ from ..lib import get_yt_dlp_http_headers, get_yt_dlp_sleep_opts
|
|||
logger.getChild(__name__)
|
||||
|
||||
|
||||
def get_video_for_app(file_group_id: int) -> Tuple[dict, Optional[dict], Optional[dict]]:
|
||||
def get_video_for_app(file_group_id: int, skip_viewed: bool = False) -> Tuple[dict, Optional[dict], Optional[dict]]:
|
||||
"""
|
||||
Get a Video by its FileGroup ID, with its prev/next videos. Mark the Video as viewed.
|
||||
"""
|
||||
with get_db_session(commit=True) as session:
|
||||
video = Video.find_by_file_group_id(session, file_group_id)
|
||||
video.file_group.set_viewed()
|
||||
if not skip_viewed:
|
||||
video.file_group.set_viewed()
|
||||
previous_video, next_video = video.get_surrounding_videos()
|
||||
|
||||
video = video.__json__()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue