Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Python 3 Tkinter Script to Get Views, Likes, and Title of a YouTube Video Using YouTube Data API V3

Posted on February 12, 2023

 

 

Welcome folks today in this blog post we will be getting the likes,views and title of the youtube video using data api v3 in tkinter using python. All the full source code of the application is shown below.

 

 

Get Started

 

 

Now we need to install the below library using the pip command as show below

 

 

pip install googleapis

 

 

In order to get started you need to make an app.py file and copy paste the following code

 

 

app.py

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Import Module
from tkinter import *
from googleapiclient.discovery import build
 
# Create Object
root = Tk()
 
# Set Geometry
root.geometry("500x300")
 
# Add Label, Entry Box and Button
 
Label(root,text="Title, Views, Likes of YouTube Video", fg="blue",
font=("Helvetica 20 bold"),relief="solid",bg="white").pack(pady=10)
Label(root,text="Enter video URL or ID", font=("10")).pack()
 
video_url = Entry(root,width=40,font=("15"))
video_url.pack(pady=10)
 
Button(root,text="Get Details" ,font=("Helvetica 15 bold"),command=video_details).pack()
 
details = Label(root,text="")
details.pack(pady=10)
 
# Execute Tkinter
root.mainloop()

 

 

As you can see we have defined the widgets on the screen where we have the input field where we allow the user to enter the youtube video url and then we have the button to submit the form. And on the button onclick event we have defined the method called video_details() method. Inside this method we will calling the youtube data api to fetch the information and display it inside the tkinter app

 

Now we need to define the video_details() function as shown below

 

 

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
def video_details():
if "youtube" in video_url.get():
video_id = video_url.get()[len("https://www.youtube.com/watch?v="):]
else:
video_id = video_url.get()
 
# creating youtube resource object
youtube = build('youtube','v3',developerKey='AIzaSyBRLUapy2zEFIx9AmbaHeulBnnaJr-W4Io')
 
# retrieve youtube video results
video_request=youtube.videos().list(
part='snippet,statistics',
id=video_id
)
 
video_response = video_request.execute()
 
title = video_response['items'][0]['snippet']['title']
likes = video_response['items'][0]['statistics']['likeCount']
views = video_response['items'][0]['statistics']['viewCount']
 
details.config(text=f"Title:- {title}nLikes:- {likes}nViews:- {views}")

 

 

And inside the above code we are getting the value of the input field using the get() method. And then we are using the google apis build() method in which we will be providing the api_key. And after that we are using the list() method to retrieve the video meta information and inside this method we are passing the video_id. And then we are displaying the title,viewcount and likes of the video as shown below

 

 

 

Recent Posts

  • Angular 14/15 JWT Login & Registration Auth System in Node.js & Express Using MongoDB in Browser
  • Build a JWT Login & Registration Auth System in Node.js & Express Using MongoDB in Browser
  • React-Admin Example to Create CRUD REST API Using JSON-Server Library in Browser Using Javascript
  • Javascript Papaparse Example to Parse CSV Files and Export to JSON File and Download it as Attachment
  • Javascript Select2.js Example to Display Single & Multi-Select Dropdown & Fetch Remote Data Using Ajax in Dropdown
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme