UNPKG

streaming-availability

Version:

Streaming Availability API allows getting streaming availability information of movies and series; and querying the list of available shows on streaming services such as Netflix, Disney+, Apple TV, Max and Hulu across 59 countries!

71 lines (67 loc) 2.36 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Search Example</title> <style> #result { display: flex; flex-wrap: wrap; gap: 1em; } </style> </head> <body> <label for="title">Title:</label><input id="title" type="text"> <div id="result"></div> <script src="https://cdn.jsdelivr.net/gh/movieofthenight/ts-streaming-availability@2.1.0/bundle.js"></script> <script> // Create the client const RAPID_API_KEY = "PUT_YOUR_RAPIDAPI_KEY_HERE"; const client = new streamingAvailability.DefaultApi(new streamingAvailability.Configuration({apiKey: RAPID_API_KEY})); const country = "us"; // Update with other country codes as you want const titleInput = document.getElementById("title"); const resultDiv = document.getElementById("result"); // When there's a new input on the title input, then search for the given title titleInput.addEventListener("input", () => { let title = titleInput.value; // Title is too short, don't do anything if(title.length < 3) { return; } client.searchByTitle({ title: title, country: country, }).then(response => { const result = response.result; // Clean the resultDiv from the previous items added, if any resultDiv.innerHTML = ""; response.result.forEach(show => { // If no streaming options are available, then skip if(show.streamingInfo[country] == null) { return; } show.streamingInfo[country].forEach(streamingOption => { // Prepare the display text for the streaming option let text = `${show.title} is available on ${streamingOption.service} via ${streamingOption.streamingType}`; // If the video quality info is available, insert it to the text if(streamingOption.quality != null) { text += ` with ${streamingOption.quality.toUpperCase()} quality`; } // If the price info (for rentable/buyable shows) is available, insert it to the text if(streamingOption.price != null) { text += ` for ${streamingOption.price.formatted}`; } // Create a new link let a = document.createElement("a"); // Give a link deep to the streaming option a.href = streamingOption.link; a.innerText = text; resultDiv.appendChild(a); }); }); }); }); </script> </body> </html>