I've been using video embed field for months now, awesome, awesome module!!!
It would be awesome if it would support youtube playlists. They are in the format: http://www.youtube.com/playlist?list=PLAFAD1CE9CCB21F73

When I embed that link it will show the youtube player window but with an "an error occurred" message.

The iframe code is:

<iframe style="width:640px; height:360px;" src="http://www.youtube.com/embed/playlist?width=640&amp;height=360&amp;autoplay=0&amp;hd=1&amp;rel=0&amp;autohide=2&amp;showinfo=1&amp;theme=dark&amp;wmode=opaque" frameborder="0" allowfullscreen=""></iframe>

but according to the youtube embed code it should be:

<iframe width="560" height="315" src="http://www.youtube.com/embed/videoseries?list=PLAFAD1CE9CCB21F73&amp;hl=en_US" frameborder="0" allowfullscreen></iframe>

When I copy that embed code into the window it plays just fine.
Also, the video thumbnail doesn't show if you enter a playlist URL.

Thanks

UWE

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wbobeirne’s picture

Status: Active » Needs review
FileSize
1.65 KB

Good request, just needed an extra if to check for playlists. The only odd thing is that playlists need an extra ampersand on the end to take options, i.e. /embed/playlist?list=%id%&?width=640, as opposed to single videos which just do /embed/%id%?width=640

Attached is a patch that adds the support. I didn't do any heavy testing though, only your supplied playlist.

wbobeirne’s picture

It's just occurred to me that that patch does nothing for thumbnails on playlists. I'll work on that shortly. I guess I'll just grab the thumb of the first video, or something.

wbobeirne’s picture

I'm really striking out today. Patch in #1 includes a left-over dpm statement. Apologies! Attached is one that removes it.

mototribe’s picture

cool, thanks for the quick fixes. Yes, the thumbnail of the first video would be perfect.
Now, how would you retrieve an image from a playlist id?

When I view a playlist from my account it shows this url for sharing: http://www.youtube.com/playlist?list=PLE5959DFE442479A7
When I click "play all" and then copy the URL I get this:
http://www.youtube.com/watch?v=lb7vHYrTzDo&feature=share&list=PLE5959DFE...

If I click the "share" below the video I get:
http://www.youtube.com/watch?v=lb7vHYrTzDo&list=PLE5959DFE442479A7&featu...

Maybe it's easier to work with those playlist URLs?

thanks again

UWE

jec006’s picture

https://developers.google.com/youtube/2.0/reference#Playlist_feed

might be some data here or in the various docs for the youtube api about how to retrieve that info.

jec006’s picture

So it basically look like the format is something like this:

A playlist has a url like this:
http://www.youtube.com/playlist?list=PLE5959DFE442479A7

The playlist's id is then the list id minus PL so : E5959DFE442479A7

The playlists info is stored (as xml) at : https://gdata.youtube.com/feeds/api/playlists/E5959DFE442479A7?v=2

and in the xml we have:

<media:group>
<media:content url="http://www.youtube.com/p/E5959DFE442479A7" type="application/x-shockwave-flash" yt:format="5"/>
<media:description type="plain"/>
<media:thumbnail url="http://i.ytimg.com/vi/lb7vHYrTzDo/default.jpg" height="90" width="120" yt:name="default"/>
<media:thumbnail url="http://i.ytimg.com/vi/lb7vHYrTzDo/hqdefault.jpg" height="360" width="480" yt:name="hqdefault"/>
<media:title type="plain">Motorcycle Road Reviews</media:title>
<yt:duration seconds="2875"/>
</media:group>

which tells us that we have 2 thumbnails - the bigger of which is http://i.ytimg.com/vi/lb7vHYrTzDo/hqdefault.jpg

So ... should be a similar processor to how we get the regular thumbnail, just some additional api work in the thumbnail section.

jec006’s picture

Sidenote - this is also a valid link to the aforementioned playlist, which the current patch doesn't deal with:

https://www.youtube.com/view_play_list?p=E5959DFE442479A7

wbobeirne’s picture

Alright guys, I think I've covered all the bases. view_play_list links now work (Oddly enough, the ID in them is different. It lacks the 'PL' suffix that playlists have) and playlists are generating thumbnails now. If there's any other cases you can think of that this patch doesn't handle, let me know.

mototribe’s picture

