diff --git a/components/Crunchyroll/ListAnimes.ts b/components/Crunchyroll/ListAnimes.ts index 695f653..1d707ac 100644 --- a/components/Crunchyroll/ListAnimes.ts +++ b/components/Crunchyroll/ListAnimes.ts @@ -1,6 +1,6 @@ import type { CrunchyrollSearchResults } from '../Search/Types' import { crunchyLogin } from './Account' -import type { CrunchySearchFetch } from './Types' +import type { CrunchyAnimeFetch, CrunchySearchFetch } from './Types' export async function searchCrunchy(q: string) { const { data: token, error: tokenerror } = await crunchyLogin() @@ -49,3 +49,41 @@ export async function searchCrunchy(q: string) { return results } + +export async function getCRSeries(q: string) { + const { data: token, error: tokenerror } = await crunchyLogin() + + if (!token.value) { + return + } + + const { data, error } = await useFetch(`https://beta-api.crunchyroll.com/content/v2/cms/series/${q}`, { + method: 'GET', + headers: { + Authorization: `Bearer ${token.value.access_token}` + } + }) + + if (error.value) { + console.error(error.value) + throw new Error(JSON.stringify(error.value)) + } + + if (!data.value) return + + const anime = data.value.data[0] + + return { + ID: anime.id, + Url: `https://www.crunchyroll.com/series/${anime.id}/${anime.slug_title}`, + Title: anime.title, + Description: anime.description, + Dubs: anime.audio_locales, + Subs: anime.subtitle_locales, + Episodes: anime.episode_count, + Seasons: anime.season_count, + PEGI: anime.maturity_ratings, + Year: anime.series_launch_year, + Images: anime.images + } +} diff --git a/components/Crunchyroll/Types.ts b/components/Crunchyroll/Types.ts index 2e3c24e..864bf4a 100644 --- a/components/Crunchyroll/Types.ts +++ b/components/Crunchyroll/Types.ts @@ -57,6 +57,59 @@ export interface CrunchySearchFetch { }> } +export interface CrunchyAnimeFetch { + total: number + data: Array<{ + promo_description: string + title: string + promo_title: string + channel_id: string + slug_title: string + search_metadata: { + score: number + } + audio_locales: Array + availability_notes: string + episode_count: number + extended_description: string + extended_maturity_rating: string + is_dubbed: boolean + is_mature: boolean + is_simulcast: boolean + is_subbed: boolean + mature_blocked: boolean + maturity_ratings: Array + season_count: number + series_launch_year: number + subtitle_locales: Array + id: string + slug: string + external_id: string + description: string + new: boolean + images: { + poster_tall: Array< + Array<{ + height: number + source: string + type: string + width: number + }> + > + poster_wide: Array< + Array<{ + height: number + source: string + type: string + width: number + }> + > + } + linked_resource_key: string + type: string + }> +} + export interface CrunchyLogin { access_token: string refresh_token: string diff --git a/pages/addanime.vue b/pages/addanime.vue index 6a1ee0b..abf8a84 100644 --- a/pages/addanime.vue +++ b/pages/addanime.vue @@ -3,7 +3,7 @@
-