Endpoint compatibile OMDb

GET https://api.amodb.dev/omdb/ risponde a richieste in stile OMDb con gli stessi nomi. Cerca un titolo per ID IMDb con i o per titolo con t, oppure cerca con s. I link alle locandine puntano a img.amodb.dev. Sono serviti solo r=json, film e serie. Cambia l'URL di base e la chiave e un client tipico continua a funzionare.

Aggiornato il Vedi in Markdown

Cercare un titolo per ID IMDb o per titolo

GET https://api.amodb.dev/omdb/ restituisce un titolo come JSON piatto con i nomi dei campi di OMDb. Passa i per un ID IMDb come tt0137523, oppure t per un titolo. L'autenticazione è il parametro di query apikey. La risposta ha Response impostato su True in caso di successo e su False in caso di errore.

L'esempio carica Fight Club per ID IMDb e si ferma con il testo di errore di OMDb quando Response è False.

bashjspyphpgo
curl -sf "https://api.amodb.dev/omdb/?i=tt0137523&plot=short&apikey=$AMODB_KEY"
const params = new URLSearchParams({ i: 'tt0137523', plot: 'short', apikey: process.env.AMODB_KEY });
const res = await fetch(`https://api.amodb.dev/omdb/?${params}`);
if (!res.ok) throw new Error(`amodb returned ${res.status}`);
const data = await res.json();
if (data.Response === 'False') throw new Error(data.Error);
console.log(data.Title, data.Year, data.imdbRating);
import os
import requests

r = requests.get(
    "https://api.amodb.dev/omdb/",
    params={"i": "tt0137523", "plot": "short", "apikey": os.environ["AMODB_KEY"]},
    timeout=10,
)
r.raise_for_status()
data = r.json()
if data["Response"] == "False":
    raise SystemExit(data["Error"])
print(data["Title"], data["Year"], data["imdbRating"])
<?php
$query = http_build_query(['i' => 'tt0137523', 'plot' => 'short', 'apikey' => getenv('AMODB_KEY')]);
$ch = curl_init('https://api.amodb.dev/omdb/?' . $query);
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status !== 200) {
    throw new RuntimeException("amodb returned $status");
}
$data = json_decode($body, true);
if ($data['Response'] === 'False') {
    throw new RuntimeException($data['Error']);
}
echo $data['Title'], ' ', $data['Year'], ' ', $data['imdbRating'], PHP_EOL;
package main

import (
	"encoding/json"
	"fmt"
	"net/http"
	"net/url"
	"os"
	"time"
)

type Title struct {
	Title      string `json:"Title"`
	Year       string `json:"Year"`
	ImdbRating string `json:"imdbRating"`
	Response   string `json:"Response"`
	Error      string `json:"Error"`
}

func main() {
	q := url.Values{"i": {"tt0137523"}, "plot": {"short"}, "apikey": {os.Getenv("AMODB_KEY")}}
	client := &http.Client{Timeout: 10 * time.Second}
	res, err := client.Get("https://api.amodb.dev/omdb/?" + q.Encode())
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()
	if res.StatusCode != http.StatusOK {
		panic(res.Status)
	}
	var t Title
	if err := json.NewDecoder(res.Body).Decode(&t); err != nil {
		panic(err)
	}
	if t.Response == "False" {
		panic(t.Error)
	}
	fmt.Println(t.Title, t.Year, t.ImdbRating)
}

Parametri

  • apikeyqueryobbligatorio
    La tua chiave amodb.
  • iqueryuno tra i, t, s
    ID IMDb del titolo: tt più 7-9 cifre, per esempio tt0137523.
  • tqueryuno tra i, t, s
    Titolo da cercare, restituisce la corrispondenza migliore.
  • squeryuno tra i, t, s
    Testo di ricerca di almeno 3 lettere, restituisce una lista.
  • typequery
    movie o series. episode non trova nulla.
  • yquery
    Anno di uscita.
  • plotquery
    short o full. Predefinito short.
  • pagequery
    Pagina dei risultati di ricerca, da 1 a 100. Si usa con s.
  • rquery
    Solo json. Qualsiasi altro valore restituisce HTTP 400.

I parametri Season, Episode, callback e v dell'API OMDb originale non sono supportati e vengono ignorati.

Campi della risposta

CampoNote
Title, Year, Rated, Released, RuntimeTesto. Released si legge come 15 Oct 1999.
Genre, Director, Writer, ActorsNomi separati da virgole.
Plot, Language, Country, AwardsTesto.
PosterIndirizzo su https://img.amodb.dev/t/p/w300/.
RatingsArray di oggetti con Source e Value.
Metascore, imdbRating, imdbVotes, imdbIDTesto, compreso il numero di voti con le virgole.
Typemovie o series.
DVD, BoxOffice, Production, WebsiteSolo film. BoxOffice porta un valore quando noto. DVD, Production e Website valgono sempre N/A.
totalSeasonsSolo serie, come testo. Le risposte delle serie non hanno DVD, BoxOffice, Production né Website.
ResponseTrue o False, sempre una stringa.

I campi seguono OMDb, quindi un parser OMDb esistente non richiede modifiche oltre all'URL di base.

Risposta di esempio

