diff --git a/ao.ts b/ao.ts index 2892c78..e684a67 100644 --- a/ao.ts +++ b/ao.ts @@ -697,14 +697,20 @@ export default class AnimeOnegai implements ServiceClass { keys[key.kid] = key.key; });*/ - if (this.cfg.bin.mp4decrypt) { - const commandBase = `--show-progress --key ${encryptionKeys[cdm === 'playready' ? 0 : 1].kid}:${encryptionKeys[cdm === 'playready' ? 0 : 1].key} `; - const commandVideo = commandBase+`"${tempTsFile}.video.enc.mp4" "${tempTsFile}.video.mp4"`; - const commandAudio = commandBase+`"${tempTsFile}.audio.enc.mp4" "${tempTsFile}.audio.mp4"`; + if (this.cfg.bin.mp4decrypt || this.cfg.bin.shaka) { + let commandBase = `--show-progress --key ${encryptionKeys[cdm === 'playready' ? 0 : 1].kid}:${encryptionKeys[cdm === 'playready' ? 0 : 1].key} `; + let commandVideo = commandBase+`"${tempTsFile}.video.enc.mp4" "${tempTsFile}.video.mp4"`; + let commandAudio = commandBase+`"${tempTsFile}.audio.enc.mp4" "${tempTsFile}.audio.mp4"`; + + if (this.cfg.bin.shaka) { + commandBase = ` --enable_raw_key_decryption --keys key_id=${encryptionKeys[cdm === 'playready' ? 0 : 1].kid}:key=${encryptionKeys[cdm === 'playready' ? 0 : 1].key}`; + commandVideo = `input="${tempTsFile}.video.enc.m4s",stream=video,output="${tempTsFile}.video.m4s"`+commandBase; + commandAudio = `input="${tempTsFile}.audio.enc.m4s",stream=audio,output="${tempTsFile}.audio.m4s"`+commandBase; + } if (videoDownloaded) { - console.info('Started decrypting video'); - const decryptVideo = exec('mp4decrypt', `"${this.cfg.bin.mp4decrypt}"`, commandVideo); + console.info('Started decrypting video,', this.cfg.bin.shaka ? 'using shaka' : 'using mp4decrypt'); + const decryptVideo = exec(this.cfg.bin.shaka ? 'shaka-packager' : 'mp4decrypt', this.cfg.bin.shaka ? `"${this.cfg.bin.shaka}"` : `"${this.cfg.bin.mp4decrypt}"`, commandVideo); if (!decryptVideo.isOk) { console.error(decryptVideo.err); console.error(`Decryption failed with exit code ${decryptVideo.err.code}`); @@ -725,8 +731,8 @@ export default class AnimeOnegai implements ServiceClass { } if (audioDownloaded) { - console.info('Started decrypting audio'); - const decryptAudio = exec('mp4decrypt', `"${this.cfg.bin.mp4decrypt}"`, commandAudio); + console.info('Started decrypting audio,', this.cfg.bin.shaka ? 'using shaka' : 'using mp4decrypt'); + const decryptAudio = exec(this.cfg.bin.shaka ? 'shaka' : 'mp4decrypt', this.cfg.bin.shaka ? `"${this.cfg.bin.shaka}"` : `"${this.cfg.bin.mp4decrypt}"`, commandAudio); if (!decryptAudio.isOk) { console.error(decryptAudio.err); console.error(`Decryption failed with exit code ${decryptAudio.err.code}`); @@ -746,7 +752,7 @@ export default class AnimeOnegai implements ServiceClass { } } } else { - console.warn('mp4decrypt not found, files need decryption. Decryption Keys:', encryptionKeys); + console.warn('mp4decrypt/shaka not found, files need decryption. Decryption Keys:', encryptionKeys); } } else { if (videoDownloaded) { diff --git a/config/bin-path.yml b/config/bin-path.yml index 8c08eb7..e09af5e 100644 --- a/config/bin-path.yml +++ b/config/bin-path.yml @@ -2,3 +2,4 @@ ffmpeg: "ffmpeg.exe" mkvmerge: "mkvmerge.exe" ffprobe: "ffprobe.exe" mp4decrypt: "mp4decrypt.exe" +shaka: "shaka-packager.exe" diff --git a/crunchy.ts b/crunchy.ts index 1d29cb5..392d233 100644 --- a/crunchy.ts +++ b/crunchy.ts @@ -1767,14 +1767,20 @@ export default class Crunchy implements ServiceClass { keys[key.kid] = key.key; });*/ - if (this.cfg.bin.mp4decrypt) { - const commandBase = `--show-progress --key ${encryptionKeys[cdm === 'playready' ? 0 : 1].kid}:${encryptionKeys[cdm === 'playready' ? 0 : 1].key} `; - const commandVideo = commandBase+`"${tempTsFile}.video.enc.m4s" "${tempTsFile}.video.m4s"`; - const commandAudio = commandBase+`"${tempTsFile}.audio.enc.m4s" "${tempTsFile}.audio.m4s"`; + if (this.cfg.bin.mp4decrypt || this.cfg.bin.shaka) { + let commandBase = `--show-progress --key ${encryptionKeys[cdm === 'playready' ? 0 : 1].kid}:${encryptionKeys[cdm === 'playready' ? 0 : 1].key} `; + let commandVideo = commandBase+`"${tempTsFile}.video.enc.m4s" "${tempTsFile}.video.m4s"`; + let commandAudio = commandBase+`"${tempTsFile}.audio.enc.m4s" "${tempTsFile}.audio.m4s"`; + + if (this.cfg.bin.shaka) { + commandBase = ` --enable_raw_key_decryption --keys key_id=${encryptionKeys[cdm === 'playready' ? 0 : 1].kid}:key=${encryptionKeys[cdm === 'playready' ? 0 : 1].key}`; + commandVideo = `input="${tempTsFile}.video.enc.m4s",stream=video,output="${tempTsFile}.video.m4s"`+commandBase; + commandAudio = `input="${tempTsFile}.audio.enc.m4s",stream=audio,output="${tempTsFile}.audio.m4s"`+commandBase; + } if (videoDownloaded) { - console.info('Started decrypting video'); - const decryptVideo = exec('mp4decrypt', `"${this.cfg.bin.mp4decrypt}"`, commandVideo); + console.info('Started decrypting video,', this.cfg.bin.shaka ? 'using shaka' : 'using mp4decrypt'); + const decryptVideo = exec(this.cfg.bin.shaka ? 'shaka-packager' : 'mp4decrypt', this.cfg.bin.shaka ? `"${this.cfg.bin.shaka}"` : `"${this.cfg.bin.mp4decrypt}"`, commandVideo); if (!decryptVideo.isOk) { console.error(decryptVideo.err); console.error(`Decryption failed with exit code ${decryptVideo.err.code}`); @@ -1796,8 +1802,8 @@ export default class Crunchy implements ServiceClass { } if (audioDownloaded) { - console.info('Started decrypting audio'); - const decryptAudio = exec('mp4decrypt', `"${this.cfg.bin.mp4decrypt}"`, commandAudio); + console.info('Started decrypting audio,', this.cfg.bin.shaka ? 'using shaka' : 'using mp4decrypt'); + const decryptAudio = exec(this.cfg.bin.shaka ? 'shaka' : 'mp4decrypt', this.cfg.bin.shaka ? `"${this.cfg.bin.shaka}"` : `"${this.cfg.bin.mp4decrypt}"`, commandAudio); if (!decryptAudio.isOk) { console.error(decryptAudio.err); console.error(`Decryption failed with exit code ${decryptAudio.err.code}`); @@ -1818,7 +1824,7 @@ export default class Crunchy implements ServiceClass { } } } else { - console.warn('mp4decrypt not found, files need decryption. Decryption Keys:', encryptionKeys); + console.warn('mp4decrypt/shaka not found, files need decryption. Decryption Keys:', encryptionKeys); } } else { if (videoDownloaded) { diff --git a/hidive.ts b/hidive.ts index 284be97..e4a0d78 100644 --- a/hidive.ts +++ b/hidive.ts @@ -824,11 +824,16 @@ export default class Hidive implements ServiceClass { return undefined; } if (this.cfg.bin.mp4decrypt) { - const commandBase = `--show-progress --key ${encryptionKeys[cdm === 'playready' ? 0 : 1].kid}:${encryptionKeys[cdm === 'playready' ? 0 : 1].key} `; - const commandVideo = commandBase+`"${tempTsFile}.video.enc.m4s" "${tempTsFile}.video.m4s"`; + let commandBase = `--show-progress --key ${encryptionKeys[cdm === 'playready' ? 0 : 1].kid}:${encryptionKeys[cdm === 'playready' ? 0 : 1].key} `; + let commandVideo = commandBase+`"${tempTsFile}.video.enc.m4s" "${tempTsFile}.video.m4s"`; + + if (this.cfg.bin.shaka) { + commandBase = ` --enable_raw_key_decryption --keys key_id=${encryptionKeys[cdm === 'playready' ? 0 : 1].kid}:key=${encryptionKeys[cdm === 'playready' ? 0 : 1].key}`; + commandVideo = `input="${tempTsFile}.video.enc.m4s",stream=video,output="${tempTsFile}.video.m4s"`+commandBase; + } - console.info('Started decrypting video'); - const decryptVideo = exec('mp4decrypt', `"${this.cfg.bin.mp4decrypt}"`, commandVideo); + console.info('Started decrypting video,', this.cfg.bin.shaka ? 'using shaka' : 'using mp4decrypt'); + const decryptVideo = exec(this.cfg.bin.shaka ? 'shaka-packager' : 'mp4decrypt', this.cfg.bin.shaka ? `"${this.cfg.bin.shaka}"` : `"${this.cfg.bin.mp4decrypt}"`, commandVideo); if (!decryptVideo.isOk) { console.error(decryptVideo.err); console.error(`Decryption failed with exit code ${decryptVideo.err.code}`); @@ -848,7 +853,7 @@ export default class Hidive implements ServiceClass { }); } } else { - console.warn('mp4decrypt not found, files need decryption. Decryption Keys:', encryptionKeys); + console.warn('mp4decrypt/shaka not found, files need decryption. Decryption Keys:', encryptionKeys); } } } diff --git a/modules/module.cfg-loader.ts b/modules/module.cfg-loader.ts index f09da06..3839f6c 100644 --- a/modules/module.cfg-loader.ts +++ b/modules/module.cfg-loader.ts @@ -87,6 +87,7 @@ export type ConfigObject = { mkvmerge?: string, ffprobe?: string, mp4decrypt?: string + shaka?: string }, cli: { [key: string]: any @@ -151,7 +152,8 @@ const loadBinCfg = async () => { ffmpeg: 'ffmpeg', mkvmerge: 'mkvmerge', ffprobe: 'ffprobe', - mp4decrypt: 'mp4decrypt' + mp4decrypt: 'mp4decrypt', + shaka: 'shaka-packager' }; const keys = Object.keys(defaultBin) as (keyof typeof defaultBin)[]; for(const dir of keys){