WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 14 months ago

#24660 closed defect (bug) (fixed)

YouTube oEmbeds don't work for full-width YouTube video links

Reported by: designsimply Owned by: wonderboymusic
Milestone: 4.0 Priority: normal
Severity: normal Version:
Component: Embeds Keywords: has-patch
Focuses: Cc:

Description

Steps to reproduce:

  1. Go to Posts > Add New
  2. Add this to its own line in the content area: http://www.youtube.com/embed/8N_tupPBtWQ
  3. Publish the post

Screencast: http://screencast.com/t/nMCYr3N3uF

Tested with WordPress trunk version 24528 on Bluehost

Should links like http://www.youtube.com/embed/tgbNymZ7vqY be working for oEmbed, or do you just need to make sure to use links like http://www.youtube.com/watch?v=tgbNymZ7vqY to avoid the problem?

Attachments (2)

24660_patch.diff (1.2 KB) - added by fahmiadib 14 months ago.
Patch added
24660.diff (1.6 KB) - added by wonderboymusic 14 months ago.

Download all attachments as: .zip

Change History (14)

comment:1 @SergeyBiryukov2 years ago

Looks like YouTube oEmbed endpoint only works for /watch?v=... links.

This works:

http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch%3Fv%3DtgbNymZ7vqY&format=json

This returns a 404 error:

http://www.youtube.com/oembed?url=http%3A//www.youtube.com/embed/tgbNymZ7vqY&format=json
Version 0, edited 2 years ago by SergeyBiryukov (next)

comment:2 @ocean902 years ago

  • Keywords close added

The src of the returned iframe from the oEmbed endpoint contains the embed part. You should just use the links, which YouTube gives you.

comment:3 @designsimply2 years ago

I think users tend to copy out the URL from the Share > Embed section on YouTube pages, and that's what gets them confused (it gets reported from time to time in WP.com support which is why I created this ticket).

Aside: the long version of youtube.com mobile URLs have the same problem. If you are on a mobile device such as an iPad and copy the URL directly from a YouTube page, the link will not auto embed. Example link:

In contrast, auto embeds for the short version of mobile URLs worked fine in my tests:

Tested with WP trunk r24579 on Bluehost + Twenty Thirteen theme.

To fix both the "/embed/" URL and the mobile URL issues, could the unique identifier (such as "tgbNymZ7vqY") be pulled out and then used in whatever oEmbed URL structure is supported?

comment:4 @SergeyBiryukov2 years ago

  • Keywords close removed

comment:5 @aaronholbrook2 years ago

  • Keywords dev-feedback 2nd-opinion added

I tend to agree with designsimply, this may be something we wish to do simply to make the user experience that much more intuitive and simple, especially if people are having an issue copying out the URL on mobile.

I am +1 to implementing this change, but would like some dev-feedback and a second opinion on this matter.

comment:6 @wonderboymusic2 years ago

If you go to Share > Embed, it gives you the <iframe> code to paste in - using the src from there is a you-break-it-you-bought-it situation. The /embed/ and mobile with # would have to be new YouTube oEmbed providers in WP, but would need additional hacks to turn /embed/ into /watch?v=. Might be best tackled in pre_kses or something.

Jetpack does all kinds of crazy stuff to YouTube URLs. I actually turned off most of what it does on a site I am building, but for these scenarios, there is probably some useful code in there.

comment:7 @alexufo15 months ago

this is not a bug. Youtube give two types url for users:
1) short: youtu.be/tgbNymZ7vqY
2) and full: youtube.com/watch?v=tgbNymZ7vqY

link like yours youtube.com/embed/8N_tupPBtWQ
provided only for embed src in iframe or <object> tag and
not intended for use by users

comment:8 @designsimply15 months ago

If it's not a bug, then it should be an enhancement ticket. :) I posted it because I saw support tickets from several users saying it was broken. Not a crazy high priority, but it seemed like something that could just be made to work nicely with popular types of URLs that users find and enter (even if they're doing it wrong).

comment:9 @wonderboymusic15 months ago

  • Keywords needs-patch added; dev-feedback 2nd-opinion removed
  • Milestone changed from Awaiting Review to 4.0

I was about to close this, then I realized there is a slightly-relevant precedent with wp_embed_handler_googlevideo

Someone can patch this for 4.0, or we can decide that we aren't going to do anything

@fahmiadib14 months ago

Patch added

comment:10 @fahmiadib14 months ago

This patch should support embed/ and #/ for YouTube video links. Am i in the right direction here?

@wonderboymusic14 months ago

comment:11 @wonderboymusic14 months ago

  • Keywords has-patch added; needs-patch removed

24660.diff fixes /embed/.* URLs and makes them to display watch?v=.* videos

comment:12 @wonderboymusic14 months ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 28652:

Because of YouTube's overwhelming dominance in the online video space, we should help our users who paste bad URLs when possible. It is easy to fix http://youtube.com/embed/acb1233 URLs by turning them into http://youtube.com/watch?v=abc1233 embeds using an embed handler (we already have one to fix Google Video embeds).

We should avoid doing this in almost every other case, but it's YouTube, and it's an easy error for a novice to make.

Fixes #24660.

Note: See TracTickets for help on using tickets.