Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Enhance thumbnail retriever to support author thumbnails #85

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

mitsuki31
Copy link
Owner

Overview

This pull request addresses issues with the thumbnail retriever functions by adding support for author thumbnails, which have a different structure compared to video thumbnails. The changes enhance the logic to correctly identify and retrieve thumbnails for both video and author entities, ensuring broader compatibility and improved functionality.

Changes Made

getAuthorThumbnails

  • Now retrieves thumbnails from the author object if the property exists and is an array.

getVideoThumbnails

  • Adjusted to access thumbnails directly from video details.

getThumbnailByResolution

  • Improved the resolution-matching logic by introducing a fallback mechanism for author thumbnails.
  • Recognizes author thumbnails by their distinct attributes (e.g., square resolutions or size parameters in URLs).
  • Refined resolution fallback, setting 'high' as the default when 'max' is unavailable.
  • Added conditional logic to handle edge cases where thumbnail dimensions or identifiers differ.

Impact

  • Fixes errors when attempting to retrieve thumbnails from authors.
  • Ensures compatibility with both video and author thumbnail structures.
  • Improves robustness of thumbnail resolution matching and fallback handling.
  • Guarantees a more consistent and reliable API for retrieving thumbnails.

Summary

This PR resolves inconsistencies in thumbnail retrieval by enhancing the retriever logic for both video and author thumbnails. It introduces targeted fixes and fallback mechanisms to handle edge cases, ensuring the library provides accurate and reliable thumbnails across different use cases.

Related changes: #84

- Fixed the `getAuthorThumbnails` function to ensure `videoDetails.author.thumbnails` is an array before accessing it.
- Updated `getVideoThumbnails` to check if `videoDetails.thumbnails` is an array for consistent thumbnail retrieval.
- Enhanced getThumbnailByResolution logic:
  - Added fallback mechanism to handle author thumbnails, recognizing their distinct properties (e.g., square dimensions or size parameters in URLs).
  - Improved resolution type fallback for cases where `max` is unavailable, defaulting to `high`.
  - Refactored key-matching logic to ensure more reliable thumbnail retrieval.
- Introduced conditional handling for thumbnails with atypical dimensions (e.g., square resolutions).
- Improved type validation for author and video thumbnail objects to prevent potential runtime errors.
@mitsuki31 mitsuki31 added bugfix Fixes any issue and bug patch Patch changes labels Jan 9, 2025
@mitsuki31 mitsuki31 self-assigned this Jan 9, 2025
@mitsuki31 mitsuki31 added this to the YTMP3-JS v2.0.0 milestone Jan 9, 2025
@mitsuki31 mitsuki31 merged commit 2344336 into master Jan 9, 2025
15 of 18 checks passed
@mitsuki31 mitsuki31 deleted the fix/validate-thumbnail-retrieval-logic branch January 9, 2025 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fixes any issue and bug patch Patch changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant