Skip to content

Instantly share code, notes, and snippets.

@firebelly
Created September 20, 2011 20:04
Show Gist options
  • Save firebelly/1230168 to your computer and use it in GitHub Desktop.
Save firebelly/1230168 to your computer and use it in GitHub Desktop.
mp3 enclosure tag length attribute to minutes:seconds
# in => <enclosure url="http://url.com/feed/some_final_url.mp3" length="42102758" type="audio/mpeg"/>
time = ((item.enclosure.length/1024.0) / 16.0)
p [time.to_i/60 % 60, time.to_i % 60].map{|t| t.to_s.rjust(2, '0')}.join(':')
# out => "42:49"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment