feat: update version to 2.0 in manifest.json; refactor getMeta and getPosts functions for improved data extraction

This commit is contained in:
Himanshu
2026-03-27 11:53:02 +05:30
parent 67167ec8d1
commit 5c7b986db8
5 changed files with 165 additions and 64 deletions

View File

@@ -40,42 +40,103 @@ export const getMeta = async ({
},
});
const $ = cheerio.load(response.data);
const infoContainer = $(".entry-content,.post-inner");
const heading = infoContainer?.find("h3");
const imdbId =
//@ts-ignore
heading?.next("p")?.find("a")?.[0]?.attribs?.href?.match(/tt\d+/g)?.[0] ||
infoContainer.text().match(/tt\d+/g)?.[0] ||
"";
// console.log(imdbId)
const infoContainer = $(
".entry-content, .post-inner, .post-content, .page-body",
);
const type = heading?.next("p")?.text()?.includes("Series Name")
? "series"
: "movie";
// console.log(type);
// title
const titleRegex = /Name: (.+)/;
const title = heading?.next("p")?.text()?.match(titleRegex)?.[1] || "";
let title = $("h1.post-title").text().trim();
if (!title) {
const heading = infoContainer?.find("h3");
const titleRegex = /Name: (.+)/;
title = heading?.next("p")?.text()?.match(titleRegex)?.[1] || "";
}
// console.log(title);
// imdbId
let imdbId =
$('a[href*="imdb.com"]').attr("href")?.match(/tt\d+/)?.[0] || "";
if (!imdbId) {
const heading = infoContainer?.find("h3");
imdbId =
//@ts-ignore
heading
?.next("p")
?.find("a")?.[0]
?.attribs?.href?.match(/tt\d+/g)?.[0] ||
infoContainer.text().match(/tt\d+/g)?.[0] ||
"";
}
// console.log(imdbId)
// type
let type = "movie";
const heading = infoContainer?.find("h3");
if (heading?.next("p")?.text()?.includes("Series Name")) {
type = "series";
}
// console.log(type);
// synopsis
const synopsisNode = //@ts-ignore
infoContainer?.find("p")?.next("h3,h4")?.next("p")?.[0]?.children?.[0];
const synopsis =
synopsisNode && "data" in synopsisNode ? synopsisNode.data : "";
let synopsis = "";
const synopsisHeader = $("h3").filter(
(i, el) =>
$(el).text().includes("SYNOPSIS/PLOT") || $(el).text().includes("Plot"),
);
if (synopsisHeader.length > 0) {
synopsis = synopsisHeader.next("p").text().trim();
}
if (!synopsis) {
const synopsisNode = //@ts-ignore
infoContainer?.find("p")?.next("h3,h4")?.next("p")?.[0]?.children?.[0];
synopsis =
synopsisNode && "data" in synopsisNode ? synopsisNode.data : "";
}
// console.log(synopsis);
// image
let image =
infoContainer?.find("img[data-lazy-src]")?.attr("data-lazy-src") || "";
infoContainer?.find("img[data-lazy-src]")?.attr("data-lazy-src") ||
infoContainer
?.find("img")
?.filter((i, el) => {
const src = $(el).attr("src");
return (
!!src &&
!src.includes("logo") &&
!src.includes("svg") &&
!src.includes("placeholder") &&
!src.includes("icon")
);
})
?.first()
?.attr("src") ||
"";
if (image.startsWith("//")) {
image = "https:" + image;
}
// console.log(image);
// console.log({title, synopsis, image, imdbId, type});
console.log({ title, synopsis, image, imdbId, type });
/// Links
const hr = infoContainer?.first()?.find("hr");
let hr = infoContainer?.first()?.find("hr");
// Try to find the HR before the download buttons if possible
const firstButton = $(".dwd-button").first();
if (firstButton.length > 0) {
const containerP = firstButton.closest("p");
let prev = containerP.prev();
while (prev.length && !prev.is("hr")) {
prev = prev.prev();
}
if (prev.is("hr")) {
hr = prev;
}
}
const list = hr?.nextUntil("hr");
const links: Link[] = [];
list.each((index, element: any) => {
@@ -86,39 +147,41 @@ export const getMeta = async ({
const quality = element?.text().match(/\d+p\b/)?.[0] || "";
// console.log(title);
// movieLinks
const movieLinks = element
?.next()
.find(".dwd-button")
.text()
.toLowerCase()
.includes("download")
? element?.next().find(".dwd-button")?.parent()?.attr("href")
: "";
const movieLinks =
element
?.next()
.find(".dwd-button")
.text()
.toLowerCase()
.includes("download") ||
element.next().find("a").text().toLowerCase().includes("download")
? element?.next().find(".dwd-button")?.parent()?.attr("href") ||
element?.next().find("a[href]")?.attr("href")
: "";
// episode links
const vcloudLinks = element
?.next()
.find(
".btn-outline[style='background:linear-gradient(135deg,#ed0b0b,#f2d152); color: white;'],.btn-outline[style='background:linear-gradient(135deg,#ed0b0b,#f2d152); color: #fdf8f2;']"
".btn-outline[style='background:linear-gradient(135deg,#ed0b0b,#f2d152); color: white;'],.btn-outline[style='background:linear-gradient(135deg,#ed0b0b,#f2d152); color: #fdf8f2;'],.btn-outline[style='background:linear-gradient(135deg,#ed0b0b,#f2d152);color: white']",
)
?.parent()
?.attr("href");
console.log(title);
const episodesLink =
(vcloudLinks
? vcloudLinks
: element
?.next()
.find(".dwd-button")
.text()
.toLowerCase()
.includes("episode")
? element?.next().find(".dwd-button")?.parent()?.attr("href")
: "") ||
?.next()
.find(".dwd-button")
.text()
.toLowerCase()
.includes("episode")
? element?.next().find(".dwd-button")?.parent()?.attr("href")
: "") ||
element
?.next()
.find(
".btn-outline[style='background:linear-gradient(135deg,#0ebac3,#09d261); color: white;']"
".btn-outline[style='background:linear-gradient(135deg,#0ebac3,#09d261); color: white;']",
)
?.parent()
?.attr("href");