GUI to get views, likes, and title of a YouTube video using YouTube API in Python

GUI to get views, likes, and title of a YouTube video using YouTube API in Python

Creating a GUI application in Python to fetch views, likes, and the title of a YouTube video using the YouTube API involves several steps. You'll need to use the google-api-python-client library to interact with the YouTube API and a GUI framework like Tkinter for the interface.

Steps to Create the Application:

Step 1: Install Necessary Libraries

Install google-api-python-client for YouTube API interaction and tkinter for the GUI (Tkinter is usually included with Python standard library):

pip install google-api-python-client 

Step 2: Set Up YouTube API

  1. Go to Google Cloud Console.
  2. Create a new project.
  3. Navigate to "APIs & Services > Library".
  4. Search for "YouTube Data API v3" and enable it.
  5. Go to "Credentials" and create credentials for your application to get an API key.

Step 3: Create the GUI Application

Write a Python script to create the GUI and handle API requests:

import tkinter as tk from tkinter import ttk from googleapiclient.discovery import build # Function to fetch video details def fetch_video_details(): api_key = "YOUR_API_KEY" # Replace with your API Key youtube = build('youtube', 'v3', developerKey=api_key) video_id = url_entry.get() request = youtube.videos().list(part='snippet,statistics', id=video_id) response = request.execute() if response['items']: video_details = response['items'][0] title = video_details['snippet']['title'] views = video_details['statistics']['viewCount'] likes = video_details['statistics']['likeCount'] title_label.config(text=f"Title: {title}") views_label.config(text=f"Views: {views}") likes_label.config(text=f"Likes: {likes}") else: title_label.config(text="Video not found") views_label.config(text="") likes_label.config(text="") # Create the main window root = tk.Tk() root.title("YouTube Video Details") # Create and place widgets url_label = ttk.Label(root, text="Enter YouTube Video ID:") url_label.pack() url_entry = ttk.Entry(root) url_entry.pack() fetch_button = ttk.Button(root, text="Fetch Details", command=fetch_video_details) fetch_button.pack() title_label = ttk.Label(root, text="") title_label.pack() views_label = ttk.Label(root, text="") views_label.pack() likes_label = ttk.Label(root, text="") likes_label.pack() # Run the application root.mainloop() 

In this script, replace "YOUR_API_KEY" with your actual YouTube API key. The user will enter the YouTube video ID, and the script fetches and displays the video's title, views, and likes.

Note:

  • Ensure you have a valid YouTube API key, and quota limits are in place.
  • This script assumes the user inputs a valid YouTube video ID. You may want to add error handling for invalid inputs or API request failures.
  • The GUI is basic and functional. You can enhance it with additional features and styling as per your requirements.

By following these steps, you can create a simple GUI application to interact with the YouTube API and display video details.


More Tags

digits finite-automata dummy-data javax.activation iso8601 multimap android-sdk-tools libraries config uiactivityviewcontroller

More Programming Guides

Other Guides

More Programming Examples