Last active
April 1, 2024 22:44
-
-
Save hubgit/b62c8d249b21c02c532b7a8a56ad8c90 to your computer and use it in GitHub Desktop.
Fetch Independent Music Podcast audio files: `deno run fetch-imp-audio.ts`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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