Class: Podcast::Feed

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/podcast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFeed

Returns a new instance of Feed.



18
19
20
21
22
23
# File 'lib/podcast.rb', line 18

def initialize
  @mp3s = []
  @language = "en-us"
  @about = "Made with #{NAME}"
  @base = ''
end

Instance Attribute Details

#aboutObject

Returns the value of attribute about.



13
14
15
# File 'lib/podcast.rb', line 13

def about
  @about
end

#baseObject

Returns the value of attribute base.



13
14
15
# File 'lib/podcast.rb', line 13

def base
  @base
end

#descriptionObject

Returns the value of attribute description.



13
14
15
# File 'lib/podcast.rb', line 13

def description
  @description
end

#imageObject

Returns the value of attribute image.



13
14
15
# File 'lib/podcast.rb', line 13

def image
  @image
end

#languageObject

Returns the value of attribute language.



13
14
15
# File 'lib/podcast.rb', line 13

def language
  @language
end

Returns the value of attribute link.



13
14
15
# File 'lib/podcast.rb', line 13

def link
  @link
end

#titleObject

Returns the value of attribute title.



13
14
15
# File 'lib/podcast.rb', line 13

def title
  @title
end

#versionObject

Returns the value of attribute version.



13
14
15
# File 'lib/podcast.rb', line 13

def version
  @version
end

Instance Method Details

#add_dir(dir) ⇒ Object

add a directory location to the podcast the directory will be recursively search for mp3 files.



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/podcast.rb', line 42

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 './'
      add_mp3(f)
    end
  end
  # go back to original directory
  Dir.chdir(pwd)
end

#add_mp3(file) ⇒ Object

add an mp3 file to the podcast



26
27
28
29
30
31
32
33
# File 'lib/podcast.rb', line 26

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

#eachObject



101
102
103
104
105
# File 'lib/podcast.rb', line 101

def each
  @songs.each do |s|
    yield s
  end
end

#get_rssObject

write the podcast file



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/podcast.rb', line 62

def get_rss
  #version = "1.0" # ["0.9", "1.0", "2.0"]
  version = @version

  content = RSS::Maker.make(@version) do |m|
    m.channel.title = @title
    m.channel.description = @description 
    m.channel.link = @link 
    m.channel.language = @language
    m.channel.about = @about
    m.items.do_sort = true # sort items by date
    m.channel.updated = Time.now.to_s
    m.channel.author = NAME

    if @image != nil
      m.image.url = @image
      m.image.title = @title
    end

    for mp3 in @mp3s 
      item = m.items.new_item
      item.title = mp3
      ## add a base url 
      if base != ''
        link = base + '/' + URI::escape(mp3.path)
      else 
        link = URI::escape(mp3.path)
      end
      item.link = link
      item.date = mp3.mtime
      item.enclosure.url = link
      item.enclosure.length = mp3.length
      item.enclosure.type = mp3.type
    end
  end

  return content
end

#sizeObject

the total amount of files in the podcast



57
58
59
# File 'lib/podcast.rb', line 57

def size
  @mp3s.size
end

#valid?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/podcast.rb', line 35

def valid?
  title != nil && description != nil && link != nil
end