Vimeo API: get a list of links for downloading all

2019-08-24 04:04发布

问题:

Good day.

I'm trying to get a list of all video files (links to direct downloading) from Vimeo account.

Is there a way to do it in a 1 GET request? OK, times to 100, if it is restriction of API.

I had hardcoded script, where I am making 12 GET request (1100+ videos, according to documentation, request is limited by 100 results), and then making over 1 000 requests to receive direct links.

Is there a way to to receive a list of links for downloading videous from Vimeo with one API request to server?

PS Account is PRO

import vimeo
import json
import config #token is here

client = vimeo.VimeoClient(
    token = config.token
)
per_page = 100
answerDataAll = []
for i in range(12):
    page=i+1
    getString = 'https://api.vimeo.com/me/videos?per_page='+str(per_page) + '&page=' + str(page)
    dataFromServer = client.get(getString).json()['data']
    answerDataAll.extend(dataFromServer)    

# creating list of videos
listOfItems = []
for item in answerDataAll:
    listOfItems.append( item ['uri'])

# creating list of direct links, it is the goal
listOfUrls = []

for item in listOfItems:
    # isolating digits
    videoID = ""
    for sign in item:
        if sign.isdigit():
            videoID = videoID + sign 

    requestForDownloading = client.get ('http://player.vimeo.com/video/' + videoID + '/config').json()['request']['files']['progressive']
    for itm in requestForDownloading:
        if itm['width']==640:
            urlForDownloading = itm['url']
            listOfUrls.append(urlForDownloading)

回答1:

You can get up to 100 videos per request, but understand that a request like that to /me/videos will return the full metadata for each video, which is a lot of data to parse through. The API or your client may also timeout while Vimeo's servers try to render your request.

You should use the fields parameter so that only the download metadata you need is returned. You should also specify the sort and direction, so you know exactly order the videos should be returning in. The request uri should be formatted like this:

https://api.vimeo.com/me/videos?fields=uri,name,download&page=1&per_page=100&sort=date&direction=desc

Documentation of those parameters is found here:

https://developer.vimeo.com/api/common-formats#json-filter

https://developer.vimeo.com/api/common-formats#using-the-pagination-parameter

https://developer.vimeo.com/api/common-formats#using-the-sort-parameters