Skip to content

feat(media): add filename and readiness filters to shared listing - #126

Open
FaiziNerd wants to merge 8 commits into
grayhatdevelopers:mainfrom
FaiziNerd:feat/media-search-filters
Open

feat(media): add filename and readiness filters to shared listing#126
FaiziNerd wants to merge 8 commits into
grayhatdevelopers:mainfrom
FaiziNerd:feat/media-search-filters

Conversation

@FaiziNerd

@FaiziNerd FaiziNerd commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Closes #80

Summary

Larger repositories can now be narrowed in list_media / workspace without paging through the full catalog client-side.

ListMediaCommand accepts optional filename and state filters. The same semantics are projected through CLI (--filename, --state), HTTP (GET /media, GET /workspace), and MCP (list_media, get_workspace). Filtering runs in the existing SQLite media catalog (COUNT + LIST with the same predicates). Pagination and repository scoping are unchanged: cursors still encode offset in the current repository, and a filtered page uses the filtered total.

Filename matching is a case-insensitive substring of original_filename (so clip and CLIP both match Holiday-Clip.mp4). LIKE wildcards in the query are escaped. Readiness filtering uses the existing MediaState values (ready, pending, failed). The two filters combine. This is catalog lookup, not a second library index and not video-content search.

The browser UI lists ready media with state=ready so the registered-video picker does not mix incomplete or failed imports. No storage or index rebuild is required.

Test plan

  • Catalog: filename substring (case-insensitive), state filter, combined filters, filtered pagination
  • HTTP/CLI/MCP: filename and state are passed through ListMediaCommand with the same meaning
  • Unfiltered listing and existing cursors still work
  • Frontend registered-video list only requests ready media

Validation

uv run --no-sync ruff check .
uv run --no-sync pytest -q tests/test_media_catalog.py tests/test_media_services.py tests/test_api.py tests/test_cli.py tests/test_mcp.py tests/test_frontend.py

@tulayha tulayha left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding filters to workspace() makes the existing action calculation incorrect. page.total is now the filtered count, while indexed_media still contains every indexed media item in the repository. Comparing them can hide index_media even when later filtered results are not indexed. Please calculate workspace actions using consistent filtered or unfiltered values.

raise ValueError("The media cursor is invalid.") from exc
total = self.catalog.count_media()
total = self.catalog.count_media(
filename=command.filename,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cursor is scoped only to the repository, so it can be reused with different filters. For example, a cursor from filename=clip can be sent with state=failed, and the failed-media results will start at the old offset and skip items. Please include filename and state in the cursor scope so a cursor is valid only for the query that created it.

Comment thread tests/test_frontend.py
@FaiziNerd

Copy link
Copy Markdown
Contributor Author

Workspace action consistency
workspace() now computes index_media using repository-wide totals (consistent scope), so filtered page.total no longer hides indexing prompts.

Cursor/filter scoping
Pagination cursors are now filter-bound (filename + state), preventing reuse across different filter combinations and offset-skipping.

Frontend ready-only picker
The registered-video dropdown now requests only ready media (ListMediaCommand(..., state=MediaState.ready)), so pending/failed imports are excluded from selection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add filename and readiness filters to shared media listing

2 participants