Skip to content

Instantly share code, notes, and snippets.

@felipemeres
Last active February 22, 2023 14:26
Show Gist options
  • Save felipemeres/64cb16a69c3b58b21c5e343831c522c3 to your computer and use it in GitHub Desktop.
Save felipemeres/64cb16a69c3b58b21c5e343831c522c3 to your computer and use it in GitHub Desktop.
Python script to retrieve Vimeo thumbnails using the API
import requests
import json
# Replace with your Vimeo access token
access_token = "TOKEN"
# List of Vimeo video IDs to retrieve thumbnail images for
video_ids = ["#######", "..."]
# List to store the thumbnail image URLs and video names
thumbnails = []
# Loop through the video IDs and retrieve the largest thumbnail image URL for each
for video_id in video_ids:
url = f"https://api.vimeo.com/videos/{video_id}"
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json",
"Accept": "application/vnd.vimeo.*+json;version=3.4"
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = json.loads(response.text)
sizes = data["pictures"]["sizes"]
largest_size = max(sizes, key=lambda size: size["width"])
thumbnail_url = largest_size["link"]
video_name = data["name"]
thumbnails.append((thumbnail_url, video_name))
# Write the thumbnail image URLs and video names to a text file
with open("thumbnail_urls.txt", "w") as file:
for thumbnail_url, video_name in thumbnails:
file.write(f"{video_name}: {thumbnail_url}\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment