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.
Cercare un titolo per ID IMDb o per titolo
GET https:/ 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.
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
apikeyqueryobbligatorioLa tua chiave amodb.iqueryuno trai,t,sID IMDb del titolo:ttpiù 7-9 cifre, per esempiott0137523.tqueryuno trai,t,sTitolo da cercare, restituisce la corrispondenza migliore.squeryuno trai,t,sTesto di ricerca di almeno 3 lettere, restituisce una lista.typequerymovieoseries.episodenon trova nulla.yqueryAnno di uscita.plotqueryshortofull. Predefinitoshort.pagequeryPagina dei risultati di ricerca, da 1 a 100. Si usa cons.rquerySolojson. 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
| Campo | Note |
|---|---|
Title, Year, Rated, Released, Runtime | Testo. Released si legge come 15 Oct 1999. |
Genre, Director, Writer, Actors | Nomi separati da virgole. |
Plot, Language, Country, Awards | Testo. |
Poster | Indirizzo su https:/. |
Ratings | Array di oggetti con Source e Value. |
Metascore, imdbRating, imdbVotes, imdbID | Testo, compreso il numero di voti con le virgole. |
Type | movie o series. |
DVD, BoxOffice, Production, Website | Solo film. BoxOffice porta un valore quando noto. DVD, Production e Website valgono sempre N/A. |
totalSeasons | Solo serie, come testo. Le risposte delle serie non hanno DVD, BoxOffice, Production né Website. |
Response | True 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
{
"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 -sf "https://api.amodb.dev/omdb/?s=Matrix&type=movie&page=1&apikey=$AMODB_KEY"| Campo | Note |
|---|---|
Search | Array di al massimo 10 elementi con Title, Year, imdbID, Type, Poster. |
totalResults | Conteggio di tutte le corrispondenze, come stringa. |
Response | True o False. |
{
"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",. La maggior parte arriva con HTTP 200, quindi leggi Error e decidi in base al testo, non solo allo stato HTTP.
Testo di Error | HTTP | Quando |
|---|---|---|
Movie not found! | 200 | Nessun titolo corrisponde a t, il valore di i è valido ma sconosciuto, o una pagina di ricerca è oltre l'ultima. |
Incorrect IMDb ID. | 200 | Il valore di i non ha la forma di un ID IMDb. |
Too many results. | 200 | Il testo di ricerca è più corto di 3 lettere o corrisponde a troppi titoli. Allunga il testo o aggiungi type o y. |
Something went wrong. | 200 | Non è stato inviato nessuno tra i, t e s. |
Only r= | 400 | r è impostato su qualcosa di diverso da json. |
No API key provided. o Invalid API key! | 401 | L'apikey manca o è sbagliata. |
Request limit reached! | 429 | Oltre 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.
// 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,imdbRatingetotalResults, e trattaN/Acome mancante. - Usa
plot=fullsolo quando mostri la trama lunga.shortmantiene le risposte più piccole. - Le ricerche per
iotrestano in cache più a lungo delle ricerche cons, 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 dalposter_pathin stile TMDB e dall'elenco delle dimensioni di immagini. - Tieni la chiave su un server. Una
apikeynell'URL di una pagina è visibile a ogni visitatore.