From 553c799e2dbe528d082acda1c735a49aa67e0243 Mon Sep 17 00:00:00 2001 From: Joshua Pohl Date: Thu, 5 Dec 2024 09:36:11 -0700 Subject: [PATCH] feat: add 'episode-regex-exclude' option closes #91 --- README.md | 1 + bin/bin.js | 3 +++ bin/commander.js | 4 ++++ bin/util.js | 10 ++++++++++ 4 files changed, 18 insertions(+) diff --git a/README.md b/README.md index a67301f..48005a6 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Type values surrounded in square brackets (`[]`) can be used as used as boolean | --after | String | false | Only download episodes after this date (i.e. MM/DD/YYY, inclusive). | | --before | String | false | Only download episodes before this date (i.e. MM/DD/YYY, inclusive) | | --episode-regex | String | false | Match episode title against provided regex before starting download. | +| --episode-regex-exclude | String | false | Matched episode titles against provided regex will be excluded. | | --episode-digits | Number | false | Minimum number of digits to use for episode numbering (e.g. 3 would generate "001" instead of "1"). Default is 0. | | --episode-num-offset | Number | false | Offset the acquired episode number. Default is 0. | | --episode-source-order | String | false | Attempted order to extract episode audio URL from RSS feed. Default is "enclosure,link". | diff --git a/bin/bin.js b/bin/bin.js index 3ce9b7a..9feea6c 100755 --- a/bin/bin.js +++ b/bin/bin.js @@ -39,6 +39,7 @@ const { episodeDigits, episodeNumOffset, episodeRegex, + episodeRegexExclude, episodeSourceOrder, episodeTemplate, episodeCustomTemplateOptions, @@ -114,6 +115,7 @@ const main = async () => { after, before, episodeRegex, + episodeRegexExclude, }); } else { logErrorAndExit("No episodes found to list"); @@ -219,6 +221,7 @@ const main = async () => { episodeDigits, episodeNumOffset, episodeRegex, + episodeRegexExclude, episodeSourceOrder, episodeTemplate, episodeCustomTemplateOptions, diff --git a/bin/commander.js b/bin/commander.js index 3dd3b8e..e815b22 100644 --- a/bin/commander.js +++ b/bin/commander.js @@ -111,6 +111,10 @@ export const setupCommander = (program) => { "--episode-regex ", "match episode title against regex before downloading" ) + .option( + "--episode-regex-exclude ", + "matched episode titles against regex will be excluded" + ) .option( "--after ", "download episodes only after this date (inclusive)" diff --git a/bin/util.js b/bin/util.js index e5e58aa..6fb3318 100644 --- a/bin/util.js +++ b/bin/util.js @@ -166,6 +166,7 @@ const getItemsToDownload = ({ episodeDigits, episodeNumOffset, episodeRegex, + episodeRegexExclude, episodeSourceOrder, episodeTemplate, episodeCustomTemplateOptions, @@ -196,6 +197,13 @@ const getItemsToDownload = ({ } } + if (episodeRegexExclude) { + const generatedEpisodeRegexExclude = new RegExp(episodeRegexExclude); + if (title && generatedEpisodeRegexExclude.test(title)) { + isValid = false; + } + } + if (before) { const beforeDateDay = dayjs(new Date(before)); if ( @@ -336,6 +344,7 @@ const logItemsList = ({ before, after, episodeRegex, + episodeRegexExclude, }) => { const items = getItemsToDownload({ feed, @@ -345,6 +354,7 @@ const logItemsList = ({ before, after, episodeRegex, + episodeRegexExclude, }); if (!items.length) {