Skip to main content

Command Palette

Search for a command to run...

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

Updated
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.

F

I love watching new movies and I know there are channels on YouTube that add a lot of movies to their pages for free to watch, but video ads are becoming more intrusive, so I can't enjoy watching as usual. So I needed the opportunity to watch the video without a break for advertising. We managed to find a cool program youtube vanced thanks to it you can watch videos from YouTube without advertising, it is possible because the videos are downloaded directly to the phone and the quality is maintained. Now I can safely enjoy watching the video.

N

Awesome....Very nice....Keep it up😊😊👍👍

12
S
Sai Ansul5y ago

Thanks, glad to know you found it interesting.💯

2
S

Awesome post Sai Ansul

Thank you so much for the mention!

2
S
Sai Ansul5y ago

Thanks, your words means a lot, Btw your articles are amazing!💯

7

More from this blog

Sai Ansul's Blog

26 posts

13 Year Old Exploring Programming |Scratch | HTML | Microsoft Office Certified | Camp Google 2020 Participant 👨‍🎓