fix: torrent size

This commit is contained in:
ner committed 2024-03-19 20:15:42 +02:00
1 parent 8d7e2df869
commit c6d306cb7b
22 files changed
+1638 -300

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
'use client';
import List from '@/components/Movie/List';
import usePopular from './usePopular';
export default function Container() {
const { data: top, hasNextPage, fetchNextPage, isFetched } = usePopular();
return (
<>
<List pages={top?.pages || []} fetchNextPage={fetchNextPage} hasNextPage={hasNextPage} />
{isFetched && !top?.pages?.[0]?.results?.length && (
<div className='h-40 w-full flex items-center justify-center text-xl text-muted-foreground'>
Nothing was found
</div>
)}
</>
);
}
+24
View File
@@ -0,0 +1,24 @@
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
import { popularMovies } from '@/lib/api';
import getQueryClient from '@/lib/queryClient';
import Container from './container';
export default async function Popular() {
const queryClient = getQueryClient();
await queryClient.prefetchInfiniteQuery({
queryKey: ['popular'],
queryFn: () => popularMovies({}),
initialPageParam: '1'
});
return (
<HydrationBoundary state={dehydrate(queryClient)}>
<Container />
</HydrationBoundary>
);
}
export const revalidate = 3600;
+23
View File
@@ -0,0 +1,23 @@
'use client';
import { useInfiniteQuery } from '@tanstack/react-query';
import { popularMovies } from '@/lib/api';
const usePopular = () => {
return useInfiniteQuery({
queryKey: ['popular'],
queryFn: ({ pageParam }) => {
return popularMovies({ page: pageParam as string });
},
getNextPageParam(lastPage) {
const { page, total_pages } = lastPage as { page: number; total_pages: number };
if (page === total_pages) return undefined;
return `${page + 1}`;
},
initialPageParam: '1'
});
};
export default usePopular;
+32
View File
@@ -0,0 +1,32 @@
'use client';
import { useSearchParams } from 'next/navigation';
import List from '@/components/Movie/List';
import useSimilar from './useSimilar';
export default function Container() {
const params = useSearchParams();
const title = params.get('title');
const movieId = params.get('movieId') || undefined;
const { data: top, hasNextPage, fetchNextPage, isFetched } = useSimilar({ movieId });
return (
<>
{Boolean(title) && (
<span className='inline-flex w-full h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground mb-2'>
Similar: {decodeURIComponent(title || '')}
</span>
)}
<List pages={top?.pages || []} fetchNextPage={fetchNextPage} hasNextPage={hasNextPage} />
{isFetched && !top?.pages?.[0]?.results?.length && (
<div className='h-40 w-full flex items-center justify-center text-xl text-muted-foreground'>
Nothing was found
</div>
)}
</>
);
}
+26
View File
@@ -0,0 +1,26 @@
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
import { similarMovies } from '@/lib/api';
import getQueryClient from '@/lib/queryClient';
import Container from './container';
export default async function Similar({ searchParams }: { searchParams: Record<string, string> }) {
const queryClient = getQueryClient();
const { movieId } = searchParams || {};
await queryClient.prefetchInfiniteQuery({
queryKey: ['similar', movieId],
queryFn: () => similarMovies({ movieId }),
initialPageParam: '1'
});
return (
<HydrationBoundary state={dehydrate(queryClient)}>
<Container />
</HydrationBoundary>
);
}
export const revalidate = 3600;
+24
View File
@@ -0,0 +1,24 @@
'use client';
import { useInfiniteQuery } from '@tanstack/react-query';
import { similarMovies } from '@/lib/api';
const useSimilar = ({ movieId }: { movieId?: string }) => {
return useInfiniteQuery({
queryKey: ['similar', movieId],
enabled: Boolean(movieId),
queryFn: ({ pageParam }) => {
return similarMovies({ page: pageParam as string, movieId });
},
getNextPageParam(lastPage) {
const { page, total_pages } = lastPage as { page: number; total_pages: number };
if (page === total_pages) return undefined;
return `${page + 1}`;
},
initialPageParam: '1'
});
};
export default useSimilar;
+32
View File
@@ -0,0 +1,32 @@
'use client';
import { useSearchParams } from 'next/navigation';
import List from '@/components/Movie/List';
import useStarring from './useStarring';
export default function Container() {
const params = useSearchParams();
const title = params.get('title');
const actorId = params.get('actorId') || undefined;
const { data: top, hasNextPage, fetchNextPage, isFetched } = useStarring({ actorId });
return (
<>
{Boolean(title) && (
<span className='inline-flex w-full h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground mb-2'>
Starring: {decodeURIComponent(title || '')}
</span>
)}
<List pages={top?.pages || []} fetchNextPage={fetchNextPage} hasNextPage={hasNextPage} />
{isFetched && !top?.pages?.[0]?.results?.length && (
<div className='h-40 w-full flex items-center justify-center text-xl text-muted-foreground'>
Nothing was found
</div>
)}
</>
);
}
+26
View File
@@ -0,0 +1,26 @@
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
import { topMovies } from '@/lib/api';
import getQueryClient from '@/lib/queryClient';
import Container from './container';
export default async function Starring({ searchParams }: { searchParams: Record<string, string> }) {
const queryClient = getQueryClient();
const { actorId } = searchParams || {};
await queryClient.prefetchInfiniteQuery({
queryKey: ['starring', actorId],
queryFn: () => topMovies({ starring: actorId }),
initialPageParam: '1'
});
return (
<HydrationBoundary state={dehydrate(queryClient)}>
<Container />
</HydrationBoundary>
);
}
export const revalidate = 3600;
+24
View File
@@ -0,0 +1,24 @@
'use client';
import { useInfiniteQuery } from '@tanstack/react-query';
import { topMovies } from '@/lib/api';
const useStarring = ({ actorId }: { actorId?: string }) => {
return useInfiniteQuery({
queryKey: ['starring', actorId],
enabled: Boolean(actorId),
queryFn: ({ pageParam }) => {
return topMovies({ page: pageParam as string, starring: actorId });
},
getNextPageParam(lastPage) {
const { page, total_pages } = lastPage as { page: number; total_pages: number };
if (page === total_pages) return undefined;
return `${page + 1}`;
},
initialPageParam: '1'
});
};
export default useStarring;
+1 -14
View File
@@ -1,27 +1,14 @@
'use client'; 'use client';
import { useSearchParams } from 'next/navigation';
import List from '@/components/Movie/List'; import List from '@/components/Movie/List';
import useTop from './useTop'; import useTop from './useTop';
export default function Container() { export default function Container() {
const params = useSearchParams(); const { data: top, hasNextPage, fetchNextPage, isFetched } = useTop();
const starring = params.get('starring')!;
const similar = params.get('similar')!;
const title = params.get('title');
const { data: top, hasNextPage, fetchNextPage, isFetched } = useTop({ starring, similar });
return ( return (
<> <>
{Boolean(title && (starring || similar)) && (
<span className='inline-flex w-full h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground mb-2'>
{starring ? 'Starring' : 'Similar'}: {decodeURIComponent(title || '')}
</span>
)}
<List pages={top?.pages || []} fetchNextPage={fetchNextPage} hasNextPage={hasNextPage} /> <List pages={top?.pages || []} fetchNextPage={fetchNextPage} hasNextPage={hasNextPage} />
{isFetched && !top?.pages?.[0]?.results?.length && ( {isFetched && !top?.pages?.[0]?.results?.length && (
<div className='h-40 w-full flex items-center justify-center text-xl text-muted-foreground'> <div className='h-40 w-full flex items-center justify-center text-xl text-muted-foreground'>
+4 -6
View File
@@ -1,18 +1,16 @@
import { dehydrate, HydrationBoundary } from '@tanstack/react-query'; import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
import { similarMovies, topMovies } from '@/lib/api'; import { topMovies } from '@/lib/api';
import getQueryClient from '@/lib/queryClient'; import getQueryClient from '@/lib/queryClient';
import Container from './container'; import Container from './container';
export default async function Top({ searchParams }: { searchParams: Record<string, string> }) { export default async function Top() {
const queryClient = getQueryClient(); const queryClient = getQueryClient();
const { starring, similar } = searchParams || {};
await queryClient.prefetchInfiniteQuery({ await queryClient.prefetchInfiniteQuery({
queryKey: ['top', starring, similar], queryKey: ['top'],
queryFn: () => (similar ? similarMovies({ movieId: similar }) : topMovies({ starring })), queryFn: () => topMovies({}),
initialPageParam: '1' initialPageParam: '1'
}); });
+4 -6
View File
@@ -2,15 +2,13 @@
import { useInfiniteQuery } from '@tanstack/react-query'; import { useInfiniteQuery } from '@tanstack/react-query';
import { similarMovies, topMovies } from '@/lib/api'; import { topMovies } from '@/lib/api';
const useTop = ({ starring, similar }: { starring?: string; similar?: string }) => { const useTop = () => {
return useInfiniteQuery({ return useInfiniteQuery({
queryKey: ['top', starring, similar], queryKey: ['top'],
queryFn: ({ pageParam }) => { queryFn: ({ pageParam }) => {
return similar return topMovies({ page: pageParam as string });
? similarMovies({ page: pageParam as string, movieId: similar })
: topMovies({ page: pageParam as string, starring: starring! });
}, },
getNextPageParam(lastPage) { getNextPageParam(lastPage) {
const { page, total_pages } = lastPage as { page: number; total_pages: number }; const { page, total_pages } = lastPage as { page: number; total_pages: number };
+1 -1
View File
@@ -9,7 +9,7 @@ import '@/styles/index.css';
export const metadata: Metadata = { export const metadata: Metadata = {
title: 'Movie advisor', title: 'Movie advisor',
description: 'It will help you find a movie for evening' description: 'It is going to help you find a movie for evening'
}; };
export const viewport: Viewport = { export const viewport: Viewport = {
@@ -7,17 +7,19 @@ import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
export default function Navigation() { export default function Navigation() {
const path = usePathname(); const path = usePathname();
return ( return (
<Tabs value={path} className='flex-grow mt-2'> <Tabs value={path} className='flex-grow mt-2'>
<TabsList className='grid w-full grid-cols-3'> <TabsList className='flex w-full'>
{[ {[
['/', 'Random'], { path: '/', title: 'Random' },
['/top', 'Top'], { path: '/popular', title: 'Popular' },
['/favorites', 'Favorites'] { path: '/top', title: 'Top rated' },
].map(([path, label]) => ( { path: '/favorites', title: 'Favorites' }
].map(({ path, title }) => (
<Link href={path} className='w-full' key={path}> <Link href={path} className='w-full' key={path}>
<TabsTrigger className='w-full' value={path}> <TabsTrigger className='w-full' value={path}>
{label} {title}
</TabsTrigger> </TabsTrigger>
</Link> </Link>
))} ))}
@@ -22,7 +22,7 @@ export default function Actions({ onClose, movie }: Props) {
<Button <Button
className='h-8 grow' className='h-8 grow'
onClick={() => { onClick={() => {
router.push(`/top?similar=${movie.id}&title=${encodeURIComponent(movie.title)}`); router.push(`/similar?movieId=${movie.id}&title=${encodeURIComponent(movie.title)}`);
onClose?.(); onClose?.();
}} }}
> >
+3 -3
View File
@@ -21,9 +21,9 @@ interface Props {
const variants = { const variants = {
enter: (direction: number) => ({ enter: (direction: number) => ({
scale: 0.8, scale: direction === 0 ? 1 : 0.8,
opacity: 0, opacity: direction === 0 ? 1 : 0,
[direction === 0 ? 'y' : 'x']: direction === 0 ? -100 : direction * 300 x: direction === 0 ? 0 : direction * 300
}), }),
center: { x: 0, opacity: 1, y: 0, scale: 1 }, center: { x: 0, opacity: 1, y: 0, scale: 1 },
exit: (direction: number) => ({ scale: 0.8, opacity: 1, x: direction * -300 }) exit: (direction: number) => ({ scale: 0.8, opacity: 1, x: direction * -300 })
@@ -17,7 +17,7 @@ const container = {
hidden: {}, hidden: {},
visible: { visible: {
transition: { transition: {
staggerChildren: 0.15 staggerChildren: 0.03
} }
} }
}; };
@@ -44,7 +44,7 @@ const Credits: FC<Props> = ({ movieId, onPersonClick }) => {
key={`${actor.id}_${actor.cast_id}`} key={`${actor.id}_${actor.cast_id}`}
title={actor.name} title={actor.name}
onTap={() => { onTap={() => {
router.push(`/top?starring=${actor.id}&title=${encodeURIComponent(actor.name)}`); router.push(`/starring?actorId=${actor.id}&title=${encodeURIComponent(actor.name)}`);
onPersonClick?.(actor.id.toString()); onPersonClick?.(actor.id.toString());
}} }}
className='p-2 rounded-lg border bg-card text-card-foreground self-end max-w-[150px] w-full shrink-0 cursor-pointer transition-shadow hover:shadow-lg' className='p-2 rounded-lg border bg-card text-card-foreground self-end max-w-[150px] w-full shrink-0 cursor-pointer transition-shadow hover:shadow-lg'
@@ -52,7 +52,7 @@ const hostAtom = atomWithStorage<string>('magnet-host', '');
const showHostManagerModal = create(({ onResolve, isOpen }) => { const showHostManagerModal = create(({ onResolve, isOpen }) => {
const [host, setHost] = useAtom(hostAtom); const [host, setHost] = useAtom(hostAtom);
return ( return (
<Modal className='p-3 pt-0 max-w-[200px] m-auto' isOpen={isOpen} onClose={() => onResolve()}> <Modal className='p-3 max-w-[200px] m-auto' isOpen={isOpen} onClose={() => onResolve()}>
<Input <Input
autoFocus autoFocus
placeholder='Enter host of Elementum' placeholder='Enter host of Elementum'
+14 -2
View File
@@ -29,7 +29,19 @@ export const randomMovies = async ({ filters }: { filters: Partial<Filters> }):
.then((data: unknown) => (data as MovieDBResponse).results); .then((data: unknown) => (data as MovieDBResponse).results);
}; };
export const topMovies = async ({ page, starring }: { page?: string; starring: string }): Promise<MovieDBResponse> => { export const popularMovies = async ({ page }: { page?: string }): Promise<MovieDBResponse> => {
return server.get('/discover/movie', {
params: {
page,
sort_by: 'popularity.desc',
'vote_count.gte': 0,
'vote_average.lte': 10,
'vote_average.gte': 0
}
});
};
export const topMovies = async ({ page, starring }: { page?: string; starring?: string }): Promise<MovieDBResponse> => {
return server.get('/discover/movie', { return server.get('/discover/movie', {
params: { params: {
page, page,
@@ -48,7 +60,7 @@ export const similarMovies = async ({
movieId movieId
}: { }: {
page?: string; page?: string;
movieId: string; movieId?: string;
}): Promise<MovieDBResponse> => { }): Promise<MovieDBResponse> => {
return server.get(`/movie/${movieId}/recommendations`, { return server.get(`/movie/${movieId}/recommendations`, {
params: { params: {
+12 -11
View File
@@ -30,19 +30,20 @@ export class PirateBay {
return this.client.post(`/search/${query}/${page}/${order}/${category}`, null).then(({ data }) => { return this.client.post(`/search/${query}/${page}/${order}/${category}`, null).then(({ data }) => {
const html = parse(data); const html = parse(data);
const table = html?.getElementById('searchResult'); const table = html?.getElementById('searchResult');
const rows = table?.querySelectorAll('tr:not(.header)');
const titles = rows?.map((row) => row.querySelector('td:nth-child(2) a')?.innerText).filter(Boolean);
const seeders = rows?.map((row) => row.querySelector('td:nth-child(6)')?.innerText);
const sizes = rows?.reduce((sizes, row) => {
const size = row.querySelector('td:nth-child(5)')?.innerText;
if (!size) return sizes;
const titles = table?.querySelectorAll('.vertTh + td > a').map((link) => link.innerText);
const seeders = table
?.querySelectorAll('td[align="right"]')
.filter((_, index) => index % 2 === 0)
.map((cell) => cell.innerText);
const sizes = table?.querySelectorAll('.detDesc').reduce((sizes, description) => {
const list = description.innerText?.split(', ');
if (list.length === 1) return sizes;
const [, size] = list;
sizes.push(size.replace('&nbsp;', ' ').replace('Size ', '')); sizes.push(size.replace('&nbsp;', ' ').replace('Size ', ''));
return sizes; return sizes;
}, [] as string[]); }, [] as string[]);
const magnets = table?.querySelectorAll('a[href^="magnet:"]').map((link) => link.getAttribute('href')); const magnets = table?.querySelectorAll('a[href^="magnet:"]').map((link) => link.getAttribute('href'));
return titles.map((title, index) => { return titles.map((title, index) => {
@@ -50,8 +51,8 @@ export class PirateBay {
title, title,
id: title, id: title,
size: sizes[index], size: sizes[index],
seeders: parseInt(seeders[index]), seeders: parseInt(seeders[index]!),
magnet: magnets[index] magnet: magnets[index]!
}; };
}); });
}); });
+1349 -241
View File
File diff suppressed because it is too large. Load diff
+7 -6
View File
@@ -10,10 +10,12 @@
}, },
"dependencies": { "dependencies": {
"@radix-ui/react-dialog": "^1.0.5", "@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.5", "@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-hover-card": "^1.0.7",
"@radix-ui/react-icons": "^1.3.0", "@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.0.2", "@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-menubar": "^1.0.3", "@radix-ui/react-menubar": "^1.0.3",
"@radix-ui/react-navigation-menu": "^1.1.4",
"@radix-ui/react-popover": "^1.0.6", "@radix-ui/react-popover": "^1.0.6",
"@radix-ui/react-scroll-area": "^1.0.4", "@radix-ui/react-scroll-area": "^1.0.4",
"@radix-ui/react-separator": "^1.0.3", "@radix-ui/react-separator": "^1.0.3",
@@ -22,22 +24,21 @@
"@radix-ui/react-switch": "^1.0.3", "@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tabs": "^1.0.4", "@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-toggle": "^1.0.3", "@radix-ui/react-toggle": "^1.0.3",
"@radix-ui/react-tooltip": "^1.0.6", "@radix-ui/react-tooltip": "^1.0.7",
"@tanstack/react-query": "^5.17.3", "@tanstack/react-query": "^5.17.3",
"axios": "^1.4.0", "axios": "^1.4.0",
"class-variance-authority": "^0.7.0", "class-variance-authority": "^0.7.0",
"classnames": "^2.3.2", "classnames": "^2.3.2",
"clsx": "^2.0.0", "clsx": "^2.0.0",
"cmdk": "^0.2.0", "cmdk": "^0.2.1",
"eslint": "8.45.0", "eslint": "8.45.0",
"eslint-config-next": "^14.0.4", "eslint-config-next": "^14.1.3",
"framer-motion": "^10.16.16", "framer-motion": "^10.16.16",
"jotai": "^2.2.2", "jotai": "^2.2.2",
"js-cookie": "^3.0.5", "js-cookie": "^3.0.5",
"lucide-react": "^0.263.0", "lucide-react": "^0.263.0",
"next": "^14.0.4", "next": "^14.1.3",
"node-html-parser": "^6.1.5", "node-html-parser": "^6.1.5",
"openai": "^3.3.0",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-fast-marquee": "^1.6.0", "react-fast-marquee": "^1.6.0",