that is freaking awesome!!!
Thanks so much. Both versions of the URL worked:
https://www.youtube.com/view_play_list?p=E5959DFE442479A7
http://www.youtube.com/playlist?list=PLE5959DFE442479A7

The URLs that are generated from a video within a playlist don't work (they only show the video, not the playlist):
http://www.youtube.com/watch?v=lb7vHYrTzDo&feature=share&list=PLE5959DFE...
http://www.youtube.com/watch?v=lb7vHYrTzDo&list=PLE5959DFE442479A7&featu...

I don't think that's critical, more like a "nice to have".

Thanks again for the quick turnaround and the great work!!!
Members are loving the module on my site, both for youtube and vimeo videos.
http://cruiser.mototribe.com/videos

Cheers

UWE

jec006’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

fixed ending tag

handkerchief’s picture

Version: 7.x-2.0-beta4 » 8.x-1.0-rc5
Issue summary: View changes
Status: Closed (fixed) » Active

Now the drupal 8 version doesn't support youtube playlists.

i made a quick and dirty workaround in the two functions below:

video_embed_field/src/Plugin/video_embed_field/Provider/YouTube.php

  public function renderEmbedCode($width, $height, $autoplay) {
    $videoId = $this->getVideoId();
    if (strpos($videoId, 'list') !== false) {
      return [
        '#type' => 'video_embed_iframe',
        '#provider' => 'youtube',
        '#url' => sprintf('https://www.youtube.com/embed/%s', $this->getVideoId()),
        '#attributes' => [
          'width' => $width,
          'height' => $height,
          'frameborder' => '0',
          'allowfullscreen' => 'allowfullscreen',
        ],
      ];
    }
    else {
      return [
        '#type' => 'video_embed_iframe',
        '#provider' => 'youtube',
        '#url' => sprintf('https://www.youtube.com/embed/%s', $this->getVideoId()),
        '#query' => [
          'autoplay' => $autoplay,
          'start' => $this->getTimeIndex(),
          'rel' => '0',
        ],
        '#attributes' => [
          'width' => $width,
          'height' => $height,
          'frameborder' => '0',
          'allowfullscreen' => 'allowfullscreen',
        ],
      ];
    }
  }

  public static function getIdFromInput($input) {
    $playlist = '';
    if (strpos($input, 'list') !== false) {
      // Get playlist id.
      $copy = $input;
      preg_match('([\w\-]{12,})', $copy, $playlist_id);
      $playlist = '?list=' . array_shift($playlist_id);
    }

    preg_match('/^https?:\/\/(www\.)?(youtube\.com\/watch\?.*v=|youtu\.be\/)(?<id>[0-9A-Za-z_-]*)/', $input, $matches);
    return isset($matches['id']) ? $matches['id'] . $playlist : FALSE;
  }

Note: Again, this is a quick and dirty solution, i'm sure the module contributers can integrate a better code solution in the module.

I hope this feature will be added soon.

Sam152’s picture

Status: Active » Closed (fixed)

Thanks for the feature request and reference implementation. I've opened #2688449: Support playlists in YouTube provider to deal with this. If you would like to create a patch, I can provide feedback on the code.

Sam152’s picture

Playlists added to 8.x, see above issue.

handkerchief’s picture

Oh that's great thank you. I have tested it but it is not working.

  • I checked the checkbox YouTube AND YouTube Playlist in the Video Embed field settings.
  • I edited and saved my node.

I also clear all caches but the paylist will not show up, only the first video of the playlist.

Sam152’s picture

The embedded playlists look a lot like normal videos, but they have a tab that slide in from the right. Do you want to log any further support questions in the issue above?

handkerchief’s picture

I know this, because with my temporary and dirty code the playlist has worked. But now i see only the first video without a playlist tab, like before my first comment.

Ok i found the reason:

The URL should look like this:
https://www.youtube.com/watch?v=lYFSqKXAfHM&list=PLhIv90n3FQfZPYQ-zJM5DbLl7msn-g8Em

But i insert this kind of URL:
https://www.youtube.com/watch?list=PLhIv90n3FQfZPYQ-zJM5DbLl7msn-g8Em&v=lYFSqKXAfHM

It's the same playlist and on youtube works both. But only the structure of the first URL works with the module. Maybe you can implement this other structure or you can document this somewhere. In any case thank you again.

Sam152’s picture

Ah, interesting. I'll implement both order of parameters.

Sam152’s picture