Skip to content

Commit 1d16c24

Browse files
authored
Merge pull request #61 from ajcwebdev/rss
Add `--date` and `--lastDays` RSS options
2 parents e86f070 + ee29e4d commit 1d16c24

File tree

5 files changed

+91
-3
lines changed

5 files changed

+91
-3
lines changed

docs/examples.md

+36-3
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,43 @@ Process multiple RSS feeds:
181181

182182
```bash
183183
npm run as -- \
184-
--rss "https://ajcwebdev.substack.com/feed" \
185-
--rss "https://feeds.transistor.fm/fsjam-podcast/" \
186184
--last 1 \
187-
--whisper tiny
185+
--whisper tiny \
186+
--rss "https://ajcwebdev.substack.com/feed" \
187+
"https://feeds.transistor.fm/fsjam-podcast/"
188+
```
189+
190+
Download episodes from a specific date:
191+
192+
```bash
193+
npm run as -- \
194+
--rss "https://ajcwebdev.substack.com/feed" \
195+
--date 2021-05-10
196+
```
197+
198+
Download episodes from multiple dates:
199+
200+
```bash
201+
npm run as -- \
202+
--rss "https://ajcwebdev.substack.com/feed" \
203+
--date 2021-05-10 2022-05-10
204+
```
205+
206+
Download episodes from multiple dates on multiple RSS feeds:
207+
208+
```bash
209+
npm run as -- \
210+
--rss "https://ajcwebdev.substack.com/feed" \
211+
"https://feeds.transistor.fm/fsjam-podcast/" \
212+
--date 2021-05-10 2022-05-10
213+
```
214+
215+
Download episodes from a specific number of previous days, for example to download episodes from the last 7 days:
216+
217+
```bash
218+
npm run as -- \
219+
--rss "https://ajcwebdev.substack.com/feed" \
220+
--lastDays 7
188221
```
189222

190223
## Language Model (LLM) Options

src/cli/commander.ts

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ program
6868
.option('--order <order>', 'Specify the order for RSS feed processing (newest or oldest)')
6969
.option('--skip <number>', 'Number of items to skip when processing RSS feed', parseInt)
7070
.option('--last <number>', 'Number of most recent items to process (overrides --order and --skip)', parseInt)
71+
.option('--date <dates...>', 'Process items from these dates (YYYY-MM-DD)')
72+
.option('--lastDays <number>', 'Number of days to look back for items', parseInt)
7173
.option('--info', 'Skip processing and write metadata to JSON objects (supports --urls, --rss, --playlist, --channel)')
7274
// Transcription service options
7375
.option('--whisper [model]', 'Use Whisper.cpp for transcription with optional model specification')

src/commands/process-rss.ts

+21
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,23 @@ function selectItemsToProcess(items: RSSItem[], options: ProcessingOptions): RSS
136136
return matchedItems
137137
}
138138

139+
if (options.lastDays !== undefined) {
140+
const now = new Date()
141+
const cutoff = new Date(now.getTime() - (options.lastDays * 24 * 60 * 60 * 1000))
142+
143+
const matchedItems = items.filter((item) => {
144+
const itemDate = new Date(item.publishDate)
145+
return itemDate >= cutoff
146+
})
147+
return matchedItems
148+
}
149+
150+
if (options.date && options.date.length > 0) {
151+
const selectedDates = new Set(options.date)
152+
const matchedItems = items.filter((item) => selectedDates.has(item.publishDate))
153+
return matchedItems
154+
}
155+
139156
if (options.last) {
140157
return items.slice(0, options.last)
141158
}
@@ -242,6 +259,10 @@ export async function processRSS(
242259
}
243260

244261
const itemsToProcess = selectItemsToProcess(items, options)
262+
if (itemsToProcess.length === 0) {
263+
l(wait(`\nNo items found matching the provided criteria for this feed. Skipping...`))
264+
return
265+
}
245266
logProcessingStatus(items.length, itemsToProcess.length, options)
246267
await processItems(itemsToProcess, options, llmServices, transcriptServices)
247268
} catch (error) {

src/types/main.ts

+6
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ export type ProcessingOptions = {
9999
/** Number of most recent items to process (overrides --order and --skip). */
100100
last?: number
101101

102+
/** Date of RSS items to process. */
103+
date?: string[]
104+
105+
/** Number of previous days to check for RSS items to process. */
106+
lastDays?: number
107+
102108
/** Whether to run in interactive mode. */
103109
interactive?: boolean
104110
}

src/utils/validate-option.ts

+26
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,30 @@ export function validateRSSOptions(options: ProcessingOptions): void {
6464
err("Error: The --order option must be either 'newest' or 'oldest'.")
6565
process.exit(1)
6666
}
67+
68+
if (options.lastDays !== undefined) {
69+
if (!Number.isInteger(options.lastDays) || options.lastDays < 1) {
70+
err('Error: The --lastDays option must be a positive integer.')
71+
process.exit(1)
72+
}
73+
if (options.last !== undefined || options.skip !== undefined || options.order !== undefined || (options.date && options.date.length > 0)) {
74+
err('Error: The --lastDays option cannot be used with --last, --skip, --order, or --date.')
75+
process.exit(1)
76+
}
77+
}
78+
79+
if (options.date && options.date.length > 0) {
80+
const dateRegex = /^\d{4}-\d{2}-\d{2}$/
81+
for (const d of options.date) {
82+
if (!dateRegex.test(d)) {
83+
err(`Error: Invalid date format "${d}". Please use YYYY-MM-DD format.`)
84+
process.exit(1)
85+
}
86+
}
87+
88+
if (options.last !== undefined || options.skip !== undefined || options.order !== undefined) {
89+
err('Error: The --date option cannot be used with --last, --skip, or --order.')
90+
process.exit(1)
91+
}
92+
}
6793
}

0 commit comments

Comments
 (0)