Search code examples
pythonlistdictionaryvimeo

Obtain relevant data from dictionaries in list


I'm trying to obtain information about my videos with certain tags on Vimeo. I've read through the API, but I can't find anything about requesting your videos which contain a certain tag. It only offers a tag search for public videos and a get all function for your own videos. So the only option it leaves me is to request all videos, then search through the dictionary for the relevant data.

However, Vimeo only allows you to request 100 videos at a time. Since there are more than 100 videos on my account I have to create a list of dictionaries to obtain all videos. This is the simplified list of dictionaries I'm talking about:

[{'data': [{'download': [{'created_time': '2017-11-30T15:01:44+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 25,
                      'height': 360,
                      'link': 'https://player.vimeo.com/play/884123433?s=245200119_1512117636_a70a08b2710ec2c731c9d39729895c76&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=05%2BF1%2BClassic%2BRaces%2B1983.%2BMonaco%2BHighlights164.mp4',
                      'md5': 'f87ad14ecf73f27bc4fd2ff537f9cf9b',
                      'quality': 'sd',
                      'size': 128905331,
                      'type': 'video/mp4',
                      'width': 520},
                     {'created_time': '2017-11-30T15:01:44+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 50,
                      'height': 1080,
                      'link': 'https://player.vimeo.com/play/884123432?s=245200119_1512117636_ffaf6e2eb391b06cff5e534dfd026204&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=05%2BF1%2BClassic%2BRaces%2B1983.%2BMonaco%2BHighlights169.mp4',
                      'md5': 'fe06de889adf38dceb92089427c4a0cc',
                      'quality': 'hd',
                      'size': 1072969191,
                      'type': 'video/mp4',
                      'width': 1560},
                     {'created_time': '2017-11-30T15:01:44+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 50,
                      'height': 720,
                      'link': 'https://player.vimeo.com/play/884123428?s=245200119_1512117636_4f7665421693d392a0e7caabb331c075&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=05%2BF1%2BClassic%2BRaces%2B1983.%2BMonaco%2BHighlights174.mp4',
                      'md5': '6b62e4aaa044f8802f6ba30c29047b69',
                      'quality': 'hd',
                      'size': 562614988,
                      'type': 'video/mp4',
                      'width': 1040},
                     {'created_time': '2017-11-30T15:01:44+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 25,
                      'height': 540,
                      'link': 'https://player.vimeo.com/play/884123427?s=245200119_1512117636_a1718ab65d37637e0406c8ab099f8f50&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=05%2BF1%2BClassic%2BRaces%2B1983.%2BMonaco%2BHighlights165.mp4',
                      'md5': '4d014ea00d0c8620869f5ad4c5b4e404',
                      'quality': 'sd',
                      'size': 364759333,
                      'type': 'video/mp4',
                      'width': 780},
                     {'created_time': '2017-11-30T15:01:44+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 25,
                      'height': 1080,
                      'link': 'https://player.vimeo.com/play/884123417?s=245200119_1512117636_9c7ad015a30585c3cedb9429ffd0c9f2&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=05%2BF1%2BClassic%2BRaces%2B1983.%2BMonaco%2BHighlights175.mp4',
                      'md5': 'd73682a6385154a83fe1653176bf17ab',
                      'quality': 'hd',
                      'size': 1071546729,
                      'type': 'video/mp4',
                      'width': 1560},
                     {'created_time': '2017-11-30T14:51:00+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 50,
                      'height': 1080,
                      'link': 'https://player.vimeo.com/play/884114225?s=245200119_1512117636_034586db598d6b398ecf86fe7bb50fb7&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=05%2BF1%2BClassic%2BRaces%2B1983.%2BMonaco%2BHighlightssource.webm',
                      'md5': '76bcb8c1cd19b7ffa4d59f7961bb3076',
                      'quality': 'source',
                      'size': 1429585788,
                      'type': 'source',
                      'width': 1560}],
        'tags': []},
    {'download': [{'created_time': '2017-11-25T18:13:28+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 25,
                      'height': 540,
                      'link': 'https://player.vimeo.com/play/880414686?s=244460915_1512117636_e99e772d06f2be1f3e792e2eaf9649ab&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=Formula1%2B2017%2BAbudhabi%2BQUalifying165.mp4',
                      'md5': '8e920c971257c4578ce9a23bcd532b2a',
                      'quality': 'sd',
                      'size': 1913433310,
                      'type': 'video/mp4',
                      'width': 960},
                     {'created_time': '2017-11-25T18:13:28+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 50,
                      'height': 720,
                      'link': 'https://player.vimeo.com/play/880414685?s=244460915_1512117636_219ce4f61b0c8169d06951488b07a242&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=Formula1%2B2017%2BAbudhabi%2BQUalifying174.mp4',
                      'md5': 'c4a58556df95ca0ee2283793b6f099cb',
                      'quality': 'hd',
                      'size': 3090734703,
                      'type': 'video/mp4',
                      'width': 1280},
                     {'created_time': '2017-11-25T18:13:28+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 50,
                      'height': 1080,
                      'link': 'https://player.vimeo.com/play/880414684?s=244460915_1512117636_5ade2bfdffc7932dd0598bfff9f7ea58&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=Formula1%2B2017%2BAbudhabi%2BQUalifying169.mp4',
                      'md5': '019552bae7ca1c71e5964c54dbdf8949',
                      'quality': 'hd',
                      'size': 5891693868,
                      'type': 'video/mp4',
                      'width': 1920},
                     {'created_time': '2017-11-25T18:13:28+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 25,
                      'height': 360,
                      'link': 'https://player.vimeo.com/play/880414679?s=244460915_1512117636_4d1dc529cad10c2753b967987b3c6b06&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=Formula1%2B2017%2BAbudhabi%2BQUalifying164.mp4',
                      'md5': '3daca0303792d0b7506b3247e7b6ee99',
                      'quality': 'sd',
                      'size': 719988849,
                      'type': 'video/mp4',
                      'width': 640},
                     {'created_time': '2017-11-25T18:13:28+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 25,
                      'height': 1080,
                      'link': 'https://player.vimeo.com/play/880414677?s=244460915_1512117636_49c3975dd10c202fddd9e4e3418a150d&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=Formula1%2B2017%2BAbudhabi%2BQUalifying175.mp4',
                      'md5': 'f1f38a8aa8612d9fa1331410a3a153f1',
                      'quality': 'hd',
                      'size': 5883105557,
                      'type': 'video/mp4',
                      'width': 1920},
                     {'created_time': '2017-11-25T18:11:34+00:00',
                      'expires': '2017-11-30T23:40:36+00:00',
                      'fps': 50,
                      'height': 1080,
                      'link': 'https://player.vimeo.com/play/880414164?s=244460915_1512117636_4a9ae40250b8d5f1ab803973cb4617cc&loc=external&context=Vimeo%5CController%5CApi%5CResources%5CUser%5CVideosController.&download=1&filename=Formula1%2B2017%2BAbudhabi%2BQUalifyingsource.',
                      'md5': '21425a206698038bc9e8114698a187e9',
                      'quality': 'source',
                      'size': 7026953324,
                      'type': 'source',
                      'width': 1920}],
        'tags': [{'canonical': 'foo',
                  'metadata': {'connections': {'videos': {'options': ['GET'],
                                                          'total': 109,
                                                          'uri': '/tags/foo/videos'}}},
                  'name': 'Foo',
                  'resource_key': '3b4ab793385a07c695ef0081210c8fd586e2d890',
                  'tag': 'Foo',
                  'uri': '/tags/foo'},
                 {'canonical': '2017',
                  'metadata': {'connections': {'videos': {'options': ['GET'],
                                                          'total': 158765,
                                                          'uri': '/tags/2017/videos'}}},
                  'name': '2017',
                  'resource_key': 'a5c9f20cc79135f49b431c20b779e7b93bd26415',
                  'tag': '2017',
                  'uri': '/tags/2017'}]}]
},"second_dict"]

What I want: I want to find all videos which contain the tag Foo, then get the download link from 'type': 'source'. So I want to end up with ["data"]["download"]["link"] where 'type':'source'.

I tried writing a bit of code which checks for tags and then creates a list with only the videos containing the 'Foo' tag:

videosFiltered = []
for entry in videos:
    for subentry in entry["data"]:
        if subentry["tags"] and subentry["tags"][0]["name"] == "Foo":
            videosFiltered.append()

But as you can see I'm failing miserably, since I'm just writing terrifying nests of for loops and if loops. I'm pretty sure I will eventually get what I want, but I was hoping you could help me find a more elegant solution to this problem.


Solution

  • /tags/:word/videos is the resource you're looking for. Hitting /tags/foo/videos should return a paginated list of videos that have the "foo" tag.

    https://developer.vimeo.com/api/endpoints/tags#GET/tags/{word}/videos