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.
Comment | File | Size | Author |
---|---|---|---|
#5 | youtube-video_quality-7.x-1.x-3.patch | 2.11 KB | chrisvanwormer |
#4 | youtube-video_quality-7.x-1.x-2.patch | 2.11 KB | chrisvanwormer |
youtube-video_quality-7.x-1.x.patch | 1.62 KB | chrisvanwormer | |
Comments
Comment #2
chrisvanwormer CreditAttribution: chrisvanwormer commentedComment #3
guschilds CreditAttribution: guschilds at Chromatic commentedThanks 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:
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:
$form['youtube_global']
"parameters" fieldset (since, like the rest in that fieldset, it works by adding a parameter)youtube_quality
fieldset and just have a$form['youtube_global']['youtube_quality']
settingselect
field type rather thanradios
(I just committed another option to that page that uses a select list)youtube_quality
to the list of variables that get deleted withinyoutube_uninstall()
Finally, could you add the aforementioned warning in the setting's
#description
?Thanks!
Comment #4
chrisvanwormer CreditAttribution: chrisvanwormer commentedThanks 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!
Comment #5
chrisvanwormer CreditAttribution: chrisvanwormer commentedNoticed an issue with the default_value. Patched.
Comment #6
guschilds CreditAttribution: guschilds at Chromatic commentedHi 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!
Comment #7
chrisvanwormer CreditAttribution: chrisvanwormer commentedguschilds,
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. :)
Comment #8
guschilds CreditAttribution: guschilds at Chromatic commentedHey 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.