Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const m3u8 = require('m3u8');
- const ffmpeg = require('fluent-ffmpeg');
- const fs = require('fs');
- const util = require('util');
- const ffprobe = util.promisify(ffmpeg.ffprobe);
- function parse_aa(file){
- const parser = m3u8.createStream();
- const ffile = fs.createReadStream(file);
- ffile.pipe(parser);
- return new Promise((resolve, reject)=>{
- parser.on('error',reject);
- parser.on('m3u',resolve);
- });
- }
- parse_aa('sample_0').then((m3u)=>{
- const items = m3u.items.PlaylistItem;
- const promises = items.map((item,index)=>{
- return ffprobe(item.get('uri')).catch((error)=>{
- m3u.removePlaylistItemUri(item.get('uri'));
- });
- });
- return Promise.all(promises).then(()=>{;
- return {
- m3u
- };
- });
- }).then((a)=>console.log(JSON.stringify(a,null,4))).catch(error=>console.log(error));
- output:
- {
- "m3u": {
- "items": {
- "PlaylistItem": [
- {
- "attributes": {
- "attributes": {}
- },
- "properties": {
- "byteRange": null,
- "daiPlacementOpportunity": null,
- "date": null,
- "discontinuity": null,
- "duration": -1,
- "title": "REDE TV",
- "uri": "https://evpp.mm.uol.com.br/redetv1/redetv1/chunklist_w483035285.m3u8"
- }
- },
- {
- "attributes": {
- "attributes": {}
- },
- "properties": {
- "byteRange": null,
- "daiPlacementOpportunity": null,
- "date": null,
- "discontinuity": null,
- "duration": -1,
- "title": "ABC NEWS",
- "uri": "https://abclive2-lh.akamaihd.net/i/abc_live11@423404/index_800_av-p.m3u8?sd=10&rebase=on"
- }
- }
- ],
- "StreamItem": [],
- "IframeStreamItem": [],
- "MediaItem": []
- },
- "properties": {}
- }
- }
- perfect!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement