From 383a53e8d360f4819e6202ef54a9cf831d8b6b87 Mon Sep 17 00:00:00 2001 From: lem6ns Date: Sun, 30 Jan 2022 11:45:32 -0700 Subject: [PATCH] Implement vidzstore as a Movie source --- src/lib/index.js | 6 +++++- src/lib/scraper/vidzstore.js | 41 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/lib/scraper/vidzstore.js diff --git a/src/lib/index.js b/src/lib/index.js index be24b993..75e73d22 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -1,11 +1,13 @@ import lookmovie from './scraper/lookmovie'; import theflix from './scraper/theflix'; +import vidzstore from './scraper/vidzstore'; async function findContent(searchTerm, type) { const results = { options: []}; const content = await Promise.all([ lookmovie.findContent(searchTerm, type), - theflix.findContent(searchTerm, type) + theflix.findContent(searchTerm, type), + vidzstore.findContent(searchTerm, type) ]); content.forEach((o) => { @@ -26,6 +28,8 @@ async function getStreamUrl(slug, type, source, season, episode) { return await lookmovie.getStreamUrl(slug, type, season, episode); case 'theflix': return await theflix.getStreamUrl(slug, type, season, episode); + case 'vidzstore': + return await vidzstore.getStreamUrl(slug); default: return; } diff --git a/src/lib/scraper/vidzstore.js b/src/lib/scraper/vidzstore.js new file mode 100644 index 00000000..414bc712 --- /dev/null +++ b/src/lib/scraper/vidzstore.js @@ -0,0 +1,41 @@ +const BASE_URL = `${process.env.REACT_APP_CORS_PROXY_URL}https://stream.vidzstore.com`; + +async function findContent(searchTerm, type) { + if (type === 'show') return { options: [] }; + try { + const searchUrl = `${BASE_URL}/search.php?sd=${searchTerm.replace(/ /g, "_")}`; + const searchRes = await fetch(searchUrl).then((d) => d.text()); + + const parser = new DOMParser(); + const doc = parser.parseFromString(searchRes, "text/html"); + const nodes = [...doc.querySelectorAll(".post")]; + const results = nodes.map(node => { + const title = node.querySelector("a").title.replace(/-/g, " ").trim(); + const titleArray = title.split(" "); + titleArray.splice(-2); + return { + type, + title: titleArray.join(" "), + year: node.querySelector(".post-meta").innerText.split(" ").pop().split("-").shift(), + slug: encodeURIComponent(node.querySelector("a").href.split('/').pop()), + source: "vidzstore", + } + }); + + return { options: results }; + } catch { + return { options: [] }; + } +} + +async function getStreamUrl(slug) { + const url = `${BASE_URL}/${decodeURIComponent(slug)}`; + + const res = await fetch(url).then(d => d.text()); + const DOM = new DOMParser().parseFromString(res, "text/html"); + + return { url: `${process.env.REACT_APP_CORS_PROXY_URL}${DOM.querySelector("source").src}` }; +} + +const vidzstore = { findContent, getStreamUrl } +export default vidzstore; \ No newline at end of file