To create a Python script that displays the titles and links to your "Watch Later" videos on Youtube, you can use the Youtube API and the Tkinter library to create a GUI window.
Here are the general steps you can follow:
-
Install the Google API client library for Python and authenticate with your Google account. You can follow the instructions provided in the Google API documentation to create a project and obtain the necessary credentials.
-
Use the Youtube API to retrieve the list of videos in your "Watch Later" playlist. You can use the youtube.playlistItems().list() method to retrieve the list of videos in the playlist and their details.
-
Create a Tkinter window to display the list of videos. You can create a window with a scrollable frame that contains a label for each video title and a hyperlink to the video.
Here is an example code snippet that demonstrates how to retrieve the list of videos from your "Watch Later" playlist and display them in a Tkinter window:
import tkinter as tk
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
# Set up the Youtube API client
creds = Credentials.from_authorized_user_file('credentials.json', ['https://www.googleapis.com/auth/youtube.force-ssl'])
youtube = build('youtube', 'v3', credentials=creds)
# Retrieve the list of videos in the "Watch Later" playlist
playlist_items = []
next_page_token = ''
while next_page_token is not None:
playlist_response = youtube.playlistItems().list(
part='snippet',
playlistId='WL',
maxResults=50,
pageToken=next_page_token
).execute()
playlist_items += playlist_response['items']
next_page_token = playlist_response.get('nextPageToken')
# Create the Tkinter window
window = tk.Tk()
window.title('Watch Later Videos')
# Create a scrollable frame for the video titles
frame = tk.Frame(window)
frame.pack(fill=tk.BOTH, expand=True)
canvas = tk.Canvas(frame)
scrollbar = tk.Scrollbar(frame, orient=tk.VERTICAL, command=canvas.yview)
scrollable_frame = tk.Frame(canvas)
scrollable_frame.bind(
"<Configure>",
lambda e: canvas.configure(
scrollregion=canvas.bbox("all")
)
)
canvas.create_window((0, 0), window=scrollable_frame, anchor=tk.NW)
canvas.configure(yscrollcommand=scrollbar.set)
# Add a label for each video title and a hyperlink to the video
for i, item in enumerate(playlist_items):
title = item['snippet']['title']
video_id = item['snippet']['resourceId']['videoId']
link = f'https://www.youtube.com/watch?v={video_id}'
label = tk.Label(
scrollable_frame,
text=f"{i+1}. {title}",
fg="blue",
cursor="hand2"
)
label.pack(padx=10, pady=5)
label.bind("<Button-1>", lambda e: webbrowser.open_new(link))
# Pack the elements into the window and start the main loop
canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
window.mainloop()
Note that this is just an example code snippet and you may need to modify it to suit your specific requirements. You will also need to provide your own credentials file (credentials.json) and replace the playlist ID with your own "Watch Later" playlist ID if it is different.