Open Error-Cezar opened 2 years ago
Updated Main.js
const Util = require("./Util"); const Constants = require("./Constants"); const miniget = require("miniget"); const m3u8 = require("m3u8stream"); const { PassThrough } = require("stream");
const createStream = () => { const stream = new PassThrough({ highWaterMark: 1024 * 512, }); stream.destroy = () => { stream._isDestroyed = true; }; return stream; };
class XVDL { constructor() { throw new Error("Cannot instantiate static class"); }
/**
@param {string} [path] Browsing path
*/
static async browse(path = undefined) {
const html = await Util.getHTML(${Constants.BASE_URL}${path && typeof path === "string" ? path : ""}
);
const { document } = Util.getDOM(html).window;
const videos = document.querySelectorAll('div[class="frame-block thumb-block "]');
let lastPageElement = document.querySelector(".last-page");
let lastPage = lastPageElement ? parseInt(lastPageElement.textContent) || 1 : 1;
const data = { videos: [], lastPage: lastPage //parseInt(document.querySelector(".last-page").textContent) || 1 };
videos.forEach(video => { const paragraph = video.querySelector('p.title'); const titleAnchor = paragraph?.querySelector("a"); const durationSpan = paragraph?.querySelector('span.duration'); const metadataParagraph = video.querySelector('p.metadata'); const channelAnchor = metadataParagraph?.querySelector('a'); const nameSpan = video.querySelector('span.name'); const img = video.querySelector('img');
if (paragraph && titleAnchor && durationSpan && metadataParagraph && channelAnchor && nameSpan && img) {
const title = titleAnchor.title;
const url = `${Constants.BASE_URL}${titleAnchor.getAttribute("href")}`;
const duration = durationSpan.textContent;
const channelUrl = `${Constants.BASE_URL}${channelAnchor.getAttribute("href")}`;
const channelName = nameSpan.textContent;
const dynamicThumbnail = img.src;
const staticThumbnail = img.getAttribute("data-src");
data.videos.push({
id: video.getAttribute("data-id"),
title: title,
url: url,
duration: duration,
channel: {
url: channelUrl,
name: channelName
},
thumbnail: {
dynamic: dynamicThumbnail,
static: staticThumbnail
}
});
} else {
console.warn('Elemento esperado não encontrado no vÃdeo:', video);
}
}); return data; }
/**
@param {string} url Video url */ static async getInfo(url) { if (!url || typeof url !== "string") throw new Error("URL must be a string."); const html = await Util.getHTML(url);
const { document } = Util.getDOM(html).window; const ratings = document.querySelectorAll(".rating-inbtn"); const vidMetadata = document.querySelector(".video-metadata");
const info = { url: url, title: document .querySelector("meta[property='og:title']") .getAttribute("content"), length: parseInt( document .querySelector("meta[property='og:duration']") .getAttribute("content") ) || 0, views: parseInt( document.querySelector(".mobile-hide").textContent.split(",").join("") ) || 0, streams: { hq: html.split("html5player.setVideoUrlHigh('")[1].split("');")[0], lq: html.split("html5player.setVideoUrlLow('")[1].split("');")[0], hls: html.split("html5player.setVideoHLS('")[1].split("');")[0], }, thumbnail: document .querySelector('meta[property="og:image"]') .getAttribute("content"), relatedVideos: Util.parseRelated( html .split(" Githubissues.
so i was trying to get info of a video but i get
TypeError: Cannot read properties of null (reading 'textContent')