How to watch a YouTube video using python with just 2 lines of code

ยท

3 min read

How to watch a YouTube video using python with just  2 lines of code

Hey Guys! Welcome back to another brand new post of Sai Ansul's Blog. Today we are gonna find out How to watch a YouTube video using python with just 2 lines of code , yes you heard it right just 2 lines of code.

So the process of this is also similar, though sharing the part 1 and 2.

The process is also divided in 3 parts that are:

  • Creating a project
  • Installing pywhatkit
  • 2 lines of code

Part 1

First of all you need to a python interpreter for this project in your device.

I have here used pycharm by JetBrains, you can use any other also.

image.png Then you have to name the file. I have named it as YouTube.

image.png

Then press create, after that a page would open. image.png

Then select the whole over there with Ctrl+A and click on Backspace. So now you have a empty slate open just like the below image. image.png

Part 2

Then you need to go to your Browser and search for pywhatkit.

image.png Then after you open the site, you'll see a interface like this,

image.png Then you need to click on pip install pywhatkit to copy the code. image.png

Then we again need to go to the project created. And open Terminal and paste this.

Untitled.png After clicking on that you need to paste the codepip install pywhatkit.

image.png Like this and press Enter, it will take 1-2 mins to get downloaded, till that you need to open your And when it shows the message as shown in the image, then we are good to start. image.png

Now lets proceed towards the part 3 that is to code

Now first we need to write

import pywhatkit

After that you need to write

pywhatkit.playonyt('Say hello to hashnode sponsors')

Inside the bracket you need to write the name of the video,

image.png And in just 5 seconds the video opens and it starts to play.

You can check the results out below.

You can also paste the link instead of the name of the video, this also works as the same like shown in the above video.

image.png That is it for today guys! I hope you liked the article and got to know something new.

Stay tuned for some more interesting blogs coming up soon.

If you like my content and want to support my efforts please like๐Ÿ‘๐Ÿป, share๐Ÿ“ฒ & subscribe to the newsletter to be get notified whenever I post a new blog.

You can also check out Download YouTube Videos Using Python - Your Own YouTube Downloader , In this blog Siddharth Chandra will let you know how to download a YouTube video using just 10 lines of code.

ย