Skip to content

fix: Improve music keyword detection for playback speed - #4352

Merged
ImprovedTube2 merged 2 commits into
code-charity:masterfrom
hkzo:fix/playback-speed-music-keyword-check
Sep 23, 2026
Merged

ImprovedTube2 merged 2 commits into
code-charity:masterfrom
hkzo:fix/playback-speed-music-keyword-check

Conversation

@hkzo

@hkzo hkzo commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR improves the music content detection logic to accurately identify videos and apply the appropriate playback speed adjustments.

Changes

  • Refactored keyword counting to use an array-based mechanism (splitting, trimming, and filtering) instead of match(/,/).
  • Updated the musicIdentifiersTagsOnly regex to match exact keywords without relying on surrounding comma delimiters.
  • Refactored testSongDuration to perform a proper type check using typeof.

Why

  • Inaccurate Keyword Counting: The previous logic relied on match(/,/) to count keywords, which only matched the first comma and failed to determine the total count. This resulted in an incorrect denominator and inflated music match ratios.
  • Delimiter Dependency & Loose Boundaries: The musicIdentifiersTagsOnly regex required specific surrounding delimiters (commas) and had loose boundary definitions, making it brittle, position-dependent, and prone to matching unintended strings.
  • Incorrect Type Check: testSongDuration returns undefined for video durations outside of the expected ranges (e.g., < 45s or > 720s), but the logic incorrectly compared the result against the string 'undefined' instead of verifying the type undefined.

This PR addresses these issues by normalizing input data and ensuring the implementation aligns with the original design intent for ratio calculations. The threshold of 0.08 remains unchanged.

Impact of Accurate Keyword Counting

Because the keyword ratio is now calculated using the actual count of valid keyword tags, videos with numerous general tags but only a few music-related tags may see a lower overall music match score.

Testing

  • Verified that the music identification logic correctly processes keyword arrays.
  • Confirmed that the new logic safely handles a keywordsAmount of 0 to avoid potential division-by-zero errors.
  • Verified that testSongDuration accurately validates the return value.

Notes

AI assistance was used solely for translating this PR description. All code changes and tests were performed manually.

@ImprovedTube2
ImprovedTube2 merged commit bd6ce16 into code-charity:master Sep 23, 2026
1 check passed
@ImprovedTube2

Copy link
Copy Markdown
Member

hi! @hkzo

@hkzo
hkzo deleted the fix/playback-speed-music-keyword-check branch September 24, 2026 14:06
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