mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Tags can be created and deleted in UI. Adding tag_file using id to avoid session error. Using UTC in test. Matching tag_names style in test. Tag icon is displayed on file rows. Archives, Videos and Files can be filtered by their tags. Tags can be added and removed from UI. Tags are displayed in VideoPlayer. The tags of a file are returned in it's JSON. Video favorites are converted to Favorite tag on channel config import. Updating tests to match frontend usage. PDF creator and modification time are displayed. Reworking file search to use Video.__json__ for complex video relations. Archives can be viewed. Removing ebook.title. Reworking alembic migration to be an upgrade rather than a replace. Skipping test on circleci. Clearing out video caption index only if extract_subtitles if off. Channel tests pass. Some video tests pass. Missing videos can be found. A video can be downloaded. Orphaned files can be found. Videos can be tagged. Videos can be searched. Videos can be modeled. Converting some tests to use FileGroup.primary_path. Adding archive and domains to alembic migration. Testing cascading Archive titles. Archives now uses FileGroup. archive.lib tests pass. Archive is partially converted to FileGroup. Calculating FileGroup.primary file on refresh, rather than on select. wrolpi tests pass. Using FilesType to convert between str/pathlib.Path for FileGroup.files. Using list of files in FileGroup.files instead of dictionary. Storing files in dedicated FileGroup.files to avoid overwriting them. Adding comment explaining CASE. Not overwriting FileGroup.data on refresh if no change has been detected. Removing File model in favor of FileGroup.data. Adding typing to Files methods. Files are indexed using the primary mimetype of the FileGroup. files test_lib tests pass. Removing file_group_file in favor of simple one-to-many relationship. PDF files are indexed during refresh. Adding Tag and TagFile to tag files with specific tags. Only iterating when full_stem_ids has contents. Testing that FileGroups are related to their Files. Files and file_groups are created and linked. Bump webpack from 5.75.0 to 5.76.1 in /app (#160) Bumps [webpack](https://github.com/webpack/webpack) from 5.75.0 to 5.76.1. - [Release notes](https://github.com/webpack/webpack/releases) - [Commits](https://github.com/webpack/webpack/compare/v5.75.0...v5.76.1) --- updated-dependencies: - dependency-name: webpack dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
89 lines
3.2 KiB
Python
89 lines
3.2 KiB
Python
import asyncio
|
|
from typing import List, Tuple
|
|
|
|
from modules.videos.models import Video, Channel
|
|
from wrolpi.common import logger, limit_concurrent, register_modeler, register_after_refresh
|
|
from wrolpi.db import get_db_curs, get_db_session
|
|
from wrolpi.files.models import FileGroup
|
|
from wrolpi.vars import PYTEST
|
|
from .downloader import video_downloader # Import downloaders so they are registered.
|
|
|
|
logger = logger.getChild(__name__)
|
|
|
|
__all__ = ['video_modeler']
|
|
|
|
VIDEO_PROCESSING_LIMIT = 20
|
|
|
|
|
|
@register_modeler
|
|
async def video_modeler():
|
|
while True:
|
|
with get_db_session(commit=True) as session:
|
|
file_groups = session.query(FileGroup, Video).filter(
|
|
FileGroup.indexed != True,
|
|
FileGroup.mimetype.like('video/%'),
|
|
).outerjoin(Video, Video.file_group_id == FileGroup.id) \
|
|
.limit(VIDEO_PROCESSING_LIMIT)
|
|
file_groups: List[Tuple[FileGroup, Video]] = list(file_groups)
|
|
|
|
processed = 0
|
|
for file_group, video in file_groups:
|
|
processed += 1
|
|
|
|
video_id = None
|
|
try:
|
|
if not video:
|
|
video = Video(file_group=file_group)
|
|
session.add(video)
|
|
session.flush([video])
|
|
video_id = video.id
|
|
video.validate()
|
|
except Exception as e:
|
|
if PYTEST:
|
|
raise
|
|
logger.error(f'Unable to model Video {video_id=}', exc_info=e)
|
|
|
|
file_group.indexed = True
|
|
|
|
if processed < VIDEO_PROCESSING_LIMIT:
|
|
# Did not reach limit, do not query again.
|
|
break
|
|
|
|
logger.debug(f'Modeled {processed} videos')
|
|
|
|
# Sleep to catch cancel.
|
|
await asyncio.sleep(0)
|
|
|
|
@register_after_refresh
|
|
@limit_concurrent(1)
|
|
def video_cleanup():
|
|
logger.info('Claiming Videos for their Channels')
|
|
with get_db_curs(commit=True) as curs:
|
|
# Delete all Videos if the FileModel no longer contains a video.
|
|
curs.execute('''
|
|
WITH deleted AS
|
|
(UPDATE file_group SET model=null WHERE model='video' AND mimetype NOT LIKE 'video/%' RETURNING id)
|
|
DELETE FROM video WHERE file_group_id = ANY(select id from deleted)
|
|
''')
|
|
# Claim all Videos in a Channel's directory for that Channel. But, only if they have not yet been claimed.
|
|
curs.execute('''
|
|
UPDATE video v
|
|
SET
|
|
channel_id = c.id
|
|
FROM channel c
|
|
LEFT JOIN file_group fg ON fg.primary_path LIKE c.directory || '/%'::VARCHAR
|
|
WHERE
|
|
v.channel_id IS NULL
|
|
AND fg.id = v.file_group_id
|
|
''')
|
|
curs.execute('''
|
|
UPDATE file_group fg
|
|
SET
|
|
-- Update channel information in file_group.data
|
|
-- Example: data = {'channel': {'id': 1, 'name': 'example'}}
|
|
data = fg.data::jsonb || jsonb_build_object('channel',
|
|
jsonb_build_object('id', v.channel_id, 'name', c.name))
|
|
FROM video v
|
|
LEFT JOIN channel c on c.id = v.channel_id
|
|
WHERE fg.id = v.file_group_id
|
|
''')
|