From d9fe95dd2570fcebecd5b8f76881d92c1c2e5e5b Mon Sep 17 00:00:00 2001 From: stratuma Date: Fri, 21 Jun 2024 16:27:58 +0200 Subject: [PATCH] added default crunchyroll language selector --- components/Crunchyroll/ListAnimes.ts | 39 ++++++++++++++++++++++++-- components/Crunchyroll/ListEpisodes.ts | 11 ++++++++ components/Crunchyroll/ListSeasons.ts | 11 ++++++++ components/Settings/Crunchyroll.vue | 28 ++++++++++++++++++ pages/addanime.vue | 16 +++++++++-- src/electron/background.ts | 19 +++++++++++++ src/electron/preload.ts | 10 ++++++- 7 files changed, 128 insertions(+), 6 deletions(-) diff --git a/components/Crunchyroll/ListAnimes.ts b/components/Crunchyroll/ListAnimes.ts index d7bb6ec..da3e787 100644 --- a/components/Crunchyroll/ListAnimes.ts +++ b/components/Crunchyroll/ListAnimes.ts @@ -5,9 +5,14 @@ import type { CrunchyAnimeFetch, CrunchyEpisodeFetch, CrunchyEpisodesFetch, Crun export async function searchCrunchy(q: string) { var isProxyActive: boolean | undefined + var selectedLanguage: string | undefined + ;(window as any).myAPI.getProxyActive().then((result: boolean) => { isProxyActive = result }) + ;(window as any).myAPI.getDefaultCrunchyrollLanguage().then((result: string) => { + selectedLanguage = result + }) var proxies @@ -32,7 +37,9 @@ export async function searchCrunchy(q: string) { q: q, n: 100, type: 'series', - ratings: false + ratings: false, + preferred_audio_language: selectedLanguage, + locale: selectedLanguage } }) @@ -61,7 +68,9 @@ export async function searchCrunchy(q: string) { q: q, n: 100, type: 'series', - ratings: false + ratings: false, + preferred_audio_language: selectedLanguage, + locale: selectedLanguage } }) @@ -119,9 +128,14 @@ export async function searchCrunchy(q: string) { export async function getCRSeries(q: string) { var isProxyActive: boolean | undefined + var selectedLanguage: string | undefined + ;(window as any).myAPI.getProxyActive().then((result: boolean) => { isProxyActive = result }) + ;(window as any).myAPI.getDefaultCrunchyrollLanguage().then((result: string) => { + selectedLanguage = result + }) var proxies @@ -141,6 +155,10 @@ export async function getCRSeries(q: string) { method: 'GET', headers: { Authorization: `Bearer ${token.value.access_token}` + }, + query: { + preferred_audio_language: selectedLanguage, + locale: selectedLanguage } }) @@ -162,6 +180,10 @@ export async function getCRSeries(q: string) { method: 'GET', headers: { Authorization: `Bearer ${tokeng.value.access_token}` + }, + query: { + preferred_audio_language: selectedLanguage, + locale: selectedLanguage } }) @@ -201,9 +223,14 @@ export async function getCRSeries(q: string) { export async function getCREpisodeSeriesID(q: string) { var isProxyActive: boolean | undefined + var selectedLanguage: string | undefined + ;(window as any).myAPI.getProxyActive().then((result: boolean) => { isProxyActive = result }) + ;(window as any).myAPI.getDefaultCrunchyrollLanguage().then((result: string) => { + selectedLanguage = result + }) var proxies @@ -223,6 +250,10 @@ export async function getCREpisodeSeriesID(q: string) { method: 'GET', headers: { Authorization: `Bearer ${token.value.access_token}` + }, + query: { + preferred_audio_language: selectedLanguage, + locale: selectedLanguage } }) @@ -244,6 +275,10 @@ export async function getCREpisodeSeriesID(q: string) { method: 'GET', headers: { Authorization: `Bearer ${tokeng.value.access_token}` + }, + query: { + preferred_audio_language: selectedLanguage, + locale: selectedLanguage } }) diff --git a/components/Crunchyroll/ListEpisodes.ts b/components/Crunchyroll/ListEpisodes.ts index b8b0865..50956f3 100644 --- a/components/Crunchyroll/ListEpisodes.ts +++ b/components/Crunchyroll/ListEpisodes.ts @@ -2,6 +2,13 @@ import { crunchyLogin } from './Account' import type { CrunchyEpisodesFetch } from './Types' export async function listEpisodeCrunchy(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') if (!token.value) { @@ -12,6 +19,10 @@ export async function listEpisodeCrunchy(q: string, geo: string | undefined) { method: 'GET', headers: { Authorization: `Bearer ${token.value.access_token}` + }, + query: { + preferred_audio_language: selectedLanguage, + locale: selectedLanguage } }) diff --git a/components/Crunchyroll/ListSeasons.ts b/components/Crunchyroll/ListSeasons.ts index 45f0a01..0489a97 100644 --- a/components/Crunchyroll/ListSeasons.ts +++ b/components/Crunchyroll/ListSeasons.ts @@ -3,6 +3,13 @@ import { getProxies } from './Proxy' 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') if (!token.value) { @@ -13,6 +20,10 @@ export async function listSeasonCrunchy(q: string, geo: string | undefined) { method: 'GET', headers: { Authorization: `Bearer ${token.value.access_token}` + }, + query: { + preferred_audio_language: selectedLanguage, + locale: selectedLanguage } }) diff --git a/components/Settings/Crunchyroll.vue b/components/Settings/Crunchyroll.vue index 045e84b..c6d861a 100644 --- a/components/Settings/Crunchyroll.vue +++ b/components/Settings/Crunchyroll.vue @@ -1,5 +1,22 @@