Update index.js
Browse files182 unmodified lines1831841851861871881 unmodified line190191192193194195196197198199200201202203204205206207182 unmodified linesreturn q;}// Function to get metadata from IMDB or Stremio Cinemetaasync function getMeta(id, type) {const [tt, s, e] = id.split(":");1 unmodified linetry {const response = await fetch(`https://v2.sg.media-imdb.com/suggestion/t/${tt}.json`);const json = await response.json();return { name: json.d[0].l, year: json.d[0].y };} catch (err) {console.log(`IMDB fetch error: ${err.message}`);try {const response = await fetch(`https://v3-cinemeta.strem.io/meta/${type}/${tt}.json`);const json = await response.json();return json.meta;} catch (err2) {console.log(`Cinemeta fetch error: ${err2.message}`);console.log(`Cinemeta response text: ${await response.text()}`);throw err2;}}}182 unmodified lines1831841851861871881891 unmodified line191192193194195196197198199200201202203204205206207208209210211212213214215216217218219182 unmodified linesreturn q;}// Function to get metadata from IMDB or Stremio Cinemeta// Function to get metadata from IMDB or Stremio Cinemetaasync function getMeta(id, type) {const [tt, s, e] = id.split(":");1 unmodified linetry {const response = await fetch(`https://v2.sg.media-imdb.com/suggestion/t/${tt}.json`);const json = await response.json();// Check if the response contains valid dataif (json.d && json.d.length > 0) {return { name: json.d[0].l, year: json.d[0].y };} else {console.log(`No data found for IMDb ID: ${tt}`);throw new Error("No valid data received from IMDb");}} catch (err) {console.log(`IMDB fetch error: ${err.message}`);let response; // Declare response variable for scopetry {response = await fetch(`https://v3-cinemeta.strem.io/meta/${type}/${tt}.json`);const json = await response.json();return json.meta || { name: "Unknown", year: "Unknown" }; // Fallback if meta is not present} catch (err2) {console.log(`Cinemeta fetch error: ${err2.message}`);if (response) {// Log the response text if availableconst text = await response.text();console.log(`Cinemeta response text: ${text}`);}throw err2; // Rethrow the error for further handling}}}
index.js+17-5