patreon-dl 1.0.0 → 1.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/README.md +90 -7
- package/dist/cli/CommandLineParser.d.ts +1 -0
- package/dist/cli/CommandLineParser.d.ts.map +1 -1
- package/dist/cli/CommandLineParser.js +16 -0
- package/dist/cli/CommandLineParser.js.map +1 -1
- package/dist/cli/helper/YouTubeConfigurator.d.ts +5 -0
- package/dist/cli/helper/YouTubeConfigurator.d.ts.map +1 -0
- package/dist/cli/helper/YouTubeConfigurator.js +111 -0
- package/dist/cli/helper/YouTubeConfigurator.js.map +1 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +14 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/downloaders/Downloader.d.ts.map +1 -1
- package/dist/downloaders/Downloader.js +8 -3
- package/dist/downloaders/Downloader.js.map +1 -1
- package/dist/downloaders/DownloaderOptions.d.ts +2 -1
- package/dist/downloaders/DownloaderOptions.d.ts.map +1 -1
- package/dist/downloaders/DownloaderOptions.js +2 -0
- package/dist/downloaders/DownloaderOptions.js.map +1 -1
- package/dist/downloaders/PostDownloader.d.ts.map +1 -1
- package/dist/downloaders/PostDownloader.js +9 -3
- package/dist/downloaders/PostDownloader.js.map +1 -1
- package/dist/downloaders/task/DownloadTaskBatch.js +1 -1
- package/dist/downloaders/task/DownloadTaskBatch.js.map +1 -1
- package/dist/downloaders/task/DownloadTaskFactory.d.ts.map +1 -1
- package/dist/downloaders/task/DownloadTaskFactory.js +36 -15
- package/dist/downloaders/task/DownloadTaskFactory.js.map +1 -1
- package/dist/downloaders/task/FFmpegDownloadTaskBase.d.ts +35 -0
- package/dist/downloaders/task/FFmpegDownloadTaskBase.d.ts.map +1 -0
- package/dist/downloaders/task/FFmpegDownloadTaskBase.js +231 -0
- package/dist/downloaders/task/FFmpegDownloadTaskBase.js.map +1 -0
- package/dist/downloaders/task/FetcherDownloadTask.js +2 -2
- package/dist/downloaders/task/FetcherDownloadTask.js.map +1 -1
- package/dist/downloaders/task/M3U8DownloadTask.d.ts +13 -0
- package/dist/downloaders/task/M3U8DownloadTask.d.ts.map +1 -0
- package/dist/downloaders/task/M3U8DownloadTask.js +37 -0
- package/dist/downloaders/task/M3U8DownloadTask.js.map +1 -0
- package/dist/downloaders/task/YouTubeDownloadTask.d.ts +14 -0
- package/dist/downloaders/task/YouTubeDownloadTask.d.ts.map +1 -0
- package/dist/downloaders/task/YouTubeDownloadTask.js +176 -0
- package/dist/downloaders/task/YouTubeDownloadTask.js.map +1 -0
- package/dist/entities/Downloadable.d.ts +3 -3
- package/dist/entities/Downloadable.d.ts.map +1 -1
- package/dist/entities/Downloadable.js +2 -3
- package/dist/entities/Downloadable.js.map +1 -1
- package/dist/entities/Post.d.ts +6 -1
- package/dist/entities/Post.d.ts.map +1 -1
- package/dist/entities/Post.js.map +1 -1
- package/dist/entities/index.d.ts +1 -1
- package/dist/entities/index.d.ts.map +1 -1
- package/dist/entities/index.js.map +1 -1
- package/dist/parsers/Parser.d.ts +4 -1
- package/dist/parsers/Parser.d.ts.map +1 -1
- package/dist/parsers/Parser.js +5 -2
- package/dist/parsers/Parser.js.map +1 -1
- package/dist/parsers/PostParser.d.ts.map +1 -1
- package/dist/parsers/PostParser.js +4 -3
- package/dist/parsers/PostParser.js.map +1 -1
- package/dist/utils/InnertubeLoader.d.ts +11 -0
- package/dist/utils/InnertubeLoader.d.ts.map +1 -0
- package/dist/utils/InnertubeLoader.js +95 -0
- package/dist/utils/InnertubeLoader.js.map +1 -0
- package/dist/utils/YouTubeCredentialsCapturer.d.ts +21 -0
- package/dist/utils/YouTubeCredentialsCapturer.d.ts.map +1 -0
- package/dist/utils/YouTubeCredentialsCapturer.js +59 -0
- package/dist/utils/YouTubeCredentialsCapturer.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +9 -5
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
A Patreon downloader written in [Node.js](https://nodejs.org).
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
### Features
|
|
8
8
|
- Access to patron-only content through cookie
|
|
9
9
|
- Download posts by user, in a collection or single post
|
|
10
10
|
- Download products (aka shop purchases)
|
|
@@ -18,13 +18,28 @@ A Patreon downloader written in [Node.js](https://nodejs.org).
|
|
|
18
18
|
|
|
19
19
|
You can run `patreon-dl` from the command-line or use it as a library for your project. Node.js v16.16.0 or higher required.
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
### Limitations
|
|
22
22
|
|
|
23
|
-
- Embedded videos,
|
|
23
|
+
- Embedded videos, other than those from YouTube, are not supported (e.g. Vimeo). Only info about these embeds is saved.
|
|
24
24
|
- Likewise, embedded links are not followed; only info about the embed is saved.
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
### FFmpeg dependency
|
|
27
|
+
|
|
28
|
+
[FFmpeg](https://ffmpeg.org) is required when downloading:
|
|
29
|
+
- videos that are provided only in streaming format; and
|
|
30
|
+
- embedded YouTube videos.
|
|
31
|
+
|
|
32
|
+
Not all video downloads require FFmpeg, but you should have it installed on your system anyway.
|
|
33
|
+
|
|
34
|
+
### Embedded YouTube videos - Premium access
|
|
35
|
+
|
|
36
|
+
`patreon-dl` supports downloading embedded YouTube videos. In addition, if you have a YouTube Premium subscription, you can connect `patreon-dl` to your account and download videos at qualities available only to Premium accounts (e.g. '1080p Premium'). For CLI users, you would configure `patreon-dl` as follows:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
$ patreon-dl --configure-youtube
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
For library usage, see [Configuring YouTube connection](#configuring-youtube-connection).
|
|
28
43
|
|
|
29
44
|
## Installation
|
|
30
45
|
|
|
@@ -49,7 +64,8 @@ Options
|
|
|
49
64
|
-l, --log-level <level> Log level of the console logger: 'info', 'debug',
|
|
50
65
|
'warn' or 'error'; set to 'none' to disable the
|
|
51
66
|
logger.
|
|
52
|
-
-y, --no-prompt Do not prompt for confirmation to proceed
|
|
67
|
+
-y, --no-prompt Do not prompt for confirmation to proceed
|
|
68
|
+
--configure-youtube Configure YouTube connection
|
|
53
69
|
```
|
|
54
70
|
|
|
55
71
|
#### Supported URL formats
|
|
@@ -128,6 +144,7 @@ An object with the following properties (all *optional*):
|
|
|
128
144
|
| `cookie` | Cookie to include in requests; required for accessing patron-only content. See [How to obtain Cookie](https://github.com/patrickkfkan/patreon-dl/wiki/How-to-obtain-Cookie). |
|
|
129
145
|
| `useStatusCache` | Whether to use status cache to quickly determine whether a target that had been downloaded before has changed since the last download. Default: `true` |
|
|
130
146
|
| `pathToFFmpeg` | Path to `ffmpeg` executable. If not specified, `ffmpeg` will be called directly when needed, so make sure it is in the PATH. |
|
|
147
|
+
| `pathToYouTubeCredentials` | Path to file storing YouTube credentials for connecting to a YouTube account when downloading embedded YouTube videos. Its purpose is to allow YouTube Premium accounts to download videos at higher than normal qualities. For more information, see [Configuring YouTube connection](#configuring-youtube-connection).
|
|
131
148
|
| `outDir` | Path to directory where content is saved. Default: current working directory |
|
|
132
149
|
| `dirNameFormat` | How to name directories: (object)<ul><li>`campaign`: see [Campaign directory name format](#campaign-directory-name-format)</li><li>`content`: see [Content directory name format](#content-directory-name-format)</li></ul> |
|
|
133
150
|
| `filenameFormat` | Naming of files: (object)<ul><li>`media`: see [Media filename format](#media-filename-format) |
|
|
@@ -203,6 +220,65 @@ Characters enclosed in square brackets followed by a question mark denote condit
|
|
|
203
220
|
Default: '{media.filename}'</br>
|
|
204
221
|
Fallback: '{media.type}-{media.id}'
|
|
205
222
|
|
|
223
|
+
### Configuring YouTube connection
|
|
224
|
+
|
|
225
|
+
In its simplest form, the process of connecting `patreon-dl` to a YouTube account is as follows:
|
|
226
|
+
|
|
227
|
+
1. Obtain credentials by having the user visit a Google page that links his or her account to a 'device' (which in this case is actually `patreon-dl`).
|
|
228
|
+
2. Save the credentials, as a JSON string, to a file.
|
|
229
|
+
3. Pass the path of the file to `PatreonDownloader.getInstance()`
|
|
230
|
+
|
|
231
|
+
To obtain credentials, you can use the `YouTubeCredentialsCapturer` class:
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
import { YouTubeCredentialsCapturer } from 'patreon-dl';
|
|
235
|
+
|
|
236
|
+
// Note: you should wrap the following logic inside an async
|
|
237
|
+
// process, and resolve when the credentials have been saved.
|
|
238
|
+
|
|
239
|
+
const capturer = new YouTubeCredentialsCapturer();
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* 'pending' event emitted when verification data is ready and waiting
|
|
243
|
+
* for user to carry out the verification process.
|
|
244
|
+
*/
|
|
245
|
+
capturer.on('pending', (data) => {
|
|
246
|
+
// `data` is an object: { verificationURL: <string>, code: <string> }
|
|
247
|
+
// Use `data` to provide instructions to the user:
|
|
248
|
+
console.log(
|
|
249
|
+
`In a browser, go to the following Verification URL and enter Code:
|
|
250
|
+
|
|
251
|
+
- Verification URL: ${data.verificationURL}
|
|
252
|
+
- Code: ${data.code}
|
|
253
|
+
|
|
254
|
+
Then wait for this script to complete.`);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* 'capture' event emitted when the user has completed verification and the
|
|
259
|
+
* credentials have been relayed back to the capturer.
|
|
260
|
+
*/
|
|
261
|
+
capturer.on('capture', (credentials) => {
|
|
262
|
+
// `credentials` is an object which you need to save to file as JSON string.
|
|
263
|
+
fs.writeFileSync('/path/to/yt-credentials.json', JSON.stringify(credentials));
|
|
264
|
+
console.log('Credentials saved!');
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
// When you have added the listeners, start the capture process.
|
|
268
|
+
capturer.begin();
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Then, pass the path of the file to `PatreonDownloader.getInstance()`:
|
|
272
|
+
|
|
273
|
+
```
|
|
274
|
+
const downloader = await PatreonDownloader.getInstance(url, {
|
|
275
|
+
...
|
|
276
|
+
pathToYouTubeCredentials: '/path/to/yt-credentials.json'
|
|
277
|
+
});
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
You should ensure the credentials file is writable, as it needs to be updated with new credentials when the current ones expire. The process of renewing credentials is done automatically by the downloader.
|
|
281
|
+
|
|
206
282
|
### Logger
|
|
207
283
|
|
|
208
284
|
Logging is optional, but provides useful information about the download process. You can implement your own logger by extending the `Logger` abstract class:
|
|
@@ -343,7 +419,7 @@ abortController.abort();
|
|
|
343
419
|
3. Downloader begins saving media belonging to target (again, subject to downloader configuration). Emits `phaseBegin` event with `phase: saveMedia`.
|
|
344
420
|
1. Downloader saves files that do not need to be downloaded, e.g. embedded video / link info.
|
|
345
421
|
2. Downloader proceeds to download files (images, videos, audio, attachments, etc.) belonging to the target in batches. For each batch, downloader emits `phaseBegin` event with `phase: batchDownload`. When done, downloader emits `phaseEnd` event with `phase: batchDownload`.
|
|
346
|
-
- In this `phaseBegin` event, you can attach listeners to the download batch to monitor events for each download. See Download Task Batch.
|
|
422
|
+
- In this `phaseBegin` event, you can attach listeners to the download batch to monitor events for each download. See [Download Task Batch](#download-task-batch).
|
|
347
423
|
4. Downloader emits `phaseEnd` event with `phase: saveMedia`.
|
|
348
424
|
5. Downloader emits `targetEnd` event with `isSkipped: false`, and proceeds to the next target.
|
|
349
425
|
4. When there are no more targets to be processed, or a fatal error occurred, downloader ends with `end` event.
|
|
@@ -418,5 +494,12 @@ Each event emitted by a download task batch has a payload, which is an object wi
|
|
|
418
494
|
|
|
419
495
|
## Changelog
|
|
420
496
|
|
|
497
|
+
v1.1.0
|
|
498
|
+
- Add support for downloading embedded YouTube videos
|
|
499
|
+
|
|
500
|
+
v1.0.1
|
|
501
|
+
- Fix missing types when importing as library
|
|
502
|
+
- Fix link in this README
|
|
503
|
+
|
|
421
504
|
v1.0.0
|
|
422
505
|
- Initial release
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandLineParser.d.ts","sourceRoot":"","sources":["../../src/cli/CommandLineParser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEnE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGjE,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAC7G,UAAU,CAAC,EAAE,oBAAoB,CAAC;CACnC;
|
|
1
|
+
{"version":3,"file":"CommandLineParser.d.ts","sourceRoot":"","sources":["../../src/cli/CommandLineParser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEnE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGjE,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAC7G,UAAU,CAAC,EAAE,oBAAoB,CAAC;CACnC;AA2ED,MAAM,CAAC,OAAO,OAAO,iBAAiB;;IAEpC,MAAM,CAAC,KAAK,IAAI,sBAAsB;IA6FtC,MAAM,CAAC,SAAS;IAyChB,MAAM,CAAC,gBAAgB;CAmBxB"}
|
|
@@ -10,6 +10,7 @@ import { EOL } from 'os';
|
|
|
10
10
|
import { getPackageInfo } from '../utils/PackageInfo.js';
|
|
11
11
|
const COMMAND_LINE_ARGS = {
|
|
12
12
|
help: 'help',
|
|
13
|
+
configureYouTube: 'configure-youtube',
|
|
13
14
|
configFile: 'config-file',
|
|
14
15
|
targetURL: 'target-url',
|
|
15
16
|
cookie: 'cookie',
|
|
@@ -71,6 +72,11 @@ const OPT_DEFS = [
|
|
|
71
72
|
description: 'Do not prompt for confirmation to proceed',
|
|
72
73
|
alias: 'y',
|
|
73
74
|
type: Boolean
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: COMMAND_LINE_ARGS.configureYouTube,
|
|
78
|
+
description: 'Configure YouTube connection',
|
|
79
|
+
type: Boolean
|
|
74
80
|
}
|
|
75
81
|
];
|
|
76
82
|
export default class CommandLineParser {
|
|
@@ -200,6 +206,16 @@ export default class CommandLineParser {
|
|
|
200
206
|
}
|
|
201
207
|
return false;
|
|
202
208
|
}
|
|
209
|
+
static configureYouTube() {
|
|
210
|
+
let opts;
|
|
211
|
+
try {
|
|
212
|
+
opts = __classPrivateFieldGet(this, _a, "m", _CommandLineParser_parseArgs).call(this);
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
return opts['configure-youtube'];
|
|
218
|
+
}
|
|
203
219
|
}
|
|
204
220
|
_a = CommandLineParser, _CommandLineParser_parseArgs = function _CommandLineParser_parseArgs() {
|
|
205
221
|
const opts = commandLineArgs(OPT_DEFS, { stopAtFirstUnknown: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandLineParser.js","sourceRoot":"","sources":["../../src/cli/CommandLineParser.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,GAAG,EAAE,MAAM,IAAI,CAAC;AAEzB,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAMzD,MAAM,iBAAiB,GAAG;IACxB,IAAI,EAAE,MAAM;IACZ,UAAU,EAAE,aAAa;IACzB,SAAS,EAAE,YAAY;IACvB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,SAAS;IACjB,QAAQ,EAAE,WAAW;IACrB,QAAQ,EAAE,WAAW;CACb,CAAC;AAEX,MAAM,QAAQ,GAAG;IACf;QACE,IAAI,EAAE,iBAAiB,CAAC,IAAI;QAC5B,WAAW,EA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commandLineUsage from 'command-line-usage';\nimport { CLIOptionParserEntry, CLIOptions } from './CLIOptions.js';\nimport { EOL } from 'os';\nimport { DeepPartial, RecursivePropsTo } from '../utils/Misc.js';\nimport { getPackageInfo } from '../utils/PackageInfo.js';\n\nexport interface CommandLineParseResult extends RecursivePropsTo<DeepPartial<CLIOptions>, CLIOptionParserEntry> {\n configFile?: CLIOptionParserEntry;\n}\n\nconst COMMAND_LINE_ARGS = {\n help: 'help',\n configFile: 'config-file',\n targetURL: 'target-url',\n cookie: 'cookie',\n ffmpeg: 'ffmpeg',\n outDir: 'out-dir',\n logLevel: 'log-level',\n noPrompt: 'no-prompt'\n} as const;\n\nconst OPT_DEFS = [\n {\n name: COMMAND_LINE_ARGS.help,\n description: 'Display this usage guide',\n alias: 'h',\n type: Boolean\n },\n {\n name: COMMAND_LINE_ARGS.configFile,\n description: 'Load configuration file for setting full options',\n alias: 'C',\n type: String,\n typeLabel: '<file>'\n },\n {\n name: COMMAND_LINE_ARGS.targetURL,\n description: 'URL of content to download',\n type: String,\n defaultOption: true\n },\n {\n name: COMMAND_LINE_ARGS.cookie,\n description: 'Cookie for accessing patron-only content',\n alias: 'c',\n type: String,\n typeLabel: '<string>'\n },\n {\n name: COMMAND_LINE_ARGS.ffmpeg,\n description: 'Path to FFmpeg executable',\n alias: 'f',\n type: String,\n typeLabel: '<string>'\n },\n {\n name: COMMAND_LINE_ARGS.outDir,\n description: 'Path to directory where content is saved',\n alias: 'o',\n type: String,\n typeLabel: '<dir>'\n },\n {\n name: COMMAND_LINE_ARGS.logLevel,\n description: 'Log level of the console logger: \\'info\\', \\'debug\\', \\'warn\\' or \\'error\\'; set to \\'none\\' to disable the logger.',\n alias: 'l',\n type: String,\n typeLabel: '<level>'\n },\n {\n name: COMMAND_LINE_ARGS.noPrompt,\n description: 'Do not prompt for confirmation to proceed',\n alias: 'y',\n type: Boolean\n }\n];\n\nexport default class CommandLineParser {\n\n static parse(): CommandLineParseResult {\n const opts = this.#parseArgs();\n const argv = process.argv;\n\n const __getOptNameUsed = (key: string) => {\n const name = `--${key}`;\n if (argv.includes(name)) {\n return name;\n }\n const alias = OPT_DEFS.find((def) => def.name === key)?.alias;\n if (alias) {\n return `-${alias}`;\n }\n return name;\n };\n\n const __getValue = (key: typeof COMMAND_LINE_ARGS[keyof typeof COMMAND_LINE_ARGS]): CLIOptionParserEntry | undefined => {\n let value = opts[key];\n if (key === COMMAND_LINE_ARGS.noPrompt && value !== undefined) {\n value = '1';\n }\n else if (value === null) {\n throw Error(`Command-line option requires a value for '--${key}'`);\n }\n if (value && typeof value === 'string') {\n return {\n src: 'cli',\n key: __getOptNameUsed(key),\n value: value.trim()\n };\n }\n return undefined;\n };\n\n // Handle --log-level: none\n let consoleLoggerLevel = __getValue(COMMAND_LINE_ARGS.logLevel);\n let consoleLoggerEnabled: CLIOptionParserEntry | undefined;\n if (consoleLoggerLevel?.value === 'none') {\n consoleLoggerEnabled = {\n src: 'cli',\n key: '',\n value: '0'\n };\n consoleLoggerLevel = undefined;\n }\n\n return {\n configFile: __getValue(COMMAND_LINE_ARGS.configFile),\n targetURL: __getValue(COMMAND_LINE_ARGS.targetURL),\n cookie: __getValue(COMMAND_LINE_ARGS.cookie),\n useStatusCache: undefined,\n pathToFFmpeg: __getValue(COMMAND_LINE_ARGS.ffmpeg),\n outDir: __getValue(COMMAND_LINE_ARGS.outDir),\n dirNameFormat: {\n campaign: undefined,\n content: undefined\n },\n filenameFormat: {\n media: undefined\n },\n include: {\n campaignInfo: undefined,\n contentInfo: undefined,\n previewMedia: undefined,\n contentMedia: undefined,\n allMediaVariants: undefined\n },\n request: {\n maxRetries: undefined,\n maxConcurrent: undefined,\n minTime: undefined\n },\n fileExistsAction: {\n content: undefined,\n info: undefined,\n infoAPI: undefined\n },\n noPrompt: __getValue(COMMAND_LINE_ARGS.noPrompt),\n consoleLogger: {\n enabled: consoleLoggerEnabled,\n logLevel: consoleLoggerLevel,\n include: {\n dateTime: undefined,\n level: undefined,\n originator: undefined,\n errorStack: undefined\n },\n dateTimeFormat: undefined,\n color: undefined\n }\n };\n }\n\n static showUsage() {\n let opts;\n try {\n opts = this.#parseArgs();\n }\n catch (error) {\n return false;\n }\n if (opts.help) {\n const content = [\n 'Command-line options override corresponding options in configuration file loaded through \\'-C\\'.',\n EOL,\n 'Project home: {underline https://github.com/patrickkfkan/patreon-dl}'\n ];\n const sections: commandLineUsage.Section[] = [\n {\n header: 'Usage',\n content: 'patreon-dl [OPTION]... URL'\n },\n {\n header: 'Options',\n optionList: OPT_DEFS,\n hide: 'target-url'\n },\n {\n content: content.join(EOL)\n }\n ];\n const banner = getPackageInfo().banner;\n if (banner) {\n sections.unshift({ header: banner, raw: true });\n }\n const usage = commandLineUsage(sections);\n console.log(usage);\n\n return true;\n }\n\n return false;\n }\n\n static #parseArgs() {\n const opts = commandLineArgs(OPT_DEFS, { stopAtFirstUnknown: true });\n if (opts['_unknown']) {\n const unknownOpt = Object.keys(opts['_unknown'])[0];\n throw Error(`Unknown command-line option '${unknownOpt}'`);\n }\n return opts;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CommandLineParser.js","sourceRoot":"","sources":["../../src/cli/CommandLineParser.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,GAAG,EAAE,MAAM,IAAI,CAAC;AAEzB,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAMzD,MAAM,iBAAiB,GAAG;IACxB,IAAI,EAAE,MAAM;IACZ,gBAAgB,EAAE,mBAAmB;IACrC,UAAU,EAAE,aAAa;IACzB,SAAS,EAAE,YAAY;IACvB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,SAAS;IACjB,QAAQ,EAAE,WAAW;IACrB,QAAQ,EAAE,WAAW;CACb,CAAC;AAEX,MAAM,QAAQ,GAAG;IACf;QACE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C,CAAC;CAUF;;IAPG,MAAM,IAAI,GAAG,eAAe,CAAC,QAAQ,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC;IACrE,IAAI,IAAI,CAAC,UAAU,CAAC,EAAE;QACpB,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACpD,MAAM,KAAK,CAAC,gCAAgC,UAAU,GAAG,CAAC,CAAC;KAC5D;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import commandLineArgs from 'command-line-args';\nimport commandLineUsage from 'command-line-usage';\nimport { CLIOptionParserEntry, CLIOptions } from './CLIOptions.js';\nimport { EOL } from 'os';\nimport { DeepPartial, RecursivePropsTo } from '../utils/Misc.js';\nimport { getPackageInfo } from '../utils/PackageInfo.js';\n\nexport interface CommandLineParseResult extends RecursivePropsTo<DeepPartial<CLIOptions>, CLIOptionParserEntry> {\n configFile?: CLIOptionParserEntry;\n}\n\nconst COMMAND_LINE_ARGS = {\n help: 'help',\n configureYouTube: 'configure-youtube',\n configFile: 'config-file',\n targetURL: 'target-url',\n cookie: 'cookie',\n ffmpeg: 'ffmpeg',\n outDir: 'out-dir',\n logLevel: 'log-level',\n noPrompt: 'no-prompt'\n} as const;\n\nconst OPT_DEFS = [\n {\n name: COMMAND_LINE_ARGS.help,\n description: 'Display this usage guide',\n alias: 'h',\n type: Boolean\n },\n {\n name: COMMAND_LINE_ARGS.configFile,\n description: 'Load configuration file for setting full options',\n alias: 'C',\n type: String,\n typeLabel: '<file>'\n },\n {\n name: COMMAND_LINE_ARGS.targetURL,\n description: 'URL of content to download',\n type: String,\n defaultOption: true\n },\n {\n name: COMMAND_LINE_ARGS.cookie,\n description: 'Cookie for accessing patron-only content',\n alias: 'c',\n type: String,\n typeLabel: '<string>'\n },\n {\n name: COMMAND_LINE_ARGS.ffmpeg,\n description: 'Path to FFmpeg executable',\n alias: 'f',\n type: String,\n typeLabel: '<string>'\n },\n {\n name: COMMAND_LINE_ARGS.outDir,\n description: 'Path to directory where content is saved',\n alias: 'o',\n type: String,\n typeLabel: '<dir>'\n },\n {\n name: COMMAND_LINE_ARGS.logLevel,\n description: 'Log level of the console logger: \\'info\\', \\'debug\\', \\'warn\\' or \\'error\\'; set to \\'none\\' to disable the logger.',\n alias: 'l',\n type: String,\n typeLabel: '<level>'\n },\n {\n name: COMMAND_LINE_ARGS.noPrompt,\n description: 'Do not prompt for confirmation to proceed',\n alias: 'y',\n type: Boolean\n },\n {\n name: COMMAND_LINE_ARGS.configureYouTube,\n description: 'Configure YouTube connection',\n type: Boolean\n }\n];\n\nexport default class CommandLineParser {\n\n static parse(): CommandLineParseResult {\n const opts = this.#parseArgs();\n const argv = process.argv;\n\n const __getOptNameUsed = (key: string) => {\n const name = `--${key}`;\n if (argv.includes(name)) {\n return name;\n }\n const alias = OPT_DEFS.find((def) => def.name === key)?.alias;\n if (alias) {\n return `-${alias}`;\n }\n return name;\n };\n\n const __getValue = (key: typeof COMMAND_LINE_ARGS[keyof typeof COMMAND_LINE_ARGS]): CLIOptionParserEntry | undefined => {\n let value = opts[key];\n if (key === COMMAND_LINE_ARGS.noPrompt && value !== undefined) {\n value = '1';\n }\n else if (value === null) {\n throw Error(`Command-line option requires a value for '--${key}'`);\n }\n if (value && typeof value === 'string') {\n return {\n src: 'cli',\n key: __getOptNameUsed(key),\n value: value.trim()\n };\n }\n return undefined;\n };\n\n // Handle --log-level: none\n let consoleLoggerLevel = __getValue(COMMAND_LINE_ARGS.logLevel);\n let consoleLoggerEnabled: CLIOptionParserEntry | undefined;\n if (consoleLoggerLevel?.value === 'none') {\n consoleLoggerEnabled = {\n src: 'cli',\n key: '',\n value: '0'\n };\n consoleLoggerLevel = undefined;\n }\n\n return {\n configFile: __getValue(COMMAND_LINE_ARGS.configFile),\n targetURL: __getValue(COMMAND_LINE_ARGS.targetURL),\n cookie: __getValue(COMMAND_LINE_ARGS.cookie),\n useStatusCache: undefined,\n pathToFFmpeg: __getValue(COMMAND_LINE_ARGS.ffmpeg),\n outDir: __getValue(COMMAND_LINE_ARGS.outDir),\n dirNameFormat: {\n campaign: undefined,\n content: undefined\n },\n filenameFormat: {\n media: undefined\n },\n include: {\n campaignInfo: undefined,\n contentInfo: undefined,\n previewMedia: undefined,\n contentMedia: undefined,\n allMediaVariants: undefined\n },\n request: {\n maxRetries: undefined,\n maxConcurrent: undefined,\n minTime: undefined\n },\n fileExistsAction: {\n content: undefined,\n info: undefined,\n infoAPI: undefined\n },\n noPrompt: __getValue(COMMAND_LINE_ARGS.noPrompt),\n consoleLogger: {\n enabled: consoleLoggerEnabled,\n logLevel: consoleLoggerLevel,\n include: {\n dateTime: undefined,\n level: undefined,\n originator: undefined,\n errorStack: undefined\n },\n dateTimeFormat: undefined,\n color: undefined\n }\n };\n }\n\n static showUsage() {\n let opts;\n try {\n opts = this.#parseArgs();\n }\n catch (error) {\n return false;\n }\n if (opts.help) {\n const content = [\n 'Command-line options override corresponding options in configuration file loaded through \\'-C\\'.',\n EOL,\n 'Project home: {underline https://github.com/patrickkfkan/patreon-dl}'\n ];\n const sections: commandLineUsage.Section[] = [\n {\n header: 'Usage',\n content: 'patreon-dl [OPTION]... URL'\n },\n {\n header: 'Options',\n optionList: OPT_DEFS,\n hide: 'target-url'\n },\n {\n content: content.join(EOL)\n }\n ];\n const banner = getPackageInfo().banner;\n if (banner) {\n sections.unshift({ header: banner, raw: true });\n }\n const usage = commandLineUsage(sections);\n console.log(usage);\n\n return true;\n }\n\n return false;\n }\n\n static configureYouTube() {\n let opts;\n try {\n opts = this.#parseArgs();\n }\n catch (error) {\n return false;\n }\n return opts['configure-youtube'];\n }\n\n static #parseArgs() {\n const opts = commandLineArgs(OPT_DEFS, { stopAtFirstUnknown: true });\n if (opts['_unknown']) {\n const unknownOpt = Object.keys(opts['_unknown'])[0];\n throw Error(`Unknown command-line option '${unknownOpt}'`);\n }\n return opts;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"YouTubeConfigurator.d.ts","sourceRoot":"","sources":["../../../src/cli/helper/YouTubeConfigurator.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,OAAO,OAAO,mBAAmB;;WAEzB,KAAK,CAAC,WAAW,EAAE,MAAM;CAwHvC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var _a, _YouTubeConfigurator_startConnect, _YouTubeConfigurator_doConnectAndSaveCredentials, _YouTubeConfigurator_revokeCredentials, _YouTubeConfigurator_promptInput;
|
|
7
|
+
import { EOL } from 'os';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import fs from 'fs';
|
|
10
|
+
import PromptSync from 'prompt-sync';
|
|
11
|
+
import FSHelper from '../../utils/FSHelper.js';
|
|
12
|
+
import YouTubeCredentialsCapturer from '../../utils/YouTubeCredentialsCapturer.js';
|
|
13
|
+
export default class YouTubeConfigurator {
|
|
14
|
+
static async start(ytCredsPath) {
|
|
15
|
+
const prompt = PromptSync({ sigint: true });
|
|
16
|
+
console.log(`Welcome to patreon-dl YouTube Configurator!
|
|
17
|
+
|
|
18
|
+
If you have a YouTube Premium subscription, connecting patreon-dl to your
|
|
19
|
+
YouTube account will allow it to download embedded YouTube videos at
|
|
20
|
+
qualities available only to Premium subscribers, such as '1080p Premium'.
|
|
21
|
+
|
|
22
|
+
This script begins the YouTube connection process. During this process,
|
|
23
|
+
YouTube credentials are captured and saved to:
|
|
24
|
+
|
|
25
|
+
"${ytCredsPath}".
|
|
26
|
+
|
|
27
|
+
When patreon-dl starts, the credentials will be loaded and used for
|
|
28
|
+
authenticating access to Premium-quality YouTube streams.
|
|
29
|
+
|
|
30
|
+
What would you like to do?
|
|
31
|
+
1. Connect to YouTube
|
|
32
|
+
2. Revoke existing YouTube credentials
|
|
33
|
+
`);
|
|
34
|
+
const connectOrRevoke = __classPrivateFieldGet(this, _a, "m", _YouTubeConfigurator_promptInput).call(this, prompt, 'Enter your choice (1-2): ', ['1', '2'], ['connect', 'revoke']);
|
|
35
|
+
if (connectOrRevoke === 'connect') {
|
|
36
|
+
return await __classPrivateFieldGet(this, _a, "m", _YouTubeConfigurator_startConnect).call(this, ytCredsPath, prompt);
|
|
37
|
+
}
|
|
38
|
+
return __classPrivateFieldGet(this, _a, "m", _YouTubeConfigurator_revokeCredentials).call(this, ytCredsPath);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
_a = YouTubeConfigurator, _YouTubeConfigurator_startConnect = async function _YouTubeConfigurator_startConnect(ytCredsPath, prompt) {
|
|
42
|
+
if (fs.existsSync(ytCredsPath)) {
|
|
43
|
+
console.log('YouTube credentials file already exists. Proceeding will overwrite it.');
|
|
44
|
+
const overwriteOrExit = __classPrivateFieldGet(this, _a, "m", _YouTubeConfigurator_promptInput).call(this, prompt, 'Proceed (y/N)? ', ['y', 'n'], ['overwrite', 'exit'], 'exit');
|
|
45
|
+
if (overwriteOrExit === 'exit') {
|
|
46
|
+
console.log('Bye!');
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const code = await __classPrivateFieldGet(this, _a, "m", _YouTubeConfigurator_doConnectAndSaveCredentials).call(this, ytCredsPath);
|
|
51
|
+
if (code === 0) {
|
|
52
|
+
console.log('YouTube connection process completed successfully.');
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
console.log('YouTube connection process ended with error.');
|
|
56
|
+
}
|
|
57
|
+
return code;
|
|
58
|
+
}, _YouTubeConfigurator_doConnectAndSaveCredentials = function _YouTubeConfigurator_doConnectAndSaveCredentials(ytCredsPath) {
|
|
59
|
+
return new Promise(async (resolve) => {
|
|
60
|
+
const capturer = new YouTubeCredentialsCapturer();
|
|
61
|
+
capturer.on('pending', (data) => {
|
|
62
|
+
console.log(`In a browser, go to the following Verification URL and enter Code:
|
|
63
|
+
|
|
64
|
+
- Verification URL: ${data.verificationURL}
|
|
65
|
+
- Code: ${data.code}
|
|
66
|
+
|
|
67
|
+
Then wait for this script to complete.
|
|
68
|
+
`);
|
|
69
|
+
});
|
|
70
|
+
capturer.on('capture', (credentials) => {
|
|
71
|
+
try {
|
|
72
|
+
FSHelper.createDir(path.parse(ytCredsPath).dir);
|
|
73
|
+
fs.writeFileSync(ytCredsPath, JSON.stringify(credentials));
|
|
74
|
+
console.log(`YouTube connected; credentials saved to "${ytCredsPath}"`, EOL);
|
|
75
|
+
resolve(0);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
console.error(`Error saving credentials to "${ytCredsPath}": `, error instanceof Error ? error.message : error, EOL);
|
|
79
|
+
resolve(1);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
await capturer.begin();
|
|
83
|
+
});
|
|
84
|
+
}, _YouTubeConfigurator_revokeCredentials = function _YouTubeConfigurator_revokeCredentials(ytCredsPath) {
|
|
85
|
+
if (fs.existsSync(ytCredsPath)) {
|
|
86
|
+
try {
|
|
87
|
+
fs.unlinkSync(ytCredsPath);
|
|
88
|
+
console.log(`Deleted "${ytCredsPath}"`);
|
|
89
|
+
return 0;
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
console.error(`Error deleting "${ytCredsPath}": `, error instanceof Error ? error.message : error);
|
|
93
|
+
return 1;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
console.log(`No credentials found: "${ytCredsPath}" does not exist.`);
|
|
97
|
+
return 0;
|
|
98
|
+
}, _YouTubeConfigurator_promptInput = function _YouTubeConfigurator_promptInput(prompt, message, acceptValues, retValues, defaultValue) {
|
|
99
|
+
const input = prompt(message).trim().toLowerCase();
|
|
100
|
+
if (!input && defaultValue !== undefined) {
|
|
101
|
+
console.log('');
|
|
102
|
+
return defaultValue;
|
|
103
|
+
}
|
|
104
|
+
const acceptIndex = acceptValues.indexOf(input);
|
|
105
|
+
if (acceptIndex >= 0) {
|
|
106
|
+
console.log('');
|
|
107
|
+
return retValues[acceptIndex];
|
|
108
|
+
}
|
|
109
|
+
return __classPrivateFieldGet(this, _a, "m", _YouTubeConfigurator_promptInput).call(this, prompt, message, acceptValues, retValues);
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=YouTubeConfigurator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"YouTubeConfigurator.js","sourceRoot":"","sources":["../../../src/cli/helper/YouTubeConfigurator.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,QAAQ,MAAM,yBAAyB,CAAC;AAC/C,OAAO,0BAA0B,MAAM,2CAA2C,CAAC;AAEnF,MAAM,CAAC,OAAO,OAAO,mBAAmB;IAEtC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,WAAmB;QACpC,MAAM,MAAM,GAAG,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QAE5C,OAAO,CAAC,GAAG,CAAC;;;;;;;;;GASb,WAAW;;;;;;;;CAQb,CAAC,CAAC;QAEC,MAAM,eAAe,GAAG,uBAAA,IAAI,4CAAa,MAAjB,IAAI,EAC1B,MAAM,EACN,2BAA2B,EAC3B,CAAE,GAAG,EAAE,GAAG,CAAE,EACZ,CAAE,SAAS,EAAE,QAAQ,CAAE,CAAC,CAAC;QAE3B,IAAI,eAAe,KAAK,SAAS,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AAC,+EAGsB,MAAyB,EAAE,OAAe,EAAE,YAAsB,EAAE,SAAc,EAAE,YAAgB;IACzH,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACnD,IAAI,CAAC,KAAK,IAAI,YAAY,KAAK,SAAS,EAAE;QACxC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChB,OAAO,YAAY,CAAC;KACrB;IACD,MAAM,WAAW,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAChD,IAAI,WAAW,IAAI,CAAC,EAAE;QACpB,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChB,OAAO,SAAS,CAAC,WAAW,CAAC,CAAC;KAC/B;IACD,OAAO,uBAAA,IAAI,4CAAa,MAAjB,IAAI,EAAc,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import { EOL } from 'os';\nimport path from 'path';\nimport fs from 'fs';\nimport PromptSync from 'prompt-sync';\nimport FSHelper from '../../utils/FSHelper.js';\nimport YouTubeCredentialsCapturer from '../../utils/YouTubeCredentialsCapturer.js';\n\nexport default class YouTubeConfigurator {\n\n static async start(ytCredsPath: string) {\n const prompt = PromptSync({ sigint: true });\n\n console.log(`Welcome to patreon-dl YouTube Configurator!\n\nIf you have a YouTube Premium subscription, connecting patreon-dl to your\nYouTube account will allow it to download embedded YouTube videos at\nqualities available only to Premium subscribers, such as '1080p Premium'.\n\nThis script begins the YouTube connection process. During this process,\nYouTube credentials are captured and saved to:\n\n\"${ytCredsPath}\".\n\nWhen patreon-dl starts, the credentials will be loaded and used for\nauthenticating access to Premium-quality YouTube streams.\n\nWhat would you like to do?\n1. Connect to YouTube\n2. Revoke existing YouTube credentials\n`);\n\n const connectOrRevoke = this.#promptInput<'connect' | 'revoke'>(\n prompt,\n 'Enter your choice (1-2): ',\n [ '1', '2' ],\n [ 'connect', 'revoke' ]);\n\n if (connectOrRevoke === 'connect') {\n return await this.#startConnect(ytCredsPath, prompt);\n }\n\n return this.#revokeCredentials(ytCredsPath);\n }\n\n static async #startConnect(ytCredsPath: string, prompt: PromptSync.Prompt) {\n if (fs.existsSync(ytCredsPath)) {\n console.log('YouTube credentials file already exists. Proceeding will overwrite it.');\n const overwriteOrExit = this.#promptInput<'overwrite' | 'exit'>(\n prompt,\n 'Proceed (y/N)? ',\n [ 'y', 'n' ],\n [ 'overwrite', 'exit' ],\n 'exit'\n );\n if (overwriteOrExit === 'exit') {\n console.log('Bye!');\n return 0;\n }\n }\n const code = await this.#doConnectAndSaveCredentials(ytCredsPath);\n if (code === 0) {\n console.log('YouTube connection process completed successfully.');\n }\n else {\n console.log('YouTube connection process ended with error.');\n }\n return code;\n }\n\n static #doConnectAndSaveCredentials(ytCredsPath: string) {\n return new Promise<number>(async (resolve) => {\n const capturer = new YouTubeCredentialsCapturer();\n capturer.on('pending', (data) => {\n console.log(`In a browser, go to the following Verification URL and enter Code:\n\n- Verification URL: ${data.verificationURL}\n- Code: ${data.code}\n\nThen wait for this script to complete.\n`);\n });\n\n capturer.on('capture', (credentials) => {\n try {\n FSHelper.createDir(path.parse(ytCredsPath).dir);\n fs.writeFileSync(ytCredsPath, JSON.stringify(credentials));\n console.log(`YouTube connected; credentials saved to \"${ytCredsPath}\"`, EOL);\n resolve(0);\n }\n catch (error) {\n console.error(`Error saving credentials to \"${ytCredsPath}\": `, error instanceof Error ? error.message : error, EOL);\n resolve(1);\n }\n });\n\n await capturer.begin();\n });\n }\n\n static #revokeCredentials(ytCredsPath: string) {\n if (fs.existsSync(ytCredsPath)) {\n try {\n fs.unlinkSync(ytCredsPath);\n console.log(`Deleted \"${ytCredsPath}\"`);\n return 0;\n }\n catch (error) {\n console.error(`Error deleting \"${ytCredsPath}\": `, error instanceof Error ? error.message : error);\n return 1;\n }\n }\n console.log(`No credentials found: \"${ytCredsPath}\" does not exist.`);\n return 0;\n }\n\n\n static #promptInput<T>(prompt: PromptSync.Prompt, message: string, acceptValues: string[], retValues: T[], defaultValue?: T): T {\n const input = prompt(message).trim().toLowerCase();\n if (!input && defaultValue !== undefined) {\n console.log('');\n return defaultValue;\n }\n const acceptIndex = acceptValues.indexOf(input);\n if (acceptIndex >= 0) {\n console.log('');\n return retValues[acceptIndex];\n }\n return this.#promptInput(prompt, message, acceptValues, retValues);\n }\n}"]}
|
package/dist/cli/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,OAAO,OAAO,oBAAoB;;;IAajC,KAAK;IA0JL,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM;CAMzB"}
|
package/dist/cli/index.js
CHANGED
|
@@ -9,9 +9,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _PatreonDownloaderCLI_instances, _PatreonDownloaderCLI_logger, _PatreonDownloaderCLI_packageInfo, _PatreonDownloaderCLI_confirmProceed, _PatreonDownloaderCLI_createLoggers;
|
|
12
|
+
var _PatreonDownloaderCLI_instances, _PatreonDownloaderCLI_logger, _PatreonDownloaderCLI_packageInfo, _PatreonDownloaderCLI_globalConfPath, _PatreonDownloaderCLI_confirmProceed, _PatreonDownloaderCLI_createLoggers;
|
|
13
13
|
import { EOL } from 'os';
|
|
14
14
|
import PromptSync from 'prompt-sync';
|
|
15
|
+
import path from 'path';
|
|
16
|
+
import fs from 'fs';
|
|
15
17
|
import Downloader from '../downloaders/Downloader.js';
|
|
16
18
|
import ConsoleLogger from '../utils/logging/ConsoleLogger.js';
|
|
17
19
|
import { getCLIOptions } from './CLIOptions.js';
|
|
@@ -20,13 +22,18 @@ import { commonLog } from '../utils/logging/Logger.js';
|
|
|
20
22
|
import FileLogger from '../utils/logging/FileLogger.js';
|
|
21
23
|
import ChainLogger from '../utils/logging/ChainLogger.js';
|
|
22
24
|
import { getPackageInfo } from '../utils/PackageInfo.js';
|
|
25
|
+
import envPaths from 'env-paths';
|
|
26
|
+
import YouTubeConfigurator from './helper/YouTubeConfigurator.js';
|
|
27
|
+
const YT_CREDENTIALS_FILENAME = 'youtube-credentials.json';
|
|
23
28
|
export default class PatreonDownloaderCLI {
|
|
24
29
|
constructor() {
|
|
25
30
|
_PatreonDownloaderCLI_instances.add(this);
|
|
26
31
|
_PatreonDownloaderCLI_logger.set(this, void 0);
|
|
27
32
|
_PatreonDownloaderCLI_packageInfo.set(this, void 0);
|
|
33
|
+
_PatreonDownloaderCLI_globalConfPath.set(this, void 0);
|
|
28
34
|
__classPrivateFieldSet(this, _PatreonDownloaderCLI_logger, null, "f");
|
|
29
35
|
__classPrivateFieldSet(this, _PatreonDownloaderCLI_packageInfo, getPackageInfo(), "f");
|
|
36
|
+
__classPrivateFieldSet(this, _PatreonDownloaderCLI_globalConfPath, envPaths(__classPrivateFieldGet(this, _PatreonDownloaderCLI_packageInfo, "f").name || 'patreon-dl', { suffix: '' }).config, "f");
|
|
30
37
|
}
|
|
31
38
|
async start() {
|
|
32
39
|
if (CommandLineParser.showUsage()) {
|
|
@@ -35,6 +42,10 @@ export default class PatreonDownloaderCLI {
|
|
|
35
42
|
if (__classPrivateFieldGet(this, _PatreonDownloaderCLI_packageInfo, "f").banner) {
|
|
36
43
|
console.log(`${EOL}${__classPrivateFieldGet(this, _PatreonDownloaderCLI_packageInfo, "f").banner}${EOL}`);
|
|
37
44
|
}
|
|
45
|
+
const ytCredsPath = path.resolve(__classPrivateFieldGet(this, _PatreonDownloaderCLI_globalConfPath, "f"), YT_CREDENTIALS_FILENAME);
|
|
46
|
+
if (CommandLineParser.configureYouTube()) {
|
|
47
|
+
return this.exit(await YouTubeConfigurator.start(ytCredsPath));
|
|
48
|
+
}
|
|
38
49
|
let options;
|
|
39
50
|
try {
|
|
40
51
|
options = getCLIOptions();
|
|
@@ -50,6 +61,7 @@ export default class PatreonDownloaderCLI {
|
|
|
50
61
|
try {
|
|
51
62
|
downloader = await Downloader.getInstance(options.targetURL, {
|
|
52
63
|
...options,
|
|
64
|
+
pathToYouTubeCredentials: fs.existsSync(ytCredsPath) ? ytCredsPath : null,
|
|
53
65
|
logger
|
|
54
66
|
});
|
|
55
67
|
}
|
|
@@ -117,7 +129,7 @@ export default class PatreonDownloaderCLI {
|
|
|
117
129
|
process.exit(code);
|
|
118
130
|
}
|
|
119
131
|
}
|
|
120
|
-
_PatreonDownloaderCLI_logger = new WeakMap(), _PatreonDownloaderCLI_packageInfo = new WeakMap(), _PatreonDownloaderCLI_instances = new WeakSet(), _PatreonDownloaderCLI_confirmProceed = function _PatreonDownloaderCLI_confirmProceed(prompt) {
|
|
132
|
+
_PatreonDownloaderCLI_logger = new WeakMap(), _PatreonDownloaderCLI_packageInfo = new WeakMap(), _PatreonDownloaderCLI_globalConfPath = new WeakMap(), _PatreonDownloaderCLI_instances = new WeakSet(), _PatreonDownloaderCLI_confirmProceed = function _PatreonDownloaderCLI_confirmProceed(prompt) {
|
|
121
133
|
if (!prompt) {
|
|
122
134
|
prompt = PromptSync({ sigint: true });
|
|
123
135
|
}
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,UAAU,MAAM,8BAA8B,CAAC;AACtD,OAA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AM,EAAE,GAAG,IAAI,UAAU,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;YAC7D,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SACjB;QACD,OAAO,KAAK,EAAE;YACZ,OAAO,CAAC,IAAI,CAAC,gCAAgC,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;SAChG;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;IAEb,wBAAwB;IACxB,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAE/D,eAAe;IACf,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC;QAClC,aAAa;QACb,GAAG,WAAW;KACf,CAAC,CAAC;IAEH,OAAO;QACL,WAAW;QACX,aAAa;QACb,WAAW;KACZ,CAAC;AACJ,CAAC","sourcesContent":["import { EOL } from 'os';\nimport PromptSync from 'prompt-sync';\nimport Downloader from '../downloaders/Downloader.js';\nimport ConsoleLogger from '../utils/logging/ConsoleLogger.js';\nimport { CLIOptions, getCLIOptions } from './CLIOptions.js';\nimport CommandLineParser from './CommandLineParser.js';\nimport Logger, { commonLog } from '../utils/logging/Logger.js';\nimport FileLogger, { FileLoggerInit } from '../utils/logging/FileLogger.js';\nimport ChainLogger from '../utils/logging/ChainLogger.js';\nimport { PackageInfo, getPackageInfo } from '../utils/PackageInfo.js';\n\nexport default class PatreonDownloaderCLI {\n\n #logger: Logger | null;\n #packageInfo: PackageInfo;\n\n constructor() {\n this.#logger = null;\n this.#packageInfo = getPackageInfo();\n }\n\n async start() {\n if (CommandLineParser.showUsage()) {\n return this.exit(0);\n }\n\n if (this.#packageInfo.banner) {\n console.log(`${EOL}${this.#packageInfo.banner}${EOL}`);\n }\n\n let options;\n try {\n options = getCLIOptions();\n }\n catch (error) {\n console.error(\n 'Error processing options: ',\n error instanceof Error ? error.message : error,\n EOL,\n 'See usage with \\'-h\\' option.');\n return this.exit(1);\n }\n\n const { chainLogger: logger, consoleLogger, fileLoggers } = this.#createLoggers(options);\n this.#logger = logger;\n\n // Create downloader\n let downloader;\n try {\n downloader = await Downloader.getInstance(options.targetURL, {\n ...options,\n logger\n });\n }\n catch (error) {\n commonLog(logger, 'error', null, 'Failed to get downloader instance:', error);\n return this.exit(1);\n }\n\n if (!downloader) {\n commonLog(logger, 'error', null, 'Failed to get downloader instance (unknown reason)');\n return this.exit(1);\n }\n\n const downloaderName = downloader.name;\n\n if (!options.noPrompt) {\n if (!consoleLogger.getConfig().enabled) {\n console.log('Console logging disabled', EOL);\n }\n\n if (fileLoggers.length > 0) {\n console.log('Log files');\n console.log('---------');\n for (const fl of fileLoggers) {\n const flConf = fl.getConfig();\n console.log(`- ${flConf.logLevel}: ${flConf.logFilePath}`);\n }\n console.log(EOL);\n }\n\n console.log(`Created ${downloaderName} instance with config: `, downloader.getConfig(), EOL);\n\n if (!this.#confirmProceed()) {\n console.log('Abort');\n return this.exit(1);\n }\n }\n else {\n commonLog(logger, 'debug', null, `Created ${downloaderName} instance with config: `, downloader.getConfig());\n }\n\n let hasDownloaderError = false;\n downloader.on('end', ({aborted, error}) => {\n if (aborted) {\n commonLog(logger, 'info', null, `${downloaderName} aborted`);\n }\n else if (!error) {\n commonLog(logger, 'info', null, `${downloaderName} end`);\n }\n else {\n commonLog(logger, 'warn', null, `${downloaderName} end with error`);\n hasDownloaderError = true;\n }\n });\n\n try {\n const abortController = new AbortController();\n process.on('SIGINT', () => {\n abortController.abort();\n });\n await downloader.start({ signal: abortController.signal });\n return this.exit(hasDownloaderError ? 1 : 0);\n }\n catch (error) {\n commonLog(logger, 'error', null, `Uncaught ${downloaderName} error:`, error);\n return this.exit(1);\n }\n }\n\n #confirmProceed(prompt?: PromptSync.Prompt): boolean {\n if (!prompt) {\n prompt = PromptSync({ sigint: true });\n }\n const confirmProceed = prompt('Proceed (Y/n)? ');\n if (!confirmProceed.trim() || confirmProceed.trim().toLowerCase() === 'y') {\n return true;\n }\n else if (confirmProceed.trim().toLowerCase() === 'n') {\n return false;\n }\n\n return this.#confirmProceed(prompt);\n }\n\n #createLoggers(options: CLIOptions) {\n // Create file loggers\n const fileLoggerInit: FileLoggerInit = {\n targetURL: options.targetURL,\n outDir: options.outDir,\n date: new Date()\n };\n const fileLoggers = options.fileLoggers?.reduce<FileLogger[]>((result, fileLoggerOptions) => {\n try {\n const fl = new FileLogger(fileLoggerInit, fileLoggerOptions);\n result.push(fl);\n }\n catch (error) {\n console.warn('Failed to create file logger: ', error instanceof Error ? error.message : error);\n }\n return result;\n }, []) || [];\n\n // Create console logger\n const consoleLogger = new ConsoleLogger(options.consoleLogger);\n\n // Chain logger\n const chainLogger = new ChainLogger([\n consoleLogger,\n ...fileLoggers\n ]);\n\n return {\n chainLogger,\n consoleLogger,\n fileLoggers\n };\n }\n\n async exit(code?: number) {\n if (this.#logger) {\n await this.#logger.end();\n }\n process.exit(code);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,UAAU,MAAM,8BAA8B,CAAC;AACtD,OAAO,aAAa,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAc,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AACvD,OAAe,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,UAA8B,MAAM,gCAAgC,CAAC;AAC5E,OAAO,WAAW,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAe,cAAc,EAAE,MAAM,yBA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B,IAAI,EAAiB,MAAM,CAAC,CAAC;AACtC,CAAC,qFAEc,OAAmB;IAChC,sBAAsB;IACtB,MAAM,cAAc,GAAmB;QACrC,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,IAAI,EAAE,IAAI,IAAI,EAAE;KACjB,CAAC;IACF,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,EAAE,MAAM,CAAe,CAAC,MAAM,EAAE,iBAAiB,EAAE,EAAE;QAC1F,IAAI;YACF,MAAM,EAAE,GAAG,IAAI,UAAU,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;YAC7D,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SACjB;QACD,OAAO,KAAK,EAAE;YACZ,OAAO,CAAC,IAAI,CAAC,gCAAgC,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;SAChG;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;IAEb,wBAAwB;IACxB,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAE/D,eAAe;IACf,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC;QAClC,aAAa;QACb,GAAG,WAAW;KACf,CAAC,CAAC;IAEH,OAAO;QACL,WAAW;QACX,aAAa;QACb,WAAW;KACZ,CAAC;AACJ,CAAC","sourcesContent":["import { EOL } from 'os';\nimport PromptSync from 'prompt-sync';\nimport path from 'path';\nimport fs from 'fs';\nimport Downloader from '../downloaders/Downloader.js';\nimport ConsoleLogger from '../utils/logging/ConsoleLogger.js';\nimport { CLIOptions, getCLIOptions } from './CLIOptions.js';\nimport CommandLineParser from './CommandLineParser.js';\nimport Logger, { commonLog } from '../utils/logging/Logger.js';\nimport FileLogger, { FileLoggerInit } from '../utils/logging/FileLogger.js';\nimport ChainLogger from '../utils/logging/ChainLogger.js';\nimport { PackageInfo, getPackageInfo } from '../utils/PackageInfo.js';\nimport envPaths from 'env-paths';\nimport YouTubeConfigurator from './helper/YouTubeConfigurator.js';\n\nconst YT_CREDENTIALS_FILENAME = 'youtube-credentials.json';\n\nexport default class PatreonDownloaderCLI {\n\n #logger: Logger | null;\n #packageInfo: PackageInfo;\n #globalConfPath: string;\n\n constructor() {\n this.#logger = null;\n this.#packageInfo = getPackageInfo();\n this.#globalConfPath = envPaths(\n this.#packageInfo.name || 'patreon-dl', { suffix: '' }).config;\n }\n\n async start() {\n if (CommandLineParser.showUsage()) {\n return this.exit(0);\n }\n\n if (this.#packageInfo.banner) {\n console.log(`${EOL}${this.#packageInfo.banner}${EOL}`);\n }\n\n const ytCredsPath = path.resolve(this.#globalConfPath, YT_CREDENTIALS_FILENAME);\n if (CommandLineParser.configureYouTube()) {\n return this.exit(await YouTubeConfigurator.start(ytCredsPath));\n }\n\n let options;\n try {\n options = getCLIOptions();\n }\n catch (error) {\n console.error(\n 'Error processing options: ',\n error instanceof Error ? error.message : error,\n EOL,\n 'See usage with \\'-h\\' option.');\n return this.exit(1);\n }\n\n const { chainLogger: logger, consoleLogger, fileLoggers } = this.#createLoggers(options);\n this.#logger = logger;\n\n // Create downloader\n let downloader;\n try {\n downloader = await Downloader.getInstance(options.targetURL, {\n ...options,\n pathToYouTubeCredentials: fs.existsSync(ytCredsPath) ? ytCredsPath : null,\n logger\n });\n }\n catch (error) {\n commonLog(logger, 'error', null, 'Failed to get downloader instance:', error);\n return this.exit(1);\n }\n\n if (!downloader) {\n commonLog(logger, 'error', null, 'Failed to get downloader instance (unknown reason)');\n return this.exit(1);\n }\n\n const downloaderName = downloader.name;\n\n if (!options.noPrompt) {\n if (!consoleLogger.getConfig().enabled) {\n console.log('Console logging disabled', EOL);\n }\n\n if (fileLoggers.length > 0) {\n console.log('Log files');\n console.log('---------');\n for (const fl of fileLoggers) {\n const flConf = fl.getConfig();\n console.log(`- ${flConf.logLevel}: ${flConf.logFilePath}`);\n }\n console.log(EOL);\n }\n\n console.log(`Created ${downloaderName} instance with config: `, downloader.getConfig(), EOL);\n\n if (!this.#confirmProceed()) {\n console.log('Abort');\n return this.exit(1);\n }\n }\n else {\n commonLog(logger, 'debug', null, `Created ${downloaderName} instance with config: `, downloader.getConfig());\n }\n\n let hasDownloaderError = false;\n downloader.on('end', ({aborted, error}) => {\n if (aborted) {\n commonLog(logger, 'info', null, `${downloaderName} aborted`);\n }\n else if (!error) {\n commonLog(logger, 'info', null, `${downloaderName} end`);\n }\n else {\n commonLog(logger, 'warn', null, `${downloaderName} end with error`);\n hasDownloaderError = true;\n }\n });\n\n try {\n const abortController = new AbortController();\n process.on('SIGINT', () => {\n abortController.abort();\n });\n await downloader.start({ signal: abortController.signal });\n return this.exit(hasDownloaderError ? 1 : 0);\n }\n catch (error) {\n commonLog(logger, 'error', null, `Uncaught ${downloaderName} error:`, error);\n return this.exit(1);\n }\n }\n\n #confirmProceed(prompt?: PromptSync.Prompt): boolean {\n if (!prompt) {\n prompt = PromptSync({ sigint: true });\n }\n const confirmProceed = prompt('Proceed (Y/n)? ');\n if (!confirmProceed.trim() || confirmProceed.trim().toLowerCase() === 'y') {\n return true;\n }\n else if (confirmProceed.trim().toLowerCase() === 'n') {\n return false;\n }\n\n return this.#confirmProceed(prompt);\n }\n\n #createLoggers(options: CLIOptions) {\n // Create file loggers\n const fileLoggerInit: FileLoggerInit = {\n targetURL: options.targetURL,\n outDir: options.outDir,\n date: new Date()\n };\n const fileLoggers = options.fileLoggers?.reduce<FileLogger[]>((result, fileLoggerOptions) => {\n try {\n const fl = new FileLogger(fileLoggerInit, fileLoggerOptions);\n result.push(fl);\n }\n catch (error) {\n console.warn('Failed to create file logger: ', error instanceof Error ? error.message : error);\n }\n return result;\n }, []) || [];\n\n // Create console logger\n const consoleLogger = new ConsoleLogger(options.consoleLogger);\n\n // Chain logger\n const chainLogger = new ChainLogger([\n consoleLogger,\n ...fileLoggers\n ]);\n\n return {\n chainLogger,\n consoleLogger,\n fileLoggers\n };\n }\n\n async exit(code?: number) {\n if (this.#logger) {\n await this.#logger.end();\n }\n process.exit(code);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Downloader.d.ts","sourceRoot":"","sources":["../../src/downloaders/Downloader.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,OAAO,MAAM,qBAAqB,CAAC;AAC1C,OAAkB,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,gBAAgB,EAAqB,MAAM,wBAAwB,CAAC;AAChH,OAAO,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,MAAM,EAAE,EAAE,QAAQ,EAAa,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAiB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,iBAAiB,MAAM,6BAA6B,CAAC;AAK5D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"Downloader.d.ts","sourceRoot":"","sources":["../../src/downloaders/Downloader.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,OAAO,MAAM,qBAAqB,CAAC;AAC1C,OAAkB,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,gBAAgB,EAAqB,MAAM,wBAAwB,CAAC;AAChH,OAAO,EAAE,eAAe,EAAE,wBAAwB,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C,CAAC,SAAS,eAAe,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,wBAAwB,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI;IAKrG,IAAI,CAAC,CAAC,SAAS,eAAe,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,wBAAwB,CAAC,CAAC,CAAC,GAAG,OAAO;CAItF"}
|
|
@@ -27,6 +27,7 @@ import path from 'path';
|
|
|
27
27
|
import URLHelper from '../utils/URLHelper.js';
|
|
28
28
|
import { AbortError } from 'node-fetch';
|
|
29
29
|
import ffmpeg from 'fluent-ffmpeg';
|
|
30
|
+
import InnertubeLoader from '../utils/InnertubeLoader.js';
|
|
30
31
|
export default class Downloader extends EventEmitter {
|
|
31
32
|
constructor(bootstrap, options) {
|
|
32
33
|
super();
|
|
@@ -37,11 +38,15 @@ export default class Downloader extends EventEmitter {
|
|
|
37
38
|
...bootstrap,
|
|
38
39
|
...getDownloaderInit(options)
|
|
39
40
|
});
|
|
41
|
+
this.fetcher = new Fetcher(options?.cookie, options?.logger);
|
|
42
|
+
this.logger = options?.logger;
|
|
40
43
|
if (this.config.pathToFFmpeg) {
|
|
41
44
|
ffmpeg.setFfmpegPath(this.config.pathToFFmpeg);
|
|
42
45
|
}
|
|
43
|
-
this.
|
|
44
|
-
this.
|
|
46
|
+
InnertubeLoader.setLogger(this.logger);
|
|
47
|
+
if (this.config.pathToYouTubeCredentials) {
|
|
48
|
+
InnertubeLoader.loadCredentials(this.config.pathToYouTubeCredentials);
|
|
49
|
+
}
|
|
45
50
|
__classPrivateFieldSet(this, _Downloader_hasEmittedEndEventOnAbort, false, "f");
|
|
46
51
|
}
|
|
47
52
|
createDownloadTaskBatch(name, ...createTasks) {
|
|
@@ -302,7 +307,7 @@ export default class Downloader extends EventEmitter {
|
|
|
302
307
|
return super.on(event, listener);
|
|
303
308
|
}
|
|
304
309
|
once(event, listener) {
|
|
305
|
-
return super.
|
|
310
|
+
return super.once(event, listener);
|
|
306
311
|
}
|
|
307
312
|
off(event, listener) {
|
|
308
313
|
return super.off(event, listener);
|