Update app.js
Browse files30 unmodified lines313233343536373839404142434445464748495051525 unmodified lines5859606162634 unmodified lines6869707172737 unmodified lines8182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611730 unmodified linesconst builder = new addonBuilder(manifest);// List of exact filenames to hard-code for streamingconst hardCodedFiles = ["Writers on the Borders A Journey to Palestine(s) Samir Abdallah.avi","With God on our Side (2010) Porter Speakman Jr..avi","Witchhunt 2019.m4v","Where Should the Birds Fly (2013) Fida Qishta.m4v","Wall 2004 Simone Bitton.m4v","True.Stories Defamation 2010.mkv","This_World_-_The_Balfour_Declaration_Britains_Promise_to_the_Holy_Land.mp4","This Is Palestine 720P 2017.mp4","The.Gatekeepers 2012 Dror Moreh 720p h264.m4v","The Zionist Story (2010) Ronen Berelovich.mpg","The Occupation of the American Mind - Israel's Public Relations War in the United States (2016) 1080p Documentary.mp4","The Law In These Parts (2011) Ra'anan Alexandrowicz.m4v","The Iron Wall (2006) Mohammed Alatar.AVI"];// Catalog handlerbuilder.defineCatalogHandler(({ type, id }) => {5 unmodified linesposter: "https://via.placeholder.com/150", // Placeholder image URLdescription: `File size: ${file.size}`}));return Promise.resolve({ metas });}return Promise.reject("Invalid catalog request.");4 unmodified linesconst index = parseInt(id.split("_")[1]);const file = torrentInfo.files[index];if (file) {return Promise.resolve({meta: {id,7 unmodified linesreturn Promise.reject("Invalid meta request.");});// Stream handlerbuilder.defineStreamHandler(({ id }) => {const index = parseInt(id.split("_")[1]);const file = torrentInfo.files[index];if (file) {return new Promise((resolve, reject) => {const existingTorrent = client.get(magnetURI);const onTorrentReady = (torrent) => {console.log("Torrent ready. Files available:");// Force log the files in the torrent for debugging purposestorrent.files.forEach((f) => {console.log(`Available file in torrent: ${f.name}`);});// Hard-code matching the file by exact name or a substring matchconst streamFile = torrent.files.find(f =>hardCodedFiles.some(fileName => {console.log(`Checking if "${f.name}" matches "${fileName}"`);return f.name.toLowerCase().includes(fileName.toLowerCase());}));if (streamFile) {streamFile.select();const streamURL = `http://localhost:3000/${encodeURIComponent(streamFile.name)}`;console.log(`Matched and streaming file: ${streamFile.name}`);resolve({ streams: [{ url: streamURL }] });} else {console.warn(`File not found in torrent`);resolve({ streams: [{ title: "File not available", url: "" }] });}};30 unmodified lines31323334353637385 unmodified lines444546474849505152534 unmodified lines585960616263647 unmodified lines7273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011130 unmodified linesconst builder = new addonBuilder(manifest);// Normalize function to standardize file namesconst normalize = (str) => str.toLowerCase().trim().replace(/\s+/g, " ");// Catalog handlerbuilder.defineCatalogHandler(({ type, id }) => {5 unmodified linesposter: "https://via.placeholder.com/150", // Placeholder image URLdescription: `File size: ${file.size}`}));// Log the catalog files to check which ones are being returnedconsole.log("Catalog handler triggered. Returning metas:", metas.map((meta) => meta.name)); // Logs filenamesreturn Promise.resolve({ metas });}return Promise.reject("Invalid catalog request.");4 unmodified linesconst index = parseInt(id.split("_")[1]);const file = torrentInfo.files[index];if (file) {console.log(`Meta handler triggered for file: ${file.path}`); // Logging meta handler outputreturn Promise.resolve({meta: {id,7 unmodified linesreturn Promise.reject("Invalid meta request.");});// Stream handler with detailed loggingbuilder.defineStreamHandler(({ id }) => {const index = parseInt(id.split("_")[1]);const file = torrentInfo.files[index];console.log(`Stream handler triggered for ID: ${id}, looking for file at index: ${index}`);if (file) {console.log("Attempting to find the file in the torrent:", file.path);console.log("File name from the torrent JSON:", torrentInfo.files.map((f) => f.path)); // Log all available torrent file namesreturn new Promise((resolve, reject) => {const existingTorrent = client.get(magnetURI);const onTorrentReady = (torrent) => {console.log("Torrent ready. Files available:");// Log all files in the torrent for debuggingtorrent.files.forEach((f) => {console.log(`Available file in torrent: ${f.name}`);});// Match file using normalized namesconst streamFile = torrent.files.find((f) => normalize(f.name) === normalize(file.path));if (streamFile) {console.log(`Matched file: ${file.path}`);streamFile.select();const streamURL = `http://localhost:3000/${encodeURIComponent(file.path)}`;resolve({ streams: [{ url: streamURL }] });} else {console.warn(`File not found in torrent: ${file.path}`);resolve({ streams: [{ title: "File not available", url: "" }] });}};
app.js+21-27