To accomplish this task, you'll need to use the YouTube API to retrieve the list of videos from your Watch Later playlist, and a graphical user interface (GUI) toolkit to create a window to display the information.
Here's an example Python script using the google-auth, google-auth-oauthlib, google-auth-httplib2, google-api-python-client, and tkinter libraries to accomplish this:
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
import tkinter as tk
# Set up credentials
creds = Credentials.from_authorized_user_file('credentials.json', ['https://www.googleapis.com/auth/youtube.readonly'])
# Set up YouTube API client
youtube = build('youtube', 'v3', credentials=creds)
# Get list of videos from Watch Later playlist
playlist_items = []
next_page_token = None
while True:
request = youtube.playlistItems().list(
part='snippet',
playlistId='WL',
maxResults=50,
pageToken=next_page_token
)
response = request.execute()
playlist_items += response['items']
next_page_token = response.get('nextPageToken')
if not next_page_token:
break
# Create GUI window
root = tk.Tk()
root.title('Watch Later Videos')
root.geometry('600x400')
# Create listbox to display titles and links
listbox = tk.Listbox(root)
listbox.pack(expand=True, fill='both')
# Populate listbox with video titles and links
for item in playlist_items:
title = item['snippet']['title']
video_id = item['snippet']['resourceId']['videoId']
link = f'https://www.youtube.com/watch?v={video_id}'
listbox.insert('end', f'{title}: {link}')
# Start GUI event loop
root.mainloop()
Here's how the script works:
-
First, it sets up the google-auth and google-api-python-client libraries to authenticate with the YouTube API using OAuth2. You'll need to generate credentials for a project in the Google Cloud Console and save them to a credentials.json file in the same directory as the script.
-
It uses the build() function from the googleapiclient.discovery module to create a YouTube API client with the authenticated credentials.
-
It uses the playlistItems().list() method of the YouTube API client to retrieve the list of videos from your Watch Later playlist. The part parameter specifies that we want to retrieve the snippet data for each video, and the maxResults parameter specifies that we want to retrieve up to 50 videos at a time (the maximum allowed by the API). We loop through all pages of results using the nextPageToken field until we have retrieved all videos in the playlist.
-
It creates a tkinter window with a Listbox widget to display the video titles and links.
-
It loops through each video in the playlist, extracts the title and video ID from the snippet data, generates a link to the video using the video ID, and adds the title and link to the Listbox.
-
Finally, it starts the tkinter event loop to display the window and handle user interaction.
Note that this script assumes that you have already authenticated with the YouTube API and authorized access to your Watch Later playlist using OAuth2. If you haven't done this yet, you'll need to follow the instructions in the YouTube API documentation to set up authentication and authorization before running the script.