From c4f68615cd2fc0efe959506e4747439ff6165f87 Mon Sep 17 00:00:00 2001 From: Honkertonken <94032937+Honkertonken@users.noreply.github.com> Date: Wed, 27 Mar 2024 18:20:57 +0530 Subject: [PATCH 1/7] Update tmdb.ts --- src/backend/metadata/tmdb.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/backend/metadata/tmdb.ts b/src/backend/metadata/tmdb.ts index b143b312..88412c84 100644 --- a/src/backend/metadata/tmdb.ts +++ b/src/backend/metadata/tmdb.ts @@ -173,12 +173,17 @@ export async function multiSearch( language: "en-US", page: 1, }); - // filter out results that aren't movies or shows - const results = data.results.filter( - (r) => - r.media_type === TMDBContentTypes.MOVIE || - r.media_type === TMDBContentTypes.TV, - ); + const currentDate = new Date(); + // filter out results that aren't movies or shows or are unreleased + const results = data.results.filter((r) => { + if (r.media_type === TMDBContentTypes.MOVIE) { + return new Date(r.release_date) <= currentDate; + } + if (r.media_type === TMDBContentTypes.TV) { + return new Date(r.first_air_date) <= currentDate; + } + return false; + }); return results; } From e431626bfa767b5c8c1e2b328a39171b1c9d912b Mon Sep 17 00:00:00 2001 From: Honkertonken <94032937+Honkertonken@users.noreply.github.com> Date: Wed, 27 Mar 2024 23:19:12 +0530 Subject: [PATCH 2/7] Update MediaCard.tsx --- src/components/media/MediaCard.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/media/MediaCard.tsx b/src/components/media/MediaCard.tsx index cad3ae6a..ac6c243c 100644 --- a/src/components/media/MediaCard.tsx +++ b/src/components/media/MediaCard.tsx @@ -35,10 +35,14 @@ function MediaCardContent({ const { t } = useTranslation(); const percentageString = `${Math.round(percentage ?? 0).toFixed(0)}%`; - const canLink = linkable && !closable; + const canLink = linkable && !closable && !!media.year; const dotListContent = [t(`media.types.${media.type}`)]; - if (media.year) dotListContent.push(media.year.toFixed()); + if (media.year) { + dotListContent.push(media.year.toFixed()); + } else { + dotListContent.push(t("Unreleased")); + } return (
{content}; + if (!props.linkable || !props.media.year) return {content}; return ( Date: Wed, 27 Mar 2024 23:19:35 +0530 Subject: [PATCH 3/7] Revert "Update tmdb.ts" This reverts commit c4f68615cd2fc0efe959506e4747439ff6165f87. --- src/backend/metadata/tmdb.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/backend/metadata/tmdb.ts b/src/backend/metadata/tmdb.ts index 88412c84..b143b312 100644 --- a/src/backend/metadata/tmdb.ts +++ b/src/backend/metadata/tmdb.ts @@ -173,17 +173,12 @@ export async function multiSearch( language: "en-US", page: 1, }); - const currentDate = new Date(); - // filter out results that aren't movies or shows or are unreleased - const results = data.results.filter((r) => { - if (r.media_type === TMDBContentTypes.MOVIE) { - return new Date(r.release_date) <= currentDate; - } - if (r.media_type === TMDBContentTypes.TV) { - return new Date(r.first_air_date) <= currentDate; - } - return false; - }); + // filter out results that aren't movies or shows + const results = data.results.filter( + (r) => + r.media_type === TMDBContentTypes.MOVIE || + r.media_type === TMDBContentTypes.TV, + ); return results; } From 4386772404de469d3980252fc38aa327a95846a6 Mon Sep 17 00:00:00 2001 From: Honkertonken <94032937+Honkertonken@users.noreply.github.com> Date: Thu, 28 Mar 2024 13:27:05 +0530 Subject: [PATCH 4/7] Update MediaCard.tsx --- src/components/media/MediaCard.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/media/MediaCard.tsx b/src/components/media/MediaCard.tsx index ac6c243c..ce4eeffe 100644 --- a/src/components/media/MediaCard.tsx +++ b/src/components/media/MediaCard.tsx @@ -35,13 +35,15 @@ function MediaCardContent({ const { t } = useTranslation(); const percentageString = `${Math.round(percentage ?? 0).toFixed(0)}%`; - const canLink = linkable && !closable && !!media.year; + const currentYear = new Date().getFullYear(); + const isReleased = media.year && media.year < currentYear; + const canLink = linkable && !closable && isReleased; const dotListContent = [t(`media.types.${media.type}`)]; - if (media.year) { + if (isReleased) { dotListContent.push(media.year.toFixed()); } else { - dotListContent.push(t("Unreleased")); + dotListContent.push(t("media.unreleased")); } return ( @@ -146,7 +148,9 @@ function MediaCardContent({ export function MediaCard(props: MediaCardProps) { const content = ; - const canLink = props.linkable && !props.closable; + const currentYear = new Date().getFullYear(); + const isReleased = props.media.year && props.media.year < currentYear; + const canLink = props.linkable && !props.closable && isReleased; let link = canLink ? `/media/${encodeURIComponent(mediaItemToId(props.media))}` @@ -161,7 +165,7 @@ export function MediaCard(props: MediaCardProps) { } } - if (!props.linkable || !props.media.year) return {content}; + if (!canLink) return {content}; return ( Date: Thu, 28 Mar 2024 13:36:56 +0530 Subject: [PATCH 5/7] Update MediaCard.tsx --- src/components/media/MediaCard.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/media/MediaCard.tsx b/src/components/media/MediaCard.tsx index ce4eeffe..937ff1c6 100644 --- a/src/components/media/MediaCard.tsx +++ b/src/components/media/MediaCard.tsx @@ -36,11 +36,11 @@ function MediaCardContent({ const percentageString = `${Math.round(percentage ?? 0).toFixed(0)}%`; const currentYear = new Date().getFullYear(); - const isReleased = media.year && media.year < currentYear; - const canLink = linkable && !closable && isReleased; + const canLink = + linkable && !closable && media.year && media.year < currentYear; const dotListContent = [t(`media.types.${media.type}`)]; - if (isReleased) { + if (media.year && media.year < currentYear) { dotListContent.push(media.year.toFixed()); } else { dotListContent.push(t("media.unreleased")); @@ -149,8 +149,11 @@ export function MediaCard(props: MediaCardProps) { const content = ; const currentYear = new Date().getFullYear(); - const isReleased = props.media.year && props.media.year < currentYear; - const canLink = props.linkable && !props.closable && isReleased; + const canLink = + props.linkable && + !props.closable && + props.media.year && + props.media.year < currentYear; let link = canLink ? `/media/${encodeURIComponent(mediaItemToId(props.media))}` From d82de1f7c89c214ec983bc244f4f1d3381410342 Mon Sep 17 00:00:00 2001 From: Captain Jack Sparrow <163903675+sussy-code@users.noreply.github.com> Date: Thu, 28 Mar 2024 05:17:17 -0400 Subject: [PATCH 6/7] Better scrape error text for extension (#1042) * Add better scrape error messages for the extension * Remove config.js silly me * Polish and resolve issues * Update src/pages/parts/player/ScrapeErrorPart.tsx Co-authored-by: William Oldham * Update src/pages/parts/player/ScrapeErrorPart.tsx Co-authored-by: William Oldham * Update src/pages/parts/player/ScrapeErrorPart.tsx Co-authored-by: William Oldham * Update src/pages/parts/player/ScrapeErrorPart.tsx Co-authored-by: William Oldham * Update src/pages/parts/player/ScrapeErrorPart.tsx Co-authored-by: William Oldham * Update src/pages/parts/player/ScrapeErrorPart.tsx Co-authored-by: William Oldham * Fix duplicate button value * Resolve issues * Ok now i fixed it all * Apply suggestions from code review * I am dum --------- Co-authored-by: Cooper Ransom Co-authored-by: William Oldham --- index.html | 2 +- src/assets/locales/en.json | 7 +++ src/pages/onboarding/OnboardingExtension.tsx | 23 +------- src/pages/parts/player/ScrapeErrorPart.tsx | 61 +++++++++++++++++++- src/utils/extension.ts | 20 +++++++ 5 files changed, 90 insertions(+), 23 deletions(-) create mode 100644 src/utils/extension.ts diff --git a/index.html b/index.html index 1d1c3577..4555b17a 100644 --- a/index.html +++ b/index.html @@ -162,4 +162,4 @@ - \ No newline at end of file + diff --git a/src/assets/locales/en.json b/src/assets/locales/en.json index eeda3629..ab128219 100644 --- a/src/assets/locales/en.json +++ b/src/assets/locales/en.json @@ -388,6 +388,13 @@ "homeButton": "Go home", "text": "We have searched through our providers and cannot find the media you are looking for! We do not host the media and have no control over what is available. Please click 'Show details' below for more details.", "title": "We couldn't find that" + }, + "extensionFailure": { + "badge": "Extension disabled", + "homeButton": "Go home", + "enableExtension": "Enable extension", + "title": "Please enable the extension", + "text": "You've installed the movie-web extension. To start using it, you need to enable the extension for this site." } }, "time": { diff --git a/src/pages/onboarding/OnboardingExtension.tsx b/src/pages/onboarding/OnboardingExtension.tsx index db351dda..66e662e2 100644 --- a/src/pages/onboarding/OnboardingExtension.tsx +++ b/src/pages/onboarding/OnboardingExtension.tsx @@ -2,8 +2,7 @@ import { ReactNode, useCallback, useEffect, useMemo, useState } from "react"; import { Trans, useTranslation } from "react-i18next"; import { useAsyncFn, useInterval } from "react-use"; -import { isAllowedExtensionVersion } from "@/backend/extension/compatibility"; -import { extensionInfo, sendPage } from "@/backend/extension/messaging"; +import { sendPage } from "@/backend/extension/messaging"; import { Button } from "@/components/buttons/Button"; import { Icon, Icons } from "@/components/Icon"; import { Loading } from "@/components/layout/Loading"; @@ -22,24 +21,8 @@ import { ExtensionDetectionResult, detectExtensionInstall, } from "@/utils/detectFeatures"; - -type ExtensionStatus = - | "unknown" - | "failed" - | "disallowed" - | "noperms" - | "outdated" - | "success"; - -async function getExtensionState(): Promise { - const info = await extensionInfo(); - if (!info) return "unknown"; // cant talk to extension - if (!info.success) return "failed"; // extension failed to respond - if (!info.allowed) return "disallowed"; // extension is not enabled on this page - if (!info.hasPermission) return "noperms"; // extension has no perms to do it's tasks - if (!isAllowedExtensionVersion(info.version)) return "outdated"; // extension is too old - return "success"; // no problems -} +import { getExtensionState } from "@/utils/extension"; +import type { ExtensionStatus } from "@/utils/extension"; function RefreshBar() { const { t } = useTranslation(); diff --git a/src/pages/parts/player/ScrapeErrorPart.tsx b/src/pages/parts/player/ScrapeErrorPart.tsx index 127a69a6..bc1f78e6 100644 --- a/src/pages/parts/player/ScrapeErrorPart.tsx +++ b/src/pages/parts/player/ScrapeErrorPart.tsx @@ -1,7 +1,8 @@ -import { useMemo } from "react"; -import { useTranslation } from "react-i18next"; +import { useEffect, useMemo, useState } from "react"; +import { Trans, useTranslation } from "react-i18next"; import { useLocation } from "react-router-dom"; +import { sendPage } from "@/backend/extension/messaging"; import { Button } from "@/components/buttons/Button"; import { Icons } from "@/components/Icon"; import { IconPill } from "@/components/layout/IconPill"; @@ -10,6 +11,8 @@ import { Paragraph } from "@/components/text/Paragraph"; import { Title } from "@/components/text/Title"; import { ScrapingItems, ScrapingSegment } from "@/hooks/useProviderScrape"; import { ErrorContainer, ErrorLayout } from "@/pages/layouts/ErrorLayout"; +import { getExtensionState } from "@/utils/extension"; +import type { ExtensionStatus } from "@/utils/extension"; import { getProviderApiUrls } from "@/utils/proxyUrls"; import { ErrorCardInModal } from "../errors/ErrorCard"; @@ -25,6 +28,8 @@ export function ScrapeErrorPart(props: ScrapeErrorPartProps) { const { t } = useTranslation(); const modal = useModal("error"); const location = useLocation(); + const [extensionState, setExtensionState] = + useState("unknown"); const error = useMemo(() => { const data = props.data; @@ -42,6 +47,58 @@ export function ScrapeErrorPart(props: ScrapeErrorPartProps) { return str; }, [props, location]); + useEffect(() => { + getExtensionState().then((state: ExtensionStatus) => { + setExtensionState(state); + }); + }, [t]); + + if (extensionState === "disallowed") { + return ( + + + + {t("player.scraping.extensionFailure.badge")} + + {t("player.scraping.extensionFailure.title")} + + + ), + }} + /> + +
+ + +
+
+
+ ); + } + return ( diff --git a/src/utils/extension.ts b/src/utils/extension.ts new file mode 100644 index 00000000..8874146b --- /dev/null +++ b/src/utils/extension.ts @@ -0,0 +1,20 @@ +import { isAllowedExtensionVersion } from "@/backend/extension/compatibility"; +import { extensionInfo } from "@/backend/extension/messaging"; + +export type ExtensionStatus = + | "unknown" + | "failed" + | "disallowed" + | "noperms" + | "outdated" + | "success"; + +export async function getExtensionState(): Promise { + const info = await extensionInfo(); + if (!info) return "unknown"; // cant talk to extension + if (!info.success) return "failed"; // extension failed to respond + if (!info.allowed) return "disallowed"; // extension is not enabled on this page + if (!info.hasPermission) return "noperms"; // extension has no perms to do it's tasks + if (!isAllowedExtensionVersion(info.version)) return "outdated"; // extension is too old + return "success"; // no problems +} From bfee71f44620e4d66e338f0f7e86303a811916c1 Mon Sep 17 00:00:00 2001 From: Honkertonken <94032937+Honkertonken@users.noreply.github.com> Date: Thu, 28 Mar 2024 16:47:18 +0530 Subject: [PATCH 7/7] Update MediaCard.tsx --- src/components/media/MediaCard.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/media/MediaCard.tsx b/src/components/media/MediaCard.tsx index 937ff1c6..563e4d9b 100644 --- a/src/components/media/MediaCard.tsx +++ b/src/components/media/MediaCard.tsx @@ -37,10 +37,12 @@ function MediaCardContent({ const currentYear = new Date().getFullYear(); const canLink = - linkable && !closable && media.year && media.year < currentYear; + linkable && !closable && media.year && media.year <= currentYear; const dotListContent = [t(`media.types.${media.type}`)]; - if (media.year && media.year < currentYear) { + if (media.year && media.year > currentYear) { + dotListContent.push(`${media.year}`, t("media.unreleased")); + } else if (media.year) { dotListContent.push(media.year.toFixed()); } else { dotListContent.push(t("media.unreleased")); @@ -153,7 +155,7 @@ export function MediaCard(props: MediaCardProps) { props.linkable && !props.closable && props.media.year && - props.media.year < currentYear; + props.media.year <= currentYear; let link = canLink ? `/media/${encodeURIComponent(mediaItemToId(props.media))}`