podcast-dl 9.0.1 → 9.0.3

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/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,73 +1,85 @@
1
- import filenamify from "filenamify";
2
- import dayjs from "dayjs";
3
-
4
- const INVALID_CHAR_REPLACE = "_";
5
- const MAX_LENGTH_FILENAME = 251; // account for ".tmp" files
6
-
7
- const getSafeName = (name) => {
8
- return filenamify(name, {
9
- replacement: INVALID_CHAR_REPLACE,
10
- maxLength: MAX_LENGTH_FILENAME,
11
- });
12
- };
13
-
14
- const getFilename = ({ item, ext, url, feed, template, width }) => {
15
- const episodeNum = feed.items.length - item._originalIndex;
16
- const formattedPubDate = item.pubDate
17
- ? dayjs(new Date(item.pubDate)).format("YYYYMMDD")
18
- : null;
19
-
20
- const templateReplacementsTuples = [
21
- ["title", item.title || ""],
22
- ["release_date", formattedPubDate || ""],
23
- ["episode_num", `${episodeNum}`.padStart(width, "0")],
24
- ["url", url],
25
- ["podcast_title", feed.title || ""],
26
- ["podcast_link", feed.link || ""],
27
- ["duration", (item.itunes && item.itunes.duration) || ""],
28
- ];
29
-
30
- let name = template;
31
- templateReplacementsTuples.forEach((replacementTuple) => {
32
- const [matcher, replacement] = replacementTuple;
33
- const replaceRegex = new RegExp(`{{${matcher}}}`, "g");
34
-
35
- name = replacement
36
- ? name.replace(replaceRegex, replacement)
37
- : name.replace(replaceRegex, "");
38
- });
39
-
40
- name = `${name}${ext}`;
41
- return getSafeName(name);
42
- };
43
-
44
- const getFolderName = ({ feed, template }) => {
45
- const templateReplacementsTuples = [
46
- ["podcast_title", feed.title || ""],
47
- ["podcast_link", feed.link || ""],
48
- ];
49
-
50
- let name = template;
51
- templateReplacementsTuples.forEach((replacementTuple) => {
52
- const [matcher, replacement] = replacementTuple;
53
- const replaceRegex = new RegExp(`{{${matcher}}}`, "g");
54
-
55
- name = replacement
56
- ? name.replace(replaceRegex, getSafeName(replacement))
57
- : name.replace(replaceRegex, "");
58
- });
59
-
60
- return name;
61
- };
62
-
63
- const getArchiveFilename = ({ pubDate, name, ext }) => {
64
- const formattedPubDate = pubDate
65
- ? dayjs(new Date(pubDate)).format("YYYYMMDD")
66
- : null;
67
-
68
- const baseName = formattedPubDate ? `${formattedPubDate}-${name}` : name;
69
-
70
- return `${baseName}${ext}`;
71
- };
72
-
73
- export { getArchiveFilename, getFilename, getFolderName, getSafeName };
1
+ import filenamify from "filenamify";
2
+ import dayjs from "dayjs";
3
+
4
+ const INVALID_CHAR_REPLACE = "_";
5
+ const MAX_LENGTH_FILENAME = process.env.MAX_LENGTH_FILENAME
6
+ ? parseInt(process.env.MAX_LENGTH_FILENAME)
7
+ : 255;
8
+
9
+ const getSafeName = (name, maxLength = MAX_LENGTH_FILENAME) => {
10
+ return filenamify(name, {
11
+ replacement: INVALID_CHAR_REPLACE,
12
+ maxLength,
13
+ });
14
+ };
15
+
16
+ const getSimpleFilename = (name, ext = "") => {
17
+ return `${getSafeName(name, MAX_LENGTH_FILENAME - (ext?.length ?? 0))}${ext}`;
18
+ };
19
+
20
+ const getItemFilename = ({ item, ext, url, feed, template, width }) => {
21
+ const episodeNum = feed.items.length - item._originalIndex;
22
+ const formattedPubDate = item.pubDate
23
+ ? dayjs(new Date(item.pubDate)).format("YYYYMMDD")
24
+ : null;
25
+
26
+ const templateReplacementsTuples = [
27
+ ["title", item.title || ""],
28
+ ["release_date", formattedPubDate || ""],
29
+ ["episode_num", `${episodeNum}`.padStart(width, "0")],
30
+ ["url", url],
31
+ ["podcast_title", feed.title || ""],
32
+ ["podcast_link", feed.link || ""],
33
+ ["duration", item.itunes?.duration || ""],
34
+ ["guid", item.guid],
35
+ ];
36
+
37
+ let name = template;
38
+ templateReplacementsTuples.forEach((replacementTuple) => {
39
+ const [matcher, replacement] = replacementTuple;
40
+ const replaceRegex = new RegExp(`{{${matcher}}}`, "g");
41
+
42
+ name = replacement
43
+ ? name.replace(replaceRegex, replacement)
44
+ : name.replace(replaceRegex, "");
45
+ });
46
+
47
+ return getSimpleFilename(name, ext);
48
+ };
49
+
50
+ const getFolderName = ({ feed, template }) => {
51
+ const templateReplacementsTuples = [
52
+ ["podcast_title", feed.title || ""],
53
+ ["podcast_link", feed.link || ""],
54
+ ];
55
+
56
+ let name = template;
57
+ templateReplacementsTuples.forEach((replacementTuple) => {
58
+ const [matcher, replacement] = replacementTuple;
59
+ const replaceRegex = new RegExp(`{{${matcher}}}`, "g");
60
+
61
+ name = replacement
62
+ ? name.replace(replaceRegex, getSafeName(replacement))
63
+ : name.replace(replaceRegex, "");
64
+ });
65
+
66
+ return name;
67
+ };
68
+
69
+ const getArchiveFilename = ({ pubDate, name, ext }) => {
70
+ const formattedPubDate = pubDate
71
+ ? dayjs(new Date(pubDate)).format("YYYYMMDD")
72
+ : null;
73
+
74
+ const baseName = formattedPubDate ? `${formattedPubDate}-${name}` : name;
75
+
76
+ return `${baseName}${ext}`;
77
+ };
78
+
79
+ export {
80
+ getArchiveFilename,
81
+ getFolderName,
82
+ getItemFilename,
83
+ getSafeName,
84
+ getSimpleFilename,
85
+ };