Update index.js
Browse files
index.js
CHANGED
|
@@ -183,6 +183,7 @@ async function createQ(id, type) {
|
|
| 183 |
return q;
|
| 184 |
}
|
| 185 |
|
|
|
|
| 186 |
// Function to get metadata from IMDB or Stremio Cinemeta
|
| 187 |
async function getMeta(id, type) {
|
| 188 |
const [tt, s, e] = id.split(":");
|
|
@@ -190,18 +191,29 @@ async function getMeta(id, type) {
|
|
| 190 |
try {
|
| 191 |
const response = await fetch(`https://v2.sg.media-imdb.com/suggestion/t/${tt}.json`);
|
| 192 |
const json = await response.json();
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
} catch (err) {
|
| 195 |
console.log(`IMDB fetch error: ${err.message}`);
|
| 196 |
|
|
|
|
| 197 |
try {
|
| 198 |
-
|
| 199 |
const json = await response.json();
|
| 200 |
-
return json.meta;
|
| 201 |
} catch (err2) {
|
| 202 |
console.log(`Cinemeta fetch error: ${err2.message}`);
|
| 203 |
-
|
| 204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
}
|
| 206 |
}
|
| 207 |
}
|
|
|
|
| 183 |
return q;
|
| 184 |
}
|
| 185 |
|
| 186 |
+
// Function to get metadata from IMDB or Stremio Cinemeta
|
| 187 |
// Function to get metadata from IMDB or Stremio Cinemeta
|
| 188 |
async function getMeta(id, type) {
|
| 189 |
const [tt, s, e] = id.split(":");
|
|
|
|
| 191 |
try {
|
| 192 |
const response = await fetch(`https://v2.sg.media-imdb.com/suggestion/t/${tt}.json`);
|
| 193 |
const json = await response.json();
|
| 194 |
+
// Check if the response contains valid data
|
| 195 |
+
if (json.d && json.d.length > 0) {
|
| 196 |
+
return { name: json.d[0].l, year: json.d[0].y };
|
| 197 |
+
} else {
|
| 198 |
+
console.log(`No data found for IMDb ID: ${tt}`);
|
| 199 |
+
throw new Error("No valid data received from IMDb");
|
| 200 |
+
}
|
| 201 |
} catch (err) {
|
| 202 |
console.log(`IMDB fetch error: ${err.message}`);
|
| 203 |
|
| 204 |
+
let response; // Declare response variable for scope
|
| 205 |
try {
|
| 206 |
+
response = await fetch(`https://v3-cinemeta.strem.io/meta/${type}/${tt}.json`);
|
| 207 |
const json = await response.json();
|
| 208 |
+
return json.meta || { name: "Unknown", year: "Unknown" }; // Fallback if meta is not present
|
| 209 |
} catch (err2) {
|
| 210 |
console.log(`Cinemeta fetch error: ${err2.message}`);
|
| 211 |
+
if (response) {
|
| 212 |
+
// Log the response text if available
|
| 213 |
+
const text = await response.text();
|
| 214 |
+
console.log(`Cinemeta response text: ${text}`);
|
| 215 |
+
}
|
| 216 |
+
throw err2; // Rethrow the error for further handling
|
| 217 |
}
|
| 218 |
}
|
| 219 |
}
|