Questions

How to convert youtube video url to youtube embed url

0

I have this url

https://www.youtube.com/watch?v=38hVX42q3SE&t=430

and I want to convert it to the embed url like

https://www.youtube.com/embed/38hVX42q3SE

so that I can embed it to my webpage like this

<iframe width="560" height="315" src="https://www.youtube.com/embed/38hVX42q3SE" 
frameborder="0" gesture="media" allow="encrypted-media"
allowfullscreen></iframe>



asked 1 year, 10 months ago
Reputation: 1





1 Answer

0

We can do this way without using the complex regex in python.

We have 2 query parameters here:

v=38hVX42q3SE
t=430

just seperate out the parameters and construct the embed url.

from urlparse import parse_qsl, urlparse

params = parse_qsl(urlparse(article.youtube_url.strip()).query, keep_blank_values=True)

# Now just construct embed url
youtube_video = "https://www.youtube.com/embed/"+params[0][1]

answered 1 year, 10 months ago
Reputation: 1





Your Answer

Nothing to preview

Post Answer



Asked:  1 year, 10 months ago
Viewed:  387 times
Active:  1 year, 10 months ago