patreon-dl 3.6.0 → 3.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -293,6 +293,9 @@ Note the URL shown in the output. Open this URL in a web browser to begin viewin
293
293
 
294
294
  ## Changelog
295
295
 
296
+ v3.6.1
297
+ - Fix Embedly download script error on retrying with alternative URL.
298
+
296
299
  v3.6.0
297
300
  - Browse: affix nav links (previous / next post) to viewport bottom if post content overflows ([patreon-dl-gui#41](https://github.com/patrickkfkan/patreon-dl-gui/issues/41))
298
301
  - Fix error when Deno path contains spaces ([patreon-dl-gui#42](https://github.com/patrickkfkan/patreon-dl-gui/issues/42))
@@ -165,7 +165,7 @@ export default class EmbedlyDownloader {
165
165
  let code = await this.download(_url, o, videoPassword, ytdlpPath, ytdlpArgs);
166
166
  if (code !== 0 && _url !== embedURL && embedURL) {
167
167
  console.log(`Download failed - retrying with embed URL "${embedURL}"`);
168
- return await this.download(embedURL);
168
+ return await this.download(embedURL, o, videoPassword, ytdlpPath, ytdlpArgs);
169
169
  }
170
170
 
171
171
  return code;
@@ -9,7 +9,16 @@ export function getCLIOptions(skipTargetURLs = false) {
9
9
  const commandLineOptions = CommandLineParser.parse();
10
10
  const configFileOptions = commandLineOptions.configFile?.value ? ConfigFileParser.parse(commandLineOptions.configFile.value) : null;
11
11
  let targetURLs = [];
12
- if (!skipTargetURLs) {
12
+ if (commandLineOptions.debugAPI) {
13
+ const apiDataFile = commandLineOptions.targetURLs?.value;
14
+ if (!apiDataFile ||
15
+ !fs.existsSync(apiDataFile) ||
16
+ !['post-api.json', 'product-api.json'].includes(path.basename(apiDataFile))) {
17
+ throw Error(`${commandLineOptions.debugAPI.key}: target is not a local API data file`);
18
+ }
19
+ targetURLs = [{ url: apiDataFile }];
20
+ }
21
+ else if (!skipTargetURLs) {
13
22
  const targetURLValue = CLIOptionValidator.validateRequired(pickDefined(commandLineOptions.targetURLs, configFileOptions?.targetURLs), 'No target URL specified');
14
23
  const targetsFile = path.resolve(targetURLValue);
15
24
  if (fs.existsSync(targetsFile)) {
@@ -1 +1 @@
1
- {"version":3,"file":"CLIOptions.js","sourceRoot":"","sources":["../../src/cli/CLIOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAA2C,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGxF,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,iBAAkD,MAAM,wBAAwB,CAAC;AACxF,OAAO,gBAAgD,MAAM,uBAAuB,CAAC;AACrF,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,YAAY,MAAM,0BAA0B,CAAC;AA8BpD,MAAM,UAAU,aAAa,CAAC,cAAc,GAAG,KAAK;IAClD,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,UAAU,GAAwB,EAAE,CAAC;IACzC,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,cAAc,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,WAAW,CAAC,kBAAkB,CAAC,UAAU,EAAE,iBAAiB,EAAE,UAAU,CAAC,EAAE,yBAAyB,CAAC,CAAC;QACjK,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QACjD,IAAI,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/B,UAAU,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC;QAC5C,CAAC;aACI,CAAC;YACJ,UAAU,GAAG,kBAAkB;iBAC5B,kBAAkB,CAAC,cAAc,CAAC;iBAClC,GAAG,CAAC,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CAAC;iBACI,CAAC;gBACJ,MAAM,GAAG,GAAG,kBAAkB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;gBACvD,cAAc,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;QACD,OAAO,KAAU,EAAE,CAAC;YAClB,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;QACvF,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAwB,EAAE,CAAC;IACvC,KAAK,MAAM,MAAM,IAAI,cAAc,EAAE,CAAC;QACpC,MAAM,CAAC,GAAsB,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;QACjD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,MAAM,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,oBAAoB,CAAC,MAAM,CAAC,EAAE;gBACnE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI;aACtD,CAAC,CAAC;YACH,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC3C,CAAC,CAAC,OAAO,GAAG,WAAW,CAAC;YAC1B,CAAC;QACH,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import fs from 'fs';\nimport { type DownloaderIncludeOptions, type DownloaderOptions } from '../downloaders/DownloaderOptions.js';\nimport { type DeepPartial, type RecursivePropsTo, pickDefined } from '../utils/Misc.js';\nimport { type ConsoleLoggerOptions } from '../utils/logging/ConsoleLogger.js';\nimport { type FileLoggerType, type FileLoggerOptions } from '../utils/logging/FileLogger.js';\nimport CLIOptionValidator from './CLIOptionValidator.js';\nimport CommandLineParser, { type CommandLineParseResult } from './CommandLineParser.js';\nimport ConfigFileParser, { type ConfigFileParseResult } from './ConfigFileParser.js';\nimport path from 'path';\nimport ObjectHelper from '../utils/ObjectHelper.js';\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?: Omit<FileLoggerOptions<FileLoggerType.Downloader>, 'init'>[];\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(skipTargetURLs: true): Omit<CLIOptions, 'targetURLs'>;\nexport function getCLIOptions(skipTargetURLs?: false): CLIOptions;\nexport function getCLIOptions(skipTargetURLs = false): CLIOptions | Omit<CLIOptions, 'targetURLs'> {\n const commandLineOptions = CommandLineParser.parse();\n\n const configFileOptions = commandLineOptions.configFile?.value ? ConfigFileParser.parse(commandLineOptions.configFile.value) : null;\n\n let targetURLs: CLITargetURLEntry[] = [];\n if (!skipTargetURLs) {\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\n const { consoleLogger, fileLoggers } = getCLILoggerOptions(commandLineOptions, configFileOptions);\n const proxy = getProxyOptions(configFileOptions);\n\n const options = {\n cookie: CLIOptionValidator.validateString(pickDefined(commandLineOptions.cookie, configFileOptions?.cookie)),\n useStatusCache: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.useStatusCache, configFileOptions?.useStatusCache)),\n stopOn: CLIOptionValidator.validateString(pickDefined(commandLineOptions.stopOn, configFileOptions?.stopOn), 'never', 'postPreviouslyDownloaded', 'postPublishDateOutOfRange', 'previouslyDownloaded', 'publishDateOutOfRange'),\n pathToFFmpeg: CLIOptionValidator.validateString(pickDefined(commandLineOptions.pathToFFmpeg, configFileOptions?.pathToFFmpeg)),\n pathToDeno: CLIOptionValidator.validateString(pickDefined(commandLineOptions.pathToDeno, configFileOptions?.pathToDeno)),\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 proxy,\n userAgent: CLIOptionValidator.validateString(pickDefined(commandLineOptions?.request?.userAgent, configFileOptions?.request?.userAgent))\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 maxVideoResolution: CLIOptionValidator.validateNumber(pickDefined(commandLineOptions.maxVideoResolution, configFileOptions?.maxVideoResolution)),\n noPrompt: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.noPrompt, configFileOptions?.noPrompt)) || false,\n dryRun: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.dryRun, configFileOptions?.dryRun)) || false,\n consoleLogger,\n fileLoggers\n } satisfies Omit<CLIOptions, 'targetURLs'>;\n\n if (skipTargetURLs) {\n return options;\n }\n\n return {\n targetURLs,\n ...options\n } satisfies CLIOptions;\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): Omit<FileLoggerOptions<FileLoggerType.Downloader>, 'init'> => ({\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 postsPublished: {\n after: CLIOptionValidator.validateDateTime(pickDefined(commandLineOptions.include?.postsPublished?.after, configFileOptions?.include?.postsPublished?.after)) || null,\n before: CLIOptionValidator.validateDateTime(pickDefined(commandLineOptions.include?.postsPublished?.before, configFileOptions?.include?.postsPublished?.before)) || null,\n },\n productsPublished: {\n after: CLIOptionValidator.validateDateTime(pickDefined(commandLineOptions.include?.productsPublished?.after, configFileOptions?.include?.productsPublished?.after)) || null,\n before: CLIOptionValidator.validateDateTime(pickDefined(commandLineOptions.include?.productsPublished?.before, configFileOptions?.include?.productsPublished?.before)) || null,\n },\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 mediaThumbnails: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.include?.mediaThumbnails, configFileOptions?.include?.mediaThumbnails)),\n mediaByFilename: {\n images: CLIOptionValidator.validateString(pickDefined(commandLineOptions.include?.mediaByFilename?.images, configFileOptions?.include?.mediaByFilename?.images)) || null,\n audio: CLIOptionValidator.validateString(pickDefined(commandLineOptions.include?.mediaByFilename?.audio, configFileOptions?.include?.mediaByFilename?.audio)) || null,\n attachments: CLIOptionValidator.validateString(pickDefined(commandLineOptions.include?.mediaByFilename?.attachments, configFileOptions?.include?.mediaByFilename?.attachments)) || null\n },\n comments: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.include?.comments, configFileOptions?.include?.comments))\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 getProxyOptions(configFileOptions?: ConfigFileParseResult | null) {\n if (configFileOptions?.request?.proxy && configFileOptions.request.proxy.url?.value?.trim()) {\n return {\n url: CLIOptionValidator.validateProxyURL(configFileOptions.request.proxy.url),\n rejectUnauthorizedTLS: CLIOptionValidator.validateBoolean(configFileOptions.request.proxy.rejectUnauthorizedTLS)\n };\n }\n return null;\n}\n\nfunction readTargetsFile(file: string) {\n const includeKeys = {\n lockedContent: 'include.locked.content',\n postsWithMediaType: 'include.posts.with.media.type',\n postsInTier: 'include.posts.in.tier',\n postsPublishedAfter: 'include.posts.published.after',\n postsPublishedBefore: 'include.posts.published.before',\n productsPublishedAfter: 'include.products.published.after',\n productsPublishedBefore: 'include.products.published.before',\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 mediaThumbnails: 'include.media.thumbnails',\n imagesByFilename: 'include.images.by.filename',\n audioByFilename: 'include.audio.by.filename',\n attachmentsByFilename: 'include.attachments.by.filename',\n comments: 'include.comments'\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?: RecursivePropsTo<DeepPartial<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 const entry: CLIOptionParserEntry = {\n key: matchKey,\n line: ln,\n src: 'tgt',\n value: propValue\n };\n if (!target.include) {\n target.include = {};\n }\n if (matchKey === includeKeys.postsPublishedAfter || matchKey === includeKeys.postsPublishedBefore) {\n if (!target.include.postsPublished) {\n target.include.postsPublished = {};\n }\n if (matchKey === includeKeys.postsPublishedAfter) {\n target.include.postsPublished.after = entry;\n }\n else {\n target.include.postsPublished.before = entry;\n }\n }\n else if (matchKey === includeKeys.productsPublishedAfter || matchKey === includeKeys.productsPublishedBefore) {\n if (!target.include.productsPublished) {\n target.include.productsPublished = {};\n }\n if (matchKey === includeKeys.productsPublishedAfter) {\n target.include.productsPublished.after = entry;\n }\n else {\n target.include.productsPublished.before = entry;\n }\n }\n else if (matchKey === includeKeys.imagesByFilename || matchKey === includeKeys.audioByFilename ||\n matchKey === includeKeys.attachmentsByFilename) {\n if (!target.include.mediaByFilename) {\n target.include.mediaByFilename = {};\n }\n switch (matchKey) {\n case includeKeys.imagesByFilename:\n target.include.mediaByFilename.images = entry;\n break;\n case includeKeys.audioByFilename:\n target.include.mediaByFilename.audio = entry;\n break;\n case includeKeys.attachmentsByFilename:\n target.include.mediaByFilename.attachments = entry;\n break;\n }\n }\n else {\n target.include[optName as keyof DownloaderIncludeOptions] = entry;\n }\n }\n }\n }\n else {\n const url = CLIOptionValidator.validateTargetURL(line);\n currentTargets.push({ url });\n }\n }\n catch (error: any) {\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 const includeOpts = ObjectHelper.clean(getCLIIncludeOptions(target), {\n deep: true, cleanNulls: true, cleanEmptyObjects: true\n });\n if (Object.entries(includeOpts).length > 0) {\n v.include = includeOpts;\n }\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,EAA2C,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGxF,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,iBAAkD,MAAM,wBAAwB,CAAC;AACxF,OAAO,gBAAgD,MAAM,uBAAuB,CAAC;AACrF,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,YAAY,MAAM,0BAA0B,CAAC;AA8BpD,MAAM,UAAU,aAAa,CAAC,cAAc,GAAG,KAAK;IAClD,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;IACpI,IAAI,UAAU,GAAwB,EAAE,CAAC;IAEzC,IAAI,kBAAkB,CAAC,QAAQ,EAAE,CAAC;QAChC,MAAM,WAAW,GAAG,kBAAkB,CAAC,UAAU,EAAE,KAAK,CAAC;QACzD,IAAI,CAAC,WAAW;YACd,CAAC,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC;YAC3B,CAAC,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,EAC3E,CAAC;YACD,MAAM,KAAK,CAAC,GAAG,kBAAkB,CAAC,QAAQ,CAAC,GAAG,uCAAuC,CAAC,CAA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W,GAAG,YAAY,CAAC,KAAK,CAAC,oBAAoB,CAAC,MAAM,CAAC,EAAE;gBACnE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI;aACtD,CAAC,CAAC;YACH,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC3C,CAAC,CAAC,OAAO,GAAG,WAAW,CAAC;YAC1B,CAAC;QACH,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import fs from 'fs';\nimport { type DownloaderIncludeOptions, type DownloaderOptions } from '../downloaders/DownloaderOptions.js';\nimport { type DeepPartial, type RecursivePropsTo, pickDefined } from '../utils/Misc.js';\nimport { type ConsoleLoggerOptions } from '../utils/logging/ConsoleLogger.js';\nimport { type FileLoggerType, type FileLoggerOptions } from '../utils/logging/FileLogger.js';\nimport CLIOptionValidator from './CLIOptionValidator.js';\nimport CommandLineParser, { type CommandLineParseResult } from './CommandLineParser.js';\nimport ConfigFileParser, { type ConfigFileParseResult } from './ConfigFileParser.js';\nimport path from 'path';\nimport ObjectHelper from '../utils/ObjectHelper.js';\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?: Omit<FileLoggerOptions<FileLoggerType.Downloader>, 'init'>[];\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(skipTargetURLs: true): Omit<CLIOptions, 'targetURLs'>;\nexport function getCLIOptions(skipTargetURLs?: false): CLIOptions;\nexport function getCLIOptions(skipTargetURLs = false): CLIOptions | Omit<CLIOptions, 'targetURLs'> {\n const commandLineOptions = CommandLineParser.parse();\n\n const configFileOptions = commandLineOptions.configFile?.value ? ConfigFileParser.parse(commandLineOptions.configFile.value) : null;\n let targetURLs: CLITargetURLEntry[] = [];\n\n if (commandLineOptions.debugAPI) {\n const apiDataFile = commandLineOptions.targetURLs?.value;\n if (!apiDataFile ||\n !fs.existsSync(apiDataFile) ||\n !['post-api.json', 'product-api.json'].includes(path.basename(apiDataFile))\n ) {\n throw Error(`${commandLineOptions.debugAPI.key}: target is not a local API data file`);\n }\n targetURLs = [{ url: apiDataFile }];\n }\n else if (!skipTargetURLs) {\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\n const { consoleLogger, fileLoggers } = getCLILoggerOptions(commandLineOptions, configFileOptions);\n const proxy = getProxyOptions(configFileOptions);\n\n const options = {\n cookie: CLIOptionValidator.validateString(pickDefined(commandLineOptions.cookie, configFileOptions?.cookie)),\n useStatusCache: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.useStatusCache, configFileOptions?.useStatusCache)),\n stopOn: CLIOptionValidator.validateString(pickDefined(commandLineOptions.stopOn, configFileOptions?.stopOn), 'never', 'postPreviouslyDownloaded', 'postPublishDateOutOfRange', 'previouslyDownloaded', 'publishDateOutOfRange'),\n pathToFFmpeg: CLIOptionValidator.validateString(pickDefined(commandLineOptions.pathToFFmpeg, configFileOptions?.pathToFFmpeg)),\n pathToDeno: CLIOptionValidator.validateString(pickDefined(commandLineOptions.pathToDeno, configFileOptions?.pathToDeno)),\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 proxy,\n userAgent: CLIOptionValidator.validateString(pickDefined(commandLineOptions?.request?.userAgent, configFileOptions?.request?.userAgent))\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 maxVideoResolution: CLIOptionValidator.validateNumber(pickDefined(commandLineOptions.maxVideoResolution, configFileOptions?.maxVideoResolution)),\n noPrompt: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.noPrompt, configFileOptions?.noPrompt)) || false,\n dryRun: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.dryRun, configFileOptions?.dryRun)) || false,\n consoleLogger,\n fileLoggers\n } satisfies Omit<CLIOptions, 'targetURLs'>;\n\n if (skipTargetURLs) {\n return options;\n }\n\n return {\n targetURLs,\n ...options\n } satisfies CLIOptions;\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): Omit<FileLoggerOptions<FileLoggerType.Downloader>, 'init'> => ({\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 postsPublished: {\n after: CLIOptionValidator.validateDateTime(pickDefined(commandLineOptions.include?.postsPublished?.after, configFileOptions?.include?.postsPublished?.after)) || null,\n before: CLIOptionValidator.validateDateTime(pickDefined(commandLineOptions.include?.postsPublished?.before, configFileOptions?.include?.postsPublished?.before)) || null,\n },\n productsPublished: {\n after: CLIOptionValidator.validateDateTime(pickDefined(commandLineOptions.include?.productsPublished?.after, configFileOptions?.include?.productsPublished?.after)) || null,\n before: CLIOptionValidator.validateDateTime(pickDefined(commandLineOptions.include?.productsPublished?.before, configFileOptions?.include?.productsPublished?.before)) || null,\n },\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 mediaThumbnails: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.include?.mediaThumbnails, configFileOptions?.include?.mediaThumbnails)),\n mediaByFilename: {\n images: CLIOptionValidator.validateString(pickDefined(commandLineOptions.include?.mediaByFilename?.images, configFileOptions?.include?.mediaByFilename?.images)) || null,\n audio: CLIOptionValidator.validateString(pickDefined(commandLineOptions.include?.mediaByFilename?.audio, configFileOptions?.include?.mediaByFilename?.audio)) || null,\n attachments: CLIOptionValidator.validateString(pickDefined(commandLineOptions.include?.mediaByFilename?.attachments, configFileOptions?.include?.mediaByFilename?.attachments)) || null\n },\n comments: CLIOptionValidator.validateBoolean(pickDefined(commandLineOptions.include?.comments, configFileOptions?.include?.comments))\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 getProxyOptions(configFileOptions?: ConfigFileParseResult | null) {\n if (configFileOptions?.request?.proxy && configFileOptions.request.proxy.url?.value?.trim()) {\n return {\n url: CLIOptionValidator.validateProxyURL(configFileOptions.request.proxy.url),\n rejectUnauthorizedTLS: CLIOptionValidator.validateBoolean(configFileOptions.request.proxy.rejectUnauthorizedTLS)\n };\n }\n return null;\n}\n\nfunction readTargetsFile(file: string) {\n const includeKeys = {\n lockedContent: 'include.locked.content',\n postsWithMediaType: 'include.posts.with.media.type',\n postsInTier: 'include.posts.in.tier',\n postsPublishedAfter: 'include.posts.published.after',\n postsPublishedBefore: 'include.posts.published.before',\n productsPublishedAfter: 'include.products.published.after',\n productsPublishedBefore: 'include.products.published.before',\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 mediaThumbnails: 'include.media.thumbnails',\n imagesByFilename: 'include.images.by.filename',\n audioByFilename: 'include.audio.by.filename',\n attachmentsByFilename: 'include.attachments.by.filename',\n comments: 'include.comments'\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?: RecursivePropsTo<DeepPartial<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 const entry: CLIOptionParserEntry = {\n key: matchKey,\n line: ln,\n src: 'tgt',\n value: propValue\n };\n if (!target.include) {\n target.include = {};\n }\n if (matchKey === includeKeys.postsPublishedAfter || matchKey === includeKeys.postsPublishedBefore) {\n if (!target.include.postsPublished) {\n target.include.postsPublished = {};\n }\n if (matchKey === includeKeys.postsPublishedAfter) {\n target.include.postsPublished.after = entry;\n }\n else {\n target.include.postsPublished.before = entry;\n }\n }\n else if (matchKey === includeKeys.productsPublishedAfter || matchKey === includeKeys.productsPublishedBefore) {\n if (!target.include.productsPublished) {\n target.include.productsPublished = {};\n }\n if (matchKey === includeKeys.productsPublishedAfter) {\n target.include.productsPublished.after = entry;\n }\n else {\n target.include.productsPublished.before = entry;\n }\n }\n else if (matchKey === includeKeys.imagesByFilename || matchKey === includeKeys.audioByFilename ||\n matchKey === includeKeys.attachmentsByFilename) {\n if (!target.include.mediaByFilename) {\n target.include.mediaByFilename = {};\n }\n switch (matchKey) {\n case includeKeys.imagesByFilename:\n target.include.mediaByFilename.images = entry;\n break;\n case includeKeys.audioByFilename:\n target.include.mediaByFilename.audio = entry;\n break;\n case includeKeys.attachmentsByFilename:\n target.include.mediaByFilename.attachments = entry;\n break;\n }\n }\n else {\n target.include[optName as keyof DownloaderIncludeOptions] = entry;\n }\n }\n }\n }\n else {\n const url = CLIOptionValidator.validateTargetURL(line);\n currentTargets.push({ url });\n }\n }\n catch (error: any) {\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 const includeOpts = ObjectHelper.clean(getCLIIncludeOptions(target), {\n deep: true, cleanNulls: true, cleanEmptyObjects: true\n });\n if (Object.entries(includeOpts).length > 0) {\n v.include = includeOpts;\n }\n }\n result.push(v);\n }\n\n return result;\n}\n"]}
@@ -3,6 +3,7 @@ import { type DeepPartial, type RecursivePropsTo } from '../utils/Misc.js';
3
3
  export interface CommandLineParseResult extends RecursivePropsTo<DeepPartial<Omit<CLIOptions, 'targetURLs'>>, CLIOptionParserEntry> {
4
4
  targetURLs?: CLIOptionParserEntry;
5
5
  configFile?: CLIOptionParserEntry;
6
+ debugAPI?: CLIOptionParserEntry;
6
7
  }
7
8
  export default class CommandLineParser {
8
9
  #private;
@@ -21,7 +21,8 @@ const COMMAND_LINE_ARGS = {
21
21
  noPrompt: 'no-prompt',
22
22
  dryRun: 'dry-run',
23
23
  listTiers: 'list-tiers',
24
- listTiersByUserId: 'list-tiers-uid'
24
+ listTiersByUserId: 'list-tiers-uid',
25
+ debugAPI: 'debug-api'
25
26
  };
26
27
  const OPT_DEFS = [
27
28
  {
@@ -105,6 +106,11 @@ const OPT_DEFS = [
105
106
  name: COMMAND_LINE_ARGS.configureYouTube,
106
107
  description: 'Configure YouTube connection',
107
108
  type: Boolean
109
+ },
110
+ {
111
+ name: COMMAND_LINE_ARGS.debugAPI,
112
+ description: 'Process target URL as local API data file ; internal - for debugging purposes.',
113
+ type: Boolean
108
114
  }
109
115
  ];
110
116
  class CommandLineParser {
@@ -126,7 +132,8 @@ class CommandLineParser {
126
132
  let value = opts[key];
127
133
  const booleanTypeArgs = [
128
134
  COMMAND_LINE_ARGS.noPrompt,
129
- COMMAND_LINE_ARGS.dryRun
135
+ COMMAND_LINE_ARGS.dryRun,
136
+ COMMAND_LINE_ARGS.debugAPI
130
137
  ];
131
138
  if (booleanTypeArgs.includes(key) && value !== undefined) {
132
139
  value = '1';
@@ -157,6 +164,7 @@ class CommandLineParser {
157
164
  return {
158
165
  configFile: __getValue(COMMAND_LINE_ARGS.configFile),
159
166
  targetURLs: __getValue(COMMAND_LINE_ARGS.targetURL),
167
+ debugAPI: __getValue(COMMAND_LINE_ARGS.debugAPI),
160
168
  cookie: __getValue(COMMAND_LINE_ARGS.cookie),
161
169
  useStatusCache: undefined,
162
170
  pathToFFmpeg: __getValue(COMMAND_LINE_ARGS.ffmpeg),
@@ -228,7 +236,7 @@ class CommandLineParser {
228
236
  {
229
237
  header: 'Options',
230
238
  optionList: OPT_DEFS,
231
- hide: 'target-url'
239
+ hide: ['target-url', COMMAND_LINE_ARGS.debugAPI]
232
240
  },
233
241
  {
234
242
  content: content.join(EOL)
@@ -1 +1 @@
1
- {"version":3,"file":"CommandLineParser.js","sourceRoot":"","sources":["../../src/cli/CommandLineParser.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O,CAAC;YACjB,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC;QAEF,MAAM,QAAQ,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC;QAC9C,MAAM,OAAO,GAAG,YAAY,CAAC,kBAAkB,CAAC,CAAC;QACjD,IAAI,QAAQ,KAAK,IAAI,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YAC1C,MAAM,GAAG,GAAG,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,kBAAkB,CAAC;YACpE,MAAM,KAAK,CAAC,IAAI,GAAG,iBAAiB,CAAC,CAAC;QACxC,CAAC;QAED,IAAI,QAAQ,KAAK,KAAK,IAAI,OAAO,KAAK,KAAK,EAAE,CAAC;YAC5C,OAAO,IAAI,CAAC;QACd,CAAC;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,CAAC;QACrB,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;IAC7D,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;eA/MkB,iBAAiB","sourcesContent":["import commandLineArgs from 'command-line-args';\nimport commandLineUsage from 'command-line-usage';\nimport { type CLIOptionParserEntry, type CLIOptions } from './CLIOptions.js';\nimport { EOL } from 'os';\nimport { type DeepPartial, type 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 deno: 'deno',\n outDir: 'out-dir',\n logLevel: 'log-level',\n noPrompt: 'no-prompt',\n dryRun: 'dry-run',\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.deno,\n description: 'Path to Deno executable',\n alias: 'd',\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.dryRun,\n description: 'Run without writing files to disk (except logs, if any). For testing / debugging.',\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\n const booleanTypeArgs = [\n COMMAND_LINE_ARGS.noPrompt,\n COMMAND_LINE_ARGS.dryRun\n ];\n if (booleanTypeArgs.includes(key as any) && value !== undefined) {\n value = '1';\n }\n\n 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 pathToDeno: __getValue(COMMAND_LINE_ARGS.deno),\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 mediaThumbnails: undefined\n },\n request: {\n maxRetries: undefined,\n maxConcurrent: undefined,\n minTime: undefined,\n userAgent: undefined\n },\n fileExistsAction: {\n content: undefined,\n info: undefined,\n infoAPI: undefined\n },\n noPrompt: __getValue(COMMAND_LINE_ARGS.noPrompt),\n dryRun: __getValue(COMMAND_LINE_ARGS.dryRun),\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: unknown) {\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: unknown) {\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: unknown) {\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
+ {"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;AAQzD,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,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,SAAS;IACjB,QAA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Q,KAAK,IAAI,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YAC1C,MAAM,GAAG,GAAG,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,kBAAkB,CAAC;YACpE,MAAM,KAAK,CAAC,IAAI,GAAG,iBAAiB,CAAC,CAAC;QACxC,CAAC;QAED,IAAI,QAAQ,KAAK,KAAK,IAAI,OAAO,KAAK,KAAK,EAAE,CAAC;YAC5C,OAAO,IAAI,CAAC;QACd,CAAC;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,CAAC;QACrB,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;IAC7D,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;eAjNkB,iBAAiB","sourcesContent":["import commandLineArgs from 'command-line-args';\nimport commandLineUsage from 'command-line-usage';\nimport { type CLIOptionParserEntry, type CLIOptions } from './CLIOptions.js';\nimport { EOL } from 'os';\nimport { type DeepPartial, type 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 debugAPI?: 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 deno: 'deno',\n outDir: 'out-dir',\n logLevel: 'log-level',\n noPrompt: 'no-prompt',\n dryRun: 'dry-run',\n listTiers: 'list-tiers',\n listTiersByUserId: 'list-tiers-uid',\n debugAPI: 'debug-api'\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.deno,\n description: 'Path to Deno executable',\n alias: 'd',\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.dryRun,\n description: 'Run without writing files to disk (except logs, if any). For testing / debugging.',\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 name: COMMAND_LINE_ARGS.debugAPI,\n description: 'Process target URL as local API data file ; internal - for debugging purposes.',\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\n const booleanTypeArgs = [\n COMMAND_LINE_ARGS.noPrompt,\n COMMAND_LINE_ARGS.dryRun,\n COMMAND_LINE_ARGS.debugAPI\n ];\n if (booleanTypeArgs.includes(key as any) && value !== undefined) {\n value = '1';\n }\n\n 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 debugAPI: __getValue(COMMAND_LINE_ARGS.debugAPI),\n cookie: __getValue(COMMAND_LINE_ARGS.cookie),\n useStatusCache: undefined,\n pathToFFmpeg: __getValue(COMMAND_LINE_ARGS.ffmpeg),\n pathToDeno: __getValue(COMMAND_LINE_ARGS.deno),\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 mediaThumbnails: undefined\n },\n request: {\n maxRetries: undefined,\n maxConcurrent: undefined,\n minTime: undefined,\n userAgent: undefined\n },\n fileExistsAction: {\n content: undefined,\n info: undefined,\n infoAPI: undefined\n },\n noPrompt: __getValue(COMMAND_LINE_ARGS.noPrompt),\n dryRun: __getValue(COMMAND_LINE_ARGS.dryRun),\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: unknown) {\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', COMMAND_LINE_ARGS.debugAPI]\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: unknown) {\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: unknown) {\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"]}
@@ -14,6 +14,9 @@ export interface ProductDownloaderBootstrapData extends BootstrapData {
14
14
  type: 'byShop';
15
15
  vanity: string;
16
16
  campaignId?: string;
17
+ } | {
18
+ type: 'byFile';
19
+ filePath: string;
17
20
  };
18
21
  }
19
22
  export interface PostDownloaderBootstrapData extends BootstrapData {
@@ -36,6 +39,9 @@ export interface PostDownloaderBootstrapData extends BootstrapData {
36
39
  collectionId: string;
37
40
  filters?: Record<string, any>;
38
41
  campaignId?: string;
42
+ } | {
43
+ type: 'byFile';
44
+ filePath: string;
39
45
  };
40
46
  }
41
47
  export type DownloaderBootstrapData<T extends DownloaderType> = T['type'] extends 'product' ? ProductDownloaderBootstrapData : T['type'] extends 'post' ? PostDownloaderBootstrapData : never;
@@ -1,6 +1,32 @@
1
+ import { existsSync } from 'fs';
1
2
  import URLHelper from '../utils/URLHelper.js';
3
+ import path from 'path';
2
4
  export default class Bootstrap {
3
5
  static getDownloaderBootstrapDataByURL(url) {
6
+ // Check if url points to local API data file.
7
+ // This is for debugging purposes.
8
+ const fileExists = existsSync(url);
9
+ if (fileExists && path.basename(url) === 'post-api.json') {
10
+ return {
11
+ type: 'post',
12
+ targetURL: url,
13
+ postFetch: {
14
+ type: 'byFile',
15
+ filePath: path.resolve(url)
16
+ }
17
+ };
18
+ }
19
+ // Likewise for 'product-api.json'
20
+ if (fileExists && path.basename(url) === 'product-api.json') {
21
+ return {
22
+ type: 'product',
23
+ targetURL: url,
24
+ productFetch: {
25
+ type: 'byFile',
26
+ filePath: path.resolve(url)
27
+ }
28
+ };
29
+ }
4
30
  const analysis = URLHelper.analyzeURL(url);
5
31
  if (!analysis) {
6
32
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"Bootstrap.js","sourceRoot":"","sources":["../../src/downloaders/Bootstrap.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,uBAAuB,CAAC;AAiD9C,MAAM,CAAC,OAAO,OAAO,SAAS;IAE5B,MAAM,CAAC,+BAA+B,CAAC,GAAW;QAChD,MAAM,QAAQ,GAAG,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAC3C,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,QAAQ,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAChC,OAAO;gBACL,IAAI,EAAE,SAAS;gBACf,SAAS,EAAE,GAAG;gBACd,YAAY,EAAE;oBACZ,IAAI,EAAE,QAAQ;oBACd,SAAS,EAAE,QAAQ,CAAC,SAAS;iBAC9B;aACgC,CAAC;QACtC,CAAC;QAED,IAAI,QAAQ,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC7B,OAAO;gBACL,IAAI,EAAE,SAAS;gBACf,SAA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CAAC;CACF","sourcesContent":["import { type Post } from '../entities/Post.js';\nimport { type Product } from '../entities/Product.js';\nimport URLHelper from '../utils/URLHelper.js';\n\nexport type DownloaderType = Product | Post;\n\nexport interface BootstrapData {\n type: string;\n targetURL: string;\n}\n\nexport interface ProductDownloaderBootstrapData extends BootstrapData {\n type: 'product';\n productFetch: {\n type: 'single';\n productId: string;\n } | {\n type: 'byShop';\n vanity: string;\n campaignId?: string;\n };\n}\n\nexport interface PostDownloaderBootstrapData extends BootstrapData {\n type: 'post';\n postFetch: {\n type: 'single';\n postId: string;\n } | {\n type: 'byUser';\n vanity: string;\n filters?: Record<string, any>;\n campaignId?: string;\n } | {\n type: 'byUserId';\n userId: string;\n filters?: Record<string, any>;\n campaignId?: string;\n } | {\n type: 'byCollection';\n collectionId: string;\n filters?: Record<string, any>;\n campaignId?: string;\n };\n}\n\nexport type DownloaderBootstrapData<T extends DownloaderType> =\n T['type'] extends 'product' ? ProductDownloaderBootstrapData :\n T['type'] extends 'post' ? PostDownloaderBootstrapData :\n never;\n\nexport default class Bootstrap {\n\n static getDownloaderBootstrapDataByURL(url: string) {\n const analysis = URLHelper.analyzeURL(url);\n if (!analysis) {\n return null;\n }\n\n if (analysis.type === 'product') {\n return {\n type: 'product',\n targetURL: url,\n productFetch: {\n type: 'single',\n productId: analysis.productId\n }\n } as ProductDownloaderBootstrapData;\n }\n\n if (analysis.type === 'shop') {\n return {\n type: 'product',\n targetURL: url,\n productFetch: {\n type: 'byShop',\n vanity: analysis.vanity\n }\n } as ProductDownloaderBootstrapData;\n }\n\n if (analysis.type === 'postsByUser') {\n return {\n type: 'post',\n targetURL: url,\n postFetch: {\n type: 'byUser',\n vanity: analysis.vanity,\n filters: analysis.filters\n }\n } as PostDownloaderBootstrapData;\n }\n\n if (analysis.type === 'postsByUserId') {\n return {\n type: 'post',\n targetURL: url,\n postFetch: {\n type: 'byUserId',\n userId: analysis.userId,\n filters: analysis.filters\n }\n } as PostDownloaderBootstrapData;\n }\n\n if (analysis.type === 'postsByCollection') {\n return {\n type: 'post',\n targetURL: url,\n postFetch: {\n type: 'byCollection',\n collectionId: analysis.collectionId,\n filters: analysis.filters\n }\n } as PostDownloaderBootstrapData;\n }\n\n if (analysis.type === 'post') {\n return {\n type: 'post',\n targetURL: url,\n postFetch: {\n type: 'single',\n postId: analysis.postId,\n slug: analysis.slug\n }\n } as PostDownloaderBootstrapData;\n }\n\n return null;\n }\n}\n"]}
1
+ {"version":3,"file":"Bootstrap.js","sourceRoot":"","sources":["../../src/downloaders/Bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAGhC,OAAO,SAAS,MAAM,uBAAuB,CAAC;AAC9C,OAAO,IAAI,MAAM,MAAM,CAAC;AAuDxB,MAAM,CAAC,OAAO,OAAO,SAAS;IAE5B,MAAM,CAAC,+BAA+B,CAAC,GAAW;QAChD,8CAA8C;QAC9C,kCAAkC;QAClC,MAAM,UAAU,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;QACnC,IAAI,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,eAAe,EAAE,CAAC;YACzD,OAAO;gBACL,IAAI,EAAE,MAAM;gBACZ,SAAS,EAAE,GAAG;gBACd,SAAS,EAAE;oBACT,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;iBAC5B;aACoC,CAAC;QAC1C,CAAC;QAED,kCAAkC;QAClC,IAAI,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,kBAAkB,EAAE,CAAC;YAC5D,OAAO;gBACL,IAAI,EAAE,SAAS;gBACf,SAAS,EAAE,GAAG;gBACd,YAAY,EAAE;oBACZ,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;iBAC5B;aACuC,CAAC;QAC7C,CAAC;QAED,MAAM,QAA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AAG;gBACd,SAAS,EAAE;oBACT,IAAI,EAAE,cAAc;oBACpB,YAAY,EAAE,QAAQ,CAAC,YAAY;oBACnC,OAAO,EAAE,QAAQ,CAAC,OAAO;iBAC1B;aAC6B,CAAC;QACnC,CAAC;QAED,IAAI,QAAQ,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC7B,OAAO;gBACL,IAAI,EAAE,MAAM;gBACZ,SAAS,EAAE,GAAG;gBACd,SAAS,EAAE;oBACT,IAAI,EAAE,QAAQ;oBACd,MAAM,EAAE,QAAQ,CAAC,MAAM;oBACvB,IAAI,EAAE,QAAQ,CAAC,IAAI;iBACpB;aAC6B,CAAC;QACnC,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import { existsSync } from 'fs';\nimport { type Post } from '../entities/Post.js';\nimport { type Product } from '../entities/Product.js';\nimport URLHelper from '../utils/URLHelper.js';\nimport path from 'path';\n\nexport type DownloaderType = Product | Post;\n\nexport interface BootstrapData {\n type: string;\n targetURL: string;\n}\n\nexport interface ProductDownloaderBootstrapData extends BootstrapData {\n type: 'product';\n productFetch: {\n type: 'single';\n productId: string;\n } | {\n type: 'byShop';\n vanity: string;\n campaignId?: string;\n } | {\n type: 'byFile';\n filePath: string;\n };\n}\n\nexport interface PostDownloaderBootstrapData extends BootstrapData {\n type: 'post';\n postFetch: {\n type: 'single';\n postId: string;\n } | {\n type: 'byUser';\n vanity: string;\n filters?: Record<string, any>;\n campaignId?: string;\n } | {\n type: 'byUserId';\n userId: string;\n filters?: Record<string, any>;\n campaignId?: string;\n } | {\n type: 'byCollection';\n collectionId: string;\n filters?: Record<string, any>;\n campaignId?: string;\n } | {\n type: 'byFile';\n filePath: string;\n };\n}\n\nexport type DownloaderBootstrapData<T extends DownloaderType> =\n T['type'] extends 'product' ? ProductDownloaderBootstrapData :\n T['type'] extends 'post' ? PostDownloaderBootstrapData :\n never;\n\nexport default class Bootstrap {\n\n static getDownloaderBootstrapDataByURL(url: string) {\n // Check if url points to local API data file.\n // This is for debugging purposes.\n const fileExists = existsSync(url);\n if (fileExists && path.basename(url) === 'post-api.json') {\n return {\n type: 'post',\n targetURL: url,\n postFetch: {\n type: 'byFile',\n filePath: path.resolve(url)\n }\n } satisfies PostDownloaderBootstrapData;\n }\n\n // Likewise for 'product-api.json'\n if (fileExists && path.basename(url) === 'product-api.json') {\n return {\n type: 'product',\n targetURL: url,\n productFetch: {\n type: 'byFile',\n filePath: path.resolve(url)\n }\n } satisfies ProductDownloaderBootstrapData;\n }\n\n const analysis = URLHelper.analyzeURL(url);\n if (!analysis) {\n return null;\n }\n\n if (analysis.type === 'product') {\n return {\n type: 'product',\n targetURL: url,\n productFetch: {\n type: 'single',\n productId: analysis.productId\n }\n } as ProductDownloaderBootstrapData;\n }\n\n if (analysis.type === 'shop') {\n return {\n type: 'product',\n targetURL: url,\n productFetch: {\n type: 'byShop',\n vanity: analysis.vanity\n }\n } as ProductDownloaderBootstrapData;\n }\n\n if (analysis.type === 'postsByUser') {\n return {\n type: 'post',\n targetURL: url,\n postFetch: {\n type: 'byUser',\n vanity: analysis.vanity,\n filters: analysis.filters\n }\n } as PostDownloaderBootstrapData;\n }\n\n if (analysis.type === 'postsByUserId') {\n return {\n type: 'post',\n targetURL: url,\n postFetch: {\n type: 'byUserId',\n userId: analysis.userId,\n filters: analysis.filters\n }\n } as PostDownloaderBootstrapData;\n }\n\n if (analysis.type === 'postsByCollection') {\n return {\n type: 'post',\n targetURL: url,\n postFetch: {\n type: 'byCollection',\n collectionId: analysis.collectionId,\n filters: analysis.filters\n }\n } as PostDownloaderBootstrapData;\n }\n\n if (analysis.type === 'post') {\n return {\n type: 'post',\n targetURL: url,\n postFetch: {\n type: 'single',\n postId: analysis.postId,\n slug: analysis.slug\n }\n } as PostDownloaderBootstrapData;\n }\n\n return null;\n }\n}\n"]}
@@ -22,6 +22,7 @@ export class InitialData {
22
22
  let fetchCurrentUserIdFromAPI = false;
23
23
  if (this.config.type === 'post' &&
24
24
  this.config.postFetch.type !== 'single' &&
25
+ this.config.postFetch.type !== 'byFile' &&
25
26
  this.config.postFetch.campaignId) {
26
27
  campaignId = this.config.postFetch.campaignId;
27
28
  fetchCurrentUserIdFromAPI = true;
@@ -1 +1 @@
1
- {"version":3,"file":"InitialData.js","sourceRoot":"","sources":["../../src/downloaders/InitialData.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,UAAU,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,YAAY,MAAM,0BAA0B,CAAC;AAGpD,MAAM,OAAO,WAAW;IAOtB,YAAY,MAA6B,EAAE,OAAgB,EAAE,MAAsB;;QANnF,SAAI,GAAG,aAAa,CAAC;QAOnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,MAAoB;QACzC,IAAI,UAAU,GAAkB,IAAI,CAAC;QACrC,IAAI,aAAa,GAAuB,SAAS,CAAC;QAClD,IAAI,yBAAyB,GAAG,KAAK,CAAC;QACtC,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,MAAM;YAC7B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,KAAK,QAAQ;YACvC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,EAChC,CAAC;YACD,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC;YAC9C,yBAAyB,GAAG,IAAI,CAAC;QACnC,CAAC;aACI,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS;YACrC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,KAAK,QAAQ;YAC1C,IA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AAC;IAMS,GAAG,CAAC,KAAe,EAAE,GAAG,GAAU;QAC1C,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC;IACnD,CAAC;CACF;8EAPC,KAAK,8CAAyB,GAAW;IACvC,OAAO,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import PageParser from \"../parsers/PageParser.js\";\nimport { URLHelper } from \"../utils/index.js\";\nimport type Fetcher from \"../utils/Fetcher.js\";\nimport { type Logger, type LogLevel } from \"../utils/logging/index.js\";\nimport { commonLog } from \"../utils/logging/Logger.js\";\nimport ObjectHelper from \"../utils/ObjectHelper.js\";\nimport { type DownloaderConfig } from \"./Downloader.js\";\n\nexport class InitialData {\n name = 'InitialData';\n\n protected config: DownloaderConfig<any>;\n protected fetcher: Fetcher;\n protected logger?: Logger | null;\n\n constructor(config: DownloaderConfig<any>, fetcher: Fetcher, logger?: Logger | null) {\n this.config = config;\n this.fetcher = fetcher;\n this.logger = logger;\n }\n\n async get(url: string, signal?: AbortSignal) {\n let campaignId: string | null = null;\n let currentUserId: string | undefined = undefined;\n let fetchCurrentUserIdFromAPI = false;\n if (this.config.type === 'post' &&\n this.config.postFetch.type !== 'single' &&\n this.config.postFetch.campaignId\n ) {\n campaignId = this.config.postFetch.campaignId;\n fetchCurrentUserIdFromAPI = true;\n }\n else if (this.config.type === 'product' &&\n this.config.productFetch.type === 'byShop' &&\n this.config.productFetch.campaignId\n ) {\n campaignId = this.config.productFetch.campaignId;\n fetchCurrentUserIdFromAPI = true;\n }\n if (!campaignId) {\n this.log('debug', `Fetch initial data from \"${url}\"`);\n let page;\n try {\n const { html, lastUrl } = await this.fetcher.get({ url, type: 'html', maxRetries: this.config.request.maxRetries, signal });\n page = html;\n if (new URL(lastUrl).pathname === '/login-sync-domains') {\n this.log('debug', `Detected Cloudflare challenge flow at \"${lastUrl}\"`);\n page = await this.#fetchPageWithPuppeteer(url);\n // Because cookie not available to Puppeteer, we need to fetch \n // current user ID separately\n fetchCurrentUserIdFromAPI = !!this.config.cookie;\n }\n }\n catch (error) {\n if (signal?.aborted) {\n throw error;\n }\n const e = Error(`Error requesting \"${url}\"`);\n e.cause = error;\n throw e;\n }\n const pageParser = new PageParser(this.logger);\n let initialData;\n try {\n initialData = pageParser.parseInitialData(page, url);\n }\n catch (error) {\n const e = Error(`Error parsing initial data from \"${url}\"`);\n e.cause = error;\n throw e;\n }\n campaignId = ObjectHelper.getProperty(initialData, 'pageBootstrap.campaign.data.id');\n currentUserId = ObjectHelper.getProperty(initialData, 'commonBootstrap.currentUser.data.id');\n if (!campaignId) {\n throw Error(`Campaign ID not found in initial data of \"${url}\"`);\n }\n }\n if (fetchCurrentUserIdFromAPI) {\n this.log('debug', `Fetch current user ID from API`);\n const currentUserAPIURL = URLHelper.constructCurrentUserAPIURL();\n const { json: currentUserJson } = await this.fetcher.get({\n url: currentUserAPIURL,\n type: 'json',\n maxRetries: this.config.request.maxRetries,\n signal\n });\n currentUserId = ObjectHelper.getProperty(currentUserJson, 'data.id') || undefined;\n }\n this.log('debug', `Initial data: campaign ID '${campaignId}'; current user ID '${currentUserId}'`);\n return { campaignId, currentUserId };\n }\n\n async #fetchPageWithPuppeteer(url: string) {\n return this.fetcher.getPageWithPuppeteer(url);\n }\n\n protected log(level: LogLevel, ...msg: any[]) {\n commonLog(this.logger, level, this.name, ...msg);\n }\n}"]}
1
+ {"version":3,"file":"InitialData.js","sourceRoot":"","sources":["../../src/downloaders/InitialData.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,UAAU,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,YAAY,MAAM,0BAA0B,CAAC;AAGpD,MAAM,OAAO,WAAW;IAOtB,YAAY,MA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gC,CAAC,CAAC;YACrF,aAAa,GAAG,YAAY,CAAC,WAAW,CAAC,WAAW,EAAE,qCAAqC,CAAC,CAAC;YAC7F,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,MAAM,KAAK,CAAC,6CAA6C,GAAG,GAAG,CAAC,CAAC;YACnE,CAAC;QACH,CAAC;QACD,IAAI,yBAAyB,EAAE,CAAC;YAC9B,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,gCAAgC,CAAC,CAAC;YACpD,MAAM,iBAAiB,GAAG,SAAS,CAAC,0BAA0B,EAAE,CAAC;YACjE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;gBACvD,GAAG,EAAE,iBAAiB;gBACtB,IAAI,EAAE,MAAM;gBACZ,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU;gBAC1C,MAAM;aACP,CAAC,CAAC;YACH,aAAa,GAAG,YAAY,CAAC,WAAW,CAAC,eAAe,EAAE,SAAS,CAAC,IAAI,SAAS,CAAC;QACpF,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,8BAA8B,UAAU,uBAAuB,aAAa,GAAG,CAAC,CAAC;QACnG,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;IACvC,CAAC;IAMS,GAAG,CAAC,KAAe,EAAE,GAAG,GAAU;QAC1C,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC;IACnD,CAAC;CACF;8EAPC,KAAK,8CAAyB,GAAW;IACvC,OAAO,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import PageParser from \"../parsers/PageParser.js\";\nimport { URLHelper } from \"../utils/index.js\";\nimport type Fetcher from \"../utils/Fetcher.js\";\nimport { type Logger, type LogLevel } from \"../utils/logging/index.js\";\nimport { commonLog } from \"../utils/logging/Logger.js\";\nimport ObjectHelper from \"../utils/ObjectHelper.js\";\nimport { type DownloaderConfig } from \"./Downloader.js\";\n\nexport class InitialData {\n name = 'InitialData';\n\n protected config: DownloaderConfig<any>;\n protected fetcher: Fetcher;\n protected logger?: Logger | null;\n\n constructor(config: DownloaderConfig<any>, fetcher: Fetcher, logger?: Logger | null) {\n this.config = config;\n this.fetcher = fetcher;\n this.logger = logger;\n }\n\n async get(url: string, signal?: AbortSignal) {\n let campaignId: string | null = null;\n let currentUserId: string | undefined = undefined;\n let fetchCurrentUserIdFromAPI = false;\n if (this.config.type === 'post' &&\n this.config.postFetch.type !== 'single' &&\n this.config.postFetch.type !== 'byFile' &&\n this.config.postFetch.campaignId\n ) {\n campaignId = this.config.postFetch.campaignId;\n fetchCurrentUserIdFromAPI = true;\n }\n else if (this.config.type === 'product' &&\n this.config.productFetch.type === 'byShop' &&\n this.config.productFetch.campaignId\n ) {\n campaignId = this.config.productFetch.campaignId;\n fetchCurrentUserIdFromAPI = true;\n }\n if (!campaignId) {\n this.log('debug', `Fetch initial data from \"${url}\"`);\n let page;\n try {\n const { html, lastUrl } = await this.fetcher.get({ url, type: 'html', maxRetries: this.config.request.maxRetries, signal });\n page = html;\n if (new URL(lastUrl).pathname === '/login-sync-domains') {\n this.log('debug', `Detected Cloudflare challenge flow at \"${lastUrl}\"`);\n page = await this.#fetchPageWithPuppeteer(url);\n // Because cookie not available to Puppeteer, we need to fetch \n // current user ID separately\n fetchCurrentUserIdFromAPI = !!this.config.cookie;\n }\n }\n catch (error) {\n if (signal?.aborted) {\n throw error;\n }\n const e = Error(`Error requesting \"${url}\"`);\n e.cause = error;\n throw e;\n }\n const pageParser = new PageParser(this.logger);\n let initialData;\n try {\n initialData = pageParser.parseInitialData(page, url);\n }\n catch (error) {\n const e = Error(`Error parsing initial data from \"${url}\"`);\n e.cause = error;\n throw e;\n }\n campaignId = ObjectHelper.getProperty(initialData, 'pageBootstrap.campaign.data.id');\n currentUserId = ObjectHelper.getProperty(initialData, 'commonBootstrap.currentUser.data.id');\n if (!campaignId) {\n throw Error(`Campaign ID not found in initial data of \"${url}\"`);\n }\n }\n if (fetchCurrentUserIdFromAPI) {\n this.log('debug', `Fetch current user ID from API`);\n const currentUserAPIURL = URLHelper.constructCurrentUserAPIURL();\n const { json: currentUserJson } = await this.fetcher.get({\n url: currentUserAPIURL,\n type: 'json',\n maxRetries: this.config.request.maxRetries,\n signal\n });\n currentUserId = ObjectHelper.getProperty(currentUserJson, 'data.id') || undefined;\n }\n this.log('debug', `Initial data: campaign ID '${campaignId}'; current user ID '${currentUserId}'`);\n return { campaignId, currentUserId };\n }\n\n async #fetchPageWithPuppeteer(url: string) {\n return this.fetcher.getPageWithPuppeteer(url);\n }\n\n protected log(level: LogLevel, ...msg: any[]) {\n commonLog(this.logger, level, this.name, ...msg);\n }\n}"]}
@@ -97,6 +97,9 @@ _PostDownloader_startPromise = new WeakMap(), _PostDownloader_context = new Weak
97
97
  else if (postFetch.type === 'byCollection') {
98
98
  this.log('info', `Targeting posts in collection #${postFetch.collectionId}`);
99
99
  }
100
+ else if (postFetch.type === 'byFile') {
101
+ this.log('info', `Target post given by API data in "${postFetch.filePath}"`);
102
+ }
100
103
  else { // Single
101
104
  this.log('info', `Targeting post #${postFetch.postId}`);
102
105
  }
@@ -264,6 +267,9 @@ _PostDownloader_startPromise = new WeakMap(), _PostDownloader_context = new Weak
264
267
  else if (postFetch.type === 'byCollection') {
265
268
  this.log('info', `Done downloading posts in collection #${postFetch.collectionId}`);
266
269
  }
270
+ else if (postFetch.type === 'byFile') {
271
+ this.log('info', `Done downloading post given in "${postFetch.filePath}"`);
272
+ }
267
273
  else {
268
274
  this.log('info', `Done downloading post #${postFetch.postId}`);
269
275
  }