ytgrab 0.2.0 → 0.2.1
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/downloader/hls.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* HLS (M3U8) Downloader - ported from yt_dlp/downloader/hls.py
|
|
3
3
|
* Downloads HTTP Live Streaming content by fetching fragments.
|
|
4
|
+
* Uses mux.js for pure-JS TS→MP4 transmuxing (no FFmpeg required).
|
|
4
5
|
*/
|
|
5
6
|
import { FileDownloader } from './common.js';
|
|
6
7
|
import type { InfoDict } from '../types.js';
|
|
7
8
|
export declare class HlsFD extends FileDownloader {
|
|
8
9
|
realDownload(filename: string, infoDict: InfoDict): Promise<boolean>;
|
|
10
|
+
private _transmuxToMp4;
|
|
9
11
|
private _parseMediaPlaylist;
|
|
10
12
|
}
|
|
11
13
|
//# sourceMappingURL=hls.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hls.d.ts","sourceRoot":"","sources":["../../src/downloader/hls.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"hls.d.ts","sourceRoot":"","sources":["../../src/downloader/hls.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG5C,qBAAa,KAAM,SAAQ,cAAc;IACjC,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;YAiF5D,cAAc;IAgD5B,OAAO,CAAC,mBAAmB;CAoB5B"}
|
package/dist/downloader/hls.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* HLS (M3U8) Downloader - ported from yt_dlp/downloader/hls.py
|
|
4
4
|
* Downloads HTTP Live Streaming content by fetching fragments.
|
|
5
|
+
* Uses mux.js for pure-JS TS→MP4 transmuxing (no FFmpeg required).
|
|
5
6
|
*/
|
|
6
7
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
8
|
if (k2 === undefined) k2 = k;
|
|
@@ -60,10 +61,9 @@ class HlsFD extends common_js_1.FileDownloader {
|
|
|
60
61
|
throw new Error('No fragments found in HLS manifest');
|
|
61
62
|
}
|
|
62
63
|
this._log(`Downloading ${fragments.length} fragments`);
|
|
63
|
-
const tmpFilename = this.tempName(filename);
|
|
64
|
-
const stream = fs.createWriteStream(tmpFilename);
|
|
65
64
|
const startTime = Date.now();
|
|
66
65
|
let downloadedBytes = 0;
|
|
66
|
+
const tsChunks = [];
|
|
67
67
|
for (let i = 0; i < fragments.length; i++) {
|
|
68
68
|
const frag = fragments[i];
|
|
69
69
|
try {
|
|
@@ -77,7 +77,7 @@ class HlsFD extends common_js_1.FileDownloader {
|
|
|
77
77
|
if (resp.status >= 400) {
|
|
78
78
|
throw new Error(`HTTP ${resp.status} for fragment ${i + 1}`);
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
tsChunks.push(resp.body);
|
|
81
81
|
downloadedBytes += resp.body.length;
|
|
82
82
|
this._hookProgress({
|
|
83
83
|
status: 'downloading',
|
|
@@ -96,28 +96,66 @@ class HlsFD extends common_js_1.FileDownloader {
|
|
|
96
96
|
// For other errors (network), continue
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
99
|
+
// Transmux TS→MP4 using mux.js (pure JS, no FFmpeg)
|
|
100
|
+
const tsData = Buffer.concat(tsChunks);
|
|
101
|
+
if (filename.endsWith('.mp4')) {
|
|
102
|
+
try {
|
|
103
|
+
const mp4Data = await this._transmuxToMp4(tsData);
|
|
104
|
+
fs.writeFileSync(filename, mp4Data);
|
|
105
|
+
downloadedBytes = mp4Data.length;
|
|
106
|
+
this._log('Transmuxed to MP4');
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
this._log(`Transmux failed: ${err.message} - saving raw TS`);
|
|
110
|
+
fs.writeFileSync(filename, tsData);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
fs.writeFileSync(filename, tsData);
|
|
115
|
+
}
|
|
116
|
+
this.reportFinished(filename, downloadedBytes);
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
async _transmuxToMp4(tsData) {
|
|
120
|
+
// Dynamic import to avoid issues with ESM/CJS
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
122
|
+
const muxjs = require('mux.js');
|
|
123
|
+
const Transmuxer = muxjs.mp4?.Transmuxer || muxjs.default?.mp4?.Transmuxer;
|
|
124
|
+
if (!Transmuxer) {
|
|
125
|
+
throw new Error('mux.js Transmuxer not found');
|
|
126
|
+
}
|
|
127
|
+
return new Promise((resolve, reject) => {
|
|
128
|
+
const transmuxer = new Transmuxer();
|
|
129
|
+
const outputChunks = [];
|
|
130
|
+
let initSegment = null;
|
|
131
|
+
transmuxer.on('data', (segment) => {
|
|
132
|
+
if (!initSegment) {
|
|
133
|
+
initSegment = segment.initSegment;
|
|
134
|
+
outputChunks.push(segment.initSegment);
|
|
135
|
+
}
|
|
136
|
+
outputChunks.push(segment.data);
|
|
137
|
+
});
|
|
138
|
+
transmuxer.on('done', () => {
|
|
139
|
+
if (outputChunks.length === 0) {
|
|
140
|
+
reject(new Error('No output from transmuxer'));
|
|
141
|
+
return;
|
|
106
142
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
catch (err) {
|
|
114
|
-
reject(err);
|
|
115
|
-
}
|
|
143
|
+
const totalLen = outputChunks.reduce((sum, c) => sum + c.length, 0);
|
|
144
|
+
const result = Buffer.alloc(totalLen);
|
|
145
|
+
let offset = 0;
|
|
146
|
+
for (const chunk of outputChunks) {
|
|
147
|
+
result.set(chunk, offset);
|
|
148
|
+
offset += chunk.length;
|
|
116
149
|
}
|
|
150
|
+
resolve(result);
|
|
117
151
|
});
|
|
152
|
+
transmuxer.on('error', (err) => {
|
|
153
|
+
reject(err);
|
|
154
|
+
});
|
|
155
|
+
// Feed all TS data and flush
|
|
156
|
+
transmuxer.push(new Uint8Array(tsData));
|
|
157
|
+
transmuxer.flush();
|
|
118
158
|
});
|
|
119
|
-
this.reportFinished(filename, downloadedBytes);
|
|
120
|
-
return true;
|
|
121
159
|
}
|
|
122
160
|
_parseMediaPlaylist(manifest, baseUrl) {
|
|
123
161
|
const fragments = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hls.js","sourceRoot":"","sources":["../../src/downloader/hls.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"hls.js","sourceRoot":"","sources":["../../src/downloader/hls.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,4CAA8B;AAE9B,2CAA6C;AAC7C,qDAAqD;AAIrD,MAAa,KAAM,SAAQ,0BAAc;IACvC,KAAK,CAAC,YAAY,CAAC,QAAgB,EAAE,QAAkB;QACrD,MAAM,WAAW,GAAuB,CAAC,QAAQ,CAAC,GAAG,IAAK,QAAgB,CAAC,YAAY,CAAuB,CAAC;QAC/G,IAAI,CAAC,WAAW;YAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QAEzD,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QACzB,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAEjC,oBAAoB;QACpB,IAAI,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;QACtC,MAAM,YAAY,GAAG,MAAM,IAAA,sBAAW,EAAC,WAAW,EAAE;YAClD,OAAO,EAAG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CAAC,kBAAkB,CAAC,CAAC;gBAC7C,IAAI,KAAK;oBAAE,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7C,CAAC;iBAAM,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzC,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC;gBACnF,SAAS,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;gBAC3C,QAAQ,GAAG,CAAC,CAAC;YACf,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAtJD,sBAsJC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ytgrab",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "A Node.js YouTube video downloader ported from yt-dlp",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"astring": "^1.9.0",
|
|
38
38
|
"got-scraping": "^4.2.1",
|
|
39
|
-
"meriyah": "^6.1.4"
|
|
39
|
+
"meriyah": "^6.1.4",
|
|
40
|
+
"mux.js": "^6.3.0"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@types/node": "^20.0.0",
|