patreon-dl 1.4.0 → 1.6.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.
Files changed (64) hide show
  1. package/README.md +53 -2
  2. package/bin/patreon-dl-vimeo.js +140 -0
  3. package/dist/cli/CLIOptions.d.ts.map +1 -1
  4. package/dist/cli/CLIOptions.js +10 -0
  5. package/dist/cli/CLIOptions.js.map +1 -1
  6. package/dist/cli/CommandLineParser.d.ts +4 -1
  7. package/dist/cli/CommandLineParser.d.ts.map +1 -1
  8. package/dist/cli/CommandLineParser.js +34 -12
  9. package/dist/cli/CommandLineParser.js.map +1 -1
  10. package/dist/cli/ConfigFileParser.d.ts.map +1 -1
  11. package/dist/cli/ConfigFileParser.js +28 -3
  12. package/dist/cli/ConfigFileParser.js.map +1 -1
  13. package/dist/cli/index.d.ts.map +1 -1
  14. package/dist/cli/index.js +30 -24
  15. package/dist/cli/index.js.map +1 -1
  16. package/dist/downloaders/Bootstrap.d.ts +4 -0
  17. package/dist/downloaders/Bootstrap.d.ts.map +1 -1
  18. package/dist/downloaders/Bootstrap.js +11 -0
  19. package/dist/downloaders/Bootstrap.js.map +1 -1
  20. package/dist/downloaders/Downloader.d.ts +2 -1
  21. package/dist/downloaders/Downloader.d.ts.map +1 -1
  22. package/dist/downloaders/Downloader.js +13 -6
  23. package/dist/downloaders/Downloader.js.map +1 -1
  24. package/dist/downloaders/DownloaderOptions.d.ts +6 -1
  25. package/dist/downloaders/DownloaderOptions.d.ts.map +1 -1
  26. package/dist/downloaders/DownloaderOptions.js +4 -2
  27. package/dist/downloaders/DownloaderOptions.js.map +1 -1
  28. package/dist/downloaders/PostDownloader.d.ts.map +1 -1
  29. package/dist/downloaders/PostDownloader.js +63 -32
  30. package/dist/downloaders/PostDownloader.js.map +1 -1
  31. package/dist/downloaders/index.d.ts +1 -1
  32. package/dist/downloaders/index.d.ts.map +1 -1
  33. package/dist/downloaders/index.js.map +1 -1
  34. package/dist/downloaders/task/DownloadTaskFactory.d.ts +3 -1
  35. package/dist/downloaders/task/DownloadTaskFactory.d.ts.map +1 -1
  36. package/dist/downloaders/task/DownloadTaskFactory.js +18 -3
  37. package/dist/downloaders/task/DownloadTaskFactory.js.map +1 -1
  38. package/dist/downloaders/task/ExternalDownloaderTask.d.ts +22 -0
  39. package/dist/downloaders/task/ExternalDownloaderTask.d.ts.map +1 -0
  40. package/dist/downloaders/task/ExternalDownloaderTask.js +197 -0
  41. package/dist/downloaders/task/ExternalDownloaderTask.js.map +1 -0
  42. package/dist/entities/Downloadable.d.ts +2 -1
  43. package/dist/entities/Downloadable.d.ts.map +1 -1
  44. package/dist/entities/Downloadable.js +3 -0
  45. package/dist/entities/Downloadable.js.map +1 -1
  46. package/dist/entities/Post.d.ts +1 -0
  47. package/dist/entities/Post.d.ts.map +1 -1
  48. package/dist/entities/Post.js.map +1 -1
  49. package/dist/entities/User.d.ts +8 -1
  50. package/dist/entities/User.d.ts.map +1 -1
  51. package/dist/entities/User.js.map +1 -1
  52. package/dist/parsers/Parser.d.ts.map +1 -1
  53. package/dist/parsers/Parser.js +5 -2
  54. package/dist/parsers/Parser.js.map +1 -1
  55. package/dist/parsers/PostParser.d.ts.map +1 -1
  56. package/dist/parsers/PostParser.js +1 -0
  57. package/dist/parsers/PostParser.js.map +1 -1
  58. package/dist/utils/Formatter.js +1 -1
  59. package/dist/utils/Formatter.js.map +1 -1
  60. package/dist/utils/URLHelper.d.ts +8 -2
  61. package/dist/utils/URLHelper.d.ts.map +1 -1
  62. package/dist/utils/URLHelper.js +36 -8
  63. package/dist/utils/URLHelper.js.map +1 -1
  64. package/package.json +6 -2
