podcast-dl 9.1.0 → 9.2.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/LICENSE +21 -21
- package/bin/async.js +316 -313
- package/bin/bin.js +261 -261
- package/bin/commander.js +2 -1
- package/bin/logger.js +92 -92
- package/bin/naming.js +96 -85
- package/bin/util.js +593 -565
- package/bin/validate.js +43 -43
- package/bin/version.js +2 -0
- package/package.json +63 -62
package/bin/logger.js
CHANGED
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
const ERROR_STATUSES = {
|
|
2
|
-
general: 1,
|
|
3
|
-
nothingDownloaded: 2,
|
|
4
|
-
completedWithErrors: 3,
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
const LOG_LEVEL_TYPES = {
|
|
8
|
-
debug: "debug",
|
|
9
|
-
quiet: "quiet",
|
|
10
|
-
silent: "silent",
|
|
11
|
-
static: "static",
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const LOG_LEVELS = {
|
|
15
|
-
debug: 0,
|
|
16
|
-
info: 1,
|
|
17
|
-
important: 2,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const getShouldOutputProgressIndicator = () => {
|
|
21
|
-
return (
|
|
22
|
-
process.stdout.isTTY &&
|
|
23
|
-
process.env.LOG_LEVEL !== LOG_LEVEL_TYPES.static &&
|
|
24
|
-
process.env.LOG_LEVEL !== LOG_LEVEL_TYPES.quiet &&
|
|
25
|
-
process.env.LOG_LEVEL !== LOG_LEVEL_TYPES.silent
|
|
26
|
-
);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const logMessage = (message = "", logLevel = 1) => {
|
|
30
|
-
if (
|
|
31
|
-
!process.env.LOG_LEVEL ||
|
|
32
|
-
process.env.LOG_LEVEL === LOG_LEVEL_TYPES.debug ||
|
|
33
|
-
process.env.LOG_LEVEL === LOG_LEVEL_TYPES.static
|
|
34
|
-
) {
|
|
35
|
-
console.log(message);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (process.env.LOG_LEVEL === LOG_LEVEL_TYPES.silent) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
process.env.LOG_LEVEL === LOG_LEVEL_TYPES.quiet &&
|
|
45
|
-
logLevel > LOG_LEVELS.info
|
|
46
|
-
) {
|
|
47
|
-
console.log(message);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const getLogMessageWithMarker = (marker) => {
|
|
53
|
-
return (message, logLevel) => {
|
|
54
|
-
if (marker) {
|
|
55
|
-
logMessage(`${marker} | ${message}`, logLevel);
|
|
56
|
-
} else {
|
|
57
|
-
logMessage(message, logLevel);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const logError = (msg, error) => {
|
|
63
|
-
if (process.env.LOG_LEVEL === LOG_LEVEL_TYPES.silent) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
console.error(msg);
|
|
68
|
-
|
|
69
|
-
if (error) {
|
|
70
|
-
console.error(error.message);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const logErrorAndExit = (msg, error) => {
|
|
75
|
-
console.error(msg);
|
|
76
|
-
|
|
77
|
-
if (error) {
|
|
78
|
-
console.error(error.message);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
process.exit(ERROR_STATUSES.general);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export {
|
|
85
|
-
ERROR_STATUSES,
|
|
86
|
-
getShouldOutputProgressIndicator,
|
|
87
|
-
getLogMessageWithMarker,
|
|
88
|
-
LOG_LEVELS,
|
|
89
|
-
logMessage,
|
|
90
|
-
logError,
|
|
91
|
-
logErrorAndExit,
|
|
92
|
-
};
|
|
1
|
+
const ERROR_STATUSES = {
|
|
2
|
+
general: 1,
|
|
3
|
+
nothingDownloaded: 2,
|
|
4
|
+
completedWithErrors: 3,
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const LOG_LEVEL_TYPES = {
|
|
8
|
+
debug: "debug",
|
|
9
|
+
quiet: "quiet",
|
|
10
|
+
silent: "silent",
|
|
11
|
+
static: "static",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const LOG_LEVELS = {
|
|
15
|
+
debug: 0,
|
|
16
|
+
info: 1,
|
|
17
|
+
important: 2,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const getShouldOutputProgressIndicator = () => {
|
|
21
|
+
return (
|
|
22
|
+
process.stdout.isTTY &&
|
|
23
|
+
process.env.LOG_LEVEL !== LOG_LEVEL_TYPES.static &&
|
|
24
|
+
process.env.LOG_LEVEL !== LOG_LEVEL_TYPES.quiet &&
|
|
25
|
+
process.env.LOG_LEVEL !== LOG_LEVEL_TYPES.silent
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const logMessage = (message = "", logLevel = 1) => {
|
|
30
|
+
if (
|
|
31
|
+
!process.env.LOG_LEVEL ||
|
|
32
|
+
process.env.LOG_LEVEL === LOG_LEVEL_TYPES.debug ||
|
|
33
|
+
process.env.LOG_LEVEL === LOG_LEVEL_TYPES.static
|
|
34
|
+
) {
|
|
35
|
+
console.log(message);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (process.env.LOG_LEVEL === LOG_LEVEL_TYPES.silent) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (
|
|
44
|
+
process.env.LOG_LEVEL === LOG_LEVEL_TYPES.quiet &&
|
|
45
|
+
logLevel > LOG_LEVELS.info
|
|
46
|
+
) {
|
|
47
|
+
console.log(message);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const getLogMessageWithMarker = (marker) => {
|
|
53
|
+
return (message, logLevel) => {
|
|
54
|
+
if (marker) {
|
|
55
|
+
logMessage(`${marker} | ${message}`, logLevel);
|
|
56
|
+
} else {
|
|
57
|
+
logMessage(message, logLevel);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const logError = (msg, error) => {
|
|
63
|
+
if (process.env.LOG_LEVEL === LOG_LEVEL_TYPES.silent) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.error(msg);
|
|
68
|
+
|
|
69
|
+
if (error) {
|
|
70
|
+
console.error(error.message);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const logErrorAndExit = (msg, error) => {
|
|
75
|
+
console.error(msg);
|
|
76
|
+
|
|
77
|
+
if (error) {
|
|
78
|
+
console.error(error.message);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
process.exit(ERROR_STATUSES.general);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export {
|
|
85
|
+
ERROR_STATUSES,
|
|
86
|
+
getShouldOutputProgressIndicator,
|
|
87
|
+
getLogMessageWithMarker,
|
|
88
|
+
LOG_LEVELS,
|
|
89
|
+
logMessage,
|
|
90
|
+
logError,
|
|
91
|
+
logErrorAndExit,
|
|
92
|
+
};
|
package/bin/naming.js
CHANGED
|
@@ -1,85 +1,96 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
["
|
|
29
|
-
["
|
|
30
|
-
["
|
|
31
|
-
["
|
|
32
|
-
["
|
|
33
|
-
["
|
|
34
|
-
["
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
};
|
|
1
|
+
import path from "path";
|
|
2
|
+
import filenamify from "filenamify";
|
|
3
|
+
import dayjs from "dayjs";
|
|
4
|
+
|
|
5
|
+
const INVALID_CHAR_REPLACE = "_";
|
|
6
|
+
const MAX_LENGTH_FILENAME = process.env.MAX_LENGTH_FILENAME
|
|
7
|
+
? parseInt(process.env.MAX_LENGTH_FILENAME)
|
|
8
|
+
: 255;
|
|
9
|
+
|
|
10
|
+
const getSafeName = (name, maxLength = MAX_LENGTH_FILENAME) => {
|
|
11
|
+
return filenamify(name, {
|
|
12
|
+
replacement: INVALID_CHAR_REPLACE,
|
|
13
|
+
maxLength,
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const getSimpleFilename = (name, ext = "") => {
|
|
18
|
+
return `${getSafeName(name, MAX_LENGTH_FILENAME - (ext?.length ?? 0))}${ext}`;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const getItemFilename = ({ item, ext, url, feed, template, width }) => {
|
|
22
|
+
const episodeNum = feed.items.length - item._originalIndex;
|
|
23
|
+
const formattedPubDate = item.pubDate
|
|
24
|
+
? dayjs(new Date(item.pubDate)).format("YYYYMMDD")
|
|
25
|
+
: null;
|
|
26
|
+
|
|
27
|
+
const templateReplacementsTuples = [
|
|
28
|
+
["title", item.title || ""],
|
|
29
|
+
["release_date", formattedPubDate || ""],
|
|
30
|
+
["episode_num", `${episodeNum}`.padStart(width, "0")],
|
|
31
|
+
["url", url],
|
|
32
|
+
["podcast_title", feed.title || ""],
|
|
33
|
+
["podcast_link", feed.link || ""],
|
|
34
|
+
["duration", item.itunes?.duration || ""],
|
|
35
|
+
["guid", item.guid],
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
const templateSegments = template.trim().split(path.sep);
|
|
39
|
+
const nameSegments = templateSegments.map((segment) => {
|
|
40
|
+
let name = segment;
|
|
41
|
+
templateReplacementsTuples.forEach((replacementTuple) => {
|
|
42
|
+
const [matcher, replacement] = replacementTuple;
|
|
43
|
+
const replaceRegex = new RegExp(`{{${matcher}}}`, "g");
|
|
44
|
+
|
|
45
|
+
name = replacement
|
|
46
|
+
? name.replace(replaceRegex, replacement)
|
|
47
|
+
: name.replace(replaceRegex, "");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return getSimpleFilename(name);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
nameSegments[nameSegments.length - 1] = getSimpleFilename(
|
|
54
|
+
nameSegments[nameSegments.length - 1],
|
|
55
|
+
ext
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return nameSegments.join(path.sep);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const getFolderName = ({ feed, template }) => {
|
|
62
|
+
const templateReplacementsTuples = [
|
|
63
|
+
["podcast_title", feed.title || ""],
|
|
64
|
+
["podcast_link", feed.link || ""],
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
let name = template;
|
|
68
|
+
templateReplacementsTuples.forEach((replacementTuple) => {
|
|
69
|
+
const [matcher, replacement] = replacementTuple;
|
|
70
|
+
const replaceRegex = new RegExp(`{{${matcher}}}`, "g");
|
|
71
|
+
|
|
72
|
+
name = replacement
|
|
73
|
+
? name.replace(replaceRegex, getSafeName(replacement))
|
|
74
|
+
: name.replace(replaceRegex, "");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return name;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const getArchiveFilename = ({ pubDate, name, ext }) => {
|
|
81
|
+
const formattedPubDate = pubDate
|
|
82
|
+
? dayjs(new Date(pubDate)).format("YYYYMMDD")
|
|
83
|
+
: null;
|
|
84
|
+
|
|
85
|
+
const baseName = formattedPubDate ? `${formattedPubDate}-${name}` : name;
|
|
86
|
+
|
|
87
|
+
return `${baseName}${ext}`;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export {
|
|
91
|
+
getArchiveFilename,
|
|
92
|
+
getFolderName,
|
|
93
|
+
getItemFilename,
|
|
94
|
+
getSafeName,
|
|
95
|
+
getSimpleFilename,
|
|
96
|
+
};
|