class Podcastinator::FileFeed::FileItem

Public Class Methods

build(feed, files) click to toggle source
# File lib/podcastinator/file_feed.rb, line 105
def self.build(feed, files)
  files.map do |filename|
    title, subtitle, author, time, image_url = nil

    TagLib::FileRef.open(local_filename) do |fileref|
      tag      = fileref.tag

      title    = tag.title
      author   = tag.artist
      album    = tag.album
      track    = if tag.track.present? && tag.track != 0 then tag.to_s.track[/^\d+/] end
      subtitle = if album.present? && track.present? then %[#{ album } ##{ track }] end
    end

    new(feed, filename, title, subtitle, author, time, image_url)
  end
end
globs() click to toggle source
# File lib/podcastinator/file_feed.rb, line 101
def self.globs
  mime_types.keys.map { |ext| "**/*.#{ ext }" }
end
mime_types() click to toggle source
# File lib/podcastinator/file_feed.rb, line 95
def self.mime_types
  {
    "mp3" => "audio/mpeg",
  }
end
new(feed, filename) click to toggle source
# File lib/podcastinator/file_feed.rb, line 39
def initialize(feed, filename)
  @feed           = feed
  @filename       = filename
  @local_filename = File.join(feed.local_path, filename)
  @url            = "#{ feed.url }/#{ URI.escape @filename.to_s }".gsub("//", "/")

  @image_url =
    if File.file? File.join(feed.local_path, "#{ filename }.jpg")
      "#{ @url }.jpg"
    else
      feed.image_url
    end

  TagLib::FileRef.open(local_filename) do |fileref|
    tag      = fileref.tag

    @title    = tag.title
    @author   = tag.artist
    @album    = tag.album
    @track    = if tag.track.present? && tag.track != 0 then tag.to_s.track[/^\d+/] end
    @subtitle = if author.present? && @track.present? then %[#{ album } ##{ track }] end
    @duration = fileref.audio_properties.length
  end
end

Public Instance Methods

guid() click to toggle source
# File lib/podcastinator/file_feed.rb, line 71
def guid
  md5 = Digest::MD5.new

  File.open(local_filename, 'rb') do |io|
    while (buf = io.read(4096)) && (buf.length > 0)
      md5.update(buf)
    end
  end

  md5.to_s
end
keywords() click to toggle source
# File lib/podcastinator/file_feed.rb, line 91
def keywords
  []
end
mime_type() click to toggle source
# File lib/podcastinator/file_feed.rb, line 64
def mime_type
  case File.extname(filename).downcase
  when ".mp3" then "audio/mpeg"
  else raise UnknownMimeType, "podcastinator can't handle #{ filename }"
  end
end
time() click to toggle source
# File lib/podcastinator/file_feed.rb, line 87
def time
  @time || File.mtime(local_filename)
end