We had a requirement to force a default resolution on all youtube video embeds on a website. This patch adds in a fieldset to the youtube module configuration page including options to select a default resolution. The options included are Auto, 240p, 360p, 480p, 720p, and 1080p. The default behavior marks the option as "Auto" so no video is affected until a user changes the included setting.

The patch works by setting the vq parameter in the src within the embed iframe with the value set within the configuration. Youtube uses the vq parameter to set the default resolution when the video loads.

To test:

  • Navigate to the Youtube module configuration page and select an option within the new "Video Quality" fieldset and save configuration.
  • Open a page with an embedded youtube video and check the default resolution is set and/or inspect the embed iframe on the page and verify the vq parameter is being set within the src.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chrisvanwormer created an issue. See original summary.

chrisvanwormer’s picture

Issue summary: View changes
guschilds’s picture

Status: Active » Needs work

Thanks for the patch, chrisvanwormer. This option has been explored in previous issues, such as #1864920: Add ability to default to HD video. As mentioned in that issue, I was hesitant to commit something like this because YouTube seems to recommend against it. Specifically:

We recommend that you set the parameter value to default, which instructs YouTube to select the most appropriate playback quality, which will vary for different users, videos, systems and other playback conditions.

Knowing that, does it still make sense to force something other than what YouTube recommends and will provide by default? Since this has been a popular issue throughout the years, I may reconsider committing it, but would include a bit of a warning in the setting's description.

As for this specific patch, I think it would be most consistent to:

  • move this setting within the $form['youtube_global'] "parameters" fieldset (since, like the rest in that fieldset, it works by adding a parameter)
  • ditch the youtube_quality fieldset and just have a $form['youtube_global']['youtube_quality'] setting
  • use a select field type rather than radios (I just committed another option to that page that uses a select list)
  • you'll also want to add youtube_quality to the list of variables that get deleted within youtube_uninstall()

Finally, could you add the aforementioned warning in the setting's #description?

Thanks!

chrisvanwormer’s picture

Thanks so much guschilds! This was my first attempt as submitting a patch on drupal.org. Thanks a lot for the insightful response. I also apologize for my delay in responding. I've been laid up fighting off the flu.

I've included the mentioned changes within the attached patch.

We ran through the same questions you have about this functionality at our location, but in the end, the requirement kept coming up with the customer.

Thanks!

chrisvanwormer’s picture

Noticed an issue with the default_value. Patched.

guschilds’s picture

Status: Needs work » Needs review

Hi chrisvanwormer,

Happy to hear this is your first patch on d.o! Hope you've beat the flu by now.

The patch looks solid and applies properly. The setting itself works properly and applies the expected parameter to embedded videos.

That said, I'm having inconsistent results. I've tested with a few videos that have all of those size options available under "Quality" when I click on the gear. For example: https://www.youtube.com/watch?v=pFptt7Cargc. Even though I'm seeing the sizes available and am seeing the proper parameter on the embed URL, it often isn't playing the correct size. Instead it's sticking with "Auto" and plays whatever resolution it thinks is best.

Have you experienced this with any videos? Or have your tests always been successful? I believe I've had this problem in the past and am wondering if it's not reliable. That may be why they don't list in in the embed parameter documentation. Let me know what you've experienced. Thanks!

chrisvanwormer’s picture

guschilds,

My initial tests worked great. But after reading your experience I tried on multiple other videos outside of the couple tests videos I was using from our project and am now seeing mixed results. Definitely seeing the parameter being applied to the src of the embed, but it doesn't always take with the chosen option from the configuration.

You may be right. This might not be reliable in all cases. That's kind of a bummer. :)

guschilds’s picture

Status: Needs review » Closed (won't fix)

Hey chrisvanwormer, My apologies. I just saw that I never responded here. Thanks again for your work here, but I'm going to go ahead and close this because we weren't able to see consistent results. I'm guessing that will still be the case since they still do not document that parameter. If anyone comes along needing this patch and tests it with success, please reopen and I'll reconsider.