podcast-dl 7.2.0 → 7.3.2

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/bin/async.js CHANGED
@@ -22,6 +22,7 @@ import {
22
22
  writeItemMeta,
23
23
  writeToArchive,
24
24
  getUrlEmbed,
25
+ getIsInArchive,
25
26
  } from "./util.js";
26
27
 
27
28
  const pipeline = promisify(stream.pipeline);
@@ -44,6 +45,11 @@ const download = async ({
44
45
  return;
45
46
  }
46
47
 
48
+ if (key && archive && getIsInArchive({ key, archive })) {
49
+ logMessage("Download exists in archive. Skipping...");
50
+ return;
51
+ }
52
+
47
53
  let embeddedUrl = null;
48
54
  if (filterUrlTracking) {
49
55
  logMessage("Attempting to find embedded URL...");
@@ -125,14 +131,6 @@ const download = async ({
125
131
 
126
132
  fs.renameSync(tempOutputPath, outputPath);
127
133
 
128
- if (expectedSize && !isNaN(expectedSize) && expectedSize !== fileSize) {
129
- logMessage(
130
- "File size differs from expected content length. Suggestion: verify file works as expected",
131
- LOG_LEVELS.important
132
- );
133
- logMessage(`${outputPath}`, LOG_LEVELS.important);
134
- }
135
-
136
134
  logMessage("Download complete!");
137
135
 
138
136
  if (onAfterDownload) {
package/bin/bin.js CHANGED
@@ -293,6 +293,24 @@ const main = async () => {
293
293
  filterUrlTracking,
294
294
  });
295
295
 
296
+ if (hasErrors && numEpisodesDownloaded !== targetItems.length) {
297
+ logMessage(
298
+ `\n${numEpisodesDownloaded} of ${pluralize(
299
+ "episode",
300
+ targetItems.length,
301
+ true
302
+ )} downloaded\n`
303
+ );
304
+ } else if (numEpisodesDownloaded > 0) {
305
+ logMessage(
306
+ `\nSuccessfully downloaded ${pluralize(
307
+ "episode",
308
+ numEpisodesDownloaded,
309
+ true
310
+ )}\n`
311
+ );
312
+ }
313
+
296
314
  if (numEpisodesDownloaded === 0) {
297
315
  process.exit(ERROR_STATUSES.nothingDownloaded);
298
316
  }
package/bin/util.js CHANGED
@@ -97,28 +97,28 @@ const getUrlEmbed = async (url) => {
97
97
  return null;
98
98
  };
99
99
 
100
- const getLoopControls = ({ limit, offset, length, reverse }) => {
100
+ const getLoopControls = ({ offset, length, reverse }) => {
101
101
  if (reverse) {
102
102
  const startIndex = length - 1 - offset;
103
- const min = limit ? Math.max(startIndex - limit, -1) : -1;
104
- const limitCheck = (i) => i > min;
103
+ const min = -1;
104
+ const shouldGo = (i) => i > min;
105
105
  const decrement = (i) => i - 1;
106
106
 
107
107
  return {
108
108
  startIndex,
109
- limitCheck,
109
+ shouldGo,
110
110
  next: decrement,
111
111
  };
112
112
  }
113
113
 
114
114
  const startIndex = 0 + offset;
115
- const max = limit ? Math.min(startIndex + limit, length) : length;
116
- const limitCheck = (i) => i < max;
115
+ const max = length;
116
+ const shouldGo = (i) => i < max;
117
117
  const increment = (i) => i + 1;
118
118
 
119
119
  return {
120
120
  startIndex,
121
- limitCheck,
121
+ shouldGo,
122
122
  next: increment,
123
123
  };
124
124
  };
@@ -137,8 +137,7 @@ const getItemsToDownload = ({
137
137
  episodeTemplate,
138
138
  includeEpisodeImages,
139
139
  }) => {
140
- const { startIndex, limitCheck, next } = getLoopControls({
141
- limit,
140
+ const { startIndex, shouldGo, next } = getLoopControls({
142
141
  offset,
143
142
  reverse,
144
143
  length: feed.items.length,
@@ -149,7 +148,7 @@ const getItemsToDownload = ({
149
148
 
150
149
  const savedArchive = archive ? getArchive(archive) : [];
151
150
 
152
- while (limitCheck(i)) {
151
+ while (shouldGo(i)) {
153
152
  const { title, pubDate } = feed.items[i];
154
153
  const pubDateDay = dayjs(new Date(pubDate));
155
154
  let isValid = true;
@@ -215,22 +214,20 @@ const getItemsToDownload = ({
215
214
  }),
216
215
  });
217
216
 
218
- if (!savedArchive.includes(episodeImageArchiveKey)) {
219
- const episodeImageName = getFilename({
220
- item,
221
- feed,
222
- url: episodeAudioUrl,
223
- ext: episodeImageFileExt,
224
- template: episodeTemplate,
225
- });
226
-
227
- const outputImagePath = path.resolve(basePath, episodeImageName);
228
- item._extra_downloads.push({
229
- url: episodeImageUrl,
230
- outputPath: outputImagePath,
231
- key: episodeImageArchiveKey,
232
- });
233
- }
217
+ const episodeImageName = getFilename({
218
+ item,
219
+ feed,
220
+ url: episodeAudioUrl,
221
+ ext: episodeImageFileExt,
222
+ template: episodeTemplate,
223
+ });
224
+
225
+ const outputImagePath = path.resolve(basePath, episodeImageName);
226
+ item._extra_downloads.push({
227
+ url: episodeImageUrl,
228
+ outputPath: outputImagePath,
229
+ key: episodeImageArchiveKey,
230
+ });
234
231
  }
235
232
  }
236
233
 
@@ -240,7 +237,7 @@ const getItemsToDownload = ({
240
237
  i = next(i);
241
238
  }
242
239
 
243
- return items;
240
+ return limit ? items.slice(0, limit) : items;
244
241
  };
245
242
 
246
243
  const logFeedInfo = (feed) => {
@@ -295,34 +292,24 @@ const logItemsList = ({
295
292
 
296
293
  const writeFeedMeta = ({ outputPath, feed, key, archive, override }) => {
297
294
  if (key && archive && getIsInArchive({ key, archive })) {
298
- logMessage("Feed metadata exists in archive. Skipping write...");
295
+ logMessage("Feed metadata exists in archive. Skipping...");
299
296
  return;
300
297
  }
301
298
 
302
- const title = feed.title || null;
303
- const description = feed.description || null;
304
- const link = feed.link || null;
305
- const feedUrl = feed.feedUrl || null;
306
- const managingEditor = feed.managingEditor || null;
299
+ const output = {};
300
+ ["title", "description", "link", "feedUrl", "managingEditor"].forEach(
301
+ (key) => {
302
+ if (feed[key]) {
303
+ output[key] = feed[key];
304
+ }
305
+ }
306
+ );
307
307
 
308
308
  try {
309
309
  if (override || !fs.existsSync(outputPath)) {
310
- fs.writeFileSync(
311
- outputPath,
312
- JSON.stringify(
313
- {
314
- title,
315
- description,
316
- link,
317
- feedUrl,
318
- managingEditor,
319
- },
320
- null,
321
- 4
322
- )
323
- );
310
+ fs.writeFileSync(outputPath, JSON.stringify(output, null, 4));
324
311
  } else {
325
- logMessage("Feed metadata exists locally. Skipping write...");
312
+ logMessage("Feed metadata exists locally. Skipping...");
326
313
  }
327
314
 
328
315
  if (key && archive && !getIsInArchive({ key, archive })) {
@@ -348,36 +335,22 @@ const writeItemMeta = ({
348
335
  override,
349
336
  }) => {
350
337
  if (key && archive && getIsInArchive({ key, archive })) {
351
- logMessage(
352
- `${marker} | Episode metadata exists in archive. Skipping write...`
353
- );
338
+ logMessage(`${marker} | Episode metadata exists in archive. Skipping...`);
354
339
  return;
355
340
  }
356
341
 
357
- const title = item.title || null;
358
- const descriptionText = item.contentSnippet || null;
359
- const pubDate = item.pubDate || null;
360
- const creator = item.creator || null;
342
+ const output = {};
343
+ ["title", "contentSnippet", "pubDate", "creator"].forEach((key) => {
344
+ if (item[key]) {
345
+ output[key] = item[key];
346
+ }
347
+ });
361
348
 
362
349
  try {
363
350
  if (override || !fs.existsSync(outputPath)) {
364
- fs.writeFileSync(
365
- outputPath,
366
- JSON.stringify(
367
- {
368
- title,
369
- pubDate,
370
- creator,
371
- descriptionText,
372
- },
373
- null,
374
- 4
375
- )
376
- );
351
+ fs.writeFileSync(outputPath, JSON.stringify(output, null, 4));
377
352
  } else {
378
- logMessage(
379
- `${marker} | Episode metadata exists locally. Skipping write...`
380
- );
353
+ logMessage(`${marker} | Episode metadata exists locally. Skipping...`);
381
354
  }
382
355
 
383
356
  if (key && archive && !getIsInArchive({ key, archive })) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "podcast-dl",
3
- "version": "7.2.0",
3
+ "version": "7.3.2",
4
4
  "description": "A CLI for downloading podcasts.",
5
5
  "type": "module",
6
6
  "bin": "./bin/bin.js",