feat: add extended media details to Search-PatMedia output#23
Conversation
Add 11 new properties to search results with no performance impact: - Duration (milliseconds) and DurationFormatted (human-readable) - ContentRating (PG-13, R, TV-MA, etc.) - Rating and AudienceRating (critic/audience scores) - Studio (production company) - ViewCount (watch history) - OriginallyAvailableAt (release date) - ShowName, Season, Episode (for TV episodes) All fields are sourced from existing search API response data. Also adds Format-PatDuration private helper for duration formatting. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This pull request adds 11 new properties to the Search-PatMedia function's output, enriching media search results with additional metadata. The changes include creating a new private helper function Format-PatDuration to provide human-readable duration formatting.
Changes:
- Added
Format-PatDurationprivate helper function for converting milliseconds to human-readable format (e.g., "2h 16m") - Extended
Search-PatMediaoutput with 11 new properties: Duration, DurationFormatted, ContentRating, Rating, AudienceRating, Studio, ViewCount, OriginallyAvailableAt, ShowName, Season, and Episode - Added comprehensive test coverage with 17 tests for
Format-PatDurationand updatedSearch-PatMediatests with 44 additional test cases
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| PlexAutomationToolkit/Private/Format-PatDuration.ps1 | New private helper function that converts duration in milliseconds to human-readable format |
| PlexAutomationToolkit/Public/Search-PatMedia.ps1 | Added 11 new properties to search results output object with proper type conversions and null handling |
| tests/Unit/Private/Format-PatDuration.tests.ps1 | Comprehensive test suite (17 tests) covering formatting, edge cases, and pipeline support |
| tests/Unit/Public/Search-PatMedia.tests.ps1 | Updated mock data and added test cases for new properties, episode-specific fields, and null handling |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Rating = if ($item.rating) { [decimal]$item.rating } else { $null } | ||
| AudienceRating = if ($item.audienceRating) { [decimal]$item.audienceRating } else { $null } | ||
| Studio = $item.studio | ||
| ViewCount = if ($item.viewCount) { [int]$item.viewCount } else { 0 } |
There was a problem hiding this comment.
The ViewCount property is inconsistent with how other nullable properties are handled in the same object. When viewCount is null or missing, it returns 0 instead of $null. This creates a semantic difference - 0 implies "never watched" while $null would indicate "unknown". Since other properties like Duration, Rating, etc. return $null when not available, ViewCount should follow the same pattern for consistency. Consider changing the logic to: if ($item.viewCount) { [int]$item.viewCount } else { $null }
| ViewCount = if ($item.viewCount) { [int]$item.viewCount } else { 0 } | |
| ViewCount = if ($item.viewCount) { [int]$item.viewCount } else { $null } |
| Returns: "2h 16m", "45m", "1h 30m" | ||
| #> | ||
| [CmdletBinding()] | ||
| [OutputType([string])] |
There was a problem hiding this comment.
The function declares [OutputType([string])] but can return $null when the input is null or 0 (line 45). This creates a mismatch between the declared output type and actual behavior. While PowerShell doesn't strictly enforce OutputType, this could mislead developers and affect pipeline behavior. Consider either removing the OutputType attribute or changing it to allow null values. If keeping the current behavior, the test at line 110 in the test file may fail for null inputs since $null is not of type [string].
| [OutputType([string])] |
Response to Copilot Review CommentsViewCount returning
|
Summary
Search-PatMediaresults with zero performance impactFormat-PatDurationprivate helper for human-readable duration formattingNew Properties
Performance
Tested against real Plex server - no measurable performance impact since all fields come from existing search API response.
Test plan
🤖 Generated with Claude Code