const express = require("express");
const axios = require("axios");
const cheerio = require("cheerio");
const cors = require("cors");
const getSearch = require("./getSearch");
const getFilm = require("./getFilm");
const torrentStream = require("torrent-stream");
const WebSocket = require("ws");
const app = express();
const server = require('http').createServer(app);
const wss = new WebSocket.Server({ server: server });
const PORT = 5000;
app.use(cors());
let activeUsers = [];
console.log(wss);
app.get("/", async (req, res) => {
try {
} catch (error) {
console.log("err", error);
}
});
app.get("/qqq", async (req, res) => {
try {
const searchText = req.query.search;
const data = await getSearch(searchText);
res.json(data);
} catch (error) {
console.log("err", error);
}
});
app.get("/videoLink", async (req, res) => {
try {
const searchFilm = req.query.film;
const data = await getFilm(searchFilm);
console.log(data);
res.json(data);
} catch (error) {
console.log("err", error);
}
});
app.get("/test", async (req, res) => {
try {
const engine = torrentStream('magnet:?xt=urn:btih:b612e8b5035bf8f4f6e6bb3deec63699dbb93a39&tr=udp%3A%2F%2Fopentor.net%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=udp%3A%2F%2Fatrack.pow7.com%3A6969%2Fannounce&tr=udp%3A%2F%2Fpow7.com%3A6969%2Fannounce&tr=http%3A%2F%2Fsecure.pow7.com%2Fannounce&tr=http%3A%2F%2Ft1.pow7.com%2Fannounce&tr=udp%3A%2F%2Ft2.pow7.com%3A6969%2Fannounce&tr=http%3A%2F%2Ftracker.bittor.pw%3A1337%2Fannounce&tr=http%3A%2F%2Ftracker.dler.org%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.zer0day.to%3A1337%2Fannounce&tr=http%3A%2F%2Fbt2.t-ru.org%2Fann%3Fmagnet');
engine.on('ready', () => {
engine.files.forEach(function(file) {
console.log('filename:', file.name);
const stream = file.createReadStream();
});
});
} catch (error) {
console.log("err", error);
}
});
server.listen(PORT, () => {
console.log('Server is running on port 5000');
});