refactor(buzz.ffmpeg_video_player): group video metadata into dataclass to reduce instance attributes#1544
Merged
Conversation
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).
…many-statements (R0915)
…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
…video_player.py - FfmpegVideoPlayer
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…-attributes-buzz.ffmpeg_video_player-FfmpegVideoPlayer
Collaborator
|
@josiasdev Thanks for your contributions. Good stuff, we keep pushing features, but refactoring to keep code readable is also needed. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this change is necessary
The
FfmpegVideoPlayerclass 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
R0902enabled and now scores 10.00/10 with no warnings.Changes made
_VideoInfodataclass — groups the 5 video metadata fields into a single object, following the existing_VideoParamspattern.self._infoattribute.@propertyaccessors to preserve the public API._file_path,_reader,_last_frame,_info)Notes for the reviewer
_VideoInfofollows the existing@dataclassconvention used by_VideoParamsin the same file.__init__and never mutated.player.duration_ms,player.fps, etc.) is unchanged — no modifications needed invideo_player.pyor tests.buzz/ffmpeg_video_player.pywas modified (38 insertions, 8 deletions).