Retrieve video ID from YouTube link

Zorgan

Say I want the YouTube video ID from this link (VgC4b9K-gYU):

https://www.youtube.com/watch?v=VgC4b9K-gYU

How would I get it using Python?

Shoaib Zafar

You need to use 'urlparse' library.

Python2

>>> import urlparse
>>> url = "https://www.youtube.com/watch?v=VgC4b9K-gYU"
>>> url_parsed = urlparse.urlsplit(url)
>>> qsl = urlparse.parse_qs(url_parsed.query)
>>> qsl
{'v': ['VgC4b9K-gYU']}

Python3

from urllib import parse
url = "https://www.youtube.com/watch?v=VgC4b9K-gYU"
url_parsed = parse.urlparse(url)
qsl = parse.parse_qs(url_parsed.query)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

getting the youtube id from a link

Show one video in webview by link from YouTube

Play first youtube embedded video from a list of link using jQuery

Regex to extract both video id or playlist id from youtube url

Extract the video ID from youtube url in .net

How to open a Youtube video link directly from android app?

Extract just the audio link from a youtube video without converting

How can I get a Youtube video ID from the Youtube API given the video url?

Retrieve Video Stream from Youtube Link

Flutter Dart : How to extract youtube video ID from video URL?

Getting video id "Live Stream" from Youtube

Playing video from youtube link without UIWebView

Get youtube video id from youtube url in smarty template?

How to retrieve youtube comments from a specific video using Eclipse

Retrieve array of video IDs from youtube playlist ID

Fetch YouTube Video Id from youtube URL in zend framework

Retrieve what video resolutions(quality) a youtube video with youtube api?

Retrieve video ids from playlist id - youtube api v3

Seperate a youtube link to retrieve only the ID, and pass the ID into another variable

Youtube Video feeds link not working

Access YouTube Video URL With YouTube Video ID

Link to youtube video with start and stop

Link of embed youtube video scraping

Get youtube video Id from shared video Url

how to get video id from clicking youtube search page link in a webview

How to get the link from blogger video by the video ID?

How can I get the link to YouTube Channel from Video Page?

Get youtube video link in python

Python: getting the youtube author image from the video link