Update app.js
Browse files
app.js
CHANGED
|
@@ -31,22 +31,8 @@ const manifest = {
|
|
| 31 |
|
| 32 |
const builder = new addonBuilder(manifest);
|
| 33 |
|
| 34 |
-
//
|
| 35 |
-
const
|
| 36 |
-
"Writers on the Borders A Journey to Palestine(s) Samir Abdallah.avi",
|
| 37 |
-
"With God on our Side (2010) Porter Speakman Jr..avi",
|
| 38 |
-
"Witchhunt 2019.m4v",
|
| 39 |
-
"Where Should the Birds Fly (2013) Fida Qishta.m4v",
|
| 40 |
-
"Wall 2004 Simone Bitton.m4v",
|
| 41 |
-
"True.Stories Defamation 2010.mkv",
|
| 42 |
-
"This_World_-_The_Balfour_Declaration_Britains_Promise_to_the_Holy_Land.mp4",
|
| 43 |
-
"This Is Palestine 720P 2017.mp4",
|
| 44 |
-
"The.Gatekeepers 2012 Dror Moreh 720p h264.m4v",
|
| 45 |
-
"The Zionist Story (2010) Ronen Berelovich.mpg",
|
| 46 |
-
"The Occupation of the American Mind - Israel's Public Relations War in the United States (2016) 1080p Documentary.mp4",
|
| 47 |
-
"The Law In These Parts (2011) Ra'anan Alexandrowicz.m4v",
|
| 48 |
-
"The Iron Wall (2006) Mohammed Alatar.AVI"
|
| 49 |
-
];
|
| 50 |
|
| 51 |
// Catalog handler
|
| 52 |
builder.defineCatalogHandler(({ type, id }) => {
|
|
@@ -58,6 +44,10 @@ builder.defineCatalogHandler(({ type, id }) => {
|
|
| 58 |
poster: "https://via.placeholder.com/150", // Placeholder image URL
|
| 59 |
description: `File size: ${file.size}`
|
| 60 |
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
return Promise.resolve({ metas });
|
| 62 |
}
|
| 63 |
return Promise.reject("Invalid catalog request.");
|
|
@@ -68,6 +58,7 @@ builder.defineMetaHandler(({ id }) => {
|
|
| 68 |
const index = parseInt(id.split("_")[1]);
|
| 69 |
const file = torrentInfo.files[index];
|
| 70 |
if (file) {
|
|
|
|
| 71 |
return Promise.resolve({
|
| 72 |
meta: {
|
| 73 |
id,
|
|
@@ -81,37 +72,40 @@ builder.defineMetaHandler(({ id }) => {
|
|
| 81 |
return Promise.reject("Invalid meta request.");
|
| 82 |
});
|
| 83 |
|
| 84 |
-
// Stream handler
|
| 85 |
builder.defineStreamHandler(({ id }) => {
|
| 86 |
const index = parseInt(id.split("_")[1]);
|
| 87 |
const file = torrentInfo.files[index];
|
|
|
|
|
|
|
|
|
|
| 88 |
if (file) {
|
|
|
|
|
|
|
|
|
|
| 89 |
return new Promise((resolve, reject) => {
|
| 90 |
const existingTorrent = client.get(magnetURI);
|
| 91 |
|
| 92 |
const onTorrentReady = (torrent) => {
|
| 93 |
console.log("Torrent ready. Files available:");
|
| 94 |
|
| 95 |
-
//
|
| 96 |
torrent.files.forEach((f) => {
|
| 97 |
console.log(`Available file in torrent: ${f.name}`);
|
| 98 |
});
|
| 99 |
|
| 100 |
-
//
|
| 101 |
-
const streamFile = torrent.files.find(
|
| 102 |
-
|
| 103 |
-
console.log(`Checking if "${f.name}" matches "${fileName}"`);
|
| 104 |
-
return f.name.toLowerCase().includes(fileName.toLowerCase());
|
| 105 |
-
})
|
| 106 |
);
|
| 107 |
|
| 108 |
if (streamFile) {
|
|
|
|
| 109 |
streamFile.select();
|
| 110 |
-
const streamURL = `http://localhost:3000/${encodeURIComponent(
|
| 111 |
-
console.log(`Matched and streaming file: ${streamFile.name}`);
|
| 112 |
resolve({ streams: [{ url: streamURL }] });
|
| 113 |
} else {
|
| 114 |
-
console.warn(`File not found in torrent`);
|
| 115 |
resolve({ streams: [{ title: "File not available", url: "" }] });
|
| 116 |
}
|
| 117 |
};
|
|
|
|
| 31 |
|
| 32 |
const builder = new addonBuilder(manifest);
|
| 33 |
|
| 34 |
+
// Normalize function to standardize file names
|
| 35 |
+
const normalize = (str) => str.toLowerCase().trim().replace(/\s+/g, " ");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
// Catalog handler
|
| 38 |
builder.defineCatalogHandler(({ type, id }) => {
|
|
|
|
| 44 |
poster: "https://via.placeholder.com/150", // Placeholder image URL
|
| 45 |
description: `File size: ${file.size}`
|
| 46 |
}));
|
| 47 |
+
|
| 48 |
+
// Log the catalog files to check which ones are being returned
|
| 49 |
+
console.log("Catalog handler triggered. Returning metas:", metas.map((meta) => meta.name)); // Logs filenames
|
| 50 |
+
|
| 51 |
return Promise.resolve({ metas });
|
| 52 |
}
|
| 53 |
return Promise.reject("Invalid catalog request.");
|
|
|
|
| 58 |
const index = parseInt(id.split("_")[1]);
|
| 59 |
const file = torrentInfo.files[index];
|
| 60 |
if (file) {
|
| 61 |
+
console.log(`Meta handler triggered for file: ${file.path}`); // Logging meta handler output
|
| 62 |
return Promise.resolve({
|
| 63 |
meta: {
|
| 64 |
id,
|
|
|
|
| 72 |
return Promise.reject("Invalid meta request.");
|
| 73 |
});
|
| 74 |
|
| 75 |
+
// Stream handler with detailed logging
|
| 76 |
builder.defineStreamHandler(({ id }) => {
|
| 77 |
const index = parseInt(id.split("_")[1]);
|
| 78 |
const file = torrentInfo.files[index];
|
| 79 |
+
|
| 80 |
+
console.log(`Stream handler triggered for ID: ${id}, looking for file at index: ${index}`);
|
| 81 |
+
|
| 82 |
if (file) {
|
| 83 |
+
console.log("Attempting to find the file in the torrent:", file.path);
|
| 84 |
+
console.log("File name from the torrent JSON:", torrentInfo.files.map((f) => f.path)); // Log all available torrent file names
|
| 85 |
+
|
| 86 |
return new Promise((resolve, reject) => {
|
| 87 |
const existingTorrent = client.get(magnetURI);
|
| 88 |
|
| 89 |
const onTorrentReady = (torrent) => {
|
| 90 |
console.log("Torrent ready. Files available:");
|
| 91 |
|
| 92 |
+
// Log all files in the torrent for debugging
|
| 93 |
torrent.files.forEach((f) => {
|
| 94 |
console.log(`Available file in torrent: ${f.name}`);
|
| 95 |
});
|
| 96 |
|
| 97 |
+
// Match file using normalized names
|
| 98 |
+
const streamFile = torrent.files.find(
|
| 99 |
+
(f) => normalize(f.name) === normalize(file.path)
|
|
|
|
|
|
|
|
|
|
| 100 |
);
|
| 101 |
|
| 102 |
if (streamFile) {
|
| 103 |
+
console.log(`Matched file: ${file.path}`);
|
| 104 |
streamFile.select();
|
| 105 |
+
const streamURL = `http://localhost:3000/${encodeURIComponent(file.path)}`;
|
|
|
|
| 106 |
resolve({ streams: [{ url: streamURL }] });
|
| 107 |
} else {
|
| 108 |
+
console.warn(`File not found in torrent: ${file.path}`);
|
| 109 |
resolve({ streams: [{ title: "File not available", url: "" }] });
|
| 110 |
}
|
| 111 |
};
|