This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
CrunchyDL/components/Crunchyroll/ListSeasons.ts

39 lines
1.0 KiB
TypeScript
Raw Normal View History

2024-04-16 20:20:30 +02:00
import { crunchyLogin } from './Account'
import { getProxies } from './Proxy'
2024-04-16 20:20:30 +02:00
import type { CrunchySeasonsFetch } from './Types'
export async function listSeasonCrunchy(q: string, geo: string | undefined) {
var selectedLanguage: string | undefined
;(window as any).myAPI.getDefaultCrunchyrollLanguage().then((result: string) => {
selectedLanguage = result
})
const { data: token, error: tokenerror } = await crunchyLogin(geo ? geo : 'LOCAL')
2024-04-16 20:20:30 +02:00
2024-05-01 01:45:45 +02:00
if (!token.value) {
return
}
2024-04-16 20:20:30 +02:00
2024-05-01 01:45:45 +02:00
const { data, error } = await useFetch<CrunchySeasonsFetch>(`https://beta-api.crunchyroll.com/content/v2/cms/series/${q}/seasons`, {
method: 'GET',
headers: {
Authorization: `Bearer ${token.value.access_token}`
},
query: {
preferred_audio_language: selectedLanguage,
locale: selectedLanguage
2024-05-01 01:45:45 +02:00
}
})
2024-04-16 20:20:30 +02:00
2024-05-01 01:45:45 +02:00
if (error.value) {
console.error(error.value)
throw new Error(JSON.stringify(error.value))
}
2024-04-16 20:20:30 +02:00
2024-05-01 01:45:45 +02:00
if (!data.value) return
2024-04-16 20:20:30 +02:00
2024-05-01 01:45:45 +02:00
return data.value.data
2024-04-16 20:20:30 +02:00
}