package/README.md CHANGED
@@ -13,6 +13,9 @@ A Patreon downloader written in [Node.js](https://nodejs.org).
13
13
  - images
14
14
  - audio
15
15
  - attachments
16
+ - embedded videos
17
+ - YouTube downloader built-in
18
+ - Supports [external downloader](#embedded-videos---external-downloader)
16
19
  - Save campaign and content info
17
20
  - Extensively configurable
18
21
 
@@ -20,8 +23,7 @@ You can run `patreon-dl` from the command-line or use it as a library for your p
20
23
 
21
24
  ### Limitations
22
25
 
23
- - Embedded videos, other than those from YouTube, are not supported (e.g. Vimeo). Only info about these embeds is saved.
24
- - Likewise, embedded links are not followed; only info about the embed is saved.
26
+ - Embedded links are not followed; only info about the embed is saved.
25
27
 
26
28
  ### FFmpeg dependency
27
29
 
@@ -41,6 +43,14 @@ $ patreon-dl --configure-youtube
41
43
 
42
44
  For library usage, see [Configuring YouTube connection](#configuring-youtube-connection).
43
45
 
46
+ > ...or you may just refer to the next section on how to download enhanecd-quality videos without a Premium account.
47
+
48
+ ### Embedded videos - external downloader
49
+
50
+ You can specify external programs to download embedded videos. For YouTube videos, this will replace the built-in downloader. See the [example config](./example-embed.conf) on how to do this. For library usage, see [External downloaders](#external-downloaders).
51
+
52
+ > The example config utilizes [yt-dlp](https://github.com/yt-dlp/yt-dlp), a popular program capable of downloading YouTube and Vimeo content. As of current release, `yt-dlp` is also able to download Premium-quality YouTube videos without a Premium account.
53
+
44
54
  ## Installation
45
55
 
46
56
  1. First, install [Node.js](https://nodejs.org).
@@ -71,6 +81,7 @@ $ patreon-dl [OPTION]... URL
71
81
  | `--log-level <level>` | `-l` | Log level of the console logger: `info`, `debug`, `warn` or `error`; set to `none` to disable the logger. |
72
82
  | `--no-prompt` | `-y` | Do not prompt for confirmation to proceed |
73
83
  | <code><nobr>--list-tiers &lt;creator&gt;</nobr></code> | | <p>List tiers for the given creator(s). Separate multiple creators with a comma.</p>The purpose of this is to let you find out what tier IDs to set for `posts.in.tier` filtering option under `include` section of [configuration file](#configuration-file). |
84
+ | <code><nobr>--list-tiers-uid &lt;user ID&gt;</nobr></code> | | Same as `--list-tiers`, but takes user ID instead of vanity. |
74
85
  | `--configure-youtube` | | <p>Configure YouTube connection.</p>`patreon-dl` supports downloading embedded YouTube videos. If you have a YouTube Premium account, you can connect `patreon-dl` to it for downloading Premium-quality streams. |
75
86
 
76
87
  ### URL
@@ -83,6 +94,7 @@ https://www.patreon.com/<creator>/shop/<slug>-<product_id>
83
94
 
84
95
  // Download posts by creator
85
96
  https://www.patreon.com/<creator>/posts
97
+ https://www.patreon.com/user/posts?u=<user_id>
86
98
 
87
99
  // Dowload a single post
88
100
  https://www.patreon.com/posts/<slug>-<post_id>
@@ -235,6 +247,7 @@ An object with the following properties (all *optional*):
235
247
  | `include` | What to include in the download: (object) <ul><li>`lockedContent`: whether to process locked content. Default: `true`</li><li>`postInTier`: see [Filtering posts by tier](#filtering-posts-by-tier)</li><li>`postsWithMediaType`: sets the media type criteria for downloading posts. Values can be:<ul><li>`any`: download posts regardless of the type of media they contain. Also applies to posts that do not contain any media.</li><li>`none`: only download posts that do not contain media.</li><li>Array<`image` \| `video` \| `audio` \| `attachment`>: only download posts that contain the specified media type(s).</li></ul>Default: `any`</li><li>`campaignInfo`: whether to save campaign info. Default: `true`</li><li>`contentInfo`: whether to save content info. Default: `true`</li><li>`contentMedia`: the type of content media to download (images, videos, audio, attachments, excluding previews). Values can be:<ul><li>`true`: download all content media.</li><li>`false`: do not download content media.</li><li>Array<`image` \| `video` \| `audio` \| `attachment` \| `file`>: only download the specified media type(s).</li></ul>Default: `true`</li><li>`previewMedia`: the type of preview media to download, if available. Values can be:<ul><li>`true`: download all preview media.</li><li>`false`: do not download preview media.</li><li>Array<`image` \| `video` \| `audio`>: only download the specified media type(s).</li></ul>Default: `true`</li><li>`allMediaVariants`: whether to download all media variants, if available. If `false`, only the best quality variant will be downloaded. Default: `false`</li></ul> |
236
248
  | `request` | Rate limiting and retry on error: (object)<ul><li>`maxRetries`: maximum number of retries if a request or download fails. Default: 3</li><li>`maxConcurrent`: maximum number of concurrent downloads. Default: 10</li><li>`minTime`: minimum time to wait between starting requests or downloads (milliseconds). Default: 333</li></ul> |
237
249
  | `fileExistsAction` | What to do when a target file already exists: (object)<ul><li>`info`: in the context of saving info (such as campaign or post info), the action to take when a file belonging to the info already exists. Default: `saveAsCopyIfNewer`</li><li>`infoAPI`: API data is saved as part of info. Because it changes frequently, and usually used for debugging purpose only, you can set a different action when saving an API data file that already exists. Default: `overwrite`</li><li>`content`: in the context of downloading content, the action to take when a file belonging to the content already exists. Default: `skip`</li></ul><p>Supported actions:<ul><li>`overwrite`: overwrite existing file.</li><li>`skip`: skip saving the file.</li><li>`saveAsCopy`: save the file under incremented filename (e.g. "abc.jpg" becomes "abc (1).jpg").</li><li>`saveAsCopyIfNewer`: like `saveAsCopy`, but only do so if the contents have actually changed.</li></ul></p> |
250
+ | `embedDownloaders` | External downloader for embedded videos. See [External downloaders](#external-downloaders).|
238
251
  |`logger` | See [Logger](#logger) |
239
252
 
240
253
  #### Campaign directory name format
@@ -317,6 +330,10 @@ To obtain the IDs of tiers for a particular creator, first get the campaign thro
317
330
  const signal = new AbortSignal(); // optional
318
331
  const logger = new MyLogger(); // optional - see Logger section
319
332
  const campaign = await PatreonDownloader.getCampaign('johndoe', signal, logger);
333
+
334
+ // Sometimes a creator is identified only by user ID, in which case you would do this:
335
+ // const campaign = await PatreonDownloader.getCampaign({ userId: '80821958' }, signal, logger);
336
+
320
337
  const tiers = campaign.rewards;
321
338
  tiers.forEach((tier) => {
322
339
  console.log(`${tier.id} - ${tier.title}`);
@@ -324,6 +341,31 @@ tiers.forEach((tier) => {
324
341
  ```
325
342
  See [Campaign](./docs/api/interfaces/Campaign.md), [Reward](./docs/api/interfaces/Reward.md).
326
343
 
344
+ #### External downloaders
345
+
346
+ You can specify external downloaders for embedded videos. Each entry in the `embedDownloaders` option is an object with the following properties:
347
+
348
+ | Proprety | Description |
349
+ |----------|-------------|
350
+ | `provider` | Name of the provider of embedded content. E.g. `youtube`, `vimeo` (case-insensitive) |
351
+ | `exec` | The command to run to download the embedded content |
352
+
353
+ `exec` can contain fields enclosed in curly braces. They will be replaced with actual values at runtime:
354
+
355
+ | Field | Description |
356
+ |-----------------------|-------------|
357
+ | `post.id` | ID of the post containing the embedded video |
358
+ | `embed.provider` | Name of the provider |
359
+ | `embed.provider.url` | Link to the provider's site |
360
+ | `embed.url` | Link to the video page supplied by the provider |
361
+ | `embed.subject` | Subject of the video |
362
+ | `embed.html` | The HTML code that embeds the video player on the Patreon page |
363
+ | `dest.dir` | The directory where the video should be saved |
364
+
365
+ For example usage of `exec`, see [example-embed.conf](./example-embed.conf).
366
+
367
+ > External downloaders are not subject to `request.maxRetries` and `fileExistsAction` settings. This is because `patreon-dl` has no control over the downloading process nor knowledge about the outcome of it (including where and under what name the file was saved).
368
+
327
369
 
328
370
  ### Configuring YouTube connection
329
371
 
@@ -599,6 +641,15 @@ Each event emitted by a download task batch has a payload, which is an object wi
599
641
 
600
642
  ## Changelog
601
643
 
644
+ v1.6.0
645
+ - Add external downloader support for embedded videos
646
+
647
+ v1.5.0
648
+ - Add support for fetching by user ID instead of creator vanity ([#18](https://github.com/patrickkfkan/patreon-dl/issues/18)):
649
+ - Support URL format `https://www.patreon.com/user/posts?u=<user_id>`
650
+ - Overload `PatreonDownloader.getCampaign()` to take `userId` arg
651
+ - CLI: add `--list-tiers-uid`
652
+
602
653
  v1.4.0
603
654
  - Add ability to filter posts by tier ([#8](https://github.com/patrickkfkan/patreon-dl/issues/8))
604
655
  - CLI:
@@ -0,0 +1,140 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * External downloader for embedded Vimeo videos. Obtains the appropriate URL to download from and
5
+ * passes it to 'yt-dlp' (https://github.com/yt-dlp/yt-dlp).
6
+ *
7
+ * Usage
8
+ * -----
9
+ * Place the following two lines in your 'patreon-dl' config file:
10
+ *
11
+ * [embed.downloader.vimeo]
12
+ * exec = patreon-dl-vimeo -o "{dest.dir}/%(title)s.%(ext)s" --embed-html "{embed.html}" --embed-url "{embed.url}"
13
+ *
14
+ * You can append the following additional options to the exec line if necessary:
15
+ * --video-password "<password>": for password-protected videos
16
+ * --yt-dlp "</path/to/yt-dlp>": if yt-dlp is not in the PATH
17
+ *
18
+ * Upon encountering a post with embedded Vimeo content, 'patreon-dl' will call this script. The following then happens:
19
+ * - This script obtains the video URL from 'embed.html' or 'embed.url'.
20
+ * - The URL is passed to yt-dlp.
21
+ * - yt-dlp downloads the video from URL and saves it to 'dest.dir'. The filename is determined by the specified
22
+ * format '%(title)s.%(ext)s' (see: https://github.com/yt-dlp/yt-dlp?tab=readme-ov-file#output-template).
23
+ *
24
+ */
25
+
26
+ import parseArgs from 'yargs-parser';
27
+ import spawn from '@patrickkfkan/cross-spawn';
28
+ import path from 'path';
29
+
30
+ function tryGetPlayerURL(html) {
31
+ if (!html) {
32
+ return null;
33
+ }
34
+ const regex = /https:\/\/player\.vimeo\.com\/video\/\d+/g;
35
+ const match = regex.exec(html);
36
+ if (match && match[0]) {
37
+ return match[0];
38
+ }
39
+ return null;
40
+ }
41
+
42
+ function getCommandString(cmd, args) {
43
+ const quotedArgs = args.map((arg) => arg.includes(' ') ? `"${arg}"` : arg);
44
+ return [
45
+ cmd,
46
+ ...quotedArgs
47
+ ].join(' ');
48
+ }
49
+
50
+ async function download(url, o, videoPassword, ytdlpPath) {
51
+ let proc;
52
+ const ytdlp = ytdlpPath || 'yt-dlp';
53
+ try {
54
+ return await new Promise((resolve, reject) => {
55
+ let settled = false;
56
+ const args = [
57
+ '-f',
58
+ 'bv*+ba[acodec^=mp4a]',
59
+ '-o',
60
+ o
61
+ ];
62
+ const printArgs = [...args];
63
+ if (videoPassword) {
64
+ args.push('--video-password', videoPassword);
65
+ printArgs.push('--video-password', '******');
66
+ }
67
+ args.push(url);
68
+ printArgs.push(url);
69
+
70
+ console.log(`Command: ${getCommandString(ytdlp, printArgs)}`);
71
+ proc = spawn(ytdlp, args);
72
+
73
+ proc.stdout?.on('data', (data) => {
74
+ console.log(data.toString());
75
+ });
76
+
77
+ proc.stderr?.on('data', (data_1) => {
78
+ console.error(data_1.toString());
79
+ });
80
+
81
+ proc.on('error', (err) => {
82
+ if (settled) {
83
+ return;
84
+ }
85
+ settled = true;
86
+ reject(err);
87
+ });
88
+
89
+ proc.on('exit', (code) => {
90
+ if (settled) {
91
+ return;
92
+ }
93
+ settled = true;
94
+ resolve(code);
95
+ });
96
+ });
97
+ } finally {
98
+ if (proc) {
99
+ proc.removeAllListeners();
100
+ proc.stdout?.removeAllListeners();
101
+ proc.stderr?.removeAllListeners();
102
+ }
103
+ }
104
+ }
105
+
106
+ const args = parseArgs(process.argv.slice(2));
107
+ const {
108
+ 'o': _o,
109
+ 'embed-html': _embedHTML,
110
+ 'embed-url': _embedURL,
111
+ 'video-password': videoPassword,
112
+ 'yt-dlp': _ytdlpPath
113
+ } = args;
114
+ const o = _o?.trim() ? path.resolve(_o.trim()) : null;
115
+ const embedHTML = _embedHTML?.trim();
116
+ const embedURL = _embedURL?.trim();
117
+ const ytdlpPath = _ytdlpPath?.trim() ? path.resolve(_ytdlpPath.trim()) : null;
118
+
119
+ if (!o) {
120
+ console.error('No output file specified');
121
+ process.exit(1);
122
+ }
123
+
124
+ if (!embedHTML && !embedURL) {
125
+ console.error('No embed HTML or URL provided');
126
+ process.exit(1);
127
+ }
128
+
129
+ const url = tryGetPlayerURL(embedHTML) || embedURL;
130
+
131
+ if (!url) {
132
+ console.error(`Failed to obtain video URL`);
133
+ process.exit(1);
134
+ }
135
+
136
+ console.log(`Going to download video from "${url}"`);
137
+
138
+ download(url, o, videoPassword, ytdlpPath).then((code) => {
139
+ process.exit(code);
140
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"CLIOptions.d.ts","sourceRoot":"","sources":["../../src/cli/CLIOptions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAElG,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAA0B,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAO,gBAA2C,MAAM,uBAAuB,CAAC;AAGhF,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC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pC;AAED,MAAM,WAAW,UAAW,SAAQ,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC;IACnE,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,QAAQ,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,oBAAoB,CAAC;IACpC,WAAW,CAAC,EAAE,iBAAiB,EAAE,CAAC;CACnC;AAED,MAAM,MAAM,oBAAoB,GAAG,CAAC;IAClC,GAAG,EAAE,KAAK,CAAA;CACX,GAAG;IACF,GAAG,EAAE,KAAK,CAAC;IACX,OAAO,EAAE,MAAM,CAAA;CAChB,GAAG;IACF,GAAG,EAAE,KAAK,CAAC;IACX,IAAI,EAAE,MAAM,CAAA;CACb,CAAC,GAAG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAA;AAED,wBAAgB,aAAa,IAAI,UAAU,CAkD1C;AAED,wBAAgB,mBAAmB,CAAC,kBAAkB,CAAC,EAAE,sBAAsB,EAAE,iBAAiB,CAAC,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI;;;;;;;;;;;;;;EAsCvJ"}
@@ -43,6 +43,7 @@ export function getCLIOptions() {
43
43
  info: CLIOptionValidator.validateString(pickDefined(commandLineOptions.fileExistsAction?.info, configFileOptions?.fileExistsAction?.info), 'overwrite', 'skip', 'saveAsCopy', 'saveAsCopyIfNewer'),
44
44
  infoAPI: CLIOptionValidator.validateString(pickDefined(commandLineOptions.fileExistsAction?.infoAPI, configFileOptions?.fileExistsAction?.infoAPI), 'overwrite', 'skip', 'saveAsCopy', 'saveAsCopyIfNewer')
45
45
  },
46
+ embedDownloaders: getEmbedDownloaderOptions(configFileOptions),
46
47
  noPrompt: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.noPrompt, configFileOptions?.noPrompt)) || false,
47
48
  consoleLogger,
48
49
  fileLoggers
@@ -103,6 +104,15 @@ function getCLIIncludeOptions(commandLineOptions, configFileOptions) {
103
104
  allMediaVariants: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.include?.allMediaVariants, configFileOptions?.include?.allMediaVariants))
104
105
  };
105
106
  }
107
+ function getEmbedDownloaderOptions(configFileOptions) {
108
+ if (configFileOptions?.embedDownloaders) {
109
+ return configFileOptions?.embedDownloaders.map((dl) => ({
110
+ provider: CLIOptionValidator.validateRequired(dl.provider),
111
+ exec: CLIOptionValidator.validateRequired(dl.exec)
112
+ }));
113
+ }
114
+ return undefined;
115
+ }
106
116
  function readTargetsFile(file) {
107
117
  const includeKeys = {
108
118
  lockedContent: 'include.locked.content',
@@ -1 +1 @@
1
- {"version":3,"file":"CLIOptions.js","sourceRoot":"","sources":["../../src/cli/CLIOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,iBAA6C,MAAM,wBAAwB,CAAC;AACnF,OAAO,gBAA2C,MAAM,uBAAuB,CAAC;AAChF,OAAO,IAAI,MAAM,MAAM,CAAC;AA4BxB,MAAM,UAAU,aAAa;IAC3B,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,KAAK,EAAE,CAAC;IAErD,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAEpI,IAAI,UAA+B,CAAC;IACpC,MAAM,cAAc,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,WAAW,CAAC,kBAAkB,CAAC,UAAU,EAAE,iBAAiB,EAAE,UAAU,CAAC,EAAE,yBAAyB,CAAC,CAAC;IACjK,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;I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AC,CAAC,KAAK,CAAC;YAC9D,MAAM,KAAK,CAAC,oCAAoC,EAAE,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;SACtF;KACF;IAED,MAAM,MAAM,GAAwB,EAAE,CAAC;IACvC,KAAK,MAAM,MAAM,IAAI,cAAc,EAAE;QACnC,MAAM,CAAC,GAAsB,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;QACjD,IAAI,MAAM,CAAC,OAAO,EAAE;YAClB,CAAC,CAAC,OAAO,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;SAC1C;QACD,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KAChB;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import fs from 'fs';\nimport { DownloaderIncludeOptions, DownloaderOptions } from '../downloaders/DownloaderOptions.js';\nimport { pickDefined } from '../utils/Misc.js';\nimport { ConsoleLoggerOptions } from '../utils/logging/ConsoleLogger.js';\nimport { FileLoggerOptions } from '../utils/logging/FileLogger.js';\nimport CLIOptionValidator from './CLIOptionValidator.js';\nimport CommandLineParser, { CommandLineParseResult } from './CommandLineParser.js';\nimport ConfigFileParser, { ConfigFileParseResult } from './ConfigFileParser.js';\nimport path from 'path';\n\nexport interface CLITargetURLEntry {\n url: string;\n // Target-specific 'include' options\n include?: DownloaderIncludeOptions;\n}\n\nexport interface CLIOptions extends Omit<DownloaderOptions, 'logger'> {\n targetURLs: CLITargetURLEntry[];\n noPrompt: boolean;\n consoleLogger: ConsoleLoggerOptions;\n fileLoggers?: FileLoggerOptions[];\n}\n\nexport type CLIOptionParserEntry = ({\n src: 'cli'\n} | {\n src: 'cfg',\n section: string\n} | {\n src: 'tgt',\n line: number\n}) & {\n key: string;\n value?: string;\n}\n\nexport function getCLIOptions(): CLIOptions {\n const commandLineOptions = CommandLineParser.parse();\n\n const configFileOptions = commandLineOptions.configFile?.value ? ConfigFileParser.parse(commandLineOptions.configFile.value) : null;\n\n let targetURLs: CLITargetURLEntry[];\n const targetURLValue = CLIOptionValidator.validateRequired(pickDefined(commandLineOptions.targetURLs, configFileOptions?.targetURLs), 'No target URL specified');\n const targetsFile = path.resolve(targetURLValue);\n if (fs.existsSync(targetsFile)) {\n targetURLs = readTargetsFile(targetsFile);\n }\n else {\n targetURLs = CLIOptionValidator\n .validateTargetURLs(targetURLValue)\n .map((url) => ({ url }));\n }\n\n const { consoleLogger, fileLoggers } = getCLILoggerOptions(commandLineOptions, configFileOptions);\n\n const options: CLIOptions = {\n targetURLs,\n cookie: CLIOptionValidator.validateString(pickDefined(commandLineOptions.cookie, configFileOptions?.cookie)),\n useStatusCache: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.useStatusCache, configFileOptions?.useStatusCache)),\n pathToFFmpeg: CLIOptionValidator.validateString(pickDefined(commandLineOptions.pathToFFmpeg, configFileOptions?.pathToFFmpeg)),\n outDir: CLIOptionValidator.validateString(pickDefined(commandLineOptions.outDir, configFileOptions?.outDir)),\n dirNameFormat: {\n campaign: CLIOptionValidator.validateString(pickDefined(commandLineOptions.dirNameFormat?.campaign, configFileOptions?.dirNameFormat?.campaign)),\n content: CLIOptionValidator.validateString(pickDefined(commandLineOptions.dirNameFormat?.content, configFileOptions?.dirNameFormat?.content))\n },\n filenameFormat: {\n media: CLIOptionValidator.validateString(pickDefined(commandLineOptions.filenameFormat?.media, configFileOptions?.filenameFormat?.media))\n },\n include: getCLIIncludeOptions(commandLineOptions, configFileOptions),\n request: {\n maxRetries: CLIOptionValidator.validateNumber(pickDefined(commandLineOptions?.request?.maxRetries, configFileOptions?.request?.maxRetries)),\n maxConcurrent: CLIOptionValidator.validateNumber(pickDefined(commandLineOptions?.request?.maxConcurrent, configFileOptions?.request?.maxConcurrent)),\n minTime: CLIOptionValidator.validateNumber(pickDefined(commandLineOptions?.request?.minTime, configFileOptions?.request?.minTime))\n },\n fileExistsAction: {\n content: CLIOptionValidator.validateString(pickDefined(commandLineOptions.fileExistsAction?.content, configFileOptions?.fileExistsAction?.content), 'overwrite', 'skip', 'saveAsCopy', 'saveAsCopyIfNewer'),\n info: CLIOptionValidator.validateString(pickDefined(commandLineOptions.fileExistsAction?.info, configFileOptions?.fileExistsAction?.info), 'overwrite', 'skip', 'saveAsCopy', 'saveAsCopyIfNewer'),\n infoAPI: CLIOptionValidator.validateString(pickDefined(commandLineOptions.fileExistsAction?.infoAPI, configFileOptions?.fileExistsAction?.infoAPI), 'overwrite', 'skip', 'saveAsCopy', 'saveAsCopyIfNewer')\n },\n noPrompt: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.noPrompt, configFileOptions?.noPrompt)) || false,\n consoleLogger,\n fileLoggers\n };\n\n return options;\n}\n\nexport function getCLILoggerOptions(commandLineOptions?: CommandLineParseResult, configFileOptions?: ReturnType<typeof ConfigFileParser['parse']> | null) {\n if (!commandLineOptions) {\n commandLineOptions = CommandLineParser.parse();\n }\n const consoleLogger = {\n enabled: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.consoleLogger?.enabled, configFileOptions?.consoleLogger?.enabled)),\n logLevel: CLIOptionValidator.validateString(pickDefined(commandLineOptions.consoleLogger?.logLevel, configFileOptions?.consoleLogger?.logLevel), 'info', 'debug', 'warn', 'error'),\n include: {\n dateTime: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.consoleLogger?.include?.dateTime, configFileOptions?.consoleLogger?.include?.dateTime)),\n level: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.consoleLogger?.include?.level, configFileOptions?.consoleLogger?.include?.level)),\n originator: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.consoleLogger?.include?.originator, configFileOptions?.consoleLogger?.include?.originator)),\n errorStack: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.consoleLogger?.include?.errorStack, configFileOptions?.consoleLogger?.include?.errorStack))\n },\n dateTimeFormat: CLIOptionValidator.validateString(pickDefined(commandLineOptions.consoleLogger?.dateTimeFormat, configFileOptions?.consoleLogger?.dateTimeFormat)),\n color: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.consoleLogger?.color, configFileOptions?.consoleLogger?.color))\n };\n let fileLoggers;\n if (configFileOptions?.fileLoggers) {\n fileLoggers = configFileOptions.fileLoggers.map((logger): FileLoggerOptions => ({\n enabled: CLIOptionValidator.validateBoolean(logger.enabled),\n logDir: CLIOptionValidator.validateString(logger.logDir),\n logFilename: CLIOptionValidator.validateString(logger.logFilename),\n fileExistsAction: CLIOptionValidator.validateString(logger.fileExistsAction, 'append', 'overwrite'),\n logLevel: CLIOptionValidator.validateString(logger.logLevel, 'info', 'debug', 'warn', 'error'),\n include: {\n dateTime: CLIOptionValidator.validateBoolean(logger.include?.dateTime),\n level: CLIOptionValidator.validateBoolean(logger.include?.level),\n originator: CLIOptionValidator.validateBoolean(logger.include?.originator),\n errorStack: CLIOptionValidator.validateBoolean(logger.include?.errorStack)\n },\n dateTimeFormat: CLIOptionValidator.validateString(logger.dateTimeFormat),\n color: CLIOptionValidator.validateBoolean(logger.color)\n }));\n }\n return {\n consoleLogger,\n fileLoggers\n };\n}\n\nfunction getCLIIncludeOptions(commandLineOptions: CommandLineParseResult, configFileOptions?: ConfigFileParseResult | null) {\n if (!commandLineOptions) {\n commandLineOptions = CommandLineParser.parse();\n }\n return {\n lockedContent: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.include?.lockedContent, configFileOptions?.include?.lockedContent)),\n postsWithMediaType: CLIOptionValidator.validateIncludeContentWithMediaType(pickDefined(commandLineOptions.include?.postsWithMediaType, configFileOptions?.include?.postsWithMediaType)),\n postsInTier: CLIOptionValidator.validateIncludeContentInTier(pickDefined(commandLineOptions.include?.postsInTier, configFileOptions?.include?.postsInTier)),\n campaignInfo: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.include?.campaignInfo, configFileOptions?.include?.campaignInfo)),\n contentInfo: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.include?.contentInfo, configFileOptions?.include?.contentInfo)),\n previewMedia: CLIOptionValidator.validateIncludePreviewMedia(pickDefined(commandLineOptions.include?.previewMedia, configFileOptions?.include?.previewMedia)),\n contentMedia: CLIOptionValidator.validateIncludeContentMedia(pickDefined(commandLineOptions.include?.contentMedia, configFileOptions?.include?.contentMedia)),\n allMediaVariants: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.include?.allMediaVariants, configFileOptions?.include?.allMediaVariants))\n };\n}\n\nfunction readTargetsFile(file: string) {\n const includeKeys: Record<keyof DownloaderIncludeOptions, string> = {\n lockedContent: 'include.locked.content',\n postsWithMediaType: 'include.posts.with.media.type',\n postsInTier: 'include.posts.in.tier',\n campaignInfo: 'include.campaign.info',\n contentInfo: 'include.content.info',\n previewMedia: 'include.preview.media',\n contentMedia: 'include.content.media',\n allMediaVariants: 'include.all.media.variants'\n };\n\n const lines = fs.readFileSync(file)\n .toString('utf-8')\n // Replace Windows line breaks with Unix ones and then split\n .replace(/\\r\\n/g, '\\n').split('\\n')\n .map((line) => line.trim());\n\n const currentTargets: { url: string; include?: Partial<Record<keyof DownloaderIncludeOptions, CLIOptionParserEntry>>; }[] = [];\n for (let ln = 0; ln < lines.length; ln++) {\n const line = lines[ln];\n if (line === '' || line.startsWith('#')) {\n continue;\n }\n try {\n const match = Object.entries(includeKeys).find((e) => line.startsWith(e[1]));\n if (match) {\n const [ optName, matchKey ] = match;\n const eq = line.indexOf('=');\n const propValue = (eq >= matchKey.length ? line.substring(eq + 1) : '').trim();\n if (propValue) {\n const target = currentTargets.at(-1);\n if (target) {\n if (!target.include) {\n target.include = {};\n }\n target.include[optName as keyof DownloaderIncludeOptions] = {\n key: matchKey,\n line: ln,\n src: 'tgt',\n value: propValue\n };\n }\n }\n }\n else {\n const url = CLIOptionValidator.validateTargetURL(line);\n currentTargets.push({ url });\n }\n }\n catch (error) {\n const errMsg = error instanceof Error ? error.message : error;\n throw Error(`Error parsing targets file (line ${ln})${errMsg ? `: ${errMsg}` : ''}`);\n }\n }\n\n const result: CLITargetURLEntry[] = [];\n for (const target of currentTargets) {\n const v: CLITargetURLEntry = { url: target.url };\n if (target.include) {\n v.include = getCLIIncludeOptions(target);\n }\n result.push(v);\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"CLIOptions.js","sourceRoot":"","sources":["../../src/cli/CLIOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,iBAA6C,MAAM,wBAAwB,CAAC;AACnF,OAAO,gBAA2C,MAAM,uBAAuB,CAAC;AAChF,OAAO,IAAI,MAAM,MAAM,CAAC;AA4BxB,MAAM,UAAU,aAAa;IAC3B,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,KAAK,EAAE,CAAC;IAErD,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAEpI,IAAI,UAA+B,CAAC;IACpC,MAAM,cAAc,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,WAAW,CAAC,kBAAkB,CAAC,UAAU,EAAE,iBAAiB,EAAE,UAAU,CAAC,EAAE,yBAAyB,CAAC,CAAC;IACjK,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IACjD,IAAI,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE;QAC9B,UAAU,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC;KAC3C;SACI;QACH,UAAU,GAAG,kBAAkB;aAC5B,kBAAkB,CAAC,cAAc,CAAC;aAClC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAA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AAc,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;aAC9B;SACF;QACD,OAAO,KAAK,EAAE;YACZ,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;YAC9D,MAAM,KAAK,CAAC,oCAAoC,EAAE,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;SACtF;KACF;IAED,MAAM,MAAM,GAAwB,EAAE,CAAC;IACvC,KAAK,MAAM,MAAM,IAAI,cAAc,EAAE;QACnC,MAAM,CAAC,GAAsB,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;QACjD,IAAI,MAAM,CAAC,OAAO,EAAE;YAClB,CAAC,CAAC,OAAO,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;SAC1C;QACD,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KAChB;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import fs from 'fs';\nimport { DownloaderIncludeOptions, DownloaderOptions } from '../downloaders/DownloaderOptions.js';\nimport { pickDefined } from '../utils/Misc.js';\nimport { ConsoleLoggerOptions } from '../utils/logging/ConsoleLogger.js';\nimport { FileLoggerOptions } from '../utils/logging/FileLogger.js';\nimport CLIOptionValidator from './CLIOptionValidator.js';\nimport CommandLineParser, { CommandLineParseResult } from './CommandLineParser.js';\nimport ConfigFileParser, { ConfigFileParseResult } from './ConfigFileParser.js';\nimport path from 'path';\n\nexport interface CLITargetURLEntry {\n url: string;\n // Target-specific 'include' options\n include?: DownloaderIncludeOptions;\n}\n\nexport interface CLIOptions extends Omit<DownloaderOptions, 'logger'> {\n targetURLs: CLITargetURLEntry[];\n noPrompt: boolean;\n consoleLogger: ConsoleLoggerOptions;\n fileLoggers?: FileLoggerOptions[];\n}\n\nexport type CLIOptionParserEntry = ({\n src: 'cli'\n} | {\n src: 'cfg',\n section: string\n} | {\n src: 'tgt',\n line: number\n}) & {\n key: string;\n value?: string;\n}\n\nexport function getCLIOptions(): CLIOptions {\n const commandLineOptions = CommandLineParser.parse();\n\n const configFileOptions = commandLineOptions.configFile?.value ? ConfigFileParser.parse(commandLineOptions.configFile.value) : null;\n\n let targetURLs: CLITargetURLEntry[];\n const targetURLValue = CLIOptionValidator.validateRequired(pickDefined(commandLineOptions.targetURLs, configFileOptions?.targetURLs), 'No target URL specified');\n const targetsFile = path.resolve(targetURLValue);\n if (fs.existsSync(targetsFile)) {\n targetURLs = readTargetsFile(targetsFile);\n }\n else {\n targetURLs = CLIOptionValidator\n .validateTargetURLs(targetURLValue)\n .map((url) => ({ url }));\n }\n\n const { consoleLogger, fileLoggers } = getCLILoggerOptions(commandLineOptions, configFileOptions);\n\n const options: CLIOptions = {\n targetURLs,\n cookie: CLIOptionValidator.validateString(pickDefined(commandLineOptions.cookie, configFileOptions?.cookie)),\n useStatusCache: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.useStatusCache, configFileOptions?.useStatusCache)),\n pathToFFmpeg: CLIOptionValidator.validateString(pickDefined(commandLineOptions.pathToFFmpeg, configFileOptions?.pathToFFmpeg)),\n outDir: CLIOptionValidator.validateString(pickDefined(commandLineOptions.outDir, configFileOptions?.outDir)),\n dirNameFormat: {\n campaign: CLIOptionValidator.validateString(pickDefined(commandLineOptions.dirNameFormat?.campaign, configFileOptions?.dirNameFormat?.campaign)),\n content: CLIOptionValidator.validateString(pickDefined(commandLineOptions.dirNameFormat?.content, configFileOptions?.dirNameFormat?.content))\n },\n filenameFormat: {\n media: CLIOptionValidator.validateString(pickDefined(commandLineOptions.filenameFormat?.media, configFileOptions?.filenameFormat?.media))\n },\n include: getCLIIncludeOptions(commandLineOptions, configFileOptions),\n request: {\n maxRetries: CLIOptionValidator.validateNumber(pickDefined(commandLineOptions?.request?.maxRetries, configFileOptions?.request?.maxRetries)),\n maxConcurrent: CLIOptionValidator.validateNumber(pickDefined(commandLineOptions?.request?.maxConcurrent, configFileOptions?.request?.maxConcurrent)),\n minTime: CLIOptionValidator.validateNumber(pickDefined(commandLineOptions?.request?.minTime, configFileOptions?.request?.minTime))\n },\n fileExistsAction: {\n content: CLIOptionValidator.validateString(pickDefined(commandLineOptions.fileExistsAction?.content, configFileOptions?.fileExistsAction?.content), 'overwrite', 'skip', 'saveAsCopy', 'saveAsCopyIfNewer'),\n info: CLIOptionValidator.validateString(pickDefined(commandLineOptions.fileExistsAction?.info, configFileOptions?.fileExistsAction?.info), 'overwrite', 'skip', 'saveAsCopy', 'saveAsCopyIfNewer'),\n infoAPI: CLIOptionValidator.validateString(pickDefined(commandLineOptions.fileExistsAction?.infoAPI, configFileOptions?.fileExistsAction?.infoAPI), 'overwrite', 'skip', 'saveAsCopy', 'saveAsCopyIfNewer')\n },\n embedDownloaders: getEmbedDownloaderOptions(configFileOptions),\n noPrompt: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.noPrompt, configFileOptions?.noPrompt)) || false,\n consoleLogger,\n fileLoggers\n };\n\n return options;\n}\n\nexport function getCLILoggerOptions(commandLineOptions?: CommandLineParseResult, configFileOptions?: ReturnType<typeof ConfigFileParser['parse']> | null) {\n if (!commandLineOptions) {\n commandLineOptions = CommandLineParser.parse();\n }\n const consoleLogger = {\n enabled: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.consoleLogger?.enabled, configFileOptions?.consoleLogger?.enabled)),\n logLevel: CLIOptionValidator.validateString(pickDefined(commandLineOptions.consoleLogger?.logLevel, configFileOptions?.consoleLogger?.logLevel), 'info', 'debug', 'warn', 'error'),\n include: {\n dateTime: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.consoleLogger?.include?.dateTime, configFileOptions?.consoleLogger?.include?.dateTime)),\n level: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.consoleLogger?.include?.level, configFileOptions?.consoleLogger?.include?.level)),\n originator: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.consoleLogger?.include?.originator, configFileOptions?.consoleLogger?.include?.originator)),\n errorStack: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.consoleLogger?.include?.errorStack, configFileOptions?.consoleLogger?.include?.errorStack))\n },\n dateTimeFormat: CLIOptionValidator.validateString(pickDefined(commandLineOptions.consoleLogger?.dateTimeFormat, configFileOptions?.consoleLogger?.dateTimeFormat)),\n color: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.consoleLogger?.color, configFileOptions?.consoleLogger?.color))\n };\n let fileLoggers;\n if (configFileOptions?.fileLoggers) {\n fileLoggers = configFileOptions.fileLoggers.map((logger): FileLoggerOptions => ({\n enabled: CLIOptionValidator.validateBoolean(logger.enabled),\n logDir: CLIOptionValidator.validateString(logger.logDir),\n logFilename: CLIOptionValidator.validateString(logger.logFilename),\n fileExistsAction: CLIOptionValidator.validateString(logger.fileExistsAction, 'append', 'overwrite'),\n logLevel: CLIOptionValidator.validateString(logger.logLevel, 'info', 'debug', 'warn', 'error'),\n include: {\n dateTime: CLIOptionValidator.validateBoolean(logger.include?.dateTime),\n level: CLIOptionValidator.validateBoolean(logger.include?.level),\n originator: CLIOptionValidator.validateBoolean(logger.include?.originator),\n errorStack: CLIOptionValidator.validateBoolean(logger.include?.errorStack)\n },\n dateTimeFormat: CLIOptionValidator.validateString(logger.dateTimeFormat),\n color: CLIOptionValidator.validateBoolean(logger.color)\n }));\n }\n return {\n consoleLogger,\n fileLoggers\n };\n}\n\nfunction getCLIIncludeOptions(commandLineOptions: CommandLineParseResult, configFileOptions?: ConfigFileParseResult | null) {\n if (!commandLineOptions) {\n commandLineOptions = CommandLineParser.parse();\n }\n return {\n lockedContent: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.include?.lockedContent, configFileOptions?.include?.lockedContent)),\n postsWithMediaType: CLIOptionValidator.validateIncludeContentWithMediaType(pickDefined(commandLineOptions.include?.postsWithMediaType, configFileOptions?.include?.postsWithMediaType)),\n postsInTier: CLIOptionValidator.validateIncludeContentInTier(pickDefined(commandLineOptions.include?.postsInTier, configFileOptions?.include?.postsInTier)),\n campaignInfo: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.include?.campaignInfo, configFileOptions?.include?.campaignInfo)),\n contentInfo: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.include?.contentInfo, configFileOptions?.include?.contentInfo)),\n previewMedia: CLIOptionValidator.validateIncludePreviewMedia(pickDefined(commandLineOptions.include?.previewMedia, configFileOptions?.include?.previewMedia)),\n contentMedia: CLIOptionValidator.validateIncludeContentMedia(pickDefined(commandLineOptions.include?.contentMedia, configFileOptions?.include?.contentMedia)),\n allMediaVariants: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.include?.allMediaVariants, configFileOptions?.include?.allMediaVariants))\n };\n}\n\nfunction getEmbedDownloaderOptions(configFileOptions?: ConfigFileParseResult | null) {\n if (configFileOptions?.embedDownloaders) {\n return configFileOptions?.embedDownloaders.map((dl) => ({\n provider: CLIOptionValidator.validateRequired(dl.provider),\n exec: CLIOptionValidator.validateRequired(dl.exec)\n }));\n }\n return undefined;\n}\n\nfunction readTargetsFile(file: string) {\n const includeKeys: Record<keyof DownloaderIncludeOptions, string> = {\n lockedContent: 'include.locked.content',\n postsWithMediaType: 'include.posts.with.media.type',\n postsInTier: 'include.posts.in.tier',\n campaignInfo: 'include.campaign.info',\n contentInfo: 'include.content.info',\n previewMedia: 'include.preview.media',\n contentMedia: 'include.content.media',\n allMediaVariants: 'include.all.media.variants'\n };\n\n const lines = fs.readFileSync(file)\n .toString('utf-8')\n // Replace Windows line breaks with Unix ones and then split\n .replace(/\\r\\n/g, '\\n').split('\\n')\n .map((line) => line.trim());\n\n const currentTargets: { url: string; include?: Partial<Record<keyof DownloaderIncludeOptions, CLIOptionParserEntry>>; }[] = [];\n for (let ln = 0; ln < lines.length; ln++) {\n const line = lines[ln];\n if (line === '' || line.startsWith('#')) {\n continue;\n }\n try {\n const match = Object.entries(includeKeys).find((e) => line.startsWith(e[1]));\n if (match) {\n const [ optName, matchKey ] = match;\n const eq = line.indexOf('=');\n const propValue = (eq >= matchKey.length ? line.substring(eq + 1) : '').trim();\n if (propValue) {\n const target = currentTargets.at(-1);\n if (target) {\n if (!target.include) {\n target.include = {};\n }\n target.include[optName as keyof DownloaderIncludeOptions] = {\n key: matchKey,\n line: ln,\n src: 'tgt',\n value: propValue\n };\n }\n }\n }\n else {\n const url = CLIOptionValidator.validateTargetURL(line);\n currentTargets.push({ url });\n }\n }\n catch (error) {\n const errMsg = error instanceof Error ? error.message : error;\n throw Error(`Error parsing targets file (line ${ln})${errMsg ? `: ${errMsg}` : ''}`);\n }\n }\n\n const result: CLITargetURLEntry[] = [];\n for (const target of currentTargets) {\n const v: CLITargetURLEntry = { url: target.url };\n if (target.include) {\n v.include = getCLIIncludeOptions(target);\n }\n result.push(v);\n }\n\n return result;\n}\n"]}
@@ -9,6 +9,9 @@ export default class CommandLineParser {
9
9
  static parse(): CommandLineParseResult;
10
10
  static showUsage(): boolean;
11
11
  static configureYouTube(): any;
12
- static listTiers(): false | string[];
12
+ static listTiers(): {
13
+ byVanity: string[];
14
+ byUserId: string[];
15
+ } | null;
13
16
  }
14
17
  //# sourceMappingURL=CommandLineParser.d.ts.map
@@ -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,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC,EAAE,oBAAoB,CAAC;IACjI,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC,UAAU,CAAC,EAAE,oBAAoB,CAAC;CACnC;AAkFD,MAAM,CAAC,OAAO,OAAO,iBAAiB;;IAEpC,MAAM,CAAC,KAAK,IAAI,sBAAsB;IA+FtC,MAAM,CAAC,SAAS;IAyChB,MAAM,CAAC,gBAAgB;IAWvB,MAAM,CAAC,SAAS;CA8BjB"}
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,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC,EAAE,oBAAoB,CAAC;IACjI,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC,UAAU,CAAC,EAAE,oBAAoB,CAAC;CACnC;AAyFD,MAAM,CAAC,OAAO,OAAO,iBAAiB;;IAEpC,MAAM,CAAC,KAAK,IAAI,sBAAsB;IA+FtC,MAAM,CAAC,SAAS;IAyChB,MAAM,CAAC,gBAAgB;IAWvB,MAAM,CAAC,SAAS;;;;CAiDjB"}
@@ -18,7 +18,8 @@ const COMMAND_LINE_ARGS = {
18
18
  outDir: 'out-dir',
19
19
  logLevel: 'log-level',
20
20
  noPrompt: 'no-prompt',
21
- listTiers: 'list-tiers'
21
+ listTiers: 'list-tiers',
22
+ listTiersByUserId: 'list-tiers-uid'
22
23
  };
23
24
  const OPT_DEFS = [
24
25
  {
@@ -80,6 +81,12 @@ const OPT_DEFS = [
80
81
  type: String,
81
82
  typeLabel: '<creator>'
82
83
  },
84
+ {
85
+ name: COMMAND_LINE_ARGS.listTiersByUserId,
86
+ description: 'Same as \'--list-tiers\', but takes user ID instead of vanity.',
87
+ type: String,
88
+ typeLabel: '<user ID>'
89
+ },
83
90
  {
84
91
  name: COMMAND_LINE_ARGS.configureYouTube,
85
92
  description: 'Configure YouTube connection',
@@ -231,20 +238,35 @@ export default class CommandLineParser {
231
238
  opts = __classPrivateFieldGet(this, _a, "m", _CommandLineParser_parseArgs).call(this);
232
239
  }
233
240
  catch (error) {
234
- return false;
241
+ return null;
235
242
  }
236
- const listTiers = opts[COMMAND_LINE_ARGS.listTiers];
237
- if (listTiers === null) {
238
- throw Error('\'--list-tiers\' missing value');
239
- }
240
- else if (typeof listTiers === 'string') {
241
- const targets = listTiers.split(',').map((v) => v.trim()).filter((v) => v);
242
- if (targets.length === 0) {
243
- throw Error('\'--list-tiers\' has invalid value');
243
+ const __getTargets = (opt) => {
244
+ const listTiers = opt === '--list-tiers' ? opts[COMMAND_LINE_ARGS.listTiers] : opts[COMMAND_LINE_ARGS.listTiersByUserId];
245
+ if (listTiers === null) { // Option provided but has empty value
246
+ return null;
247
+ }
248
+ else if (typeof listTiers === 'string') {
249
+ const targets = listTiers.split(',').map((v) => v.trim()).filter((v) => v);
250
+ if (targets.length === 0) {
251
+ throw Error(`'${opt}' has invalid value`);
252
+ }
253
+ return targets;
244
254
  }
245
- return targets;
255
+ return false;
256
+ };
257
+ const vanities = __getTargets('--list-tiers');
258
+ const userIds = __getTargets('--list-tiers-uid');
259
+ if (vanities === null || userIds === null) {
260
+ const opt = vanities === null ? '--list-tiers' : '--list-tiers-uid';
261
+ throw Error(`'${opt}' missing value`);
246
262
  }
247
- return false;
263
+ if (vanities === false && userIds === false) {
264
+ return null;
265
+ }
266
+ return {
267
+ byVanity: vanities || [],
268
+ byUserId: userIds || []
269
+ };
248
270
  }
249
271
  }
250
272
  _a = CommandLineParser, _CommandLineParser_parseArgs = function _CommandLineParser_parseArgs() {
@@ -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,GAA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K,CAAC,oCAAoC,CAAC,CAAC;aACnD;YACD,OAAO,OAAO,CAAC;SAChB;QACD,OAAO,KAAK,CAAC;IACf,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<Omit<CLIOptions, 'targetURLs'>>, CLIOptionParserEntry> {\n targetURLs?: 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 listTiers: 'list-tiers'\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.listTiers,\n description: 'List tiers for the given creator(s). Separate multiple creators with a comma.',\n type: String,\n typeLabel: '<creator>'\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 targetURLs: __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 lockedContent: undefined,\n postsWithMediaType: undefined,\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 listTiers() {\n let opts;\n try {\n opts = this.#parseArgs();\n }\n catch (error) {\n return false;\n }\n const listTiers = opts[COMMAND_LINE_ARGS.listTiers];\n if (listTiers === null) {\n throw Error('\\'--list-tiers\\' missing value');\n }\n else if (typeof listTiers === 'string') {\n const targets = listTiers.split(',').map((v) => v.trim()).filter((v) => v);\n if (targets.length === 0) {\n throw Error('\\'--list-tiers\\' has invalid value');\n }\n return targets;\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;AAOzD,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;IACrB,SAAS,EAAE,YAAY;IACvB,iBAAiB,EAAE,gBAAgB;CAC3B,CAAC;AAEX,MAAM,QAAQ,GAAG;IACf;QACE,IAAI,EAAE,iBAAiB,CAAC,IAAI;QAC5B,WAAW,EAAE,0BAA0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OAAO,GAAG,YAAY,CAAC,kBAAkB,CAAC,CAAC;QACjD,IAAI,QAAQ,KAAK,IAAI,IAAI,OAAO,KAAK,IAAI,EAAE;YACzC,MAAM,GAAG,GAAG,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,kBAAkB,CAAC;YACpE,MAAM,KAAK,CAAC,IAAI,GAAG,iBAAiB,CAAC,CAAC;SACvC;QAED,IAAI,QAAQ,KAAK,KAAK,IAAI,OAAO,KAAK,KAAK,EAAE;YAC3C,OAAO,IAAI,CAAC;SACb;QAED,OAAO;YACL,QAAQ,EAAE,QAAQ,IAAI,EAAE;YACxB,QAAQ,EAAE,OAAO,IAAI,EAAE;SACxB,CAAC;IACJ,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<Omit<CLIOptions, 'targetURLs'>>, CLIOptionParserEntry> {\n targetURLs?: 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 listTiers: 'list-tiers',\n listTiersByUserId: 'list-tiers-uid'\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.listTiers,\n description: 'List tiers for the given creator(s). Separate multiple creators with a comma.',\n type: String,\n typeLabel: '<creator>'\n },\n {\n name: COMMAND_LINE_ARGS.listTiersByUserId,\n description: 'Same as \\'--list-tiers\\', but takes user ID instead of vanity.',\n type: String,\n typeLabel: '<user ID>'\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 targetURLs: __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 lockedContent: undefined,\n postsWithMediaType: undefined,\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 listTiers() {\n let opts: commandLineArgs.CommandLineOptions;\n try {\n opts = this.#parseArgs();\n }\n catch (error) {\n return null;\n }\n\n const __getTargets = (opt: '--list-tiers' | '--list-tiers-uid') => {\n const listTiers = opt === '--list-tiers' ? opts[COMMAND_LINE_ARGS.listTiers] : opts[COMMAND_LINE_ARGS.listTiersByUserId];\n if (listTiers === null) { // Option provided but has empty value\n return null;\n }\n else if (typeof listTiers === 'string') {\n const targets = listTiers.split(',').map((v) => v.trim()).filter((v) => v);\n if (targets.length === 0) {\n throw Error(`'${opt}' has invalid value`);\n }\n return targets;\n }\n return false;\n };\n\n const vanities = __getTargets('--list-tiers');\n const userIds = __getTargets('--list-tiers-uid');\n if (vanities === null || userIds === null) {\n const opt = vanities === null ? '--list-tiers' : '--list-tiers-uid';\n throw Error(`'${opt}' missing value`);\n }\n\n if (vanities === false && userIds === false) {\n return null;\n }\n\n return {\n byVanity: vanities || [],\n byUserId: userIds || []\n };\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 +1 @@
1
- {"version":3,"file":"ConfigFileParser.d.ts","sourceRoot":"","sources":["../../src/cli/ConfigFileParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAiEjE,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC,EAAE,oBAAoB,CAAC,GAAG;IACxH,UAAU,CAAC,EAAE,oBAAoB,CAAC;CACnC,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,gBAAgB;;IAEnC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB;CAwGlD"}
1
+ {"version":3,"file":"ConfigFileParser.d.ts","sourceRoot":"","sources":["../../src/cli/ConfigFileParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAoEjE,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC,EAAE,oBAAoB,CAAC,GAAG;IACxH,UAAU,CAAC,EAAE,oBAAoB,CAAC;CACnC,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,gBAAgB;;IAEnC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB;CAkIlD"}
@@ -3,7 +3,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
3
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
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
- var _a, _ConfigFileParser_getValueFromConfigParser, _ConfigFileParser_parseFileLoggerOptions;
6
+ var _a, _ConfigFileParser_getValueFromConfigParser, _ConfigFileParser_parseFileLoggerOptions, _ConfigFileParser_parseEmbedDownloaderOptions;
7
7
  import ConfigParser from 'configparser';
8
8
  const CONFIG_FILE_PROPS = {
9
9
  targetURL: 'downloader:target.url',
@@ -65,6 +65,9 @@ const CONFIG_FILE_PROPS = {
65
65
  },
66
66
  dateTimeFormat: ':date.time.format',
67
67
  color: ':color'
68
+ },
69
+ embedDownloader: {
70
+ exec: ':exec'
68
71
  }
69
72
  };
70
73
  export default class ConfigFileParser {
@@ -120,13 +123,14 @@ export default class ConfigFileParser {
120
123
  dateTimeFormat: __getValue(CONFIG_FILE_PROPS.consoleLogger.dateTimeFormat),
121
124
  color: __getValue(CONFIG_FILE_PROPS.consoleLogger.color)
122
125
  },
123
- fileLoggers: __classPrivateFieldGet(this, _a, "m", _ConfigFileParser_parseFileLoggerOptions).call(this, parser)
126
+ fileLoggers: __classPrivateFieldGet(this, _a, "m", _ConfigFileParser_parseFileLoggerOptions).call(this, parser),
127
+ embedDownloaders: __classPrivateFieldGet(this, _a, "m", _ConfigFileParser_parseEmbedDownloaderOptions).call(this, parser)
124
128
  };
125
129
  }
126
130
  }
127
131
  _a = ConfigFileParser, _ConfigFileParser_getValueFromConfigParser = function _ConfigFileParser_getValueFromConfigParser(parser, prop) {
128
132
  const [section, key] = prop.split(':');
129
- let value = parser.get(section, key)?.trim();
133
+ let value = parser.get(section, key, true)?.trim();
130
134
  if (value && value.startsWith('"') && value.endsWith('"')) {
131
135
  value = value.substring(1, value.length - 1);
132
136
  }
@@ -163,5 +167,26 @@ _a = ConfigFileParser, _ConfigFileParser_getValueFromConfigParser = function _Co
163
167
  return result;
164
168
  }, []);
165
169
  return loggers.length > 0 ? loggers : undefined;
170
+ }, _ConfigFileParser_parseEmbedDownloaderOptions = function _ConfigFileParser_parseEmbedDownloaderOptions(parser) {
171
+ const __getValue = (section, prop) => {
172
+ return __classPrivateFieldGet(this, _a, "m", _ConfigFileParser_getValueFromConfigParser).call(this, parser, `${section}${prop}`);
173
+ };
174
+ const sections = parser.sections().filter((section) => section.startsWith('embed.downloader.'));
175
+ const prefixLength = 'embed.downloader.'.length;
176
+ const embedDownloaders = sections.reduce((result, section) => {
177
+ const provider = section.substring(prefixLength).trim().toLowerCase();
178
+ if (!provider) {
179
+ throw Error('Config file section \'embed.downloader.<provider>\' is missing the provider name');
180
+ }
181
+ if (result.find((dl) => dl.provider?.value === provider)) {
182
+ throw Error(`Duplicate config file section 'embed.downloader.${provider}`);
183
+ }
184
+ result.push({
185
+ provider: { src: 'cfg', section: `embed.downloader.${provider}`, key: 'provider', value: provider },
186
+ exec: __getValue(section, CONFIG_FILE_PROPS.embedDownloader.exec)
187
+ });
188
+ return result;
189
+ }, []);
190
+ return embedDownloaders.length > 0 ? embedDownloaders : undefined;
166
191
  };
167
192
  //# sourceMappingURL=ConfigFileParser.js.map