首页 > 解决方案 > 尝试从 TMDB 获取系列背景

问题描述

我有一个项目,我必须为系列的每个季节下载不同的背景(宽图像),我正在使用 TMDB API,我浏览了他们的 API 文档并使用了我发现的内容,但我最终得到了一个背景

我的代码

import requests
seriesname = 'Clarice'
seasnnumb = '1'
r = requests.get(f'https://api.themoviedb.org/3/search/tv? 
api_key=apikey&page=1&query={seriesname}')
response = r.json()
result = response.get('results')
print(result)

响应

[{'backdrop_path': '/eSVvx8xys2NuFhl8fevXt41wX7v.jpg',

'first_air_date': '2021-02-11',

'genre_ids': [80, 18],

'id': 103302,

'name': 'Clarice',

'origin_country': ['US'],

'original_language': 'en',

'original_name': 'Clarice',

'overview': 'In 1993, six months after the events of The Silence of the Lambs, FBI Agent Clarice 
 Starling returns to the field to pursue serial murderers and sexual predators while navigating the 
 high stakes political world of Washington, D.C.',

'popularity': 24.836,

'poster_path': '/7OFxU0bBO0HDL4klXmM1ahJPbv8.jpg',

'vote_average': 7.5,

'vote_count': 67}]

我尝试了 get Image 方法,但它只返回海报

标签: python-3.xthemoviedb-api

解决方案


https://image.tmdb.org/t/p/original/

将此附加到背景/海报路径。 例如: 'backdrop_path':'/eSVvx8xys2NuFhl8fevXt41wX7v.jpg'

https://image.tmdb.org/t/p/original/eSVvx8xys2NuFhl8fevXt41wX7v.jpg //这是原始尺寸

//您还可以指定图像的大小,例如:https ://image.tmdb.org/t/p/w{width}/eSVvx8xys2NuFhl8fevXt41wX7v.jpg 例如://要获取大小为 500px 的图像,您可以使用

https://image.tmdb.org/t/p/w500/eSVvx8xys2NuFhl8fevXt41wX7v.jpg //这是宽度500px的大小


推荐阅读