Created
March 31, 2012 16:17
-
-
Save oparrish/2266477 to your computer and use it in GitHub Desktop.
Create podcast from directory
This file contains hidden or 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
require 'rss/maker' | |
require 'optparse' | |
require 'uri' | |
options={} | |
opts = OptionParser.new do |opts| | |
opts.on("-d", "--directory DIRECTORY", "Director of files") do |directory| | |
options[:directory] = directory | |
end | |
opts.on("-b", "--base BASE", "Base for links") do |base| | |
options[:base] = base | |
end | |
opts.on("-t", "--title TITLE", "Title of podcast") do |title| | |
options[:title] = title | |
end | |
opts.on("-l", "--link LINK", "Link of podcast") do |link| | |
options[:link] = link | |
end | |
opts.on("-i", "--image IMAGE", "Image") do |image| | |
options[:image] = image | |
end | |
opts.on("-e", "--desc DESCRIPTION", "Description of podcast") do |desc| | |
options[:desc] = desc | |
end | |
opts.on("-o", "--output OUTPUT", "Output file") do |output| | |
options[:output] = output | |
end | |
opts.on("-a", "--author [AUTHOR]", "Author of podcast items") do |author| | |
options[:author] = author | |
end | |
opts.on_tail("-h", "--help", "Show this message") do | |
puts opts | |
exit | |
end | |
end | |
opts.parse! | |
version = "2.0" | |
content = RSS::Maker.make(version) do |m| | |
m.channel.title = options[:title] | |
m.channel.link = options[:link] | |
m.channel.description = options[:desc] | |
m.channel.language = "en-us" | |
m.channel.itunes_image = options[:image] | |
m.items.do_sort = true | |
Dir.glob(options[:directory] + '/*.m4b').each do |audio| | |
file = File.new(audio) | |
i = m.items.new_item | |
i.link = options[:base] + "/" + URI.escape(File.basename(file.path), Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) | |
i.title = File.basename(file.path).gsub(File.extname(file.path),"") | |
i.author = options[:author] | |
i.pubDate = File.mtime(file) | |
i.guid.content = i.link | |
i.enclosure.url = i.link | |
i.enclosure.length = file.size | |
i.enclosure.type = 'audio/mpeg' | |
end | |
end | |
File.open(options[:output],"w") do |f| | |
f.write(content) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment