From b2c4b5489362dc1a7c1d27a65b8df9f2164eca40 Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Sun, 2 Jan 2022 09:49:21 +0000 Subject: [PATCH] Fix inconsistent TMDB season naming --- src/lib/scraper/theflix.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib/scraper/theflix.js b/src/lib/scraper/theflix.js index 63d3c798..565e02d5 100644 --- a/src/lib/scraper/theflix.js +++ b/src/lib/scraper/theflix.js @@ -56,7 +56,17 @@ async function findContent(searchTerm, type) { } async function getEpisodes(slug) { - const tmdbRes = await fetch(`${process.env.REACT_APP_CORS_PROXY_URL}https://www.themoviedb.org/tv/${slug}/seasons`).then(d => d.text()); + let tmdbRes; + + try { + tmdbRes = await fetch(`${process.env.REACT_APP_CORS_PROXY_URL}https://www.themoviedb.org/tv/${slug}/seasons`).then(d => d.text()); + } catch (err) { + tmdbRes = await fetch(`${process.env.REACT_APP_CORS_PROXY_URL}https://www.themoviedb.org/tv/${slug.split('-')[0]}/seasons`).then(d => d.text()); + + if (tmdbRes) + slug = slug.split('-')[0]; + } + const sNodes = Array.from(new DOMParser().parseFromString(tmdbRes, 'text/html').querySelectorAll('div.column_wrapper > div.flex > div')); let seasons = [];