Skip to content

Instantly share code, notes, and snippets.

@kuu
Last active November 29, 2019 10:08
Show Gist options
  • Save kuu/79e9a4f7d2e036e0dcb18c8624bc1894 to your computer and use it in GitHub Desktop.
Save kuu/79e9a4f7d2e036e0dcb18c8624bc1894 to your computer and use it in GitHub Desktop.

Usage:

$ npx {url of this gist} {url of master playlist}

How it works:

  • Downloads all the media playlists associated with the specified master playlist
  • Check if each segment's duration exceeds the target duration defined in the master playlist
  • If it exceeds, you'll see the following logs:
=== Vioration: Duration exceeds #EXT-X-TARGETDURATION ===
    Playlist URI: {plylist uri}
    TargetDuration: {target duration}
    Segment URI: {segment uri}
    Duration: {segment uri}
#!/usr/bin/env node
const hlx = require('hlx-lib');
const srcUrl = process.argv[2];
const {Transform} = require('stream');
class DurationChecker extends Transform {
constructor() {
super({objectMode: true});
}
_transform(data, _, cb) {
if (data.type === 'playlist') {
if (data.isMasterPlaylist) {
console.log(`Loading master playlist.`);
console.log(`\tURI: ${data.uri}`);
return cb(null, data);
}
console.log(`Loading media playlist.`);
console.log(`\tURI: ${data.uri}`);
const targetDuration = data.targetDuration;
for (const segment of data.segments) {
if (segment.duration > targetDuration) {
console.error('=== Vioration: Duration exceeds #EXT-X-TARGETDURATION ===');
console.error(`\tPlaylist URI: ${data.uri}`);
console.error(`\tTargetDuration: ${targetDuration}`);
console.error(`\tSegment URI: ${segment.uri}`);
console.error(`\tDuration: ${segment.uri}`);
}
}
}
cb(null, data);
}
}
hlx.src(srcUrl, {playlistOnly: true})
.pipe(new DurationChecker())
.pipe(hlx.dest())
.on('error', (err) => {
console.error(err.stack);
});
{
"name": "duration-checker",
"version": "0.0.0",
"bin": "./duration-checker.js",
"dependencies": {
"hlx-lib": "0.0.28"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment