podcast-dl 9.0.3 → 9.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/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 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
- };
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
+ };