The Movie Database 支持

Thanks for this API!

Running into a strange bug... The following code works great for a list of movies, but for a list of TV shows, it returns the correct total_results and object_ids, but the results array is empty.

Any idea why?

const fetch = require(`node-fetch`);
const Bottleneck = require(`bottleneck`);

const limiter = new Bottleneck({
  reservoir: 40, // max requests
  reservoirRefreshAmount: 40,
  reservoirRefreshInterval: 10 * 1000, // time span
  maxConcurrent: 1,
  minTime: 10000 / 40 // avg MS per request
});

async function fetchTMDBListData(listId) {
  let items = [];
  let page = 1;
  let totalPages;

  async function fetch20Items() {
    return await fetch(
      `https://api.themoviedb.org/4/list/${listId}?sort_by=release_date.desc&page=${page}`,
      {
        headers: {
          Accept: "application/json",
          Authorization: `Bearer ${process.env.TMDB_READ_ACCESS_TOKEN}`
        }
      }
    );
  }

  do {
    try {
      const response = await limiter.schedule(() => fetch20Items());
      const data = await response.json();
      totalPages = data.total_pages;
      items.push(...data.results);
    } catch (error) {
      console.log("fetchTMDBListData error", error);
    }

    page++;
  } while (page <= totalPages);

  return Promise.all(items);
}

2 回复(第 1 页,共 1 页)

Jump to last post

Nevermind! It was just the sort_by value.

When querying the tv api, release_date needs to become primary_release_date .

Hi @ooloth,

Yes, I believe the common date sort field I setup for lists is primary_release_date. Otherwise on TV, I always use first_air_date. This is the same as how discover works.

Anyways, happy to hear you sorted it.

找不到电影或剧集?登录并创建它吧。

全站通用

s 聚焦到搜索栏
p 打开个人资料菜单
esc 关闭打开的窗口
? 打开键盘快捷键窗口

在媒体页面

b 返回(或返回上级)
e 进入编辑页面

在电视季页面

(右箭头)下一季
(左箭头)前一季

在电视集页面

(右箭头)下一集
(左箭头)前一集

在所有图像页面

a 打开添加图片窗口

在所有编辑页面

t 打开翻译选择器
ctrl+ s 提交

在讨论页面

n 创建新讨论
w 切换关注状态
p 设为公开 / 私密讨论
c 关闭 / 开放讨论
a 打开活动页
r 回复讨论
l 跳转至最新回复
ctrl+ enter 发送信息
(右箭头)下一页
(左箭头)前一页

设置

想给这个条目评分或将其添加到片单中?

登录

还不是会员?

注册加入社区