Glanceway Glanceway
All sources

TMDb Trending

Entertainment v1.0.0

Trending movies and TV shows from The Movie Database

@codytseng #movies #tv #trending #entertainment

Configuration

Name Key Type Required Default Description
API Key TMDB_API_KEY secret Yes Free API key from themoviedb.org
Media Type MEDIA_TYPE select No all Type of media to show
allmovietv
Time Window TIME_WINDOW select No week Trending time window
dayweek

Source Code

version: 1.0.0
name: TMDb Trending
description: Trending movies and TV shows from The Movie Database
author: codytseng
author_url: https://github.com/codytseng
category: Entertainment
tags:
  - movies
  - tv
  - trending
  - entertainment

config:
  - key: TMDB_API_KEY
    name: API Key
    type: secret
    required: true
    description: "Free API key from themoviedb.org"
  - key: MEDIA_TYPE
    name: Media Type
    type: select
    required: false
    default: all
    description: Type of media to show
    options:
      - all
      - movie
      - tv
  - key: TIME_WINDOW
    name: Time Window
    type: select
    required: false
    default: week
    description: Trending time window
    options:
      - day
      - week
module.exports = async (api) => {
  const apiKey = api.config.get("TMDB_API_KEY");
  const mediaType = api.config.get("MEDIA_TYPE") || "all";
  const timeWindow = api.config.get("TIME_WINDOW") || "week";

  async function fetchData() {
    const url = `https://api.themoviedb.org/3/trending/${mediaType}/${timeWindow}?api_key=${apiKey}`;

    const response = await api.fetch(url);

    if (!response.ok || !response.json) {
      throw new Error(`Failed to fetch TMDB trending (HTTP ${response.status})`);
    }

    const items = response.json.results.map((item) => ({
      id: String(item.id),
      title: item.title ?? item.name ?? "Unknown",
      subtitle: item.overview,
      url: `https://www.themoviedb.org/${item.media_type}/${item.id}`,
      timestamp: item.release_date ?? item.first_air_date,
    }));
    api.emit(items);
  }

  await fetchData();

  return {
    refresh: fetchData,
  };
};