podcast-dl 11.1.1 → 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +121 -120
- package/bin/archive.js +39 -39
- package/bin/async.js +370 -370
- package/bin/bin.js +292 -289
- package/bin/commander.js +198 -193
- package/bin/exec.js +30 -30
- package/bin/ffmpeg.js +105 -105
- package/bin/items.js +247 -237
- package/bin/logger.js +84 -84
- package/bin/meta.js +66 -66
- package/bin/naming.js +112 -112
- package/bin/util.js +299 -299
- package/bin/validate.js +39 -39
- package/package.json +62 -62
package/bin/bin.js
CHANGED
|
@@ -1,289 +1,292 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { program } from "commander";
|
|
4
|
-
import fs from "fs";
|
|
5
|
-
import { bootstrap as bootstrapProxy } from "global-agent";
|
|
6
|
-
import _path from "path";
|
|
7
|
-
import pluralize from "pluralize";
|
|
8
|
-
import { getArchiveKey } from "./archive.js";
|
|
9
|
-
import { download, downloadItemsAsync } from "./async.js";
|
|
10
|
-
import { setupCommander } from "./commander.js";
|
|
11
|
-
import { getItemsToDownload, logItemsList } from "./items.js";
|
|
12
|
-
import {
|
|
13
|
-
ERROR_STATUSES,
|
|
14
|
-
LOG_LEVELS,
|
|
15
|
-
logError,
|
|
16
|
-
logErrorAndExit,
|
|
17
|
-
logMessage,
|
|
18
|
-
} from "./logger.js";
|
|
19
|
-
import { writeFeedMeta } from "./meta.js";
|
|
20
|
-
import { getFolderName, getSimpleFilename } from "./naming.js";
|
|
21
|
-
import {
|
|
22
|
-
getFileFeed,
|
|
23
|
-
getImageUrl,
|
|
24
|
-
getUrlExt,
|
|
25
|
-
getUrlFeed,
|
|
26
|
-
logFeedInfo,
|
|
27
|
-
} from "./util.js";
|
|
28
|
-
|
|
29
|
-
const opts = setupCommander(program);
|
|
30
|
-
|
|
31
|
-
const {
|
|
32
|
-
after,
|
|
33
|
-
alwaysPostprocess,
|
|
34
|
-
attempts,
|
|
35
|
-
before,
|
|
36
|
-
episodeDigits,
|
|
37
|
-
episodeNumOffset,
|
|
38
|
-
episodeRegex,
|
|
39
|
-
episodeRegexExclude,
|
|
40
|
-
episodeSourceOrder,
|
|
41
|
-
episodeTemplate,
|
|
42
|
-
episodeCustomTemplateOptions,
|
|
43
|
-
episodeTranscriptTypes,
|
|
44
|
-
exec,
|
|
45
|
-
file,
|
|
46
|
-
includeEpisodeImages,
|
|
47
|
-
includeEpisodeMeta,
|
|
48
|
-
includeEpisodeTranscripts,
|
|
49
|
-
includeMeta,
|
|
50
|
-
info,
|
|
51
|
-
limit,
|
|
52
|
-
list,
|
|
53
|
-
mono,
|
|
54
|
-
offset,
|
|
55
|
-
outDir,
|
|
56
|
-
override,
|
|
57
|
-
parserConfig,
|
|
58
|
-
proxy,
|
|
59
|
-
reverse,
|
|
60
|
-
threads,
|
|
61
|
-
url,
|
|
62
|
-
addMp3Metadata: addMp3MetadataFlag,
|
|
63
|
-
adjustBitrate: bitrate,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { program } from "commander";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import { bootstrap as bootstrapProxy } from "global-agent";
|
|
6
|
+
import _path from "path";
|
|
7
|
+
import pluralize from "pluralize";
|
|
8
|
+
import { getArchiveKey } from "./archive.js";
|
|
9
|
+
import { download, downloadItemsAsync } from "./async.js";
|
|
10
|
+
import { setupCommander } from "./commander.js";
|
|
11
|
+
import { getItemsToDownload, logItemsList } from "./items.js";
|
|
12
|
+
import {
|
|
13
|
+
ERROR_STATUSES,
|
|
14
|
+
LOG_LEVELS,
|
|
15
|
+
logError,
|
|
16
|
+
logErrorAndExit,
|
|
17
|
+
logMessage,
|
|
18
|
+
} from "./logger.js";
|
|
19
|
+
import { writeFeedMeta } from "./meta.js";
|
|
20
|
+
import { getFolderName, getSimpleFilename } from "./naming.js";
|
|
21
|
+
import {
|
|
22
|
+
getFileFeed,
|
|
23
|
+
getImageUrl,
|
|
24
|
+
getUrlExt,
|
|
25
|
+
getUrlFeed,
|
|
26
|
+
logFeedInfo,
|
|
27
|
+
} from "./util.js";
|
|
28
|
+
|
|
29
|
+
const opts = setupCommander(program);
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
after,
|
|
33
|
+
alwaysPostprocess,
|
|
34
|
+
attempts,
|
|
35
|
+
before,
|
|
36
|
+
episodeDigits,
|
|
37
|
+
episodeNumOffset,
|
|
38
|
+
episodeRegex,
|
|
39
|
+
episodeRegexExclude,
|
|
40
|
+
episodeSourceOrder,
|
|
41
|
+
episodeTemplate,
|
|
42
|
+
episodeCustomTemplateOptions,
|
|
43
|
+
episodeTranscriptTypes,
|
|
44
|
+
exec,
|
|
45
|
+
file,
|
|
46
|
+
includeEpisodeImages,
|
|
47
|
+
includeEpisodeMeta,
|
|
48
|
+
includeEpisodeTranscripts,
|
|
49
|
+
includeMeta,
|
|
50
|
+
info,
|
|
51
|
+
limit,
|
|
52
|
+
list,
|
|
53
|
+
mono,
|
|
54
|
+
offset,
|
|
55
|
+
outDir,
|
|
56
|
+
override,
|
|
57
|
+
parserConfig,
|
|
58
|
+
proxy,
|
|
59
|
+
reverse,
|
|
60
|
+
threads,
|
|
61
|
+
url,
|
|
62
|
+
addMp3Metadata: addMp3MetadataFlag,
|
|
63
|
+
adjustBitrate: bitrate,
|
|
64
|
+
season,
|
|
65
|
+
} = opts;
|
|
66
|
+
|
|
67
|
+
let { archive } = opts;
|
|
68
|
+
|
|
69
|
+
const main = async () => {
|
|
70
|
+
if (!url && !file) {
|
|
71
|
+
logErrorAndExit("No URL or file location provided");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (url && file) {
|
|
75
|
+
logErrorAndExit("Must not use URL and file location");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (proxy) {
|
|
79
|
+
bootstrapProxy();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const feed = url
|
|
83
|
+
? await getUrlFeed(url, parserConfig)
|
|
84
|
+
: await getFileFeed(file, parserConfig);
|
|
85
|
+
|
|
86
|
+
const archivePrefix = (() => {
|
|
87
|
+
if (feed.feedUrl || url) {
|
|
88
|
+
const { hostname, pathname } = new URL(feed.feedUrl || url);
|
|
89
|
+
return `${hostname}${pathname}`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return feed.title || file;
|
|
93
|
+
})();
|
|
94
|
+
|
|
95
|
+
const basePath = _path.resolve(
|
|
96
|
+
process.cwd(),
|
|
97
|
+
getFolderName({ feed, template: outDir })
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
if (info) {
|
|
101
|
+
logFeedInfo(feed);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (list) {
|
|
105
|
+
if (feed?.items?.length) {
|
|
106
|
+
const listFormat = typeof list === "boolean" ? "table" : list;
|
|
107
|
+
logItemsList({
|
|
108
|
+
type: listFormat,
|
|
109
|
+
feed,
|
|
110
|
+
limit,
|
|
111
|
+
offset,
|
|
112
|
+
reverse,
|
|
113
|
+
after,
|
|
114
|
+
before,
|
|
115
|
+
episodeRegex,
|
|
116
|
+
episodeRegexExclude,
|
|
117
|
+
season,
|
|
118
|
+
});
|
|
119
|
+
} else {
|
|
120
|
+
logErrorAndExit("No episodes found to list");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (info || list) {
|
|
125
|
+
process.exit(0);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
logFeedInfo(feed);
|
|
129
|
+
|
|
130
|
+
if (!fs.existsSync(basePath)) {
|
|
131
|
+
logMessage(`${basePath} does not exist. Creating...`, LOG_LEVELS.important);
|
|
132
|
+
fs.mkdirSync(basePath, { recursive: true });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (archive) {
|
|
136
|
+
archive =
|
|
137
|
+
typeof archive === "boolean"
|
|
138
|
+
? "./{{podcast_title}}/archive.json"
|
|
139
|
+
: archive;
|
|
140
|
+
archive = getFolderName({ feed, template: archive });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (includeMeta) {
|
|
144
|
+
const podcastImageUrl = getImageUrl(feed);
|
|
145
|
+
|
|
146
|
+
if (podcastImageUrl) {
|
|
147
|
+
const podcastImageFileExt = getUrlExt(podcastImageUrl);
|
|
148
|
+
const outputImagePath = _path.resolve(
|
|
149
|
+
basePath,
|
|
150
|
+
getSimpleFilename(
|
|
151
|
+
feed.title ? feed.title : "image",
|
|
152
|
+
feed.title ? `.image${podcastImageFileExt}` : podcastImageFileExt
|
|
153
|
+
)
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
try {
|
|
157
|
+
logMessage("\nDownloading podcast image...");
|
|
158
|
+
await download({
|
|
159
|
+
archive,
|
|
160
|
+
override,
|
|
161
|
+
marker: podcastImageUrl,
|
|
162
|
+
key: getArchiveKey({
|
|
163
|
+
prefix: archivePrefix,
|
|
164
|
+
name: `${
|
|
165
|
+
feed.title ? `${feed.title}.image` : "image"
|
|
166
|
+
}${podcastImageFileExt}`,
|
|
167
|
+
}),
|
|
168
|
+
outputPath: outputImagePath,
|
|
169
|
+
url: podcastImageUrl,
|
|
170
|
+
maxAttempts: attempts,
|
|
171
|
+
});
|
|
172
|
+
} catch (error) {
|
|
173
|
+
logError("Unable to download podcast image", error);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const outputMetaPath = _path.resolve(
|
|
178
|
+
basePath,
|
|
179
|
+
getSimpleFilename(
|
|
180
|
+
feed.title ? feed.title : "meta",
|
|
181
|
+
feed.title ? ".meta.json" : ".json"
|
|
182
|
+
)
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
try {
|
|
186
|
+
logMessage("\nSaving podcast metadata...");
|
|
187
|
+
writeFeedMeta({
|
|
188
|
+
archive,
|
|
189
|
+
override,
|
|
190
|
+
feed,
|
|
191
|
+
key: getArchiveKey({
|
|
192
|
+
prefix: archivePrefix,
|
|
193
|
+
name: `${feed.title ? `${feed.title}.meta` : "meta"}.json`,
|
|
194
|
+
}),
|
|
195
|
+
outputPath: outputMetaPath,
|
|
196
|
+
});
|
|
197
|
+
} catch (error) {
|
|
198
|
+
logError("Unable to save podcast metadata", error);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (!feed.items || feed.items.length === 0) {
|
|
203
|
+
logErrorAndExit("No episodes found to download");
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (offset >= feed.items.length) {
|
|
207
|
+
logErrorAndExit("--offset too large. No episodes to download.");
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const targetItems = getItemsToDownload({
|
|
211
|
+
archive,
|
|
212
|
+
archivePrefix,
|
|
213
|
+
addMp3MetadataFlag,
|
|
214
|
+
basePath,
|
|
215
|
+
feed,
|
|
216
|
+
limit,
|
|
217
|
+
offset,
|
|
218
|
+
reverse,
|
|
219
|
+
after,
|
|
220
|
+
before,
|
|
221
|
+
episodeDigits,
|
|
222
|
+
episodeNumOffset,
|
|
223
|
+
episodeRegex,
|
|
224
|
+
episodeRegexExclude,
|
|
225
|
+
episodeSourceOrder,
|
|
226
|
+
episodeTemplate,
|
|
227
|
+
episodeCustomTemplateOptions,
|
|
228
|
+
includeEpisodeImages,
|
|
229
|
+
includeEpisodeTranscripts,
|
|
230
|
+
episodeTranscriptTypes,
|
|
231
|
+
season,
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
if (!targetItems.length) {
|
|
235
|
+
logErrorAndExit("No episodes found with provided criteria to download");
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
logMessage(
|
|
239
|
+
`\nStarting download of ${pluralize("episode", targetItems.length, true)}\n`
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
const { numEpisodesDownloaded, hasErrors } = await downloadItemsAsync({
|
|
243
|
+
addMp3MetadataFlag,
|
|
244
|
+
archive,
|
|
245
|
+
archivePrefix,
|
|
246
|
+
attempts,
|
|
247
|
+
basePath,
|
|
248
|
+
bitrate,
|
|
249
|
+
episodeTemplate,
|
|
250
|
+
episodeCustomTemplateOptions,
|
|
251
|
+
episodeDigits,
|
|
252
|
+
episodeNumOffset,
|
|
253
|
+
episodeSourceOrder,
|
|
254
|
+
exec,
|
|
255
|
+
feed,
|
|
256
|
+
includeEpisodeImages,
|
|
257
|
+
includeEpisodeMeta,
|
|
258
|
+
mono,
|
|
259
|
+
override,
|
|
260
|
+
alwaysPostprocess,
|
|
261
|
+
targetItems,
|
|
262
|
+
threads,
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
if (hasErrors && numEpisodesDownloaded !== targetItems.length) {
|
|
266
|
+
logMessage(
|
|
267
|
+
`\n${numEpisodesDownloaded} of ${pluralize(
|
|
268
|
+
"episode",
|
|
269
|
+
targetItems.length,
|
|
270
|
+
true
|
|
271
|
+
)} downloaded\n`
|
|
272
|
+
);
|
|
273
|
+
} else if (numEpisodesDownloaded > 0) {
|
|
274
|
+
logMessage(
|
|
275
|
+
`\nSuccessfully downloaded ${pluralize(
|
|
276
|
+
"episode",
|
|
277
|
+
numEpisodesDownloaded,
|
|
278
|
+
true
|
|
279
|
+
)}\n`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (numEpisodesDownloaded === 0) {
|
|
284
|
+
process.exit(ERROR_STATUSES.nothingDownloaded);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (hasErrors) {
|
|
288
|
+
process.exit(ERROR_STATUSES.completedWithErrors);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
main();
|