Problem/Motivation

simplexml_load_file call to "http://gdata.youtube.com/feeds/api/videos/ID" returns 410 code and since the is no error handling it crashes.

Proposed resolution

Implement v3.0 API integration to fetch images. Fall back to the sane default (http://img.youtube.com/vi/[video_id]/hqdefault.jpg) if API is not configured correctly.

CommentFileSizeAuthor
#2 2619906.diff1.16 KBmikgreen
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikgreen created an issue. See original summary.

mikgreen’s picture

FileSize
1.16 KB
mikgreen’s picture

Title: YouTube API v2.0 is deprecated and does not work » Getting thumbnail through YouTube API v2.0 is deprecated and does not work
slashrsm’s picture

Issue tags: +Media Initiative, +D8Media, +Novice
+++ b/src/Plugin/MediaEntity/VideoProvider/YouTube.php
@@ -44,23 +44,7 @@ class YouTube extends VideoProviderBase implements VideoProviderInterface {
+    $maxres_thumb = 'http://img.youtube.com/vi/' . $this->matches['id'] . '/hqdefault.jpg';

Can we assume this thumbnail file exists for every video on YouTube? I remember searching docs and looking for any information about that, but I wasn't able to find anything useful.

mikgreen’s picture

Version: » 8.x-1.x-dev

It's undocumented. So we can't rely on it fully.
But seems to work on all videos. From latest to very first video no YouTube.

There's no good alternative. Using official API v3 requires getting an API key from YouTube. Which I believe is too much of a hastle for most module users.

slashrsm’s picture

I'd say we implement API v3.0 support and fall back to this thumbnail file if it is not configured properly.

slashrsm’s picture

Title: Getting thumbnail through YouTube API v2.0 is deprecated and does not work » Fetch YouTube thumbnails through v3.0 API
Issue summary: View changes
phenaproxima’s picture

Lukas von Blarer’s picture

Status: Needs review » Needs work

I tested your patch with and without an YouTube api key. Works perfectly. I only face one issue: First I used a Browser api key instead of a Server api key. When fetching a thumbnail, I got a WSOD. Shouldn't we catch that? This is the response from YouTube:

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "keyInvalid",
    "message": "Bad Request"
   }
  ],
  "code": 400,
  "message": "Bad Request"
 }
}

Except for that RTBC.

slashrsm’s picture

phenaproxima’s picture

slashrsm’s picture

Status: Needs review » Fixed

Merged. Thanks!

Lukas von Blarer’s picture

Status: Fixed » Needs review

The fallback image is not working. I created a PR for this: https://github.com/drupal-media/media_entity_embeddable_video/pull/19

phenaproxima’s picture

Status: Needs review » Fixed

That PR has been merged as well, so this is well and truly fixed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.