added more proxies / added proxy control

This commit is contained in:
stratuma 2024-05-19 23:11:54 +02:00
parent 9e3546bf49
commit 56865e767d
8 changed files with 169 additions and 74 deletions

View File

@ -5,6 +5,12 @@ import type { CrunchyAnimeFetch, CrunchySearchFetch } from './Types'
export async function searchCrunchy(q: string) { export async function searchCrunchy(q: string) {
var isProxyActive: boolean | undefined;
;(window as any).myAPI.getProxyActive().then((result: boolean) => {
isProxyActive = result
})
const { data: proxies } = await getProxies() const { data: proxies } = await getProxies()
const { data: token, error: tokenerror } = await crunchyLogin('LOCAL') const { data: token, error: tokenerror } = await crunchyLogin('LOCAL')
@ -31,7 +37,7 @@ export async function searchCrunchy(q: string) {
throw new Error(JSON.stringify(error.value)) throw new Error(JSON.stringify(error.value))
} }
if (proxies.value) { if (proxies.value && isProxyActive) {
for (const p of proxies.value) { for (const p of proxies.value) {
if (p.status !== 'offline') { if (p.status !== 'offline') {
const { data: tokeng, error: tokenerrorg } = await crunchyLogin(p.code) const { data: tokeng, error: tokenerrorg } = await crunchyLogin(p.code)
@ -106,6 +112,13 @@ export async function searchCrunchy(q: string) {
} }
export async function getCRSeries(q: string) { export async function getCRSeries(q: string) {
var isProxyActive: boolean | undefined;
;(window as any).myAPI.getProxyActive().then((result: boolean) => {
isProxyActive = result
})
const { data: proxies } = await getProxies() const { data: proxies } = await getProxies()
const { data: token, error: tokenerror } = await crunchyLogin('LOCAL') const { data: token, error: tokenerror } = await crunchyLogin('LOCAL')
@ -126,7 +139,7 @@ export async function getCRSeries(q: string) {
throw new Error(JSON.stringify(error.value)) throw new Error(JSON.stringify(error.value))
} }
if (!data.value && proxies.value) { if (!data.value && proxies.value && isProxyActive) {
for (const p of proxies.value) { for (const p of proxies.value) {
if (p.status !== 'offline') { if (p.status !== 'offline') {
const { data: tokeng, error: tokenerrorg } = await crunchyLogin(p.code) const { data: tokeng, error: tokenerrorg } = await crunchyLogin(p.code)

View File

@ -3,7 +3,6 @@ import { getProxies } from './Proxy'
import type { CrunchySeasonsFetch } from './Types' import type { CrunchySeasonsFetch } from './Types'
export async function listSeasonCrunchy(q: string, geo: string | undefined) { export async function listSeasonCrunchy(q: string, geo: string | undefined) {
const { data: proxies } = await getProxies()
const { data: token, error: tokenerror } = await crunchyLogin(geo ? geo : 'LOCAL') const { data: token, error: tokenerror } = await crunchyLogin(geo ? geo : 'LOCAL')
@ -25,23 +24,5 @@ export async function listSeasonCrunchy(q: string, geo: string | undefined) {
if (!data.value) return if (!data.value) return
if (proxies.value) {
for (const p of proxies.value) {
if (p.status !== 'offline') {
const { data: gdata, error: gerror } = await useFetch<CrunchySeasonsFetch>(`https://beta-api.crunchyroll.com/content/v2/cms/series/${q}/seasons`, {
method: 'GET',
headers: {
Authorization: `Bearer ${token.value.access_token}`
}
})
if (gerror.value) {
console.error(error.value)
throw new Error(JSON.stringify(error.value))
}
}
}
}
return data.value.data return data.value.data
} }

View File

@ -3,13 +3,16 @@
<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"> Proxy Settings </div> <div class="text-sm mb-2"> Proxy Settings </div>
<div class="flex flex-row"> <div class="flex flex-row">
<input type="checkbox" name="Login Proxy" class="cursor-pointer"> <input v-model="isProxyLogin" @change="setProxyActive(isProxyLogin)" type="checkbox" name="Login Proxy" class="cursor-pointer">
<div class="text-sm ml-1.5"> <div class="text-sm ml-1.5">
Use Login Proxies Use Login Proxies
</div> </div>
</div> </div>
<div class="text-xs mt-2">
Used for bypassing geoblocking
</div>
</div> </div>
<div class="flex flex-col items-center p-3 bg-[#11111189] rounded-xl select-none" :class="fetchingProxies ? 'h-44' : 'h-auto'"> <div class="flex flex-col items-center p-3 bg-[#11111189] rounded-xl select-none gap-1" :class="fetchingProxies ? 'h-44' : 'h-auto'">
<div class="text-sm mb-2"> Global Proxies </div> <div class="text-sm mb-2"> Global Proxies </div>
<div v-if="fetchingProxies" class="flex flex-row items-center mt-5 text-sm"> <div v-if="fetchingProxies" class="flex flex-row items-center mt-5 text-sm">
<Icon name="mdi:loading" class="h-5 w-5 text-white animate-spin mr-2" /> <Icon name="mdi:loading" class="h-5 w-5 text-white animate-spin mr-2" />
@ -39,6 +42,7 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
const isProxyLogin = ref<boolean>();
const proxies = ref<{ name: string; url: string; status: string }[]>() const proxies = ref<{ name: string; url: string; status: string }[]>()
const fetchingProxies = ref<0>(0) const fetchingProxies = ref<0>(0)
@ -63,6 +67,20 @@ const getProxies = async () => {
} }
getProxies() getProxies()
const setProxyActive = (status: boolean | undefined) => {
if (process.client) {
;(window as any).myAPI.setProxyActive(status).then((result: boolean) => {
isProxyLogin.value = result
})
}
}
onMounted(() => {
;(window as any).myAPI.getProxyActive().then((result: boolean) => {
isProxyLogin.value = result
})
})
</script> </script>
<style></style> <style></style>

View File

@ -3,7 +3,7 @@ import { server } from '../../api'
import { VideoPlaylist, VideoPlaylistNoGEO } from '../../types/crunchyroll' import { VideoPlaylist, VideoPlaylistNoGEO } from '../../types/crunchyroll'
import { useFetch } from '../useFetch' import { useFetch } from '../useFetch'
import { parse as mpdParse } from 'mpd-parser' import { parse as mpdParse } from 'mpd-parser'
import { loggedInCheck } from '../service/service.service' import { checkProxies, loggedInCheck } from '../service/service.service'
import settings from 'electron-settings' import settings from 'electron-settings'
// Crunchyroll Error message list // Crunchyroll Error message list
@ -15,14 +15,20 @@ const crErrors = [
] ]
// Login Proxies // Login Proxies
const proxies: { name: string; code: string; url: string; status: string | undefined }[] = [ // const proxies: { name: string; code: string; url: string; status: string | undefined }[] = [
{ // {
name: 'US Proxy', // name: 'US Proxy',
code: 'US', // code: 'US',
url: 'https://us-proxy.crd.cx/', // url: 'https://us-proxy.crd.cx/',
status: undefined // status: undefined
} // },
] // {
// name: 'UK Proxy',
// code: 'GB',
// url: 'https://uk-proxy.crd.cx/',
// status: undefined
// }
// ]
// Crunchyroll Login Handler // Crunchyroll Login Handler
export async function crunchyLogin(user: string, passw: string, geo: string) { export async function crunchyLogin(user: string, passw: string, geo: string) {
@ -106,6 +112,9 @@ export async function crunchyLogin(user: string, passw: string, geo: string) {
// Crunchyroll Login Fetch Proxy // Crunchyroll Login Fetch Proxy
async function crunchyLoginFetchProxy(user: string, passw: string, geo: string) { async function crunchyLoginFetchProxy(user: string, passw: string, geo: string) {
const proxies = await checkProxies()
var host: string | undefined var host: string | undefined
host = proxies.find((p) => p.code === geo)?.url host = proxies.find((p) => p.code === geo)?.url
@ -197,6 +206,20 @@ async function crunchyLoginFetch(user: string, passw: string) {
// Crunchyroll Playlist Fetch // Crunchyroll Playlist Fetch
export async function crunchyGetPlaylist(q: string, geo: string | undefined) { export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
const isProxyActive = await settings.get('proxyActive')
var proxies: {
name: string;
code: string;
url: string;
status: string | undefined;
}[] = [];
if (isProxyActive) {
proxies = await checkProxies()
}
var endpoint = await settings.get('CREndpoint') var endpoint = await settings.get('CREndpoint')
const drmL3blob = await settings.get('l3blob') const drmL3blob = await settings.get('l3blob')
const drmL3key = await settings.get('l3key') const drmL3key = await settings.get('l3key')
@ -320,6 +343,8 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
throw new Error(e as string) throw new Error(e as string)
} }
if (isProxyActive)
for (const p of proxies) { for (const p of proxies) {
if (p.code !== loginLocal.country) { if (p.code !== loginLocal.country) {
const { data: login, error } = await crunchyLogin(account.username, account.password, p.code) const { data: login, error } = await crunchyLogin(account.username, account.password, p.code)
@ -331,49 +356,40 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
'X-Cr-Disable-Drm': 'true' 'X-Cr-Disable-Drm': 'true'
} }
try { const response = await fetch(
const response = await fetch( `https://cr-play-service.prd.crunchyrollsvc.com/v1/${q}${
`https://cr-play-service.prd.crunchyrollsvc.com/v1/${q}${ endpoints.find((e) => e.id === endpoint) ? endpoints.find((e) => e.id === endpoint)?.url : '/console/switch/play'
endpoints.find((e) => e.id === endpoint) ? endpoints.find((e) => e.id === endpoint)?.url : '/console/switch/play' }`,
}`, {
{ method: 'GET',
method: 'GET', headers: headers
headers: headers }
} )
)
if (response.ok) {
if (response.ok) { const data: VideoPlaylistNoGEO = JSON.parse(await response.text())
const data: VideoPlaylistNoGEO = JSON.parse(await response.text())
data.hardSubs = Object.values((data as any).hardSubs)
data.hardSubs = Object.values((data as any).hardSubs)
data.subtitles = Object.values((data as any).subtitles)
data.subtitles = Object.values((data as any).subtitles)
for (const v of data.versions) {
for (const v of data.versions) { if (!playlist.versions.find((ver) => ver.guid === v.guid)) {
if (!playlist.versions.find((ver) => ver.guid === v.guid)) { playlist.versions.push({ ...v, geo: p.code })
playlist.versions.push({ ...v, geo: p.code }) }
} }
}
for (const v of data.subtitles) {
for (const v of data.subtitles) { if (!playlist.subtitles.find((ver) => ver.language === v.language)) {
if (!playlist.subtitles.find((ver) => ver.language === v.language)) { playlist.subtitles.push({ ...v, geo: p.code })
playlist.subtitles.push({ ...v, geo: p.code }) }
} }
}
for (const v of data.hardSubs) {
for (const v of data.hardSubs) { if (!playlist.hardSubs.find((ver) => ver.hlang === v.hlang)) {
if (!playlist.hardSubs.find((ver) => ver.hlang === v.hlang)) { playlist.hardSubs.push({ ...v, geo: p.code })
playlist.hardSubs.push({ ...v, geo: p.code }) }
}
}
} else {
const error = await response.text()
messageBox('error', ['Cancel'], 2, 'Failed to get MPD Playlist', 'Failed to get MPD Playlist', error)
throw new Error(error)
} }
} catch (e) {
throw new Error(e as string)
} }
} }
} }

View File

@ -145,6 +145,12 @@ export async function checkProxiesController(
if (!cachedData) { if (!cachedData) {
const proxies: { name: string, code: string, url: string, status: string | undefined }[] = [{ const proxies: { name: string, code: string, url: string, status: string | undefined }[] = [{
name: 'US Proxy', code: 'US', url: 'https://us-proxy.crd.cx/', status: undefined name: 'US Proxy', code: 'US', url: 'https://us-proxy.crd.cx/', status: undefined
},
{
name: 'UK Proxy', code: 'GB', url: 'https://uk-proxy.crd.cx/', status: undefined
},
{
name: 'DE Proxy', code: 'DE', url: 'https://de-proxy.crd.cx/', status: undefined
}] }]
for (const p of proxies) { for (const p of proxies) {

View File

@ -20,6 +20,7 @@ const ffmpegP = getFFMPEGPath()
const mp4e = getMP4DecryptPath() const mp4e = getMP4DecryptPath()
import util from 'util' import util from 'util'
import settings from 'electron-settings' import settings from 'electron-settings'
import { server } from '../../api'
const exec = util.promisify(require('child_process').exec) const exec = util.promisify(require('child_process').exec)
// Get All Accounts // Get All Accounts
@ -939,3 +940,43 @@ async function mergeVideoFile(video: string, audios: Array<string>, subs: Array<
}) })
}) })
} }
export async function checkProxies() {
const cachedData = server.CacheController.get('proxycheck') as { name: string, code: string, url: string, status: string | undefined }[];
if (!cachedData) {
const proxies: { name: string, code: string, url: string, status: string | undefined }[] = [{
name: 'US Proxy', code: 'US', url: 'https://us-proxy.crd.cx/', status: undefined
},
{
name: 'UK Proxy', code: 'GB', url: 'https://uk-proxy.crd.cx/', status: undefined
},
{
name: 'DE Proxy', code: 'DE', url: 'https://de-proxy.crd.cx/', status: undefined
}]
for (const p of proxies) {
const response = await fetch(
p.url + 'health',
{
method: 'GET',
}
)
if (response.ok) {
p.status = 'online'
} else {
p.status = 'offline'
}
}
server.CacheController.set('proxycheck', proxies, 60)
return proxies
}
return cachedData
}

View File

@ -211,6 +211,24 @@ ipcMain.handle('dialog:defaultArray', async (events, type: string) => {
return savedPath return savedPath
}) })
ipcMain.handle('dialog:proxyActive', async (events) => {
const savedStat = await settings.get('proxyActive')
if (!savedStat) {
await settings.set('proxyActive', false)
return false
}
return savedStat
})
ipcMain.handle('dialog:proxyActiveSet', async (events, status: boolean) => {
await settings.set('proxyActive', status)
return status
})
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
if (process.platform !== 'darwin') { if (process.platform !== 'darwin') {

View File

@ -8,6 +8,8 @@ contextBridge.exposeInMainWorld('myAPI', {
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), getArray: (type: string) => ipcRenderer.invoke('dialog:defaultArray', type),
getProxyActive: () => ipcRenderer.invoke('dialog:proxyActive'),
setProxyActive: (status: boolean) => ipcRenderer.invoke('dialog:proxyActiveSet', status),
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'),