From 5ae5e837c6389475d650454036cdc5ce866c3fd1 Mon Sep 17 00:00:00 2001 From: stratuma Date: Sat, 18 May 2024 19:48:20 +0200 Subject: [PATCH] added better quality not found error handeling --- components/Settings/Main.vue | 94 ++++++++++++++++++- .../routes/crunchyroll/crunchyroll.service.ts | 8 +- src/api/routes/service/service.service.ts | 13 ++- src/electron/background.ts | 16 +++- src/electron/preload.ts | 1 + 5 files changed, 126 insertions(+), 6 deletions(-) diff --git a/components/Settings/Main.vue b/components/Settings/Main.vue index 4497025..1cabf91 100644 --- a/components/Settings/Main.vue +++ b/components/Settings/Main.vue @@ -1,5 +1,5 @@ diff --git a/src/api/routes/crunchyroll/crunchyroll.service.ts b/src/api/routes/crunchyroll/crunchyroll.service.ts index 8264f0e..526cf14 100644 --- a/src/api/routes/crunchyroll/crunchyroll.service.ts +++ b/src/api/routes/crunchyroll/crunchyroll.service.ts @@ -66,7 +66,7 @@ export async function crunchyLogin(user: string, passw: string) { async function crunchyLoginFetch(user: string, passw: string) { const headers = { 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' } @@ -88,9 +88,9 @@ async function crunchyLoginFetch(user: string, passw: string) { country: string account_id: string profile_id: string - }>('https://beta-api.crunchyroll.com/auth/v1/token', { + }>('https://crd.cx/auth/v1/token', { type: 'POST', - body: new URLSearchParams(body).toString(), + body: JSON.stringify(body), header: headers, credentials: 'same-origin' }) @@ -103,6 +103,8 @@ async function crunchyLoginFetch(user: string, passw: string) { return { data: null, error: null } } + console.log(data.country) + return { data: data, error: null } } diff --git a/src/api/routes/service/service.service.ts b/src/api/routes/service/service.service.ts index 728fcb8..f7a290f 100644 --- a/src/api/routes/service/service.service.ts +++ b/src/api/routes/service/service.service.ts @@ -605,7 +605,18 @@ export async function downloadCrunchyrollPlaylist( 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\/)?([^_,]+)/) diff --git a/src/electron/background.ts b/src/electron/background.ts index 00c4b41..58c95cc 100644 --- a/src/electron/background.ts +++ b/src/electron/background.ts @@ -96,7 +96,7 @@ app.whenReady().then(async () => { export async function messageBox( type: 'none' | 'info' | 'error' | 'question' | 'warning' | undefined, - buttons: Array<'Cancel'>, + buttons: Array<'Cancel' | 'OK'>, defaultId: number, title: string, message: string, @@ -198,6 +198,20 @@ ipcMain.handle('dialog:defaultFile', async (events, type: string) => { 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', () => { if (process.platform !== 'darwin') { app.quit() diff --git a/src/electron/preload.ts b/src/electron/preload.ts index 0d4907d..04b3658 100644 --- a/src/electron/preload.ts +++ b/src/electron/preload.ts @@ -7,6 +7,7 @@ contextBridge.exposeInMainWorld('myAPI', { getEndpoint: () => ipcRenderer.invoke('dialog:getEndpoint'), getFolder: () => ipcRenderer.invoke('dialog:defaultDirectory'), 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), getUpdateStatus: () => ipcRenderer.invoke('updater:getUpdateStatus'), startUpdateDownload: () => ipcRenderer.invoke('updater:download'),