added better quality not found error handeling

This commit is contained in:
stratuma 2024-05-18 19:48:20 +02:00
parent be78d588b1
commit 5ae5e837c6
5 changed files with 126 additions and 6 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="flex flex-col mt-3 font-dm" style="-webkit-app-region: no-drag"> <div class="flex flex-col mt-3 gap-3 font-dm" style="-webkit-app-region: no-drag">
<div class="flex flex-col items-center p-3 bg-[#11111189] rounded-xl select-none"> <div class="flex flex-col items-center p-3 bg-[#11111189] rounded-xl select-none">
<div class="text-sm mb-2"> Account Management </div> <div class="text-sm mb-2"> Account Management </div>
<div v-for="account in accounts" class="flex flex-row items-center h-12 p-3 w-full bg-[#4b4b4b89] rounded-xl"> <div v-for="account in accounts" class="flex flex-row items-center h-12 p-3 w-full bg-[#4b4b4b89] rounded-xl">
@ -18,10 +18,91 @@
</div> </div>
</div> </div>
</div> </div>
<div class="flex flex-col items-center p-3 bg-[#11111189] rounded-xl select-none">
<div class="text-sm mb-2"> Default Dubs </div>
<div class="w-full bg-[#636363] rounded-xl grid grid-cols-10 gap-1 p-1 z-10">
<button
v-for="l in locales"
@click="toggleDub(l)"
class="flex flex-row items-center justify-center gap-3 py-2 rounded-xl text-sm"
:class="dubLocales.find((i) => i.locale === l.locale) ? 'bg-[#424242]' : 'hover:bg-[#747474]'"
>
{{ l.name }}
</button>
</div>
</div>
<div class="flex flex-col items-center p-3 bg-[#11111189] rounded-xl select-none">
<div class="text-sm mb-2"> Default Subs </div>
<div class="w-full bg-[#636363] rounded-xl grid grid-cols-10 gap-1 p-1 z-10">
<button
v-for="l in locales"
@click="toggleSub(l)"
class="flex flex-row items-center justify-center gap-3 py-2 rounded-xl text-sm"
:class="subLocales.find((i) => i.locale === l.locale) ? 'bg-[#424242]' : 'hover:bg-[#747474]'"
>
{{ l.name }}
</button>
</div>
</div>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
const dubLocales = ref<Array<{ locale: string; name: string }>>([])
const subLocales = ref<Array<{ locale: string; name: string }>>([])
const locales = ref<Array<{ locale: string; name: string }>>([
{ locale: 'ja-JP', name: 'JP' },
{ locale: 'de-DE', name: 'DE' },
{ locale: 'hi-IN', name: 'HI' },
{ locale: 'ru-RU', name: 'RU' },
{ locale: 'en-US', name: 'EN' },
{ locale: 'fr-FR', name: 'FR' },
{ locale: 'pt-BR', name: 'PT' },
{ locale: 'es-419', name: 'LA-ES' },
{ locale: 'en-IN', name: 'EN-IN' },
{ locale: 'it-IT', name: 'IT' },
{ locale: 'es-ES', name: 'ES' },
{ locale: 'ta-IN', name: 'TA' },
{ locale: 'te-IN', name: 'TE' },
{ locale: 'ar-SA', name: 'AR' },
{ locale: 'ms-MY', name: 'MS' },
{ locale: 'th-TH', name: 'TH' },
{ locale: 'vi-VN', name: 'VI' },
{ locale: 'id-ID', name: 'ID' },
{ locale: 'ko-KR', name: 'KO' }
])
const toggleDub = (lang: { locale: string; name: string }) => {
const index = dubLocales.value.findIndex((i) => i.locale === lang.locale)
if (index !== -1) {
dubLocales.value.splice(index, 1)
return
}
if (index === -1) {
dubLocales.value.push(lang)
return
}
}
const toggleSub = (lang: { locale: string; name: string }) => {
const index = subLocales.value.findIndex((i) => i.locale === lang.locale)
if (index !== -1) {
subLocales.value.splice(index, 1)
return
}
if (index === -1) {
subLocales.value.push(lang)
return
}
}
const services = ref<{ name: string; service: string }[]>([ const services = ref<{ name: string; service: string }[]>([
{ {
name: 'Crunchyroll', name: 'Crunchyroll',
@ -64,6 +145,17 @@ const deleteAccount = async (id: number) => {
getAccounts() getAccounts()
} }
onMounted(() => {
;(window as any).myAPI.getArray('defdubarray').then((result: any) => {
dubLocales.value = result
})
;(window as any).myAPI.getFile('defsubarray').then((result: any) => {
subLocales.value = result
})
})
</script> </script>
<style></style> <style></style>

View File

@ -66,7 +66,7 @@ export async function crunchyLogin(user: string, passw: string) {
async function crunchyLoginFetch(user: string, passw: string) { async function crunchyLoginFetch(user: string, passw: string) {
const headers = { const headers = {
Authorization: 'Basic dC1rZGdwMmg4YzNqdWI4Zm4wZnE6eWZMRGZNZnJZdktYaDRKWFMxTEVJMmNDcXUxdjVXYW4=', Authorization: 'Basic dC1rZGdwMmg4YzNqdWI4Zm4wZnE6eWZMRGZNZnJZdktYaDRKWFMxTEVJMmNDcXUxdjVXYW4=',
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/json',
'User-Agent': 'Crunchyroll/3.46.2 Android/13 okhttp/4.12.0' 'User-Agent': 'Crunchyroll/3.46.2 Android/13 okhttp/4.12.0'
} }
@ -88,9 +88,9 @@ async function crunchyLoginFetch(user: string, passw: string) {
country: string country: string
account_id: string account_id: string
profile_id: string profile_id: string
}>('https://beta-api.crunchyroll.com/auth/v1/token', { }>('https://crd.cx/auth/v1/token', {
type: 'POST', type: 'POST',
body: new URLSearchParams(body).toString(), body: JSON.stringify(body),
header: headers, header: headers,
credentials: 'same-origin' credentials: 'same-origin'
}) })
@ -103,6 +103,8 @@ async function crunchyLoginFetch(user: string, passw: string) {
return { data: null, error: null } return { data: null, error: null }
} }
console.log(data.country)
return { data: data, error: null } return { data: data, error: null }
} }

View File

@ -605,7 +605,18 @@ export async function downloadCrunchyrollPlaylist(
var hq = mdp.playlists.find((i) => i.attributes.RESOLUTION?.height === quality) var hq = mdp.playlists.find((i) => i.attributes.RESOLUTION?.height === quality)
if (!hq) return if (!hq) {
console.log(`Res ${quality}p not found, using res ${mdp.playlists[0].attributes.RESOLUTION?.height}p instead`)
messageBox(
'warning',
['OK'],
5,
`Resolution ${quality}p not found`,
`Resolution ${quality}p not found`,
`Resolution ${quality}p not found, using resolution ${mdp.playlists[0].attributes.RESOLUTION?.height}p instead`
)
hq = mdp.playlists[0]
}
const assetId = hq.segments[0].resolvedUri.match(/\/assets\/(?:p\/)?([^_,]+)/) const assetId = hq.segments[0].resolvedUri.match(/\/assets\/(?:p\/)?([^_,]+)/)

View File

@ -96,7 +96,7 @@ app.whenReady().then(async () => {
export async function messageBox( export async function messageBox(
type: 'none' | 'info' | 'error' | 'question' | 'warning' | undefined, type: 'none' | 'info' | 'error' | 'question' | 'warning' | undefined,
buttons: Array<'Cancel'>, buttons: Array<'Cancel' | 'OK'>,
defaultId: number, defaultId: number,
title: string, title: string,
message: string, message: string,
@ -198,6 +198,20 @@ ipcMain.handle('dialog:defaultFile', async (events, type: string) => {
return savedPath return savedPath
}) })
ipcMain.handle('dialog:defaultArray', async (events, type: string) => {
if (!type) return
const savedPath = await settings.get(type)
if (!savedPath) {
return []
}
return savedPath
})
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
if (process.platform !== 'darwin') { if (process.platform !== 'darwin') {
app.quit() app.quit()

View File

@ -7,6 +7,7 @@ contextBridge.exposeInMainWorld('myAPI', {
getEndpoint: () => ipcRenderer.invoke('dialog:getEndpoint'), getEndpoint: () => ipcRenderer.invoke('dialog:getEndpoint'),
getFolder: () => ipcRenderer.invoke('dialog:defaultDirectory'), getFolder: () => ipcRenderer.invoke('dialog:defaultDirectory'),
getFile: (type: string) => ipcRenderer.invoke('dialog:defaultFile', type), getFile: (type: string) => ipcRenderer.invoke('dialog:defaultFile', type),
getArray: (type: string) => ipcRenderer.invoke('dialog:defaultArray', type),
openWindow: (opt: { title: string; url: string; width: number; height: number; backgroundColor: string }) => ipcRenderer.invoke('window:openNewWindow', opt), openWindow: (opt: { title: string; url: string; width: number; height: number; backgroundColor: string }) => ipcRenderer.invoke('window:openNewWindow', opt),
getUpdateStatus: () => ipcRenderer.invoke('updater:getUpdateStatus'), getUpdateStatus: () => ipcRenderer.invoke('updater:getUpdateStatus'),
startUpdateDownload: () => ipcRenderer.invoke('updater:download'), startUpdateDownload: () => ipcRenderer.invoke('updater:download'),