Skip to content

Implement playback viewlog tracking#2670

Open
Alex1981-tech wants to merge 2 commits intoScreenly:masterfrom
Alex1981-tech:feature/playback-viewlog
Open

Implement playback viewlog tracking#2670
Alex1981-tech wants to merge 2 commits intoScreenly:masterfrom
Alex1981-tech:feature/playback-viewlog

Conversation

@Alex1981-tech
Copy link

Summary

Implement the previously stubbed-out viewlog feature. The viewer now logs every asset playback to a SQLite database (viewlog.db), and the /api/v2/info endpoint returns the last played asset instead of "Not yet implemented".

Problem

The /api/v2/info endpoint has a viewlog field that has always returned "Not yet implemented". There's no way to know what the player is currently displaying or what it last played.

Solution

Viewer side (viewer/__init__.py):

  • On startup, creates ~/.screenly/viewlog.db with a viewlog table
  • Every time an asset starts playing in asset_loop(), writes a record with:
    • asset_id, asset_name, mimetype, uri, started_at (UTC ISO), duration

API side (api/views/mixins.py, api/views/v2.py):

  • InfoViewMixin._get_viewlog() reads the most recent entry from viewlog.db
  • Returns a dict with asset details, or "No data" if empty/missing
  • Updated OpenAPI schema to reflect the actual response format

API Response (before → after)

Before:

{ "viewlog": "Not yet implemented", ... }

After:

{
  "viewlog": {
    "asset_id": "abc123",
    "asset_name": "My Video",
    "mimetype": "video",
    "started_at": "2024-01-15T12:00:00+00:00"
  },
  ...
}

Or when no playback has occurred:

{ "viewlog": "No data", ... }

How It Works

The viewlog.db file lives in ~/.screenly/ which is shared between the viewer and server containers via the /data/.screenly bind mount. The viewer writes, the server reads.

Test plan

  • Start player with assets — verify viewlog.db is created and populated
  • Call GET /api/v2/info — verify viewlog field contains last played asset details
  • Call info endpoint on fresh install — verify viewlog returns "No data"
  • Updated existing tests to expect "No data" instead of "Not yet implemented"

Add playback logging to the viewer: every time an asset starts playing,
a record is written to ~/.screenly/viewlog.db with the asset ID, name,
mimetype, URI, timestamp, and duration. This implements the previously
stubbed-out viewlog feature in the /api/v2/info endpoint.

Changes:
- viewer/__init__.py: Add _init_viewlog_db(), _log_playback(), and
  _get_viewlog_db_path() functions. Initialize DB on viewer setup,
  log each asset playback in asset_loop()
- api/views/mixins.py: Replace 'Not yet implemented' placeholder with
  _get_viewlog() that reads the last entry from viewlog.db
- api/views/v2.py: Update InfoViewV2 to use _get_viewlog() and update
  OpenAPI schema to reflect the actual response format
- api/tests/test_info_endpoints.py: Update expected viewlog value from
  'Not yet implemented' to 'No data' (when viewlog.db doesn't exist)

The viewlog.db is shared between viewer and server containers via the
/data/.screenly bind mount, enabling the server to read what the
viewer is currently displaying.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Alex1981-tech Alex1981-tech requested a review from a team as a code owner February 15, 2026 07:48
@nicomiguelino
Copy link
Contributor

@Alex1981-tech, thank you for opening a pull request! I will test and review the changes when I get the chance.
In the meantime, please continue testing your changes and fix failures in checks—linting & formatting, tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Alex1981-tech
Copy link
Author

CI update: Fixed ruff format. The remaining test failure (test_add_asset_url) is a pre-existing flaky Selenium integration test unrelated to this PR — it fails on other PRs as well (e.g. Dependabot).

@sonarqubecloud
Copy link

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.

2 participants