podcast-dl 11.6.0 → 11.6.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 Joshua Pohl
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Joshua Pohl
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/bin/archive.js CHANGED
@@ -1,39 +1,39 @@
1
- import dayjs from "dayjs";
2
- import fs from "fs";
3
- import path from "path";
4
- import { getJsonFile } from "./util.js";
5
-
6
- export const getArchiveKey = ({ prefix, name }) => {
7
- return `${prefix}-${name}`;
8
- };
9
-
10
- export const getArchive = (archive) => {
11
- const archiveContent = getJsonFile(archive);
12
- return archiveContent === null ? [] : archiveContent;
13
- };
14
-
15
- export const writeToArchive = ({ key, archive }) => {
16
- const archivePath = path.resolve(process.cwd(), archive);
17
- const archiveResult = getArchive(archive);
18
-
19
- if (!archiveResult.includes(key)) {
20
- archiveResult.push(key);
21
- }
22
-
23
- fs.writeFileSync(archivePath, JSON.stringify(archiveResult, null, 4));
24
- };
25
-
26
- export const getIsInArchive = ({ key, archive }) => {
27
- const archiveResult = getArchive(archive);
28
- return archiveResult.includes(key);
29
- };
30
-
31
- export const getArchiveFilename = ({ pubDate, name, ext }) => {
32
- const formattedPubDate = pubDate
33
- ? dayjs(new Date(pubDate)).format("YYYYMMDD")
34
- : null;
35
-
36
- const baseName = formattedPubDate ? `${formattedPubDate}-${name}` : name;
37
-
38
- return `${baseName}${ext}`;
39
- };
1
+ import dayjs from "dayjs";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import { getJsonFile } from "./util.js";
5
+
6
+ export const getArchiveKey = ({ prefix, name }) => {
7
+ return `${prefix}-${name}`;
8
+ };
9
+
10
+ export const getArchive = (archive) => {
11
+ const archiveContent = getJsonFile(archive);
12
+ return archiveContent === null ? [] : archiveContent;
13
+ };
14
+
15
+ export const writeToArchive = ({ key, archive }) => {
16
+ const archivePath = path.resolve(process.cwd(), archive);
17
+ const archiveResult = getArchive(archive);
18
+
19
+ if (!archiveResult.includes(key)) {
20
+ archiveResult.push(key);
21
+ }
22
+
23
+ fs.writeFileSync(archivePath, JSON.stringify(archiveResult, null, 4));
24
+ };
25
+
26
+ export const getIsInArchive = ({ key, archive }) => {
27
+ const archiveResult = getArchive(archive);
28
+ return archiveResult.includes(key);
29
+ };
30
+
31
+ export const getArchiveFilename = ({ pubDate, name, ext }) => {
32
+ const formattedPubDate = pubDate
33
+ ? dayjs(new Date(pubDate)).format("YYYYMMDD")
34
+ : null;
35
+
36
+ const baseName = formattedPubDate ? `${formattedPubDate}-${name}` : name;
37
+
38
+ return `${baseName}${ext}`;
39
+ };
package/bin/bin.js CHANGED
File without changes
package/bin/exec.js CHANGED
@@ -1,30 +1,30 @@
1
- import { exec } from "child_process";
2
- import util from "util";
3
- import { escapeArgForShell } from "./util.js";
4
-
5
- export const execWithPromise = util.promisify(exec);
6
-
7
- export const runExec = async ({
8
- exec,
9
- basePath,
10
- outputPodcastPath,
11
- episodeFilename,
12
- episodeAudioUrl,
13
- }) => {
14
- const episodeFilenameBase = episodeFilename.substring(
15
- 0,
16
- episodeFilename.lastIndexOf(".")
17
- );
18
-
19
- const execCmd = exec
20
- .replace(/{{episode_path}}/g, escapeArgForShell(outputPodcastPath))
21
- .replace(/{{episode_path_base}}/g, escapeArgForShell(basePath))
22
- .replace(/{{episode_filename}}/g, escapeArgForShell(episodeFilename))
23
- .replace(
24
- /{{episode_filename_base}}/g,
25
- escapeArgForShell(episodeFilenameBase)
26
- )
27
- .replace(/{{url}}/g, escapeArgForShell(episodeAudioUrl));
28
-
29
- await execWithPromise(execCmd, { stdio: "ignore" });
30
- };
1
+ import { exec } from "child_process";
2
+ import util from "util";
3
+ import { escapeArgForShell } from "./util.js";
4
+
5
+ export const execWithPromise = util.promisify(exec);
6
+
7
+ export const runExec = async ({
8
+ exec,
9
+ basePath,
10
+ outputPodcastPath,
11
+ episodeFilename,
12
+ episodeAudioUrl,
13
+ }) => {
14
+ const episodeFilenameBase = episodeFilename.substring(
15
+ 0,
16
+ episodeFilename.lastIndexOf(".")
17
+ );
18
+
19
+ const execCmd = exec
20
+ .replace(/{{episode_path}}/g, escapeArgForShell(outputPodcastPath))
21
+ .replace(/{{episode_path_base}}/g, escapeArgForShell(basePath))
22
+ .replace(/{{episode_filename}}/g, escapeArgForShell(episodeFilename))
23
+ .replace(
24
+ /{{episode_filename_base}}/g,
25
+ escapeArgForShell(episodeFilenameBase)
26
+ )
27
+ .replace(/{{url}}/g, escapeArgForShell(episodeAudioUrl));
28
+
29
+ await execWithPromise(execCmd, { stdio: "ignore" });
30
+ };
package/bin/logger.js CHANGED
@@ -1,84 +1,84 @@
1
- /* eslint-disable no-console */
2
-
3
- export const ERROR_STATUSES = {
4
- general: 1,
5
- nothingDownloaded: 2,
6
- completedWithErrors: 3,
7
- };
8
-
9
- export const LOG_LEVEL_TYPES = {
10
- debug: "debug",
11
- quiet: "quiet",
12
- silent: "silent",
13
- static: "static",
14
- };
15
-
16
- export const LOG_LEVELS = {
17
- debug: 0,
18
- info: 1,
19
- important: 2,
20
- };
21
-
22
- export const getShouldOutputProgressIndicator = () => {
23
- return (
24
- process.stdout.isTTY &&
25
- process.env.LOG_LEVEL !== LOG_LEVEL_TYPES.static &&
26
- process.env.LOG_LEVEL !== LOG_LEVEL_TYPES.quiet &&
27
- process.env.LOG_LEVEL !== LOG_LEVEL_TYPES.silent
28
- );
29
- };
30
-
31
- export const logMessage = (message = "", logLevel = 1) => {
32
- if (
33
- !process.env.LOG_LEVEL ||
34
- process.env.LOG_LEVEL === LOG_LEVEL_TYPES.debug ||
35
- process.env.LOG_LEVEL === LOG_LEVEL_TYPES.static
36
- ) {
37
- console.log(message);
38
- return;
39
- }
40
-
41
- if (process.env.LOG_LEVEL === LOG_LEVEL_TYPES.silent) {
42
- return;
43
- }
44
-
45
- if (
46
- process.env.LOG_LEVEL === LOG_LEVEL_TYPES.quiet &&
47
- logLevel > LOG_LEVELS.info
48
- ) {
49
- console.log(message);
50
- return;
51
- }
52
- };
53
-
54
- export const getLogMessageWithMarker = (marker) => {
55
- return (message, logLevel) => {
56
- if (marker) {
57
- logMessage(`${marker} | ${message}`, logLevel);
58
- } else {
59
- logMessage(message, logLevel);
60
- }
61
- };
62
- };
63
-
64
- export const logError = (msg, error) => {
65
- if (process.env.LOG_LEVEL === LOG_LEVEL_TYPES.silent) {
66
- return;
67
- }
68
-
69
- console.error(msg);
70
-
71
- if (error) {
72
- console.error(error.message);
73
- }
74
- };
75
-
76
- export const logErrorAndExit = (msg, error) => {
77
- console.error(msg);
78
-
79
- if (error) {
80
- console.error(error.message);
81
- }
82
-
83
- process.exit(ERROR_STATUSES.general);
84
- };
1
+ /* eslint-disable no-console */
2
+
3
+ export const ERROR_STATUSES = {
4
+ general: 1,
5
+ nothingDownloaded: 2,
6
+ completedWithErrors: 3,
7
+ };
8
+
9
+ export const LOG_LEVEL_TYPES = {
10
+ debug: "debug",
11
+ quiet: "quiet",
12
+ silent: "silent",
13
+ static: "static",
14
+ };
15
+
16
+ export const LOG_LEVELS = {
17
+ debug: 0,
18
+ info: 1,
19
+ important: 2,
20
+ };
21
+
22
+ export const getShouldOutputProgressIndicator = () => {
23
+ return (
24
+ process.stdout.isTTY &&
25
+ process.env.LOG_LEVEL !== LOG_LEVEL_TYPES.static &&
26
+ process.env.LOG_LEVEL !== LOG_LEVEL_TYPES.quiet &&
27
+ process.env.LOG_LEVEL !== LOG_LEVEL_TYPES.silent
28
+ );
29
+ };
30
+
31
+ export const logMessage = (message = "", logLevel = 1) => {
32
+ if (
33
+ !process.env.LOG_LEVEL ||
34
+ process.env.LOG_LEVEL === LOG_LEVEL_TYPES.debug ||
35
+ process.env.LOG_LEVEL === LOG_LEVEL_TYPES.static
36
+ ) {
37
+ console.log(message);
38
+ return;
39
+ }
40
+
41
+ if (process.env.LOG_LEVEL === LOG_LEVEL_TYPES.silent) {
42
+ return;
43
+ }
44
+
45
+ if (
46
+ process.env.LOG_LEVEL === LOG_LEVEL_TYPES.quiet &&
47
+ logLevel > LOG_LEVELS.info
48
+ ) {
49
+ console.log(message);
50
+ return;
51
+ }
52
+ };
53
+
54
+ export const getLogMessageWithMarker = (marker) => {
55
+ return (message, logLevel) => {
56
+ if (marker) {
57
+ logMessage(`${marker} | ${message}`, logLevel);
58
+ } else {
59
+ logMessage(message, logLevel);
60
+ }
61
+ };
62
+ };
63
+
64
+ export const logError = (msg, error) => {
65
+ if (process.env.LOG_LEVEL === LOG_LEVEL_TYPES.silent) {
66
+ return;
67
+ }
68
+
69
+ console.error(msg);
70
+
71
+ if (error) {
72
+ console.error(error.message);
73
+ }
74
+ };
75
+
76
+ export const logErrorAndExit = (msg, error) => {
77
+ console.error(msg);
78
+
79
+ if (error) {
80
+ console.error(error.message);
81
+ }
82
+
83
+ process.exit(ERROR_STATUSES.general);
84
+ };
package/bin/meta.js CHANGED
@@ -1,66 +1,66 @@
1
- import fs from "fs";
2
- import { getIsInArchive, writeToArchive } from "./archive.js";
3
- import { logMessage } from "./logger.js";
4
- import { getPublicObject } from "./util.js";
5
-
6
- export const writeFeedMeta = ({ outputPath, feed, key, archive, override }) => {
7
- if (key && archive && getIsInArchive({ key, archive })) {
8
- logMessage("Feed metadata exists in archive. Skipping...");
9
- return;
10
- }
11
- const output = getPublicObject(feed, ["items"]);
12
-
13
- try {
14
- if (override || !fs.existsSync(outputPath)) {
15
- fs.writeFileSync(outputPath, JSON.stringify(output, null, 4));
16
- } else {
17
- logMessage("Feed metadata exists locally. Skipping...");
18
- }
19
-
20
- if (key && archive && !getIsInArchive({ key, archive })) {
21
- try {
22
- writeToArchive({ key, archive });
23
- } catch (error) {
24
- throw new Error(`Error writing to archive: ${error.toString()}`);
25
- }
26
- }
27
- } catch (error) {
28
- throw new Error(
29
- `Unable to save metadata file for feed: ${error.toString()}`
30
- );
31
- }
32
- };
33
-
34
- export const writeItemMeta = ({
35
- marker,
36
- outputPath,
37
- item,
38
- key,
39
- archive,
40
- override,
41
- }) => {
42
- if (key && archive && getIsInArchive({ key, archive })) {
43
- logMessage(`${marker} | Episode metadata exists in archive. Skipping...`);
44
- return;
45
- }
46
-
47
- const output = getPublicObject(item);
48
-
49
- try {
50
- if (override || !fs.existsSync(outputPath)) {
51
- fs.writeFileSync(outputPath, JSON.stringify(output, null, 4));
52
- } else {
53
- logMessage(`${marker} | Episode metadata exists locally. Skipping...`);
54
- }
55
-
56
- if (key && archive && !getIsInArchive({ key, archive })) {
57
- try {
58
- writeToArchive({ key, archive });
59
- } catch (error) {
60
- throw new Error("Error writing to archive", error);
61
- }
62
- }
63
- } catch (error) {
64
- throw new Error("Unable to save meta file for episode", error);
65
- }
66
- };
1
+ import fs from "fs";
2
+ import { getIsInArchive, writeToArchive } from "./archive.js";
3
+ import { logMessage } from "./logger.js";
4
+ import { getPublicObject } from "./util.js";
5
+
6
+ export const writeFeedMeta = ({ outputPath, feed, key, archive, override }) => {
7
+ if (key && archive && getIsInArchive({ key, archive })) {
8
+ logMessage("Feed metadata exists in archive. Skipping...");
9
+ return;
10
+ }
11
+ const output = getPublicObject(feed, ["items"]);
12
+
13
+ try {
14
+ if (override || !fs.existsSync(outputPath)) {
15
+ fs.writeFileSync(outputPath, JSON.stringify(output, null, 4));
16
+ } else {
17
+ logMessage("Feed metadata exists locally. Skipping...");
18
+ }
19
+
20
+ if (key && archive && !getIsInArchive({ key, archive })) {
21
+ try {
22
+ writeToArchive({ key, archive });
23
+ } catch (error) {
24
+ throw new Error(`Error writing to archive: ${error.toString()}`);
25
+ }
26
+ }
27
+ } catch (error) {
28
+ throw new Error(
29
+ `Unable to save metadata file for feed: ${error.toString()}`
30
+ );
31
+ }
32
+ };
33
+
34
+ export const writeItemMeta = ({
35
+ marker,
36
+ outputPath,
37
+ item,
38
+ key,
39
+ archive,
40
+ override,
41
+ }) => {
42
+ if (key && archive && getIsInArchive({ key, archive })) {
43
+ logMessage(`${marker} | Episode metadata exists in archive. Skipping...`);
44
+ return;
45
+ }
46
+
47
+ const output = getPublicObject(item);
48
+
49
+ try {
50
+ if (override || !fs.existsSync(outputPath)) {
51
+ fs.writeFileSync(outputPath, JSON.stringify(output, null, 4));
52
+ } else {
53
+ logMessage(`${marker} | Episode metadata exists locally. Skipping...`);
54
+ }
55
+
56
+ if (key && archive && !getIsInArchive({ key, archive })) {
57
+ try {
58
+ writeToArchive({ key, archive });
59
+ } catch (error) {
60
+ throw new Error("Error writing to archive", error);
61
+ }
62
+ }
63
+ } catch (error) {
64
+ throw new Error("Unable to save meta file for episode", error);
65
+ }
66
+ };