Hey guys,

I am using the youtube field module and have used it in displaying youtube videos in my website. My requirement is to have the playlist videos show up on the related videos carousel. Is that possible? If not, are there any alternate solutions for this where I can provide the playlist suggestions in the carousel other than random related videos?

Comments

sharath.chandar created an issue. See original summary.

guschilds’s picture

Title: Control over related videos carousel » Controlling the related videos carousel and/or using a custom playlist
Status: Active » Closed (works as designed)

Hi sharath.chandar,

Sorry for the delayed response, but it is possible to create a custom playlist.

Embedded YouTube videos have playlist support using a playlist parameter in the embedded video's URL (as listed here). Because this module strips any parameters by default, you'll need to do the following:

  1. Install the latest 7.x-1.x-dev release. This has the code from #2432933: Allow users to override parameters on individual videos, which has not yet made it into a release and you will need it. (It will be included in the 7.x-1.8 release when that is created, which will probably be soon.)
  2. Navigate to the YouTube module settings at admin/config/media/youtube
  3. Enable the "Allow users to override parameters." option. This is what was added in the issue I linked to. (You might want to disable "Show suggested videos when the video finishes (rel).", which is what shows the random videos at the end. It is unrelated to the playlist.)
  4. In your YouTube field, provide a value that has a playlist parameter with comma separated video IDs, as instructed by the YouTube documentation I linked to above. For example: https://www.youtube.com/watch?v=9HoUDDetAg0&playlist=Phl82D57P58,tN4WHTGWlHY,Yn2tHcZEnF0.
  5. Save the content with that field. Your embedded video should now have a playlist with the videos you've provided IDs for.

I'm going to go ahead and close this, but please reopen if you have any issues.

webservant316’s picture

Any possibility of add a default setting for the youtube after video playlist? I have many videos on my website with hundreds more expected. So rather than require a specific addition of the playlist to each video field I would instead like to express a default after video play list that is tagged on the end of all my videos.

So for example automatically paste this on the the end of every video URL, "&playlist=Phl82D57P58,tN4WHTGWlHY,Yn2tHcZEnF0". There could be other uses for this feature as well.

webservant316’s picture

Version: 7.x-1.7 » 7.x-1.8
Priority: Major » Normal
Status: Closed (works as designed) » Active
webservant316’s picture

For an initial test solution I threw these two lines in youtube.theme.inc. Works great.

// Ideally add this to the youtube module settings.  Need to consider the most flexible format.
if (!isset($query['playlist'])) { $query['playlist'] = "NB1WwAStTSc"; }

is this code block...

  // If the override setting is enabled, add any additional parameters provided
  // in the initial field value to the query of the embedded video.
  if (variable_get('youtube_override')) {
    if ($url_parts = drupal_parse_url($variables['input'])) {
      foreach ($url_parts['query'] as $key => $value) {
        if ($key == 'v') {
          continue;
        }

        $query[$key] = $value;
      }
    }
   // Ideally add this to the youtube module settings.  Need to consider the most flexible format.
   if (!isset($query['playlist'])) { $query['playlist'] = "NB1WwAStTSc"; }
  }
webservant316’s picture

any help here?

guschilds’s picture

Hi webservant316,

Because we're not actively adding new features unless they're in high demand, I wasn't planning on doing any additional development here.

If you'd like to try adding the feature, I'd recommend searching the module for "youtube_width", which is an example of a textfield setting. You could then follow that to add your own setting that eventually gets used within theme_youtube_video().

From there I'd recommend creating a patch that you can then re-apply after any additional updates. You could upload it here as well in case anyone else finds it useful. I might also be able to review it if you'd like, but I can't make any promises about it being committed.

Hope that helps!

webservant316’s picture

ok. I found the place in the code to add a one-liner for my purpose. So okay. I'll just maintain my own patch for now. Thanks for getting back to me.

guschilds’s picture

Status: Active » Closed (works as designed)

Sounds good - you're welcome. I'm going to go ahead and close this again.

webservant316’s picture

Something change in youtube. Youtube says that they play the main video first and the playlist second if available, https://developers.google.com/youtube/player_parameters. However, just noticed that if playlist is available youtube now only plays the playlist and not the main video. Dunno if this is a youtube problem or a problem with the settings in this module. I proposed #5 above to automatically add a thank you video after the main video. #5 did work, but something changed and now I use the code below...

  // If the override setting is enabled, add any additional parameters provided
  // in the initial field value to the query of the embedded video.
  if (variable_get('youtube_override')) {
    if ($url_parts = drupal_parse_url($variables['input'])) {
      foreach ($url_parts['query'] as $key => $value) {
        if ($key == 'v') {
          continue;
        }

        $query[$key] = $value;
      }
    }
	// JEFF nasty hack to add blank screen after video player
	// This should be added as a youtube module setting
	// Hack got uglier, apparently if playlist, youtube only plays the playlist
	// https://developers.google.com/youtube/player_parameters#Parameters
	if (empty($query['playlist'])) { $query['playlist'] = "$video_id,NB1WwAStTSc"; }
	else if ($query['playlist'] == $video_id) { $query['playlist'] .= ",NB1WwAStTSc"; }
  }

I will have to keep an eye out to see if youtube changes back to be in compliance with their own documentation. Worst case is that my video will play twice with this proposed code.