从列表中的词典中获取相关数据

时间:2017-12-04 17:15:25

标签: python list dictionary vimeo

我试图通过Vimeo上的某些标签获取有关我的视频的信息。我已阅读API,但无法找到有关请求包含特定代码的视频的任何信息。它只提供公共视频的标签搜索,并为您自己的视频提供所有功能。所以它留给我的唯一选择是请求所有视频,然后在字典中搜索相关数据。

但是,Vimeo只允许您一次请求100个视频。由于我的帐户中有超过100个视频,因此我必须创建一个词典列表以获取所有视频。这是我正在谈论的简化的词典列表:

[{'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"]

我想要的是:我想查找包含标记Foo的所有视频,然后从'type': 'source'获取下载链接。所以我想最后得到["data"]["download"]["link"] 'type':'source'

我尝试编写一些检查标签的代码,然后创建一个列表,其中只包含包含' Foo'标记:

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

但正如你可以看到我悲惨地失败,因为我只是在编写可怕的for for for循环和if循环。我很确定我最终会得到我想要的东西,但我希望你能帮我找到更优雅的解决方案。

1 个答案:

答案 0 :(得分:1)

/tags/:word/videos是您正在寻找的资源。点击/tags/foo/videos应该会返回一个分页列表,其中包含" foo"标签

this answer {字} /视频