Skip to content

Instantly share code, notes, and snippets.

@hate5six
Last active January 20, 2023 10:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hate5six/c6386de369f77294757623f7a644eed3 to your computer and use it in GitHub Desktop.
Save hate5six/c6386de369f77294757623f7a644eed3 to your computer and use it in GitHub Desktop.
# Python3 script for automatically downloading
# source video files from your Vimeo account.
# Provided without warranty. Run at your own risk.
# Requirements:
# Install PyVimeo package via: pip install PyVimeo
# Store your Vimeo API Key + Token as environment variables
# Play Bob Marley - Exodus while this runs.
import vimeo
import os
from urllib.request import urlretrieve
# Load Vimeo API key and token
VIMEO_KEY = os.environ['VIMEO_KEY']
VIMEO_TOKEN = os.environ['VIMEO_TOKEN']
# Create handle to Vimeo API
v = vimeo.VimeoClient(token=VIMEO_TOKEN,key=VIMEO_KEY)
# Set directory path where to save downloads.
# Leave as-is to save in current working directory.
folder = ""
# Request the first data page and render it as a JSON
request = v.get('/me/videos')
data_page = request.json()
# Begin loop
while True:
# Iterate over each video on current page
for video in data_page['data']:
# Iterate over the download options for current video
for video_file in video['download']:
# If source video file is found, download the file
if video_file['quality'] == 'source':
link = video_file['link']
file_name = os.path.basename(link).split('%20')[0]
urlretrieve(link, os.path.join(folder, file_name))
break
# Access the next page. If last page, break
next_page = data_page['paging']['next']
if next_page is None:
break
request = v.get(next_page)
data_page = request.json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment