fixed no dubs or subs showing

This commit is contained in:
Daniel Haller 2024-04-21 16:10:31 +02:00
parent df0375dc25
commit f3e749ce79
3 changed files with 100 additions and 5 deletions

View File

@ -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<CrunchyAnimeFetch>(`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
}
}

View File

@ -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<string>
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<string>
season_count: number
series_launch_year: number
subtitle_locales: Array<string>
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

View File

@ -3,7 +3,7 @@
<div class="relative flex flex-row items-center justify-center">
<button
v-if="tab === 2"
@click=";(tab = 1), (added = false)"
@click=";(tab = 1), (added = false), (CRselectedShow = null)"
class="absolute left-0 bg-[#5c5b5b] py-1 px-3 rounded-xl flex flex-row items-center justify-center gap-0.5 hover:bg-[#4b4a4a] transition-all"
style="-webkit-app-region: no-drag"
>
@ -204,7 +204,10 @@
</button>
</div>
<div v-if="added" class="relative flex flex-row gap-5 mt-auto">
<button @click=";(tab = 1), (added = false)" class="relative py-3 border-2 rounded-xl flex flex-row items-center justify-center cursor-default w-full">
<button
@click=";(tab = 1), (added = false), (CRselectedShow = null)"
class="relative py-3 border-2 rounded-xl flex flex-row items-center justify-center cursor-default w-full"
>
<div class="flex gap-1 flex-row items-center justify-center transition-all">
<Icon name="formkit:arrowleft" class="h-6 w-6" />
<div class="text-xl">Back</div>
@ -223,7 +226,7 @@
<script lang="ts" setup>
import { searchADN } from '~/components/ADN/ListAnimes'
import { searchCrunchy } from '~/components/Crunchyroll/ListAnimes'
import { getCRSeries, searchCrunchy } from '~/components/Crunchyroll/ListAnimes'
import { listEpisodeCrunchy } from '~/components/Crunchyroll/ListEpisodes'
import { listSeasonCrunchy } from '~/components/Crunchyroll/ListSeasons'
import type { CrunchyEpisode, CrunchyEpisodes } from '~/components/Episode/Types'
@ -265,7 +268,7 @@ const search = ref<string>('')
const searchActive = ref<boolean>(false)
const crunchySearchResults = ref<CrunchyrollSearchResults>()
const adnSearchResults = ref<ADNSearchResults>()
const CRselectedShow = ref<CrunchyrollSearchResult>()
const CRselectedShow = ref<CrunchyrollSearchResult | null>()
const ADNselectedShow = ref<ADNSearchResult>()
const url = ref<string>('')
const path = ref<string>()
@ -404,6 +407,7 @@ const switchToSeason = async () => {
if (url.value && url.value.includes('crunchyroll') && !CRselectedShow.value) {
const seriesID = url.value.split('/')
CRselectedShow.value = await getCRSeries(seriesID[5])
seasons.value = await listSeasonCrunchy(seriesID[5])
if (!seasons.value) {
isFetchingSeasons.value--