Skip to content

Instantly share code, notes, and snippets.

@hubgit
Last active April 1, 2024 22:44
Show Gist options
  • Save hubgit/b62c8d249b21c02c532b7a8a56ad8c90 to your computer and use it in GitHub Desktop.
Save hubgit/b62c8d249b21c02c532b7a8a56ad8c90 to your computer and use it in GitHub Desktop.
Fetch Independent Music Podcast audio files: `deno run fetch-imp-audio.ts`
import RSSParser from 'npm:rss-parser'
await Deno.mkdir('audio', { recursive: true })
const feedURL = 'https://anchor.fm/s/1252b450/podcast/rss'
const feed = await new RSSParser().parseURL(feedURL)
for (const item of feed.items) {
const { url } = item.enclosure
console.log(url)
const filename = url.split('/').at(-1)
const path = `audio/${filename}`
console.log(`\t${path}`)
try {
const response = await fetch(item.enclosure.url)
if (response.ok) {
const output = await Deno.open(path, { write: true, createNew: true })
await response.body.pipeTo(output.writable)
const mtime = response.headers.get('last-modified')
console.log(`\t${mtime}`)
await Deno.utime(path, Date.now(), new Date(mtime))
} else {
console.error(response.statusText)
}
} catch (error) {
if (error instanceof Deno.errors.AlreadyExists) {
console.log('\talready exists')
} else {
throw error
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment