ytgrab 0.1.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/LICENSE +21 -0
- package/README.md +142 -0
- package/bin/ytgrab.js +194 -0
- package/dist/downloader/common.d.ts +22 -0
- package/dist/downloader/common.d.ts.map +1 -0
- package/dist/downloader/common.js +125 -0
- package/dist/downloader/common.js.map +1 -0
- package/dist/downloader/hls.d.ts +11 -0
- package/dist/downloader/hls.d.ts.map +1 -0
- package/dist/downloader/hls.js +134 -0
- package/dist/downloader/hls.js.map +1 -0
- package/dist/downloader/http.d.ts +10 -0
- package/dist/downloader/http.d.ts.map +1 -0
- package/dist/downloader/http.js +132 -0
- package/dist/downloader/http.js.map +1 -0
- package/dist/downloader/index.d.ts +10 -0
- package/dist/downloader/index.d.ts.map +1 -0
- package/dist/downloader/index.js +24 -0
- package/dist/downloader/index.js.map +1 -0
- package/dist/extractor/common.d.ts +48 -0
- package/dist/extractor/common.d.ts.map +1 -0
- package/dist/extractor/common.js +324 -0
- package/dist/extractor/common.js.map +1 -0
- package/dist/extractor/nsig.d.ts +17 -0
- package/dist/extractor/nsig.d.ts.map +1 -0
- package/dist/extractor/nsig.js +200 -0
- package/dist/extractor/nsig.js.map +1 -0
- package/dist/extractor/youtube.d.ts +51 -0
- package/dist/extractor/youtube.d.ts.map +1 -0
- package/dist/extractor/youtube.js +1113 -0
- package/dist/extractor/youtube.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +72 -0
- package/dist/index.js.map +1 -0
- package/dist/networking/index.d.ts +33 -0
- package/dist/networking/index.d.ts.map +1 -0
- package/dist/networking/index.js +171 -0
- package/dist/networking/index.js.map +1 -0
- package/dist/postprocessor/common.d.ts +21 -0
- package/dist/postprocessor/common.d.ts.map +1 -0
- package/dist/postprocessor/common.js +42 -0
- package/dist/postprocessor/common.js.map +1 -0
- package/dist/postprocessor/ffmpeg.d.ts +44 -0
- package/dist/postprocessor/ffmpeg.d.ts.map +1 -0
- package/dist/postprocessor/ffmpeg.js +286 -0
- package/dist/postprocessor/ffmpeg.js.map +1 -0
- package/dist/types.d.ts +157 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/index.d.ts +57 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +403 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/traversal.d.ts +22 -0
- package/dist/utils/traversal.d.ts.map +1 -0
- package/dist/utils/traversal.js +112 -0
- package/dist/utils/traversal.js.map +1 -0
- package/dist/ytgrab.d.ts +48 -0
- package/dist/ytgrab.d.ts.map +1 -0
- package/dist/ytgrab.js +450 -0
- package/dist/ytgrab.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Downloader - ported from yt_dlp/downloader/http.py
|
|
3
|
+
* Downloads files via HTTP/HTTPS with resume support.
|
|
4
|
+
*/
|
|
5
|
+
import { FileDownloader } from './common.js';
|
|
6
|
+
import type { InfoDict } from '../types.js';
|
|
7
|
+
export declare class HttpFD extends FileDownloader {
|
|
8
|
+
realDownload(filename: string, infoDict: InfoDict): Promise<boolean>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/downloader/http.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG5C,qBAAa,MAAO,SAAQ,cAAc;IAClC,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;CAgG3E"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* HTTP Downloader - ported from yt_dlp/downloader/http.py
|
|
4
|
+
* Downloads files via HTTP/HTTPS with resume support.
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.HttpFD = void 0;
|
|
41
|
+
const fs = __importStar(require("node:fs"));
|
|
42
|
+
const https = __importStar(require("node:https"));
|
|
43
|
+
const http = __importStar(require("node:http"));
|
|
44
|
+
const node_url_1 = require("node:url");
|
|
45
|
+
const common_js_1 = require("./common.js");
|
|
46
|
+
const index_js_1 = require("../utils/index.js");
|
|
47
|
+
class HttpFD extends common_js_1.FileDownloader {
|
|
48
|
+
async realDownload(filename, infoDict) {
|
|
49
|
+
const url = infoDict.url || (infoDict.formats?.[0]?.url);
|
|
50
|
+
if (!url)
|
|
51
|
+
throw new Error('No URL to download');
|
|
52
|
+
this.ensureDir(filename);
|
|
53
|
+
const tmpFilename = this.tempName(filename);
|
|
54
|
+
// Check for resume
|
|
55
|
+
let resumeLen = 0;
|
|
56
|
+
if (fs.existsSync(tmpFilename)) {
|
|
57
|
+
resumeLen = fs.statSync(tmpFilename).size;
|
|
58
|
+
}
|
|
59
|
+
this.reportDestination(filename);
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
const parsedUrl = new node_url_1.URL(url);
|
|
62
|
+
const transport = parsedUrl.protocol === 'https:' ? https : http;
|
|
63
|
+
const headers = {
|
|
64
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
|
|
65
|
+
...(infoDict.http_headers || {}),
|
|
66
|
+
};
|
|
67
|
+
if (resumeLen > 0) {
|
|
68
|
+
headers['Range'] = `bytes=${resumeLen}-`;
|
|
69
|
+
this._log(`Resuming download from ${(0, index_js_1.formatBytes)(resumeLen)}`);
|
|
70
|
+
}
|
|
71
|
+
const req = transport.request(parsedUrl, { method: 'GET', headers }, (res) => {
|
|
72
|
+
// Handle redirects
|
|
73
|
+
if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
74
|
+
const redirectUrl = new node_url_1.URL(res.headers.location, parsedUrl);
|
|
75
|
+
const redirectInfoDict = { ...infoDict, url: redirectUrl.toString() };
|
|
76
|
+
this.realDownload(filename, redirectInfoDict).then(resolve).catch(reject);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (res.statusCode && res.statusCode >= 400) {
|
|
80
|
+
reject(new Error(`HTTP Error ${res.statusCode}`));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const contentLength = res.headers['content-length']
|
|
84
|
+
? parseInt(res.headers['content-length'], 10)
|
|
85
|
+
: null;
|
|
86
|
+
const totalBytes = contentLength ? contentLength + resumeLen : null;
|
|
87
|
+
const openMode = resumeLen > 0 && res.statusCode === 206 ? 'a' : 'w';
|
|
88
|
+
const stream = fs.createWriteStream(tmpFilename, { flags: openMode === 'a' ? 'a' : 'w' });
|
|
89
|
+
let downloadedBytes = resumeLen;
|
|
90
|
+
const startTime = Date.now();
|
|
91
|
+
const progressInterval = setInterval(() => {
|
|
92
|
+
this.reportProgress(downloadedBytes, totalBytes, startTime);
|
|
93
|
+
}, 1000);
|
|
94
|
+
res.on('data', (chunk) => {
|
|
95
|
+
stream.write(chunk);
|
|
96
|
+
downloadedBytes += chunk.length;
|
|
97
|
+
});
|
|
98
|
+
res.on('end', () => {
|
|
99
|
+
clearInterval(progressInterval);
|
|
100
|
+
stream.end(() => {
|
|
101
|
+
// Rename temp file to final name
|
|
102
|
+
try {
|
|
103
|
+
if (fs.existsSync(filename))
|
|
104
|
+
fs.unlinkSync(filename);
|
|
105
|
+
fs.renameSync(tmpFilename, filename);
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
// If rename fails (cross-device), copy and delete
|
|
109
|
+
fs.copyFileSync(tmpFilename, filename);
|
|
110
|
+
fs.unlinkSync(tmpFilename);
|
|
111
|
+
}
|
|
112
|
+
this.reportFinished(filename, downloadedBytes);
|
|
113
|
+
resolve(true);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
res.on('error', (err) => {
|
|
117
|
+
clearInterval(progressInterval);
|
|
118
|
+
stream.end();
|
|
119
|
+
reject(err);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
req.on('error', reject);
|
|
123
|
+
req.on('timeout', () => {
|
|
124
|
+
req.destroy();
|
|
125
|
+
reject(new Error('Download timed out'));
|
|
126
|
+
});
|
|
127
|
+
req.end();
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.HttpFD = HttpFD;
|
|
132
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/downloader/http.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,4CAA8B;AAC9B,kDAAoC;AACpC,gDAAkC;AAClC,uCAA+B;AAC/B,2CAA6C;AAE7C,gDAAgD;AAEhD,MAAa,MAAO,SAAQ,0BAAc;IACxC,KAAK,CAAC,YAAY,CAAC,QAAgB,EAAE,QAAkB;QACrD,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QACzD,IAAI,CAAC,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAEhD,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QACzB,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAE5C,mBAAmB;QACnB,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,IAAI,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/B,SAAS,GAAG,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC;QAC5C,CAAC;QAED,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAEj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|
1
|
+
/**
|
|
2
|
+
* Downloader registry - selects appropriate downloader based on protocol.
|
|
3
|
+
*/
|
|
4
|
+
export { FileDownloader } from './common.js';
|
|
5
|
+
export { HttpFD } from './http.js';
|
|
6
|
+
export { HlsFD } from './hls.js';
|
|
7
|
+
import { FileDownloader } from './common.js';
|
|
8
|
+
import type { VideoFormat } from '../types.js';
|
|
9
|
+
export declare function getSuitableDownloader(format: VideoFormat, ydl: any): FileDownloader;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/downloader/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,GAAG,GAAG,cAAc,CASnF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Downloader registry - selects appropriate downloader based on protocol.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HlsFD = exports.HttpFD = exports.FileDownloader = void 0;
|
|
7
|
+
exports.getSuitableDownloader = getSuitableDownloader;
|
|
8
|
+
var common_js_1 = require("./common.js");
|
|
9
|
+
Object.defineProperty(exports, "FileDownloader", { enumerable: true, get: function () { return common_js_1.FileDownloader; } });
|
|
10
|
+
var http_js_1 = require("./http.js");
|
|
11
|
+
Object.defineProperty(exports, "HttpFD", { enumerable: true, get: function () { return http_js_1.HttpFD; } });
|
|
12
|
+
var hls_js_1 = require("./hls.js");
|
|
13
|
+
Object.defineProperty(exports, "HlsFD", { enumerable: true, get: function () { return hls_js_1.HlsFD; } });
|
|
14
|
+
const http_js_2 = require("./http.js");
|
|
15
|
+
const hls_js_2 = require("./hls.js");
|
|
16
|
+
function getSuitableDownloader(format, ydl) {
|
|
17
|
+
const protocol = format.protocol || 'https';
|
|
18
|
+
if (protocol === 'm3u8' || protocol === 'm3u8_native') {
|
|
19
|
+
return new hls_js_2.HlsFD(ydl);
|
|
20
|
+
}
|
|
21
|
+
// Default to HTTP for https, http, and http_dash_segments
|
|
22
|
+
return new http_js_2.HttpFD(ydl);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/downloader/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAWH,sDASC;AAlBD,yCAA6C;AAApC,2GAAA,cAAc,OAAA;AACvB,qCAAmC;AAA1B,iGAAA,MAAM,OAAA;AACf,mCAAiC;AAAxB,+FAAA,KAAK,OAAA;AAGd,uCAAmC;AACnC,qCAAiC;AAGjC,SAAgB,qBAAqB,CAAC,MAAmB,EAAE,GAAQ;IACjE,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,OAAO,CAAC;IAE5C,IAAI,QAAQ,KAAK,MAAM,IAAI,QAAQ,KAAK,aAAa,EAAE,CAAC;QACtD,OAAO,IAAI,cAAK,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED,0DAA0D;IAC1D,OAAO,IAAI,gBAAM,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base InfoExtractor class - ported from yt_dlp/extractor/common.py
|
|
3
|
+
*
|
|
4
|
+
* All extractors extend this class and implement _realExtract().
|
|
5
|
+
*/
|
|
6
|
+
import { type RequestOptions, type Response } from '../networking/index.js';
|
|
7
|
+
import type { InfoDict, VideoFormat, Subtitle } from '../types.js';
|
|
8
|
+
export interface ExtractorMatch {
|
|
9
|
+
ie: InfoExtractor;
|
|
10
|
+
match: RegExpMatchArray;
|
|
11
|
+
}
|
|
12
|
+
export declare abstract class InfoExtractor {
|
|
13
|
+
abstract readonly IE_NAME: string;
|
|
14
|
+
abstract readonly _VALID_URL: RegExp;
|
|
15
|
+
protected _downloader: any;
|
|
16
|
+
protected _httpHeaders: Record<string, string>;
|
|
17
|
+
setDownloader(downloader: any): void;
|
|
18
|
+
suitable(url: string): boolean;
|
|
19
|
+
matchUrl(url: string): RegExpMatchArray | null;
|
|
20
|
+
extract(url: string): Promise<InfoDict>;
|
|
21
|
+
protected abstract _realExtract(url: string, match: RegExpMatchArray): Promise<InfoDict>;
|
|
22
|
+
protected _downloadWebpage(url: string, videoId: string, note?: string, options?: RequestOptions): Promise<string>;
|
|
23
|
+
protected _downloadJson(url: string, videoId: string, note?: string, options?: RequestOptions, fatal?: boolean): Promise<unknown>;
|
|
24
|
+
protected _requestWebpage(url: string, videoId: string, note?: string, options?: RequestOptions): Promise<Response>;
|
|
25
|
+
protected _parseJson(jsonStr: string, videoId: string, fatal?: boolean): unknown;
|
|
26
|
+
protected _searchRegex(patterns: RegExp | RegExp[], str: string, name: string, defaultVal?: string, fatal?: boolean, group?: number | string): string | null;
|
|
27
|
+
protected _htmlSearchRegex(patterns: RegExp | RegExp[], html: string, name: string, defaultVal?: string, fatal?: boolean, group?: number): string | null;
|
|
28
|
+
protected _htmlSearchMeta(names: string | string[], html: string, displayName?: string, fatal?: boolean): string | null;
|
|
29
|
+
protected _ogSearchProperty(prop: string, html: string, fatal?: boolean): string | null;
|
|
30
|
+
protected _ogSearchTitle(html: string): string | null;
|
|
31
|
+
protected _ogSearchDescription(html: string): string | null;
|
|
32
|
+
protected _ogSearchThumbnail(html: string): string | null;
|
|
33
|
+
protected _htmlExtractTitle(html: string): string | null;
|
|
34
|
+
protected _extractM3u8FormatsAndSubtitles(m3u8Url: string, videoId: string, ext?: string, preference?: number, note?: string): Promise<{
|
|
35
|
+
formats: VideoFormat[];
|
|
36
|
+
subtitles: Record<string, Subtitle[]>;
|
|
37
|
+
}>;
|
|
38
|
+
protected _extractMpdFormatsAndSubtitles(mpdUrl: string, videoId: string, note?: string): Promise<{
|
|
39
|
+
formats: VideoFormat[];
|
|
40
|
+
subtitles: Record<string, Subtitle[]>;
|
|
41
|
+
}>;
|
|
42
|
+
private _parseM3u8Attributes;
|
|
43
|
+
private _parseXmlAttributes;
|
|
44
|
+
protected _sortFormats(formats: VideoFormat[]): void;
|
|
45
|
+
protected _log(msg: string, videoId?: string): void;
|
|
46
|
+
protected _warn(msg: string, videoId?: string): void;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/extractor/common.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAe,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAMzF,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAa,MAAM,aAAa,CAAC;AAE9E,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,aAAa,CAAC;IAClB,KAAK,EAAE,gBAAgB,CAAC;CACzB;AAED,8BAAsB,aAAa;IACjC,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAErC,SAAS,CAAC,WAAW,EAAE,GAAG,CAAQ;IAClC,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IAEpD,aAAa,CAAC,UAAU,EAAE,GAAG,GAAG,IAAI;IAOpC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,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C,OAAO,EAAE,WAAW,EAAE,GAAG,IAAI;IAiBpD,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAUnD,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;CAQrD"}
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Base InfoExtractor class - ported from yt_dlp/extractor/common.py
|
|
4
|
+
*
|
|
5
|
+
* All extractors extend this class and implement _realExtract().
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.InfoExtractor = void 0;
|
|
9
|
+
const index_js_1 = require("../networking/index.js");
|
|
10
|
+
const index_js_2 = require("../utils/index.js");
|
|
11
|
+
class InfoExtractor {
|
|
12
|
+
_downloader = null;
|
|
13
|
+
_httpHeaders = {};
|
|
14
|
+
setDownloader(downloader) {
|
|
15
|
+
this._downloader = downloader;
|
|
16
|
+
if (downloader?.params?.httpHeaders) {
|
|
17
|
+
this._httpHeaders = downloader.params.httpHeaders;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
suitable(url) {
|
|
21
|
+
return this._VALID_URL.test(url);
|
|
22
|
+
}
|
|
23
|
+
matchUrl(url) {
|
|
24
|
+
return url.match(this._VALID_URL);
|
|
25
|
+
}
|
|
26
|
+
async extract(url) {
|
|
27
|
+
const match = this.matchUrl(url);
|
|
28
|
+
if (!match) {
|
|
29
|
+
throw new index_js_2.ExtractorError(`URL not suitable for ${this.IE_NAME}: ${url}`);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const result = await this._realExtract(url, match);
|
|
33
|
+
if (!result.webpage_url)
|
|
34
|
+
result.webpage_url = url;
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
if (err instanceof index_js_2.ExtractorError)
|
|
39
|
+
throw err;
|
|
40
|
+
throw new index_js_2.ExtractorError(`${this.IE_NAME}: ${err.message}`, err);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// --- HTTP helpers ---
|
|
44
|
+
async _downloadWebpage(url, videoId, note = 'Downloading webpage', options = {}) {
|
|
45
|
+
this._log(note, videoId);
|
|
46
|
+
const headers = { ...this._httpHeaders, ...options.headers };
|
|
47
|
+
const resp = await (0, index_js_1.makeRequest)(url, { ...options, headers });
|
|
48
|
+
if (resp.status >= 400) {
|
|
49
|
+
throw new index_js_2.ExtractorError(`HTTP Error ${resp.status}: ${url}`);
|
|
50
|
+
}
|
|
51
|
+
return resp.text();
|
|
52
|
+
}
|
|
53
|
+
async _downloadJson(url, videoId, note = 'Downloading JSON', options = {}, fatal = true) {
|
|
54
|
+
const webpage = await this._downloadWebpage(url, videoId, note, options);
|
|
55
|
+
return this._parseJson(webpage, videoId, fatal);
|
|
56
|
+
}
|
|
57
|
+
async _requestWebpage(url, videoId, note = 'Requesting', options = {}) {
|
|
58
|
+
this._log(note, videoId);
|
|
59
|
+
const headers = { ...this._httpHeaders, ...options.headers };
|
|
60
|
+
return (0, index_js_1.makeRequest)(url, { ...options, headers });
|
|
61
|
+
}
|
|
62
|
+
// --- Parsing helpers ---
|
|
63
|
+
_parseJson(jsonStr, videoId, fatal = true) {
|
|
64
|
+
try {
|
|
65
|
+
return JSON.parse(jsonStr);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
try {
|
|
69
|
+
return JSON.parse((0, index_js_2.jsToJson)(jsonStr));
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
if (fatal)
|
|
73
|
+
throw new index_js_2.ExtractorError(`Failed to parse JSON for ${videoId}: ${err.message}`);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
_searchRegex(patterns, str, name, defaultVal, fatal = true, group) {
|
|
79
|
+
const patternList = Array.isArray(patterns) ? patterns : [patterns];
|
|
80
|
+
for (const pattern of patternList) {
|
|
81
|
+
const match = str.match(pattern);
|
|
82
|
+
if (match) {
|
|
83
|
+
if (group !== undefined) {
|
|
84
|
+
const val = typeof group === 'number' ? match[group] : match[Number(group)];
|
|
85
|
+
return val ?? defaultVal ?? null;
|
|
86
|
+
}
|
|
87
|
+
return match[1] ?? match[0];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (defaultVal !== undefined)
|
|
91
|
+
return defaultVal;
|
|
92
|
+
if (fatal)
|
|
93
|
+
throw new index_js_2.RegexNotFoundError(name);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
_htmlSearchRegex(patterns, html, name, defaultVal, fatal = true, group) {
|
|
97
|
+
const result = this._searchRegex(patterns, html, name, defaultVal, fatal, group);
|
|
98
|
+
return result ? (0, index_js_2.unescapeHTML)(result) : result;
|
|
99
|
+
}
|
|
100
|
+
_htmlSearchMeta(names, html, displayName, fatal = false) {
|
|
101
|
+
const nameList = Array.isArray(names) ? names : [names];
|
|
102
|
+
for (const name of nameList) {
|
|
103
|
+
const patterns = [
|
|
104
|
+
new RegExp(`<meta[^>]+(?:name|property|http-equiv)=["']${name}["'][^>]+content=["']([^"']+)["']`, 'i'),
|
|
105
|
+
new RegExp(`<meta[^>]+content=["']([^"']+)["'][^>]+(?:name|property|http-equiv)=["']${name}["']`, 'i'),
|
|
106
|
+
];
|
|
107
|
+
const result = this._searchRegex(patterns, html, displayName || name, undefined, false);
|
|
108
|
+
if (result)
|
|
109
|
+
return (0, index_js_2.unescapeHTML)(result);
|
|
110
|
+
}
|
|
111
|
+
if (fatal)
|
|
112
|
+
throw new index_js_2.RegexNotFoundError(displayName || String(nameList[0]));
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
_ogSearchProperty(prop, html, fatal = true) {
|
|
116
|
+
return this._htmlSearchMeta(`og:${prop}`, html, `og:${prop}`, fatal);
|
|
117
|
+
}
|
|
118
|
+
_ogSearchTitle(html) {
|
|
119
|
+
return this._ogSearchProperty('title', html, false);
|
|
120
|
+
}
|
|
121
|
+
_ogSearchDescription(html) {
|
|
122
|
+
return this._ogSearchProperty('description', html, false);
|
|
123
|
+
}
|
|
124
|
+
_ogSearchThumbnail(html) {
|
|
125
|
+
return this._ogSearchProperty('image', html, false);
|
|
126
|
+
}
|
|
127
|
+
_htmlExtractTitle(html) {
|
|
128
|
+
return this._htmlSearchRegex(/<title[^>]*>([^<]+)<\/title>/i, html, 'title', undefined, false);
|
|
129
|
+
}
|
|
130
|
+
// --- Format helpers ---
|
|
131
|
+
async _extractM3u8FormatsAndSubtitles(m3u8Url, videoId, ext = 'mp4', preference, note = 'Downloading m3u8 manifest') {
|
|
132
|
+
const manifest = await this._downloadWebpage(m3u8Url, videoId, note);
|
|
133
|
+
const formats = [];
|
|
134
|
+
const subtitles = {};
|
|
135
|
+
// Parse master playlist
|
|
136
|
+
const lines = manifest.split('\n');
|
|
137
|
+
let currentStreamInfo = {};
|
|
138
|
+
for (let i = 0; i < lines.length; i++) {
|
|
139
|
+
const line = lines[i].trim();
|
|
140
|
+
if (line.startsWith('#EXT-X-STREAM-INF:')) {
|
|
141
|
+
currentStreamInfo = this._parseM3u8Attributes(line.slice('#EXT-X-STREAM-INF:'.length));
|
|
142
|
+
}
|
|
143
|
+
else if (line.startsWith('#EXT-X-MEDIA:')) {
|
|
144
|
+
const attrs = this._parseM3u8Attributes(line.slice('#EXT-X-MEDIA:'.length));
|
|
145
|
+
if (attrs['TYPE'] === 'SUBTITLES' && attrs['URI']) {
|
|
146
|
+
const lang = attrs['LANGUAGE'] || 'und';
|
|
147
|
+
if (!subtitles[lang])
|
|
148
|
+
subtitles[lang] = [];
|
|
149
|
+
subtitles[lang].push({
|
|
150
|
+
url: new URL(attrs['URI'], m3u8Url).toString(),
|
|
151
|
+
ext: 'vtt',
|
|
152
|
+
name: attrs['NAME'],
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else if (line && !line.startsWith('#')) {
|
|
157
|
+
// URL line
|
|
158
|
+
const streamUrl = new URL(line, m3u8Url).toString();
|
|
159
|
+
const bandwidth = (0, index_js_2.intOrNone)(currentStreamInfo['BANDWIDTH']);
|
|
160
|
+
const resolution = currentStreamInfo['RESOLUTION'];
|
|
161
|
+
let width;
|
|
162
|
+
let height;
|
|
163
|
+
if (resolution) {
|
|
164
|
+
const [w, h] = resolution.split('x');
|
|
165
|
+
width = parseInt(w, 10) || undefined;
|
|
166
|
+
height = parseInt(h, 10) || undefined;
|
|
167
|
+
}
|
|
168
|
+
const codecs = currentStreamInfo['CODECS'] || '';
|
|
169
|
+
const format = {
|
|
170
|
+
format_id: `hls-${bandwidth || formats.length}`,
|
|
171
|
+
url: streamUrl,
|
|
172
|
+
manifest_url: m3u8Url,
|
|
173
|
+
ext,
|
|
174
|
+
protocol: 'm3u8_native',
|
|
175
|
+
tbr: bandwidth ? Math.round(bandwidth / 1000) : undefined,
|
|
176
|
+
width,
|
|
177
|
+
height,
|
|
178
|
+
vcodec: codecs.split(',').find(c => /^(avc|hev|hvc|vp|av01)/i.test(c.trim()))?.trim(),
|
|
179
|
+
acodec: codecs.split(',').find(c => /^(mp4a|opus|vorb|flac|ac-3)/i.test(c.trim()))?.trim(),
|
|
180
|
+
};
|
|
181
|
+
if (preference !== undefined)
|
|
182
|
+
format.preference = preference;
|
|
183
|
+
formats.push(format);
|
|
184
|
+
currentStreamInfo = {};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// If no stream-inf found, this is a media playlist itself
|
|
188
|
+
if (formats.length === 0 && manifest.includes('#EXTINF:')) {
|
|
189
|
+
formats.push({
|
|
190
|
+
format_id: 'hls',
|
|
191
|
+
url: m3u8Url,
|
|
192
|
+
ext,
|
|
193
|
+
protocol: 'm3u8_native',
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return { formats, subtitles };
|
|
197
|
+
}
|
|
198
|
+
async _extractMpdFormatsAndSubtitles(mpdUrl, videoId, note = 'Downloading MPD manifest') {
|
|
199
|
+
const manifest = await this._downloadWebpage(mpdUrl, videoId, note);
|
|
200
|
+
const formats = [];
|
|
201
|
+
const subtitles = {};
|
|
202
|
+
// Basic MPD parsing — handles common YouTube DASH manifest structure
|
|
203
|
+
const periodMatch = manifest.match(/<Period[\s\S]*?<\/Period>/g);
|
|
204
|
+
if (!periodMatch)
|
|
205
|
+
return { formats, subtitles };
|
|
206
|
+
for (const period of periodMatch) {
|
|
207
|
+
const adaptationSets = period.match(/<AdaptationSet[\s\S]*?<\/AdaptationSet>/g) || [];
|
|
208
|
+
for (const adaptationSet of adaptationSets) {
|
|
209
|
+
const asAttrs = this._parseXmlAttributes(adaptationSet);
|
|
210
|
+
const mimeType = asAttrs['mimeType'] || '';
|
|
211
|
+
const contentType = asAttrs['contentType'] || '';
|
|
212
|
+
const lang = asAttrs['lang'];
|
|
213
|
+
// Check for subtitles
|
|
214
|
+
if (contentType === 'text' || mimeType.startsWith('text/')) {
|
|
215
|
+
const repMatches = adaptationSet.match(/<Representation[\s\S]*?(?:\/>|<\/Representation>)/g) || [];
|
|
216
|
+
for (const rep of repMatches) {
|
|
217
|
+
const repAttrs = this._parseXmlAttributes(rep);
|
|
218
|
+
const baseUrlMatch = rep.match(/<BaseURL[^>]*>([^<]+)<\/BaseURL>/);
|
|
219
|
+
if (baseUrlMatch) {
|
|
220
|
+
const subLang = lang || 'und';
|
|
221
|
+
if (!subtitles[subLang])
|
|
222
|
+
subtitles[subLang] = [];
|
|
223
|
+
subtitles[subLang].push({
|
|
224
|
+
url: new URL(baseUrlMatch[1], mpdUrl).toString(),
|
|
225
|
+
ext: (0, index_js_2.mimetypeToExt)(mimeType) || 'vtt',
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const repMatches = adaptationSet.match(/<Representation[\s\S]*?(?:\/>|<\/Representation>)/g) || [];
|
|
232
|
+
for (const rep of repMatches) {
|
|
233
|
+
const repAttrs = this._parseXmlAttributes(rep);
|
|
234
|
+
const combinedMime = repAttrs['mimeType'] || mimeType;
|
|
235
|
+
const ext = (0, index_js_2.mimetypeToExt)(combinedMime) || 'mp4';
|
|
236
|
+
const bandwidth = (0, index_js_2.intOrNone)(repAttrs['bandwidth']);
|
|
237
|
+
const width = (0, index_js_2.intOrNone)(repAttrs['width']);
|
|
238
|
+
const height = (0, index_js_2.intOrNone)(repAttrs['height']);
|
|
239
|
+
const codecs = repAttrs['codecs'] || asAttrs['codecs'] || '';
|
|
240
|
+
const id = repAttrs['id'] || '';
|
|
241
|
+
const baseUrlMatch = rep.match(/<BaseURL[^>]*>([^<]+)<\/BaseURL>/) ||
|
|
242
|
+
adaptationSet.match(/<BaseURL[^>]*>([^<]+)<\/BaseURL>/);
|
|
243
|
+
const segUrl = baseUrlMatch ? new URL(baseUrlMatch[1], mpdUrl).toString() : mpdUrl;
|
|
244
|
+
const isVideo = combinedMime.startsWith('video/') || contentType === 'video';
|
|
245
|
+
const isAudio = combinedMime.startsWith('audio/') || contentType === 'audio';
|
|
246
|
+
const format = {
|
|
247
|
+
format_id: `dash-${id || formats.length}`,
|
|
248
|
+
url: segUrl,
|
|
249
|
+
manifest_url: mpdUrl,
|
|
250
|
+
ext,
|
|
251
|
+
protocol: 'http_dash_segments',
|
|
252
|
+
tbr: bandwidth ? Math.round(bandwidth / 1000) : undefined,
|
|
253
|
+
width: isVideo ? width ?? undefined : undefined,
|
|
254
|
+
height: isVideo ? height ?? undefined : undefined,
|
|
255
|
+
vcodec: isVideo ? codecs || undefined : 'none',
|
|
256
|
+
acodec: isAudio ? codecs || undefined : (isVideo ? 'none' : undefined),
|
|
257
|
+
asr: (0, index_js_2.intOrNone)(repAttrs['audioSamplingRate']) ?? undefined,
|
|
258
|
+
};
|
|
259
|
+
formats.push(format);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return { formats, subtitles };
|
|
264
|
+
}
|
|
265
|
+
_parseM3u8Attributes(line) {
|
|
266
|
+
const attrs = {};
|
|
267
|
+
const re = /([A-Z0-9-]+)=(?:"([^"]*)"|([\w./:-]+))/g;
|
|
268
|
+
let match;
|
|
269
|
+
while ((match = re.exec(line)) !== null) {
|
|
270
|
+
attrs[match[1]] = match[2] ?? match[3];
|
|
271
|
+
}
|
|
272
|
+
return attrs;
|
|
273
|
+
}
|
|
274
|
+
_parseXmlAttributes(tag) {
|
|
275
|
+
const attrs = {};
|
|
276
|
+
const firstTag = tag.match(/<\w+([^>]*)>/)?.[1] || '';
|
|
277
|
+
const re = /(\w+)="([^"]*)"/g;
|
|
278
|
+
let match;
|
|
279
|
+
while ((match = re.exec(firstTag)) !== null) {
|
|
280
|
+
attrs[match[1]] = match[2];
|
|
281
|
+
}
|
|
282
|
+
return attrs;
|
|
283
|
+
}
|
|
284
|
+
// --- Sorting ---
|
|
285
|
+
_sortFormats(formats) {
|
|
286
|
+
formats.sort((a, b) => {
|
|
287
|
+
const getScore = (f) => {
|
|
288
|
+
let score = 0;
|
|
289
|
+
score += (f.height || 0) * 10000;
|
|
290
|
+
score += (f.tbr || 0);
|
|
291
|
+
score += (f.preference || 0) * 100000;
|
|
292
|
+
if (f.vcodec && f.vcodec !== 'none')
|
|
293
|
+
score += 1000000;
|
|
294
|
+
if (f.acodec && f.acodec !== 'none')
|
|
295
|
+
score += 500000;
|
|
296
|
+
return score;
|
|
297
|
+
};
|
|
298
|
+
return getScore(a) - getScore(b);
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
// --- Logging ---
|
|
302
|
+
_log(msg, videoId) {
|
|
303
|
+
const prefix = videoId ? `[${this.IE_NAME}] ${videoId}: ` : `[${this.IE_NAME}] `;
|
|
304
|
+
if (this._downloader?.params?.quiet)
|
|
305
|
+
return;
|
|
306
|
+
if (this._downloader) {
|
|
307
|
+
this._downloader.toScreen(`${prefix}${msg}`);
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
console.log(`${prefix}${msg}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
_warn(msg, videoId) {
|
|
314
|
+
const prefix = videoId ? `[${this.IE_NAME}] ${videoId}: ` : `[${this.IE_NAME}] `;
|
|
315
|
+
if (this._downloader) {
|
|
316
|
+
this._downloader.reportWarning(`${prefix}${msg}`);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
console.warn(`WARNING: ${prefix}${msg}`);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
exports.InfoExtractor = InfoExtractor;
|
|
324
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/extractor/common.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,qDAAyF;AACzF,gDAI2B;AAQ3B,MAAsB,aAAa;IAIvB,WAAW,GAAQ,IAAI,CAAC;IACxB,YAAY,GAA2B,EAAE,CAAC;IAEpD,aAAa,CAAC,UAAe;QAC3B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;YACpC,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,MAAM,CAAC,WAAW,CAAC;QACpD,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,GAAW;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAED,QAAQ,CAAC,GAAW;QAClB,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAW;QACvB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,yBAAc,CAA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
|
+
*
|
|
4
|
+
* Uses the yt-dlp EJS challenge solver scripts (yt.solver.core.js) with
|
|
5
|
+
* meriyah (JS parser) and astring (AST code generator) to extract and
|
|
6
|
+
* solve n-parameter transformations from YouTube player JavaScript.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Extract the player URL from a YouTube webpage.
|
|
10
|
+
*/
|
|
11
|
+
export declare function extractPlayerUrl(webpage: string): string | null;
|
|
12
|
+
/**
|
|
13
|
+
* Solve the n-parameter challenge for a given video URL.
|
|
14
|
+
*/
|
|
15
|
+
export declare function solveNChallenge(formatUrl: string, playerUrl: string): Promise<string>;
|
|
16
|
+
export declare function clearNSigCache(): void;
|
|
17
|
+
//# sourceMappingURL=nsig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nsig.d.ts","sourceRoot":"","sources":["../../src/extractor/nsig.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAWH;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAiB/D;AA0GD;;GAEG;AACH,wBAAsB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA2B3F;AAED,wBAAgB,cAAc,IAAI,IAAI,CAIrC"}
|