Allow lookmovie content search to fail

This commit is contained in:
James Hawkins 2021-10-01 16:23:10 +01:00
parent 455805cb88
commit 3627660840

View File

@ -5,50 +5,54 @@ const BASE_URL = `${process.env.REACT_APP_CORS_PROXY_URL}https://lookmovie.io`;
let phpsessid; let phpsessid;
async function findContent(searchTerm, type) { async function findContent(searchTerm, type) {
const searchUrl = `${BASE_URL}/${type}s/search/?q=${encodeURIComponent(searchTerm)}`; try {
const searchRes = await fetch(searchUrl).then((d) => d.text()); const searchUrl = `${BASE_URL}/${type}s/search/?q=${encodeURIComponent(searchTerm)}`;
const searchRes = await fetch(searchUrl).then((d) => d.text());
// Parse DOM to find search results on full search page
const parser = new DOMParser(); // Parse DOM to find search results on full search page
const doc = parser.parseFromString(searchRes, "text/html"); const parser = new DOMParser();
const nodes = Array.from(doc.querySelectorAll('.movie-item-style-1')); const doc = parser.parseFromString(searchRes, "text/html");
const results = nodes.map(node => { const nodes = Array.from(doc.querySelectorAll('.movie-item-style-1'));
return { const results = nodes.map(node => {
type, return {
title: node.querySelector('h6 a').innerText.trim(), type,
year: node.querySelector('.year').innerText.trim(), title: node.querySelector('h6 a').innerText.trim(),
slug: node.querySelector('a').href.split('/').pop(), year: node.querySelector('.year').innerText.trim(),
slug: node.querySelector('a').href.split('/').pop(),
}
});
const fuse = new Fuse(results, { threshold: 0.3, distance: 200, keys: ["title"] });
const matchedResults = fuse
.search(searchTerm.toString())
.map((result) => result.item);
if (matchedResults.length === 0) {
return { options: [] }
} }
});
if (matchedResults.length > 1) {
const fuse = new Fuse(results, { threshold: 0.3, distance: 200, keys: ["title"] }); const res = { options: [] };
const matchedResults = fuse
.search(searchTerm.toString()) matchedResults.forEach((r) => res.options.push({
.map((result) => result.item); title: r.title,
slug: r.slug,
if (matchedResults.length === 0) { type: r.type,
year: r.year,
source: 'lookmovie'
}));
return res;
} else {
const { title, slug, type, year } = matchedResults[0];
return {
options: [{ title, slug, type, year, source: 'lookmovie' }]
}
}
} catch (e) {
return { options: [] } return { options: [] }
} }
if (matchedResults.length > 1) {
const res = { options: [] };
matchedResults.forEach((r) => res.options.push({
title: r.title,
slug: r.slug,
type: r.type,
year: r.year,
source: 'lookmovie'
}));
return res;
} else {
const { title, slug, type, year } = matchedResults[0];
return {
options: [{ title, slug, type, year, source: 'lookmovie' }]
}
}
} }
async function getVideoUrl(config) { async function getVideoUrl(config) {
const { subtitles, token: accessToken } = await getAccessInfo(config); const { subtitles, token: accessToken } = await getAccessInfo(config);