@soga/m3u8 0.5.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -5
- package/dist/index.d.ts +1 -5
- package/dist/index.js +1 -88
- package/dist/index.mjs +1 -63
- package/package.json +12 -8
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,88 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
parseM3U8: () => parseM3U8
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(index_exports);
|
|
26
|
-
var import_fs_extra = require("fs-extra");
|
|
27
|
-
var import_m3u8_parser = require("m3u8-parser");
|
|
28
|
-
var import_path = require("path");
|
|
29
|
-
async function parseM3U8(input) {
|
|
30
|
-
const time = Date.now();
|
|
31
|
-
const parser = new import_m3u8_parser.Parser();
|
|
32
|
-
const manifest = await (0, import_fs_extra.readFile)(input, "utf8");
|
|
33
|
-
parser.push(manifest);
|
|
34
|
-
parser.end();
|
|
35
|
-
const result = parser.manifest;
|
|
36
|
-
const m3u8_folder = (0, import_path.dirname)(input);
|
|
37
|
-
const first = result.segments[0];
|
|
38
|
-
if (!first?.map?.uri) {
|
|
39
|
-
throw new Error(`parse ${input} failed`);
|
|
40
|
-
}
|
|
41
|
-
const init_uri = first.map.uri;
|
|
42
|
-
const init_path = (0, import_path.resolve)(m3u8_folder, init_uri);
|
|
43
|
-
const init_stat = await (0, import_fs_extra.stat)(init_path);
|
|
44
|
-
const init = {
|
|
45
|
-
uri: init_uri,
|
|
46
|
-
folder: m3u8_folder,
|
|
47
|
-
file_path: init_path,
|
|
48
|
-
size: init_stat.size
|
|
49
|
-
};
|
|
50
|
-
let last_times = 0;
|
|
51
|
-
const times = 1e6;
|
|
52
|
-
const segments = [];
|
|
53
|
-
const { length } = result.segments;
|
|
54
|
-
for (let i = 0; i < length; i++) {
|
|
55
|
-
const segment = result.segments[i];
|
|
56
|
-
const file_path = (0, import_path.resolve)(m3u8_folder, segment.uri);
|
|
57
|
-
const info = await (0, import_fs_extra.stat)(file_path);
|
|
58
|
-
const scaled_duration = segment.duration * times;
|
|
59
|
-
const start_time = last_times / times;
|
|
60
|
-
const end_time = (last_times + scaled_duration) / times;
|
|
61
|
-
segments.push({
|
|
62
|
-
index: i,
|
|
63
|
-
duration: segment.duration,
|
|
64
|
-
init_uri,
|
|
65
|
-
uri: segment.uri,
|
|
66
|
-
file_path,
|
|
67
|
-
size: info.size,
|
|
68
|
-
start_time,
|
|
69
|
-
end_time,
|
|
70
|
-
folder: m3u8_folder
|
|
71
|
-
});
|
|
72
|
-
last_times += scaled_duration;
|
|
73
|
-
}
|
|
74
|
-
const json = {
|
|
75
|
-
init,
|
|
76
|
-
...result,
|
|
77
|
-
segments
|
|
78
|
-
};
|
|
79
|
-
return {
|
|
80
|
-
duration: Date.now() - time,
|
|
81
|
-
data: json,
|
|
82
|
-
input
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
-
0 && (module.exports = {
|
|
87
|
-
parseM3U8
|
|
88
|
-
});
|
|
1
|
+
"use strict";var e,r=Object.defineProperty,t=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,s={};((e,t)=>{for(var i in t)r(e,i,{get:t[i],enumerable:!0})})(s,{parseM3U8:()=>p}),module.exports=(e=s,((e,s,n,o)=>{if(s&&"object"==typeof s||"function"==typeof s)for(let u of i(s))a.call(e,u)||u===n||r(e,u,{get:()=>s[u],enumerable:!(o=t(s,u))||o.enumerable});return e})(r({},"__esModule",{value:!0}),e));var n=require("@soga/error"),o=require("fs-extra"),u=require("m3u8-parser"),l=require("path");async function p(e){try{const r=new u.Parser,t=await(0,o.readFile)(e,"utf8");r.push(t),r.end();const i=r.manifest,a=(0,l.dirname)(e),s=i.segments[0];if(!s?.map?.uri)throw new Error(`parse ${e} failed`);const n=s.map.uri,p=(0,l.resolve)(a,n),f={uri:n,folder:a,file_path:p,size:(await(0,o.stat)(p)).size};let c=0;const d=1e6,m=[],{length:g}=i.segments;for(let e=0;e<g;e++){const r=i.segments[e],t=(0,l.resolve)(a,r.uri),s=await(0,o.stat)(t),u=r.duration*d,p=c/d,f=(c+u)/d;m.push({index:e,duration:r.duration,init_uri:n,uri:r.uri,file_path:t,size:s.size,start_time:p,end_time:f,folder:a}),c+=u}return{init:f,...i,segments:m}}catch(r){throw(0,n.buildDError)(r,{message:"parseM3U8 failed",detail:`parseM3U8 failed: ${e}`})}}
|
package/dist/index.mjs
CHANGED
|
@@ -1,63 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { readFile, stat } from "fs-extra";
|
|
3
|
-
import { Parser } from "m3u8-parser";
|
|
4
|
-
import { dirname, resolve } from "path";
|
|
5
|
-
async function parseM3U8(input) {
|
|
6
|
-
const time = Date.now();
|
|
7
|
-
const parser = new Parser();
|
|
8
|
-
const manifest = await readFile(input, "utf8");
|
|
9
|
-
parser.push(manifest);
|
|
10
|
-
parser.end();
|
|
11
|
-
const result = parser.manifest;
|
|
12
|
-
const m3u8_folder = dirname(input);
|
|
13
|
-
const first = result.segments[0];
|
|
14
|
-
if (!first?.map?.uri) {
|
|
15
|
-
throw new Error(`parse ${input} failed`);
|
|
16
|
-
}
|
|
17
|
-
const init_uri = first.map.uri;
|
|
18
|
-
const init_path = resolve(m3u8_folder, init_uri);
|
|
19
|
-
const init_stat = await stat(init_path);
|
|
20
|
-
const init = {
|
|
21
|
-
uri: init_uri,
|
|
22
|
-
folder: m3u8_folder,
|
|
23
|
-
file_path: init_path,
|
|
24
|
-
size: init_stat.size
|
|
25
|
-
};
|
|
26
|
-
let last_times = 0;
|
|
27
|
-
const times = 1e6;
|
|
28
|
-
const segments = [];
|
|
29
|
-
const { length } = result.segments;
|
|
30
|
-
for (let i = 0; i < length; i++) {
|
|
31
|
-
const segment = result.segments[i];
|
|
32
|
-
const file_path = resolve(m3u8_folder, segment.uri);
|
|
33
|
-
const info = await stat(file_path);
|
|
34
|
-
const scaled_duration = segment.duration * times;
|
|
35
|
-
const start_time = last_times / times;
|
|
36
|
-
const end_time = (last_times + scaled_duration) / times;
|
|
37
|
-
segments.push({
|
|
38
|
-
index: i,
|
|
39
|
-
duration: segment.duration,
|
|
40
|
-
init_uri,
|
|
41
|
-
uri: segment.uri,
|
|
42
|
-
file_path,
|
|
43
|
-
size: info.size,
|
|
44
|
-
start_time,
|
|
45
|
-
end_time,
|
|
46
|
-
folder: m3u8_folder
|
|
47
|
-
});
|
|
48
|
-
last_times += scaled_duration;
|
|
49
|
-
}
|
|
50
|
-
const json = {
|
|
51
|
-
init,
|
|
52
|
-
...result,
|
|
53
|
-
segments
|
|
54
|
-
};
|
|
55
|
-
return {
|
|
56
|
-
duration: Date.now() - time,
|
|
57
|
-
data: json,
|
|
58
|
-
input
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
export {
|
|
62
|
-
parseM3U8
|
|
63
|
-
};
|
|
1
|
+
import{buildDError as e}from"@soga/error";import{readFile as t,stat as r}from"fs-extra";import{Parser as i}from"m3u8-parser";import{dirname as s,resolve as a}from"path";async function o(o){try{const e=new i,n=await t(o,"utf8");e.push(n),e.end();const m=e.manifest,f=s(o),p=m.segments[0];if(!p?.map?.uri)throw new Error(`parse ${o} failed`);const u=p.map.uri,d=a(f,u),l={uri:u,folder:f,file_path:d,size:(await r(d)).size};let c=0;const h=1e6,g=[],{length:w}=m.segments;for(let e=0;e<w;e++){const t=m.segments[e],i=a(f,t.uri),s=await r(i),o=t.duration*h,n=c/h,p=(c+o)/h;g.push({index:e,duration:t.duration,init_uri:u,uri:t.uri,file_path:i,size:s.size,start_time:n,end_time:p,folder:f}),c+=o}return{init:l,...m,segments:g}}catch(t){throw e(t,{message:"parseM3U8 failed",detail:`parseM3U8 failed: ${o}`})}}export{o as parseM3U8};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soga/m3u8",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
"module": "./dist/index.mjs",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"scripts": {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
11
|
+
"demo": "tsx ./demo/demo.ts",
|
|
12
|
+
"build": "rimraf dist && tsup src/index.ts --format cjs,esm --dts --minify terser",
|
|
13
|
+
"prepublishOnly": "npm run build"
|
|
13
14
|
},
|
|
14
15
|
"files": [
|
|
15
16
|
"dist"
|
|
@@ -19,13 +20,16 @@
|
|
|
19
20
|
"license": "ISC",
|
|
20
21
|
"description": "",
|
|
21
22
|
"dependencies": {
|
|
23
|
+
"@soga/error": "^1.0.6",
|
|
22
24
|
"fs-extra": "^11.3.0",
|
|
23
|
-
"m3u8-parser": "^7.2.0"
|
|
24
|
-
"tsup": "^8.5.0"
|
|
25
|
+
"m3u8-parser": "^7.2.0"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"@types/fs-extra": "^11.0.4",
|
|
28
|
-
"@types/m3u8-parser": "^7.2.
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
"@types/m3u8-parser": "^7.2.3",
|
|
30
|
+
"rimraf": "^6.0.1",
|
|
31
|
+
"terser": "^5.43.1",
|
|
32
|
+
"tsup": "^8.5.0",
|
|
33
|
+
"tsx": "^4.20.3"
|
|
34
|
+
}
|
|
31
35
|
}
|