YouTube and Spotify placeholders not being downloaded
-
If I understand correctly, content-specific placeholders are supposed to be downloaded for blocked YouTube and Spotify content?
Instead, generic placeholders are shown.
How can it be fixed?
-
Hi @asafm7,
This is correct. Do you have an example where it doesn’t work? The ‘regular’ placeholder is used as a fallback, for example when YouTube placeholder cannot be downloaded, videos or content might be set to private for example.
If I have an example, I can have a better look. Thanks!
regards Aert
Thanks @asafm7 .
I managed to fix it for YouTube. The problem was probably LiteSpeed lazy loading the iframe.
I’m not sure regarding Spotify though. Do you have this functionality for Spotify?
Hi @asafm7,
There is no content-specific placeholder for Spotify, only for YouTube at the moment. Though if you are only using one Spotify embed, please know that you can customize your placeholders. Please refer to this article for more information on the subject: https://complianz.io/changing-the-google-maps-placeholder/
This will work for Spotify as well.
Regards,
LeonThanks @leonwimmenhoeve .
Can it be the plugin doesn’t get thumbnails for YouTube playlists?
- This reply was modified 1 year, 5 months ago by asafm7.
I’ve checked the code and it seems it tries to get thumbnails for playlist, but the
if (preg_match($series_pattern, $body, $matches))
here evaluates to false (youtube.php):/** * Get the first video id from a video series * * @param string $src * * @return string */ function cmplz_youtube_get_video_id_from_series($src) { $output = wp_remote_get($src); $youtube_id = false; if (isset($output['body'])) { $body = $output['body']; $body = stripcslashes($body); $series_pattern = '/VIDEO_ID\': "([^#\&\?].*?)"/i'; if (preg_match($series_pattern, $body, $matches)) { $youtube_id = $matches[1]; } } return $youtube_id; }
This is an example for a playlist URL I’m trying:
BTW, it might be possible to get the thumbnail from the playlist itself, without the need of getting the first video in it.
This code seems to work both for playlists and regular videos:
add_filter('cmplz_placeholder', 'filter_cmplz_placeholder', 10, 3); function filter_cmplz_placeholder($new_src, $type, $src) { switch ($type) { case 'youtube': $url = str_replace('/embed', '', $src); $url_encoded = urlencode($url); $response = wp_safe_remote_get('https://www.youtube.com/oembed?url=' . $url_encoded); if (!is_wp_error($response)) { $data = json_decode(wp_remote_retrieve_body($response)); $thumbnail_url = $data->thumbnail_url; $new_src = $thumbnail_url; } break; } return $new_src; }
I’ll have a look and get back to you on this.
@asafm7 If I try your youtube series:
https://youtube.com/watch?v=videoseries?list=PLy2PCKGkKRVbpzEZG0iue9xSM9eMXqNmo&enablejsapi-1
I get a “this video series is not available anymore”. Is it removed?
Regarding spotify: as far as I can see, getting an image from spotify requires an api token.
Thanks @rogierlankhorst .
Regarding the playlist, try this:
Regarding getting an image from Spotify, it is possible:
add_filter('cmplz_placeholder', 'filter_cmplz_placeholder', 10, 3); function filter_cmplz_placeholder($new_src, $type, $src) { switch ($type) { case 'spotify': $url = str_replace('/embed', '', $src); $url_encoded = urlencode($url); $response = wp_safe_remote_get('https://open.spotify.com/oembed?url=' . $url_encoded); if (!is_wp_error($response)) { $data = json_decode(wp_remote_retrieve_body($response)); $thumbnail_url = $data->thumbnail_url; $new_src = $thumbnail_url; } break; } return $new_src; }
I created a placeholder using it. You can see it here:
Discovering and Enjoying Music – Hobbies 4 Life
It probably won’t fit all cases though.
@asafm7 When I embed the above series, I get a screen capture without problems.
As for spotify, that looks really great on your site! I have been testing a bit with it. Problem is that it returns a square image, so I can’t return it “as is” in the current setup. We’re looking into it, to see if we can come up with a solution that is generic enough to fit in the general placeholders structure. Thanks for pointing it out!
Thanks @rogierlankhorst.
Regarding the playlists, I’m using ACF embed field, maybe it has something to do with it?
Regarding Spotify, yes, I imagine it is hard to create a generic implementation.
Thanks!
Hi @rogierlankhorst .
Did you maybe get a chance to go over the issue where placeholder images aren’t being downloaded for YouTube playlists when using the ACF oEmbed field?
A screenshot:
https://drive.google.com/file/d/1S04ZyZIsxk4mrrslIAyF49JtYTtn0esU/view?usp=drivesdk
Hi @asafm7,
Thank you for your patience, our developers are still trying to come up with a good solution for this.
Kind regards, Kim
Hi @asafm7,
It looks like playlists specifically doesn’t have the desired output to check the video id. We’re tying to workaround the YT API.
regards Aert
Thanks for the update.
- The topic ‘YouTube and Spotify placeholders not being downloaded’ is closed to new replies.