I want to fetch the max resolution thumbnail from YouTube (1280x720), but OEmbed is providing only the the 480x360 thumbnail URL and there is currently no way to override that. Could a hook be provided to alter the OEmbed data? Currently one can only change the OEmbed url via hook_oembed_resource_url_alter().
{
"author_url": "https://www.youtube.com/user/ZackScott",
"provider_name": "YouTube",
"height": 270,
"thumbnail_width": 480,
"thumbnail_height": 360,
"width": 480,
"version": "1.0",
"html": "<iframe width=\"480\" height=\"270\" src=\"https://www.youtube.com/embed/M3r2XDceM6A?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>",
"title": "Amazing Nintendo Facts",
"provider_url": "https://www.youtube.com/",
"thumbnail_url": "https://i.ytimg.com/vi/M3r2XDceM6A/hqdefault.jpg",
"author_name": "ZackScott",
"type": "video"
}
Proposed solution
https://www.drupal.org/project/drupal/issues/3042423#comment-13414737
I think maybe a hook to alter metadata in a generic way might be more useful. This also allows changing / adding metadata for non-oembed sources.
Not really sure yet what the best way would be to implement that. Each source has its own getMetadata() method and having all these methods call the alter hook might not be the best way.
https://www.drupal.org/project/drupal/issues/3042423#comment-14358053
One possible way this could work is for MediaSourceBase, and all of its subclasses, to rename getMetadata() to protected function getRawMetadata(). MediaSourceBase::getMetadata() would then just call $this->getRawMetadata(), allow modules to alter the value, and then return it. This would be consistent, but it would require contrib and custom sources to rename their getMetadata() method to getRawMetadata() in order to become "alterable". But that seems like an acceptable API change to me; it won't break existing sites, but it will be required for this new hook to work.
Release snippet
New hook (hook_media_source_metadata_alter
) is available in Media to hook into the generated data.