JSON
{
  "Title": "Fight Club",
  "Year": "1999",
  "Rated": "R",
  "Released": "15 Oct 1999",
  "Runtime": "139 min",
  "Genre": "Crime, Drama, Thriller",
  "Director": "David Fincher",
  "Writer": "Chuck Palahniuk, Jim Uhls",
  "Actors": "Brad Pitt, Edward Norton, Meat Loaf",
  "Plot": "A nameless first-person narrator attends support groups in an attempt to subdue his emotional state and relieve his insomniac state.",
  "Language": "English",
  "Country": "United States, Germany",
  "Awards": "Nominated for 1 Oscar. 12 wins & 38 nominations total",
  "Poster": "https://img.amodb.dev/t/p/w300/qkrH7rjYKU4KOwwIl6wF6H3ISvm.jpg",
  "Ratings": [
    { "Source": "Internet Movie Database", "Value": "8.8/10" },
    { "Source": "Rotten Tomatoes", "Value": "81%" },
    { "Source": "Metacritic", "Value": "67/100" }
  ],
  "Metascore": "67",
  "imdbRating": "8.8",
  "imdbVotes": "2,669,989",
  "imdbID": "tt0137523",
  "Type": "movie",
  "DVD": "N/A",
  "BoxOffice": "$38,003,039",
  "Production": "N/A",
  "Website": "N/A",
  "Response": "True"
}

Per una serie come The Wire (i=tt0306414) la risposta termina con "Type": "series", "totalSeasons": "5" e "Response": "True".

Cercare con s

Invia s per ottenere una lista invece di un solo titolo. Ogni pagina contiene 10 elementi, e totalResults dà il conteggio totale come stringa. Richiedi page=2 per gli elementi da 11 a 20, e prosegui finché non hai letto totalResults elementi. Una pagina oltre l'ultima risponde Movie not found!.

curl
curl -sf "https://api.amodb.dev/omdb/?s=Matrix&type=movie&page=1&apikey=$AMODB_KEY"
CampoNote
SearchArray di al massimo 10 elementi con Title, Year, imdbID, Type, Poster.
totalResultsConteggio di tutte le corrispondenze, come stringa.
ResponseTrue o False.
JSON
{
  "Search": [
    {
      "Title": "The Matrix",
      "Year": "1999",
      "imdbID": "tt0133093",
      "Type": "movie",
      "Poster": "https://img.amodb.dev/t/p/w300/kEDbym5htJgDQNenjUtSJxAHysB.jpg"
    },
    {
      "Title": "The Matrix Reloaded",
      "Year": "2003",
      "imdbID": "tt0234215",
      "Type": "movie",
      "Poster": "https://img.amodb.dev/t/p/w300/d0xVNNxIYxId2qHkqpgE39soOvD.jpg"
    }
  ],
  "totalResults": "20",
  "Response": "True"
}

L'elenco è tagliato a 2 dei 10 elementi.

Leggere l'array Ratings

Ratings contiene un oggetto per fonte, ciascuno con Source e Value, e Value è un testo come 8.8/10. Le fonti sono Internet Movie Database, Rotten Tomatoes e Metacritic, e sono elencate solo quelle note per il titolo. I campi piatti imdbRating, imdbVotes e Metascore ripetono parte degli stessi dati. Dividi Value sulla barra se ti serve un numero. Per numeri tipizzati e un punteggio Kinopoisk e TMDB, usa invece l'endpoint delle valutazioni.

Errori

Gli errori di ricerca restituiscono {"Response":"False","Error":"..."}. La maggior parte arriva con HTTP 200, quindi leggi Error e decidi in base al testo, non solo allo stato HTTP.

Testo di ErrorHTTPQuando
Movie not found!200Nessun titolo corrisponde a t, il valore di i è valido ma sconosciuto, o una pagina di ricerca è oltre l'ultima.
Incorrect IMDb ID.200Il valore di i non ha la forma di un ID IMDb.
Too many results.200Il testo di ricerca è più corto di 3 lettere o corrisponde a troppi titoli. Allunga il testo o aggiungi type o y.
Something went wrong.200Non è stato inviato nessuno tra i, t e s.
Only r=json is supported.400r è impostato su qualcosa di diverso da json.
No API key provided. o Invalid API key!401L'apikey manca o è sbagliata.
Request limit reached!429Oltre le tue richieste al minuto. Attendi i secondi di Retry-After.

Un piano terminato risponde HTTP 402. Vedi errori e limiti di richieste.

Migrare un client OMDb

La migrazione si fa con due modifiche: l'URL di base e la chiave. Nient'altro nella richiesta cambia.

JavaScript
// Before: the base URL and key of your current OMDb setup.
// After:
const OMDB_BASE = 'https://api.amodb.dev/omdb/';
const OMDB_KEY = process.env.AMODB_KEY;

Rimuovi r=xml se lo invii. Un client che legge episodi, Season o callback ha bisogno di un'altra fonte per quelle parti. Il limite di richieste è per chiave, quindi le chiamate in stile OMDb e le chiamate in stile TMDB condividono un unico budget di 20, 40 o 120 richieste al minuto.

Note pratiche

  • Tratta ogni valore come testo. Converti tu Year, imdbRating e totalResults, e tratta N/A come mancante.
  • Usa plot=full solo quando mostri la trama lunga. short mantiene le risposte più piccole.
  • Le ricerche per i o t restano in cache più a lungo delle ricerche con s, quindi una ricerca ripetuta restituisce la risposta salvata.
  • Per ottenere un ID TMDB da un ID IMDb, chiama la ricerca per ID esterno.
  • Le locandine sono a w300. Per altre dimensioni, costruisci l'indirizzo dal poster_path in stile TMDB e dall'elenco delle dimensioni di immagini.
  • Tieni la chiave su un server. Una apikey nell'URL di una pagina è visibile a ogni visitatore.