Skip to content

Instantly share code, notes, and snippets.

@modeverv
Forked from matchy256/makepodcast.rb
Last active February 18, 2018 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save modeverv/ed1afc9b8985cb9a8403e379c8b429c6 to your computer and use it in GitHub Desktop.
Save modeverv/ed1afc9b8985cb9a8403e379c8b429c6 to your computer and use it in GitHub Desktop.
指定ディレクトリ内のmp3ファイルから必要最低限のPodcast用RSSを生成する
#!/usr/bin/env ruby
# frozen_string_literal:true
require 'time'
require 'nkf'
title = 'band-demo'
location = 'https://lovesaemi.daemon.asia/chiaki'
files = []
Dir.glob('/var/www/chiaki/demo/**/*.mp3') do |path|
epath = File.expand_path(path)
name = File.basename(path, File.extname(path))
item = { 'path' => epath,
'name' => name,
'fname' => epath, # File.basename(path),
'time' => File.ctime(path),
'length' => File.size(path) }
files << item
end
files = files.sort do |a, b|
a['time'] <=> b['time']
end
puts <<~EOS
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
<channel>
<title>#{title}</title>
EOS
files.each do |item|
url = location + item['fname'].gsub('/demo', 'demo').gsub('var/www/chiaki', '')
mime = if /\.mp3$/ =~ item['fname']
'audio/mp3'
else
'audio/mp4'
end
puts <<-EOS
<item>
<title>#{item['name']}</title>
<enclosure url="#{url}"
length="#{item['length']}"
type="#{mime}" />
<guid isPermaLink="true">#{url}</guid>
<pubDate>#{item['time'].rfc822}</pubDate>
</item>
EOS
end
puts <<~EOS
</channel>
</rss>
EOS
@modeverv
Copy link
Author

modeverv commented May 4, 2017

  • 引数でフレキシブルに動く機能とかいらない。
  • サブディレクトリにmp3が存在する状態だったので変更
  • rubocop/ ruby2.3準拠

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment