Add trailler button

This commit is contained in:
Zoe Roux 2023-04-04 02:07:42 +09:00
parent 840b0c07ff
commit 298dc9af27
6 changed files with 36 additions and 25 deletions

View File

@ -39,6 +39,7 @@ export const MovieP = z.preprocess(
x.name = x.title; x.name = x.title;
if (x.aliases === null) x.aliases = []; if (x.aliases === null) x.aliases = [];
x.airDate = x.startAir; x.airDate = x.startAir;
x.trailer = x.images["3"];
return x; return x;
}, },
ResourceP.merge(ImagesP).extend({ ResourceP.merge(ImagesP).extend({

View File

@ -41,6 +41,7 @@ export const ShowP = z.preprocess(
// Waiting for the API to be updaded // Waiting for the API to be updaded
x.name = x.title; x.name = x.title;
if (x.aliases === null) x.aliases = []; if (x.aliases === null) x.aliases = [];
x.trailer = x.images["3"];
return x; return x;
}, },
ResourceP.merge(ImagesP).extend({ ResourceP.merge(ImagesP).extend({

View File

@ -53,7 +53,7 @@ export const ImagesP = z.object({
* will be null. If the kyoo's instance is not capable of handling this kind of image for the * will be null. If the kyoo's instance is not capable of handling this kind of image for the
* specific resource, this field won't be present. * specific resource, this field won't be present.
*/ */
trailer: z.string().transform(imageFn).optional().nullable(), trailer: z.string().optional().nullable(),
}); });
/** /**

View File

@ -50,31 +50,35 @@ export const A = ({
); );
}; };
export const PressableFeedback = forwardRef<View, PressableProps>( export const PressableFeedback = forwardRef<View, PressableProps>(function _Feedback(
function _Feedback({ children, ...props }, ref) { { children, ...props },
const theme = useTheme(); ref,
) {
const theme = useTheme();
return ( return (
<Pressable <Pressable
ref={ref} ref={ref}
// TODO: Enable ripple on tv. Waiting for https://github.com/react-native-tvos/react-native-tvos/issues/440 // TODO: Enable ripple on tv. Waiting for https://github.com/react-native-tvos/react-native-tvos/issues/440
{...(Platform.isTV {...(Platform.isTV
? {} ? {}
: { android_ripple: { foreground: true, color: alpha(theme.contrast, 0.5) as any } })} : { android_ripple: { foreground: true, color: alpha(theme.contrast, 0.5) as any } })}
{...props} {...props}
> >
{children} {children}
</Pressable> </Pressable>
); );
}, });
);
export const Link = ({ export const Link = ({
href, href,
target,
children, children,
...props ...props
}: { href: string; } & PressableProps) => { }: { href: string; target?: string } & PressableProps) => {
const linkProps = useLink({href}); const linkProps = useLink({ href });
// @ts-ignore Missing hrefAttrs type definition.
linkProps.hrefAttrs = { ...linkProps.hrefAttrs, target };
return ( return (
<PressableFeedback {...linkProps} {...props}> <PressableFeedback {...linkProps} {...props}>
{children} {children}

View File

@ -66,6 +66,7 @@ const TitleLine = ({
date, date,
poster, poster,
studio, studio,
trailerUrl,
...props ...props
}: { }: {
isLoading: boolean; isLoading: boolean;
@ -74,6 +75,7 @@ const TitleLine = ({
date?: string; date?: string;
poster?: string | null; poster?: string | null;
studio?: Studio | null; studio?: Studio | null;
trailerUrl?: string | null;
} & Stylable) => { } & Stylable) => {
const { css, theme } = useYoshiki(); const { css, theme } = useYoshiki();
const { t } = useTranslation(); const { t } = useTranslation();
@ -156,7 +158,6 @@ const TitleLine = ({
</Skeleton> </Skeleton>
)} )}
<View {...css({ flexDirection: "row" })}> <View {...css({ flexDirection: "row" })}>
{/* @ts-ignore */}
<IconFab <IconFab
icon={PlayArrow} icon={PlayArrow}
as={Link} as={Link}
@ -168,11 +169,14 @@ const TitleLine = ({
})} })}
{...tooltip(t("show.play"))} {...tooltip(t("show.play"))}
/> />
<IconButton {trailerUrl && <IconButton
icon={Theaters} icon={Theaters}
as={Link}
href={trailerUrl}
target="_blank"
color={{ xs: theme.user.contrast, md: theme.colors.white }} color={{ xs: theme.user.contrast, md: theme.colors.white }}
{...tooltip(t("show.trailer"))} {...tooltip(t("show.trailer"))}
/> />}
</View> </View>
</View> </View>
</View> </View>
@ -330,6 +334,7 @@ export const Header = ({ query, slug }: { query: QueryIdentifier<Show | Movie>;
name={data?.name} name={data?.name}
date={data ? getDisplayDate(data as any) : undefined} date={data ? getDisplayDate(data as any) : undefined}
poster={data?.poster} poster={data?.poster}
trailerUrl={data?.trailer}
studio={data?.studio} studio={data?.studio}
{...css({ {...css({
marginTop: { marginTop: {

View File

@ -155,7 +155,7 @@ class TheMovieDatabase(Provider):
logos=self.get_image(movie["images"]["logos"]), logos=self.get_image(movie["images"]["logos"]),
thumbnails=self.get_image(movie["images"]["backdrops"]), thumbnails=self.get_image(movie["images"]["backdrops"]),
trailers=[ trailers=[
f"https://www.youtube.com/watch?v{x['key']}" f"https://www.youtube.com/watch?v={x['key']}"
for x in movie["videos"]["results"] for x in movie["videos"]["results"]
if x["type"] == "Trailer" and x["site"] == "YouTube" if x["type"] == "Trailer" and x["site"] == "YouTube"
], ],
@ -231,7 +231,7 @@ class TheMovieDatabase(Provider):
logos=self.get_image(show["images"]["logos"]), logos=self.get_image(show["images"]["logos"]),
thumbnails=self.get_image(show["images"]["backdrops"]), thumbnails=self.get_image(show["images"]["backdrops"]),
trailers=[ trailers=[
f"https://www.youtube.com/watch?v{x['key']}" f"https://www.youtube.com/watch?v={x['key']}"
for x in show["videos"]["results"] for x in show["videos"]["results"]
if x["type"] == "Trailer" and x["site"] == "YouTube" if x["type"] == "Trailer" and x["site"] == "YouTube"
], ],