Skip to content

Instantly share code, notes, and snippets.

@jakebellacera
Last active May 21, 2024 06:40
Show Gist options
  • Save jakebellacera/d81bbf12b99448188f183141e6696817 to your computer and use it in GitHub Desktop.
Save jakebellacera/d81bbf12b99448188f183141e6696817 to your computer and use it in GitHub Desktop.
Learn how to get the ID of any YouTube video.

How to get the ID of any YouTube Video

This article walks you through how to get the ID of any YouTube video.

How to get a YouTube video ID from a youtube.com page URL

You may be watching the video or just happened to visit a link to a video. The video ID will be located in the URL of the video page, right after the v= URL parameter.

In this case, the URL of the video is: https://www.youtube.com/watch?v=aqz-KE-bpKQ. Therefore, the ID of the video is aqz-KE-bpKQ.

How to get a YouTube video ID from a youtu.be short URL

The youtu.be URLs are created by generating a URL intendend for sharing. They differ slightly from youtube.com URLs because there are no URL parameters. Instead, the video ID is part of the URL itself.

In this case, the URL of the video is: https://youtu.be/aqz-KE-bpKQ. Therefore, the ID of the video is aqz-KE-bpKQ.

How to get a YouTube video ID from an embedded video player

The easiest method is to use the "Stats for nerds" option.

  1. Right click the embedded video player to present a menu.
  2. Select the "Stats for nerds" option in the menu.
  3. Note the "Video ID" property.

Feel free to test on this video player in the following link: http://codepen.io/anon/pen/qReQZL

@voxelshaper
Copy link

In Javascript you can:
url.split("v=")[1].split("&")[0]

example:

var url = "https://www.youtube.com/watch?v=5Fc9A6mLHJU&list=RDqk6QvwvwgNk&index=2"
url = url.split("v=")[1].split("&")[0]
console.log(url);
// id = 5Fc9A6mLHJU

@Optiri
Copy link

Optiri commented Jun 3, 2022

Is it possible to get the YouTube Video ID from the googlevideo.com URLs such as:

https://rr2---sn-mhpnnpvo-naje.googlevideo.com/videoplayback?expire=1654318977&ei=IZOaYqG6LIT6jQSX_5WABw&ip=166.70.16.67&id=o-AJNCzjmBax64MFLH1RcEPxyHmxcQh1V-kdY2xev-9D_q&itag=398&aitags=133%2C134%2C135%2C136%2C160%2C242%2C243%2C244%2C247%2C278%2C298%2C299%2C302%2C303%2C308%2C315%2C394%2C395%2C396%2C397%2C398%2C399%2C400%2C401&source=youtube&requiressl=yes&mh=aP&mm=31%2C29&mn=sn-mhpnnpvo-naje%2Csn-naj7yn76&ms=au%2Crdu&mv=m&mvi=2&pl=19&ctier=A&pfa=5&initcwndbps=1882500&hightc=yes&spc=4ocVC5kQ3L1TBGFXHq4O1cB3n6ZUId012N5MW2g3lvQm&vprv=1&mime=video%2Fmp4&ns=icsn8T4M0-wBuc1IwB2mJVoG&gir=yes&clen=91091124&dur=634.566&lmt=1649501793701287&mt=1654297024&fvip=2&keepalive=yes&fexp=24001373%2C24007246&c=WEB&txp=4432434&n=vZ7ffwe0IJc4hA&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cctier%2Cpfa%2Chightc%2Cspc%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRQIhAIn1pzdV82ZWXW8I6cgZNOEj_AazwHaDINuS2OKI2ttzAiBJ7oe8Wzlea2hNWFf5s3EIwa_9uyqldJBjL5GIM-VWDQ%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIhANmmgoVj4D-XUx7bU9Hqu6gERSZUmJi3w5Mj4jZjXMcGAiBDy_8Bj7csapRHQ-_xKweZn85YHnlI9lzidEqjNA4LJQ%3D%3D&alr=yes&cpn=PwjHXi0pFp3YQP84&cver=2.20220602.00.00&range=3504835-5108275&rn=8&rbuf=20383&pot=GpIBCmXmi1BJJNxnTjErekgyY3dCHZI8tUjV31hUGKlZxB4BAIHmjVar3neZdRWZfzxyZvH1Ut61IDjQV06qjurJURarwZNueBlpCLLgoXyCyegafV9lsZl8hkZbEKphyWl6buA35P0rtxIpATwYQQ7egpHBnGxfjqGOs5j7RCMi7boHDMXuHevz2iLux5UCyXKMVRI=

@iamvermajayant
Copy link

Thanks for the help

@Whygal
Copy link

Whygal commented Mar 13, 2023

How can I get a list of ids, from a channel, without api key?

@thedelanyo
Copy link

How about shorts?

@JAYAMURUGANJ
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment