Skip to content

Instantly share code, notes, and snippets.

Created September 16, 2017 18:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Generates RSS file from the files in a folder with subfolders
#!/usr/bin/env ruby -wKU
# based on a script
# by Kelan Champagne
require 'date'
# Config values
podcast_title = "Title"
podcast_description = "Description"
public_url_base = "put_the_remote_file_url_here"
# Generated values
date_format = '%a, %d %b %Y %H:%M:%S %z'
podcast_pub_date =
rss_archive_filename = "archive.rss"
rss_output_filename = "new.rss"
# Build the items
items_content = ""
Dir["/Path/To/Files/**/*"].each do |file|
next if file =~ /^\./ # ignore invisible files
next unless file =~ /\.(mp3|m4a)$/ # only use audio files
item_pub_date = File.mtime(file)
previous_pub_date = File.mtime(rss_archive_filename)
next if previous_pub_date > item_pub_date
puts "adding file: #{file}"
item_size_in_bytes = File.size(file).to_s
item_title = File.basename(file, '.m4a')
item_url = "#{public_url_base}"
item_content = <<-HTML
<enclosure url="#{item_url}" length="#{item_size_in_bytes}" type="audio" />
items_content << item_content
# Build the whole file
content = <<-HTML
<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
# write it out
output_file =, 'w')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment