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) {
var isProxyActive: boolean | undefined;
;(window as any).myAPI.getProxyActive().then((result: boolean) => {
isProxyActive = result
})
const { data: proxies } = await getProxies()
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))
}
if (proxies.value) {
if (proxies.value && isProxyActive) {
for (const p of proxies.value) {
if (p.status !== 'offline') {
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) {
var isProxyActive: boolean | undefined;
;(window as any).myAPI.getProxyActive().then((result: boolean) => {
isProxyActive = result
})
const { data: proxies } = await getProxies()
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))
}
if (!data.value && proxies.value) {
if (!data.value && proxies.value && isProxyActive) {
for (const p of proxies.value) {
if (p.status !== 'offline') {
const { data: tokeng, error: tokenerrorg } = await crunchyLogin(p.code)

View File

@ -3,7 +3,6 @@ import { getProxies } from './Proxy'
import type { CrunchySeasonsFetch } from './Types'
export async function listSeasonCrunchy(q: string, geo: string | undefined) {
const { data: proxies } = await getProxies()
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 (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
}

View File

@ -3,13 +3,16 @@
<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="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">
Use Login Proxies
</div>
</div>
<div class="text-xs mt-2">
Used for bypassing geoblocking
</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 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" />
@ -39,6 +42,7 @@
</template>
<script lang="ts" setup>
const isProxyLogin = ref<boolean>();
const proxies = ref<{ name: string; url: string; status: string }[]>()
const fetchingProxies = ref<0>(0)
@ -63,6 +67,20 @@ const getProxies = async () => {
}
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>
<style></style>

View File

@ -3,7 +3,7 @@ import { server } from '../../api'
import { VideoPlaylist, VideoPlaylistNoGEO } from '../../types/crunchyroll'
import { useFetch } from '../useFetch'
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'
// Crunchyroll Error message list
@ -15,14 +15,20 @@ const crErrors = [
]
// Login Proxies
const proxies: { name: string; code: string; url: string; status: string | undefined }[] = [
{
name: 'US Proxy',
code: 'US',
url: 'https://us-proxy.crd.cx/',
status: 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: 'UK Proxy',
// code: 'GB',
// url: 'https://uk-proxy.crd.cx/',
// status: undefined
// }
// ]
// Crunchyroll Login Handler
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
async function crunchyLoginFetchProxy(user: string, passw: string, geo: string) {
const proxies = await checkProxies()
var host: string | undefined
host = proxies.find((p) => p.code === geo)?.url
@ -197,6 +206,20 @@ async function crunchyLoginFetch(user: string, passw: string) {
// Crunchyroll Playlist Fetch
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')
const drmL3blob = await settings.get('l3blob')
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)
}
if (isProxyActive)
for (const p of proxies) {
if (p.code !== loginLocal.country) {
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'
}
try {
const response = await fetch(
`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'
}`,
{
method: 'GET',
headers: headers
}
)
if (response.ok) {
const data: VideoPlaylistNoGEO = JSON.parse(await response.text())
data.hardSubs = Object.values((data as any).hardSubs)
data.subtitles = Object.values((data as any).subtitles)
for (const v of data.versions) {
if (!playlist.versions.find((ver) => ver.guid === v.guid)) {
playlist.versions.push({ ...v, geo: p.code })
}
}
for (const v of data.subtitles) {
if (!playlist.subtitles.find((ver) => ver.language === v.language)) {
playlist.subtitles.push({ ...v, geo: p.code })
}
}
for (const v of data.hardSubs) {
if (!playlist.hardSubs.find((ver) => ver.hlang === v.hlang)) {
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)
const response = await fetch(
`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'
}`,
{
method: 'GET',
headers: headers
}
)
if (response.ok) {
const data: VideoPlaylistNoGEO = JSON.parse(await response.text())
data.hardSubs = Object.values((data as any).hardSubs)
data.subtitles = Object.values((data as any).subtitles)
for (const v of data.versions) {
if (!playlist.versions.find((ver) => ver.guid === v.guid)) {
playlist.versions.push({ ...v, geo: p.code })
}
}
for (const v of data.subtitles) {
if (!playlist.subtitles.find((ver) => ver.language === v.language)) {
playlist.subtitles.push({ ...v, geo: p.code })
}
}
for (const v of data.hardSubs) {
if (!playlist.hardSubs.find((ver) => ver.hlang === v.hlang)) {
playlist.hardSubs.push({ ...v, geo: p.code })
}
}
} catch (e) {
throw new Error(e as string)
}
}
}

View File

@ -145,6 +145,12 @@ export async function checkProxiesController(
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) {

View File

@ -20,6 +20,7 @@ const ffmpegP = getFFMPEGPath()
const mp4e = getMP4DecryptPath()
import util from 'util'
import settings from 'electron-settings'
import { server } from '../../api'
const exec = util.promisify(require('child_process').exec)
// 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
})
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', () => {
if (process.platform !== 'darwin') {

View File

@ -8,6 +8,8 @@ contextBridge.exposeInMainWorld('myAPI', {
getFolder: () => ipcRenderer.invoke('dialog:defaultDirectory'),
getFile: (type: string) => ipcRenderer.invoke('dialog:defaultFile', 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),
getUpdateStatus: () => ipcRenderer.invoke('updater:getUpdateStatus'),
startUpdateDownload: () => ipcRenderer.invoke('updater:download'),