Glanceway Glanceway
सभी सोर्स

TMDb Trending

मनोरंजन v1.0.0

Trending movies and TV shows from The Movie Database

@codytseng #movies #tv #trending #entertainment

कॉन्फ़िगरेशन

नाम कुंजी प्रकार आवश्यक डिफ़ॉल्ट विवरण
API Key TMDB_API_KEY secret हाँ Free API key from themoviedb.org
Media Type MEDIA_TYPE select नहीं all Type of media to show
allmovietv
Time Window TIME_WINDOW select नहीं week Trending time window
dayweek

सोर्स कोड

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
import type { GlancewayAPI, SourceMethods } from "../../types";

export default (api: GlancewayAPI): SourceMethods => {
  const apiKey = api.config.get("TMDB_API_KEY");
  const mediaType = api.config.get("MEDIA_TYPE") || "all";
  const timeWindow = api.config.get("TIME_WINDOW") || "week";

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

      const response = await api.fetch<{
        results: {
          id: number;
          title?: string;
          name?: string;
          overview: string;
          media_type: string;
          release_date?: string;
          first_air_date?: string;
        }[];
      }>(url);

      if (response.ok && response.json) {
        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);
      }
    },
  };
};