Skip to content

refactor(buzz.ffmpeg_video_player): group video metadata into dataclass to reduce instance attributes#1544

Merged
raivisdejus merged 20 commits into
chidiwilliams:mainfrom
josiasdev:refactor/remove-code-smell-too-many-instance-attributes-buzz.ffmpeg_video_player-FfmpegVideoPlayer
Jul 2, 2026
Merged

refactor(buzz.ffmpeg_video_player): group video metadata into dataclass to reduce instance attributes#1544
raivisdejus merged 20 commits into
chidiwilliams:mainfrom
josiasdev:refactor/remove-code-smell-too-many-instance-attributes-buzz.ffmpeg_video_player-FfmpegVideoPlayer

Conversation

@josiasdev

Copy link
Copy Markdown
Contributor

Why this change is necessary

The FfmpegVideoPlayer class had 8 instance attributes, exceeding Pylint's default limit of 7 (R0902: too-many-instance-attributes). This code smell indicates low cohesion — the class was storing both internal state (_file_path, _reader, _last_frame) and video metadata (duration_ms, fps, width, height, has_video) as flat attributes.

How this was tested

All 19 existing tests pass successfully:
uv run pytest tests/ffmpeg_video_player_test.py -v

Pylint was re-run with R0902 enabled and now scores 10.00/10 with no warnings.

Changes made

  1. Created _VideoInfo dataclass — groups the 5 video metadata fields into a single object, following the existing _VideoParams pattern.
  2. Replaced 5 flat attributes with a single self._info attribute.
  3. Added read-only @property accessors to preserve the public API.
Before After
8 instance attributes 4 instance attributes (_file_path, _reader, _last_frame, _info)
Pylint score: 9.94/10 Pylint score: 10.00/10

Notes for the reviewer

  • _VideoInfo follows the existing @dataclass convention used by _VideoParams in the same file.
  • All metadata is exposed as read-only properties since they are assigned once in __init__ and never mutated.
  • The external API (player.duration_ms, player.fps, etc.) is unchanged — no modifications needed in video_player.py or tests.
  • Only buzz/ffmpeg_video_player.py was modified (38 insertions, 8 deletions).

josiasdev and others added 19 commits June 17, 2026 16:42
Decompose ModelDownloader.download_model (142 statements, > 50 limit)
into four focused helpers:
  _prepare_resume_download  - existing file validation & resume logic
  _check_range_support      - server Range-request capability
  _stream_download          - HTTP streaming with progress/cancel
  _verify_sha256            - post-download integrity check

download_model now acts as a high-level orchestrator (~16 statements).
…statements (R0915)

Extraiu 7 métodos auxiliares e 3 funções modulares do método
transcribe (166 statements, limite 50), reduzindo-o para ~30 statements.

Métodos extraídos para WhisperCpp:
  - _convert_to_wav, _build_command, _run_whisper
  - _read_json_output, _parse_word_level_timings
  - _parse_segment_timings, _cleanup_files

Funções extraídas para o módulo:
  - _make_offset_mapper, _flush_complete_chars, _append_word
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.98%. Comparing base (8a2a3de) to head (f3ebcd5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1544      +/-   ##
==========================================
+ Coverage   82.92%   82.98%   +0.05%     
==========================================
  Files         108      108              
  Lines       11675    11693      +18     
==========================================
+ Hits         9682     9703      +21     
+ Misses       1993     1990       -3     
Flag Coverage Δ
Linux 81.71% <100.00%> (+0.01%) ⬆️
macOS 82.49% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…-attributes-buzz.ffmpeg_video_player-FfmpegVideoPlayer
@raivisdejus raivisdejus enabled auto-merge (squash) July 2, 2026 04:49
@raivisdejus

Copy link
Copy Markdown
Collaborator

@josiasdev Thanks for your contributions. Good stuff, we keep pushing features, but refactoring to keep code readable is also needed. Thanks!

@raivisdejus raivisdejus merged commit 191795b into chidiwilliams:main Jul 2, 2026
17 of 19 checks passed
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