Advertisement
Guest User

Untitled

a guest
May 21st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. const m3u8 = require('m3u8');
  2. const ffmpeg = require('fluent-ffmpeg');
  3. const fs = require('fs');
  4. const util = require('util');
  5.  
  6. const ffprobe = util.promisify(ffmpeg.ffprobe);
  7.  
  8. function parse_aa(file){
  9. const parser = m3u8.createStream();
  10. const ffile = fs.createReadStream(file);
  11. ffile.pipe(parser);
  12. return new Promise((resolve, reject)=>{
  13. parser.on('error',reject);
  14. parser.on('m3u',resolve);
  15. });
  16. }
  17.  
  18. parse_aa('sample_0').then((m3u)=>{
  19. const items = m3u.items.PlaylistItem;
  20. const promises = items.map((item,index)=>{
  21. return ffprobe(item.get('uri')).catch((error)=>{
  22. m3u.removePlaylistItemUri(item.get('uri'));
  23. });
  24. });
  25. return Promise.all(promises).then(()=>{;
  26. return {
  27. m3u
  28. };
  29. });
  30. }).then((a)=>console.log(JSON.stringify(a,null,4))).catch(error=>console.log(error));
  31.  
  32.  
  33. output:
  34. {
  35. "m3u": {
  36. "items": {
  37. "PlaylistItem": [
  38. {
  39. "attributes": {
  40. "attributes": {}
  41. },
  42. "properties": {
  43. "byteRange": null,
  44. "daiPlacementOpportunity": null,
  45. "date": null,
  46. "discontinuity": null,
  47. "duration": -1,
  48. "title": "REDE TV",
  49. "uri": "https://evpp.mm.uol.com.br/redetv1/redetv1/chunklist_w483035285.m3u8"
  50. }
  51. },
  52. {
  53. "attributes": {
  54. "attributes": {}
  55. },
  56. "properties": {
  57. "byteRange": null,
  58. "daiPlacementOpportunity": null,
  59. "date": null,
  60. "discontinuity": null,
  61. "duration": -1,
  62. "title": "ABC NEWS",
  63. "uri": "https://abclive2-lh.akamaihd.net/i/abc_live11@423404/index_800_av-p.m3u8?sd=10&rebase=on"
  64. }
  65. }
  66. ],
  67. "StreamItem": [],
  68. "IframeStreamItem": [],
  69. "MediaItem": []
  70. },
  71. "properties": {}
  72. }
  73. }
  74.  
  75. perfect!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement