How to catch YouTube embed code and turn into URL

Posted by Jonathan Vanasco on Stack Overflow See other posts from Stack Overflow or by Jonathan Vanasco
Published on 2012-11-26T17:02:39Z Indexed on 2012/11/26 17:03 UTC
Read the original article Hit count: 227

Filed under:
|
|

I need to strip YouTube embed codes down to their URL only.

This is the exact opposite of all but one question on StackOverflow. Most people want to turn the URL into an embed code. This question addresses the usage patttern I want, but is tied to a specific embed code's regex ( Strip YouTube Embed Code Down to URL Only )

I'm not familiar with how YouTube has offered embeds over the years - or how the sizes differ. According to their current site, there are 2 possible embed templates and a variety of options. If that's it, I can handle a regex myself -- but I was hoping someone had more knowledge they could share, so I could write a proper regex pattern that matches them all and not run into endless edge-cases.

The full use case scenario :

  • user enters content in web based wysiwig editor
  • backend cleans out youtube & other embed codes; reformats approved embeds into an internal format as the text is all converted to markdown.
  • on display, appropriate current template/code display for youtube or other 3rd party site is generated

At a previous company, our tech-team devised a plan where YouTube videos were embedded by listing the URL only. That worked great , but it was in a CMS where everyone was trained. I'm trying to create a similar storage, but for user-generated-content.

© Stack Overflow or respective owner

Related posts about python

Related posts about regex