Skip to content

Commit

Permalink
feat: add '--episode-num-offset' option
Browse files Browse the repository at this point in the history
  • Loading branch information
lightpohl committed May 26, 2024
1 parent 55b5280 commit 7a742c5
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Type values surrounded in square brackets (`[]`) can be used as used as boolean
| --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-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". |
| --add-mp3-metadata | | false | Attempts to add a base level of episode metadata to each episode. Recommended only in cases where the original metadata is of poor quality. (**ffmpeg required**) |
| --adjust-bitrate | String (e.g. "48k") | false | Attempts to adjust bitrate of episodes. (**ffmpeg required**) |
Expand Down
3 changes: 3 additions & 0 deletions bin/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ const downloadItemsAsync = async ({
bitrate,
episodeTemplate,
episodeDigits,
episodeNumOffset,
episodeSourceOrder,
exec,
feed,
Expand Down Expand Up @@ -199,6 +200,7 @@ const downloadItemsAsync = async ({
ext: audioFileExt,
template: episodeTemplate,
width: episodeDigits,
offset: episodeNumOffset,
});
const outputPodcastPath = _path.resolve(basePath, episodeFilename);

Expand Down Expand Up @@ -282,6 +284,7 @@ const downloadItemsAsync = async ({
ext: episodeMetaExt,
template: episodeTemplate,
width: episodeDigits,
offset: episodeNumOffset,
});
const outputEpisodeMetaPath = _path.resolve(basePath, episodeMetaName);

Expand Down
37 changes: 20 additions & 17 deletions bin/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,32 @@ import { downloadItemsAsync } from "./async.js";
setupCommander(commander, process.argv);

const {
file,
url,
outDir,
episodeTemplate,
after,
alwaysPostprocess,
attempts,
before,
episodeDigits,
episodeNumOffset,
episodeRegex,
episodeSourceOrder,
includeMeta,
includeEpisodeMeta,
episodeTemplate,
exec,
file,
includeEpisodeImages,
offset,
limit,
episodeRegex,
after,
before,
override,
alwaysPostprocess,
reverse,
includeEpisodeMeta,
includeMeta,
info,
limit,
list,
exec,
mono,
threads,
attempts,
offset,
outDir,
override,
parserConfig,
proxy,
reverse,
threads,
url,
addMp3Metadata: addMp3MetadataFlag,
adjustBitrate: bitrate,
} = commander;
Expand Down Expand Up @@ -206,6 +207,7 @@ const main = async () => {
after,
before,
episodeDigits,
episodeNumOffset,
episodeRegex,
episodeSourceOrder,
episodeTemplate,
Expand All @@ -229,6 +231,7 @@ const main = async () => {
bitrate,
episodeTemplate,
episodeDigits,
episodeNumOffset,
episodeSourceOrder,
exec,
feed,
Expand Down
10 changes: 10 additions & 0 deletions bin/commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ export const setupCommander = (commander, argv) => {
createParseNumber({ min: 0, name: "--episode-digits" }),
1
)
.option(
"--episode-num-offset <number>",
"offset the acquired episode number",
createParseNumber({
min: Number.MIN_SAFE_INTEGER,
max: Number.MAX_SAFE_INTEGER,
name: "--episode-num-offset",
}),
0
)
.option(
"--episode-source-order <string>",
"attempted order to extract episode audio URL from rss feed",
Expand Down
12 changes: 10 additions & 2 deletions bin/naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ const getSimpleFilename = (name, ext = "") => {
return `${getSafeName(name, MAX_LENGTH_FILENAME - (ext?.length ?? 0))}${ext}`;
};

const getItemFilename = ({ item, ext, url, feed, template, width }) => {
const episodeNum = feed.items.length - item._originalIndex;
const getItemFilename = ({
item,
ext,
url,
feed,
template,
width,
offset = 0,
}) => {
const episodeNum = feed.items.length - item._originalIndex + offset;
const formattedPubDate = item.pubDate
? dayjs(new Date(item.pubDate)).format("YYYYMMDD")
: null;
Expand Down
4 changes: 3 additions & 1 deletion bin/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const isWin = process.platform === "win32";
Escape arguments for a shell command used with exec.
Borrowed from shell-escape: https://github.com/xxorax/node-shell-escape/
Additionally, @see https://www.robvanderwoude.com/escapechars.php for why
we avoid trying tp escape complex sequences in Windows.
we avoid trying to escape complex sequences in Windows.
*/
const escapeArgForShell = (arg) => {
let result = arg;
Expand Down Expand Up @@ -154,6 +154,7 @@ const getItemsToDownload = ({
before,
after,
episodeDigits,
episodeNumOffset,
episodeRegex,
episodeSourceOrder,
episodeTemplate,
Expand Down Expand Up @@ -243,6 +244,7 @@ const getItemsToDownload = ({
ext: episodeImageFileExt,
template: episodeTemplate,
width: episodeDigits,
offset: episodeNumOffset,
});

const outputImagePath = path.resolve(basePath, episodeImageName);
Expand Down
1 change: 0 additions & 1 deletion bin/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const createParseNumber = ({ min, max, name, required = true }) => {

try {
let number = parseInt(value);

if (isNaN(number)) {
logErrorAndExit(`${name} must be a number`);
}
Expand Down

0 comments on commit 7a742c5

Please sign in to comment.