Created
October 15, 2014 08:08
-
-
Save jincod/5d10aea93a1f07260566 to your computer and use it in GitHub Desktop.
Download podfm podcast from rss chanel
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
FeedParser = require "feedparser" | |
request = require "request" | |
fs = require "fs" | |
args = process.argv.slice(2) | |
process.exit(1) if args.length is 0 | |
req = request(args[0]) | |
feedparser = new FeedParser() | |
req.on "error", (error) -> | |
req.on "response", (res) -> | |
stream = this | |
return @emit("error", new Error("Bad status code")) unless res.statusCode is 200 | |
stream.pipe feedparser | |
return | |
feedparser.on "error", (error) -> | |
feedparser.on "readable", -> | |
stream = this | |
item = undefined | |
while item = stream.read() | |
url = item.enclosures[0].url | |
name = url.match(/\w+.mp3/)[0] | |
console.log name | |
request(url).pipe(fs.createWriteStream("./output/" + name)) | |
return |
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
{ | |
"name": "podfm-downloader", | |
"version": "0.0.1", | |
"description": "", | |
"main": "index.coffee", | |
"author": "", | |
"license": "BSD-2-Clause", | |
"dependencies": { | |
"feedparser": "~0.19.2", | |
"request": "~2.45.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment