import os import requests import json from PIL import Image from io import BytesIO def get_vimeo_thumbnail(video_id): api_url = f'https://vimeo.com/api/v2/video/{video_id}.json' response = requests.get(api_url) if response.status_code == 200: video_data = response.json()[0] return video_data['thumbnail_large'] return None def download_vimeo_video(video_id, output_folder): # Set video config URL video_config_url = f'https://player.vimeo.com/video/{video_id}/config' # Send GET request to get video JSON config video_config_response = requests.get(video_config_url) video_config_json = video_config_response.json() # Get video URL video_config = video_config_json['request']['files']['progressive'][0] video_url = video_config['url'] # Prepare file name for the video video_name = f'{video_id}_{video_config["quality"]}.mp4' file_path = os.path.join(output_folder, video_name) # Check if the file already exists if os.path.exists(file_path): print(f'Video {video_name} already exists. Skipping download.') return # Download video print(f'Downloading: {video_name}') video_response = requests.get(video_url) # Save video file with open(file_path, 'wb') as video_file: video_file.write(video_response.content) print(f'Downloaded: {video_name}') # Download and create thumbnail thumbnail_url = get_vimeo_thumbnail(video_id) if thumbnail_url: thumbnail_response = requests.get(thumbnail_url) if thumbnail_response.status_code == 200: thumbnail_image = Image.open(BytesIO(thumbnail_response.content)) thumbnail_path = os.path.join(output_folder, f'{video_id}_thumbnail.jpg') thumbnail_image.save(thumbnail_path) print(f'Thumbnail created: {thumbnail_path}') else: print(f'Failed to download thumbnail for video {video_id}') else: print(f'No thumbnail found for video {video_id}') def main(): # List of Vimeo video IDs video_ids = [ # Wir gründen einen Hackerspace "99109085", # Baustelwochenende "128079323", # in neuen Räumen "214990700", ] # Output folder output_folder = 'videos' # Create output folder if it doesn't exist if not os.path.exists(output_folder): os.makedirs(output_folder) # Download videos for video_id in video_ids: download_vimeo_video(video_id, output_folder) if __name__ == '__main__': main()