From 201c9bf04597b1ee421a6f58e5656c147e227d1d Mon Sep 17 00:00:00 2001 From: stratuma Date: Sun, 30 Jun 2024 04:33:17 +0200 Subject: [PATCH] added adn de and fr dub support --- package.json | 2 - pages/addanime.vue | 41 ++++++++------ pnpm-lock.yaml | 13 ----- src/api/routes/adn/adn.service.ts | 65 ++++++++++------------- src/api/routes/service/service.service.ts | 64 ++++++++++++++++++---- src/api/types/adn.ts | 21 ++++++++ 6 files changed, 127 insertions(+), 79 deletions(-) diff --git a/package.json b/package.json index 370a749..cd985a7 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "@types/express": "^4.17.21", "@types/fluent-ffmpeg": "^2.1.24", "@types/node-cron": "^3.0.11", - "@types/node-forge": "^1.3.11", "concurrently": "^8.2.2", "dotenv": "^16.4.5", "electron": "^30.1.2", @@ -60,7 +59,6 @@ "mpd-parser": "^1.3.0", "node-cache": "^5.1.2", "node-cron": "^3.0.3", - "node-forge": "^1.3.1", "protobufjs": "^7.3.2", "sequelize": "^6.37.3", "sqlite3": "5.1.6", diff --git a/pages/addanime.vue b/pages/addanime.vue index eb36b22..9008893 100644 --- a/pages/addanime.vue +++ b/pages/addanime.vue @@ -191,28 +191,29 @@
- + +
@@ -832,6 +833,12 @@ const toggleDub = (lang: { name: string | undefined; locale: string }) => { } } +const toggleDubADN = (lang: { name: string | undefined; locale: string }) => { + selectedDubs.value = [] + + selectedDubs.value.push(lang) +} + const toggleSub = (lang: { name: string | undefined; locale: string }) => { const index = selectedSubs.value.findIndex((i) => i.locale === lang.locale) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4913820..f185e44 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -50,9 +50,6 @@ importers: node-cron: specifier: ^3.0.3 version: 3.0.3 - node-forge: - specifier: ^1.3.1 - version: 1.3.1 protobufjs: specifier: ^7.3.2 version: 7.3.2 @@ -93,9 +90,6 @@ importers: '@types/node-cron': specifier: ^3.0.11 version: 3.0.11 - '@types/node-forge': - specifier: ^1.3.11 - version: 1.3.11 concurrently: specifier: ^8.2.2 version: 8.2.2 @@ -1391,9 +1385,6 @@ packages: '@types/node-cron@3.0.11': resolution: {integrity: sha512-0ikrnug3/IyneSHqCBeslAhlK2aBfYek1fGo4bP4QnZPmiqSGRK+Oy7ZMisLWkesffJvQ1cqAcBnJC+8+nxIAg==} - '@types/node-forge@1.3.11': - resolution: {integrity: sha512-FQx220y22OKNTqaByeBGqHWYz4cl94tpcxeFdvBo3wjG6XPBuZ0BNgNZRV5J5TFmmcsJ4IzsLkmGRiQbnYsBEQ==} - '@types/node@20.14.9': resolution: {integrity: sha512-06OCtnTXtWOZBJlRApleWndH4JsRVs1pDCc8dLSQp+7PpUpX3ePdHyeNSFTeSe7FtKyQkrlPvHwJOW3SLd8Oyg==} @@ -7655,10 +7646,6 @@ snapshots: '@types/node-cron@3.0.11': {} - '@types/node-forge@1.3.11': - dependencies: - '@types/node': 20.14.9 - '@types/node@20.14.9': dependencies: undici-types: 5.26.5 diff --git a/src/api/routes/adn/adn.service.ts b/src/api/routes/adn/adn.service.ts index 0ff3fb1..383976d 100644 --- a/src/api/routes/adn/adn.service.ts +++ b/src/api/routes/adn/adn.service.ts @@ -4,7 +4,7 @@ import { ADNLink, ADNPlayerConfig } from '../../types/adn' import { messageBox } from '../../../electron/background' import { useFetch } from '../useFetch' import { loggedInCheck } from '../service/service.service' -import * as forge from 'node-forge' +import crypto from 'crypto' export async function adnLogin(user: string, passw: string) { const cachedData: @@ -125,7 +125,7 @@ export async function getPlayerConfigADN(id: number, geo: 'de' | 'fr') { return data } else { - throw new Error('Failed to fetch ADN') + throw new Error('Failed to fetch ADN Player config') } } catch (e) { throw new Error(e as string) @@ -156,7 +156,7 @@ async function getPlayerToken(id: number, geo: 'de' | 'fr') { return data } else { - throw new Error('Failed to fetch ADN') + throw new Error('Failed to fetch ADN Player token') } } catch (e) { throw new Error(e as string) @@ -167,57 +167,48 @@ function randomHexaString(length: number) { const characters = '0123456789abcdef' let result = '' for (let i = 0; i < length; i++) { - result += characters[Math.floor(Math.random() * characters.length)] + result += characters.charAt(Math.floor(Math.random() * characters.length)) } return result } -async function getPlayerEncryptedToken(id: number, geo: 'de' | 'fr') { - const token = await getPlayerToken(id, geo) - - if (!token) return - - const publicKeyPem = `-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCbQrCJBRmaXM4gJidDmcpWDssgnumHinCLHAgS4buMtdH7dEGGEUfBofLzoEdt1jqcrCDT6YNhM0aFCqbLOPFtx9cg/X2G/G5bPVu8cuFM0L+ehp8s6izK1kjx3OOPH/kWzvstM5tkqgJkNyNEvHdeJl6KhS+IFEqwvZqgbBpKuwIDAQAB-----END PUBLIC KEY-----` - - var random = CryptoJS.lib.WordArray.random(16).toString(CryptoJS.enc.Hex) - - const data = { - k: random, - t: String(token.token) - } - - const finisheddata = JSON.stringify(data) - - const encryptedData = encryptWithPublicKey(publicKeyPem, finisheddata) - - return { data: encryptedData, random: random } -} - -function encryptWithPublicKey(publicKeyPem: string, data: string) { - const publicKey = forge.pki.publicKeyFromPem(publicKeyPem) - const encryptedData = publicKey.encrypt(data, 'RSA-OAEP', { - md: forge.md.sha256.create() - }) - return forge.util.encode64(encryptedData) -} - export async function adnGetPlaylist(animeid: number, geo: 'de' | 'fr') { - const token = await getPlayerEncryptedToken(animeid, geo) + const player = await getPlayerToken(animeid, geo) - if (!token) return + if (!player) return + + const random = randomHexaString(16) + + const authorization = crypto + .publicEncrypt( + { + key: '-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCbQrCJBRmaXM4gJidDmcpWDssg\nnumHinCLHAgS4buMtdH7dEGGEUfBofLzoEdt1jqcrCDT6YNhM0aFCqbLOPFtx9cg\n/X2G/G5bPVu8cuFM0L+ehp8s6izK1kjx3OOPH/kWzvstM5tkqgJkNyNEvHdeJl6\nKhS+IFEqwvZqgbBpKuwIDAQAB\n-----END PUBLIC KEY-----', + padding: crypto.constants.RSA_PKCS1_PADDING + }, + Buffer.from( + JSON.stringify({ + k: random, + t: player.token + }), + 'utf-8' + ) + ) + .toString('base64') + + if (!authorization) return try { const response = await fetch(`https://gw.api.animationdigitalnetwork.fr/player/video/${animeid}/link`, { method: 'GET', headers: { 'x-target-distribution': geo, - 'X-Player-Token': token.data + 'X-Player-Token': authorization } }) if (response.ok) { const data: ADNLink = await JSON.parse(await response.text()) - return { data: data, secret: token.random } + return { data: data, secret: random } } else { const data: { message: string; code: string; statusCode: string } = JSON.parse(await response.text()) diff --git a/src/api/routes/service/service.service.ts b/src/api/routes/service/service.service.ts index 1b192a8..5c3aa39 100644 --- a/src/api/routes/service/service.service.ts +++ b/src/api/routes/service/service.service.ts @@ -422,16 +422,60 @@ export async function downloadADNPlaylist( var link: string = '' - switch (quality) { - case 1080: - link = playlist.data.links.streaming.vostde.fhd - break - case 720: - link = playlist.data.links.streaming.vostde.hd - break - case 480: - link = playlist.data.links.streaming.vostde.sd - break + if (dubs.find((i) => i === 'ja-JP') && playlist.data.links.streaming.vostde) { + switch (quality) { + case 1080: + link = playlist.data.links.streaming.vostde.fhd + break + case 720: + link = playlist.data.links.streaming.vostde.hd + break + case 480: + link = playlist.data.links.streaming.vostde.sd + break + } + } + + if (dubs.find((i) => i === 'ja-JP') && playlist.data.links.streaming.vostf) { + switch (quality) { + case 1080: + link = playlist.data.links.streaming.vostf.fhd + break + case 720: + link = playlist.data.links.streaming.vostf.hd + break + case 480: + link = playlist.data.links.streaming.vostf.sd + break + } + } + + if (dubs.find((i) => i === 'de-DE')) { + switch (quality) { + case 1080: + link = playlist.data.links.streaming.vde.fhd + break + case 720: + link = playlist.data.links.streaming.vde.hd + break + case 480: + link = playlist.data.links.streaming.vde.sd + break + } + } + + if (dubs.find((i) => i === 'fr-FR')) { + switch (quality) { + case 1080: + link = playlist.data.links.streaming.vf.fhd + break + case 720: + link = playlist.data.links.streaming.vf.hd + break + case 480: + link = playlist.data.links.streaming.vf.sd + break + } } if (!link) return diff --git a/src/api/types/adn.ts b/src/api/types/adn.ts index ded6b92..ebccf31 100644 --- a/src/api/types/adn.ts +++ b/src/api/types/adn.ts @@ -45,6 +45,27 @@ export interface ADNLink { fhd: string auto: string } + vostf: { + mobile: string + sd: string + hd: string + fhd: string + auto: string + } + vde: { + mobile: string + sd: string + hd: string + fhd: string + auto: string + } + vf: { + mobile: string + sd: string + hd: string + fhd: string + auto: string + } } subtitles: { all: string