Skip to content

Commit

Permalink
pass cookie header to api needing it
Browse files Browse the repository at this point in the history
  • Loading branch information
mirsella committed Dec 22, 2024
1 parent fb7bf26 commit 3e3e43c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 28 deletions.
8 changes: 7 additions & 1 deletion pages/movies/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
let movie_id = useRoute().params.id as string;
if (movie_id === "default") movie_id = "tt1431045";
const headers = useRequestHeaders(["cookie"]) as HeadersInit;
const { data: infos, error: infos_error } = await useFetch(
`/api/movies/${movie_id}`,
{ headers },
);
const { data: subtitles } = await useFetch(
`/api/movies/${movie_id}/subtitles`,
{ headers },
);
const { data: subtitles } = await useFetch(`/api/movies/${movie_id}/subtitles`);
const { data: comments, refresh: refresh_comments } = await useFetch(
`/api/movies/${movie_id}/comments`,
{ headers },
);
if (infos_error.value) throw infos_error.value;
Expand Down
74 changes: 47 additions & 27 deletions server/api/movies/[id]/index.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export default defineEventHandler(async (event) => {
//Fetch movie infos
const response = await fetch(
`${BASE_URL}find/${id}` +
`?external_source=imdb_id` +
`&api_key=${config.tmdbApiKey}`,
`?external_source=imdb_id` +
`&api_key=${config.tmdbApiKey}`,
);
const resData = await response.json();

Expand All @@ -32,14 +32,14 @@ export default defineEventHandler(async (event) => {
//Fetch movie credits
const resCredits = await fetch(
`${BASE_URL}movie/${resData.movie_results[0].id}/credits` +
`?api_key=${config.tmdbApiKey}`,
`?api_key=${config.tmdbApiKey}`,
);
const credits = await resCredits.json();

//Fetch movie details
const resDetails = await fetch(
`${BASE_URL}movie/${resData.movie_results[0].id}` +
`?api_key=${config.tmdbApiKey}`,
`?api_key=${config.tmdbApiKey}`,
);
const details = await resDetails.json();

Expand All @@ -62,24 +62,27 @@ export default defineEventHandler(async (event) => {
};

//Fetch Numbers of comments
const headers = getRequestHeaders(event) as HeadersInit;
const resComments = await $fetch(
`http://localhost:3000/api/movies/${id}/comments`,
)
movie_infos.num_comments = resComments.length
{ headers },
);
movie_infos.num_comments = resComments.length;

//Fetch available subtitles
const resSubtitles = await $fetch(
`http://localhost:3000/api/movies/${id}/subtitles`
)
movie_infos.available_subtitles = resSubtitles
`http://localhost:3000/api/movies/${id}/subtitles`,
{ headers },
);
movie_infos.available_subtitles = resSubtitles;

//Fetch torrents from title
const resTorrents = await fetch(
"http://jackett:9117/api/v2.0/indexers/all/results/torznab/api" +
`?apikey=${config.jackettApiKey}` +
`&t=movie&q=${encodeURI(movie_infos?.title)}` +
`&year=${movie_infos.release_date.slice(0, 4)}` +
`&cat=2000`,
`?apikey=${config.jackettApiKey}` +
`&t=movie&q=${encodeURI(movie_infos?.title)}` +
`&year=${movie_infos.release_date.slice(0, 4)}` +
`&cat=2000`,
);

if (!resTorrents.ok) {
Expand All @@ -95,8 +98,8 @@ export default defineEventHandler(async (event) => {

if (torrents.error) {
throw createError({
statusCode: torrents.error?.['@_code'],
statusMessage: `Jackett: ${torrents?.error?.['@_description']}`,
statusCode: torrents.error?.["@_code"],
statusMessage: `Jackett: ${torrents?.error?.["@_description"]}`,
});
}
if (!torrents?.rss?.channel?.item) {
Expand All @@ -110,27 +113,44 @@ export default defineEventHandler(async (event) => {
movie_infos.torrents = torrents?.rss?.channel?.item
.filter(
(a: any) =>
a["guid"].split(":")[0] === "magnet"
&& parseInt(a["torznab:attr"].find((a: any) => a["@_name"] === "seeders")?.["@_value"],) >= 1
&& (a["torznab:attr"].find((a: any) => a["@_name"] === "imdbid")?.["@_value"] === id ||
(movie_infos.title.toLowerCase().split(/\s+/).every((splitTitle: string) => a?.title?.toLowerCase().includes(splitTitle))
&& a?.title.includes(movie_infos.release_date.split('-')[0]))
)
a["guid"].split(":")[0] === "magnet" &&
parseInt(
a["torznab:attr"].find((a: any) => a["@_name"] === "seeders")?.[
"@_value"
],
) >= 1 &&
(a["torznab:attr"].find((a: any) => a["@_name"] === "imdbid")?.[
"@_value"
] === id ||
(movie_infos.title
.toLowerCase()
.split(/\s+/)
.every((splitTitle: string) =>
a?.title?.toLowerCase().includes(splitTitle),
) &&
a?.title.includes(movie_infos.release_date.split("-")[0]))),
)
.sort(
(a: any, b: any) => parseInt(b["torznab:attr"]
.find((a: any) => a["@_name"] === "seeders")?.["@_value"])
-
parseInt(a["torznab:attr"].find((a: any) => a["@_name"] === "seeders")?.["@_value"]),
(a: any, b: any) =>
parseInt(
b["torznab:attr"].find((a: any) => a["@_name"] === "seeders")?.[
"@_value"
],
) -
parseInt(
a["torznab:attr"].find((a: any) => a["@_name"] === "seeders")?.[
"@_value"
],
),
)
.slice(0, 5)
.map((t: any) => ({
indexer: t.jackettindexer['#text'],
indexer: t.jackettindexer["#text"],
title: t.title,
magnet: t["guid"],
seeders: parseInt(
t["torznab:attr"].find((a: any) => a["@_name"] === "seeders")?.[
"@_value"
"@_value"
],
),
description: t["title"],
Expand Down

0 comments on commit 3e3e43c

Please sign in to comment.