Skip to content

Commit

Permalink
added shaka packager support
Browse files Browse the repository at this point in the history
  • Loading branch information
stratumadev committed Jan 7, 2025
1 parent b293e2a commit 57b3daa
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 24 deletions.
24 changes: 15 additions & 9 deletions ao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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}`);
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions config/bin-path.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ ffmpeg: "ffmpeg.exe"
mkvmerge: "mkvmerge.exe"
ffprobe: "ffprobe.exe"
mp4decrypt: "mp4decrypt.exe"
shaka: "shaka-packager.exe"
24 changes: 15 additions & 9 deletions crunchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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}`);
Expand All @@ -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) {
Expand Down
15 changes: 10 additions & 5 deletions hidive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion modules/module.cfg-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export type ConfigObject = {
mkvmerge?: string,
ffprobe?: string,
mp4decrypt?: string
shaka?: string
},
cli: {
[key: string]: any
Expand Down Expand Up @@ -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){
Expand Down

0 comments on commit 57b3daa

Please sign in to comment.