Skip to content

Commit

Permalink
Skips corrupt mp3s without failing
Browse files Browse the repository at this point in the history
Tidied up some annoying code styles
Added github link to README
Added test and data for corrupt mp3s
  • Loading branch information
boncey committed Feb 8, 2012
1 parent 490d421 commit 10bc458
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Please note:
This used to be hosted at http://podcast.rubyforge.org/
However, that version no longer works with newer versions of Ruby.

I have made changes so it to works and after getting no answer from the author or via the list on rubyforge have decided to upload my version here.
I have made changes so it to works and after getting no answer from the author or via the list on rubyforge have decided to upload my version to https://github.com/boncey/ruby-podcast
29 changes: 15 additions & 14 deletions bin/podcast
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#
# == Author
# Ed Summers <[email protected]>
# Darren Greaves https://github.com/boncey
#
# == Copyright
# Copyright (c) 2004 Ed Summers.
Expand All @@ -35,26 +36,26 @@ podcast = Podcast::Feed.new()

# read options
opts = OptionParser.new
opts.on( "-d", "--dir VAL", String ) { |val| dir=val }
opts.on( "-o", "--out VAL", String ) { |val| podcast_file=val }
opts.on( "-b", "--base VAL", String ) { |val| podcast.base=val }
opts.on( "-l", "--link VAL", String ) { |val| podcast.link=val }
opts.on( "-t", "--title VAL", String ) { |val| podcast.title=val }
opts.on( "-a", "--about VAL", String ) { |val| podcast.about=val }
opts.on( "-i", "--image VAL", String ) { |val| podcast.image=val }
opts.on( "-v", "--version VAL", String ) { |val| version=val }
opts.on( "-e", "--description VAL", String ) { |val| podcast.description=val }
opts.parse(ARGV) rescue RDoc::usage( 'usage' )
RDoc::usage( 'usage' ) if dir == nil || podcast.title == nil || podcast.description == nil
opts.on("-d", "--dir VAL", String) { |val| dir=val }
opts.on("-o", "--out VAL", String) { |val| podcast_file=val }
opts.on("-b", "--base VAL", String) { |val| podcast.base=val }
opts.on("-l", "--link VAL", String) { |val| podcast.link=val }
opts.on("-t", "--title VAL", String) { |val| podcast.title=val }
opts.on("-a", "--about VAL", String) { |val| podcast.about=val }
opts.on("-i", "--image VAL", String) { |val| podcast.image=val }
opts.on("-v", "--version VAL", String) { |val| version=val }
opts.on("-e", "--description VAL", String) { |val| podcast.description=val }
opts.parse(ARGV) rescue RDoc::usage('usage')
RDoc::usage('usage') if dir == nil || podcast.title == nil || podcast.description == nil

# add a directory
podcast.add_dir( dir )
podcast.add_dir(dir)
podcast.version = version ? version : "0.9"

# write off the rss
if podcast_file
file = File.new( podcast_file, 'w' )
file.write( podcast.get_rss() )
file = File.new(podcast_file, 'w')
file.write(podcast.get_rss())
file.close
else
puts "Outputting podcast"
Expand Down
22 changes: 13 additions & 9 deletions lib/podcast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,30 @@ def initialize
end

# add an mp3 file to the podcast
def add_mp3( file )
mp3 = Mp3File.new( file )
@mp3s.push( mp3 )
def add_mp3(file)
begin
mp3 = Mp3File.new(file)
@mp3s.push(mp3)
rescue Mp3InfoError => e
puts "Skipping #{file} as it has a problem: #{e}"
end
end

# add a directory location to the podcast
# the directory will be recursively search
# for mp3 files.
def add_dir( dir )
def add_dir(dir)
# we chdir into the directory so that file paths will be relative
pwd = Dir.pwd
Dir.chdir( dir )
Find.find( '.' ) do |f|
if ( f =~ /\.mp3$/ && File.size?(f))
f.sub!( %r{^./}, '' ) # remove leading './'
Dir.chdir(dir)
Find.find('.') do |f|
if (f =~ /\.mp3$/ && File.size?(f))
f.sub!(%r{^./}, '') # remove leading './'
add_mp3(f)
end
end
# go back to original directory
Dir.chdir( pwd )
Dir.chdir(pwd)
end

# the total amount of files in the podcast
Expand Down
1 change: 1 addition & 0 deletions test/bad.mp3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bad
8 changes: 8 additions & 0 deletions test/ts_podcast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ def test_add_mp3
assert_equal(p.size(), 3)
end

def test_add_bad_mp3
p = Podcast::Feed.new
p.add_mp3('test/test.mp3')
p.add_mp3('test/test.mp3')
p.add_mp3('test/bad.mp3')
assert_equal(p.size(), 2)
end

def test_add_dir
p = Podcast::Feed.new
p.add_dir('.')
Expand Down

0 comments on commit 10bc458

Please sign in to comment.