Category: podcast

Add Cover picture to podcast

Checked the specs for podcast from apple, the image tag or itunes:image look only for the cover page for itunes store. Set it, I still can’t see pictures.

After 50 times re-tries, I suddenly realized that the image I’m looking for is called artwork of mp3, it’s not set by podcast feed at all, it’s right in the mp3 file!!!

Scott H got the solution how to encode images into mp3. But for my case I need it running on linux.

Finally I found it, eyeD3,  a better help file can be found here.

Had to using eyeD3 to upgrade idtag to v2.3 before add cover image for itunes display purpose.

Putty is way better than the sshclient I was using. Stable, copy&paste support, and even more, colorful console!

Some date standards in Ruby

  1. rfc822   ‘Tue, 1 Jul 2003 10:52:37 +0200’
  2. rfc2616 (httpdate)  Tue, 05 Sep 2006 16:05:51 GMT
    podcast use this.
    d.strftime(“%a, %d %b %Y %H:%M:%S %z”)
  3. iso8601 2001-04-17T19:23:17.201Z

code demo:

t = # => Sat Sep 08 21:46:40 EDT 2001
t.rfc822 # => “Sat, 08 Sep 2001 21:46:40 -0400”
t.httpdate # => “Sun, 09 Sep 2001 01:46:40 GMT”
t.iso8601 # => “2001-09-08T21:46:40-04:00”

Parse string to date

Say you have a string ‘080430’, you can not simply use

Date::strptime(s, ‘%y/%m/%d’)

to convert it to a Date type. (ArgumentError: 3 elements of civil date are necessary)

Had to split to to 3 parts, then do the convert.

s = ‘080204’
s.sub!(/^(\d{2})(\d{2})(\d{2})$/, ‘\1/\2/\3’)
d = Date::strptime(s, ‘%y/%m/%d’)
How to convert a Date to Time?

Convert charset from GB2312 to Unicode in Ruby

Every Moday, a radio station in Sigapore will upload a new epsiode of their Movie Review program, one of my favorate podcasts. Unfortunately, they only update the html page part, the podcast feed updating usually happens days later.

I can’t wait that long, so I wrote my Ruby program to rip their html page, get mp3 url, and then, to generate a latest podcast feed used by my itunes.

mc =

newitem = mc.mp3_list.first

if newitem.mp3_url != mc.rss.items.first.enclosure.url
#item =
item = mc.rss.items.first
item.title = newitem.title
item.enclosure.url = newitem.mp3_url

item.description = newitem.description
item.pubDate =

mc.rss.items.push(item) =
endputs mc.generate_feed

The problem I got was, the charset from html is gb2312, while the podcast feed is utf-8. I had to covert charset. Eventually, I made it:

require ‘iconv’

title =“UTF-8″,”gbk”).iconv(title)

Here is my podcast feed of Movie Review channel, at least 2 days newer than the official one.

Parse and generate podcast rss feed using Ruby

I am a podcaster, audio only. The first thing after I wake up every morning is to sync my iPod/iShuffle. Recently, I noticed one of my favorite channels failed in update. Later I figured out the reason is the podcast owner put too many items in their rss feed. Even it was only 66 items, but due to the source is from Singapore, the slow network also kill the podcast sync.

I need to find a way to re-generate their podcast rss feed then.

Start thinking of php, then python, finally I chose Ruby. A few more resources than the other two. The example to parse and generate the regular rss feed using ruby is not hard to find. But, there is only one demo of how to generate itunes feed, which is using a rss lib created by a Japanese guy, 須藤功平(Kouhei Sutou).

My re-generate code looks like this:

require ‘rss/itunes’
require ‘open-uri’

# url of original rss feed
source = “”
content = “” # raw content of rss feed will be loaded here

# read rss feed
open(source) do |s| content = end
rss = RSS::Parser.parse(content, false)

# start re-genereat the podcast rss feed
feed =“2.0”) =

# only keep the top 5 items, slice the rest of them!( 5 , – 1 )

puts feed.to_s

When I tried to run this code on my DH share host, it failed due to no rss lib installed. I don’t have root rights, then I found another way to install my own Ruby on DH.

One lesson I learn from last night is, after download lastest ruby bin package using wget and the following installation:

./configure prefix=[YOUR_OWN_RUBY_PREFIX]
make install

I moved the ruby folder into another place I think it’s more appropriate. That extra action almost drove me nuts, I got ‘Unable to find rbconfig.rb’ problem later when I tried to run any ‘setup.rb’ code.

I looked into ruby/lib folder, there are some file with hard code path info in it. So I decided re-do my installation procedure. The problem went away.

To tell which ruby you are running, run: which ruby. What a natural command!