Class: Podcastinator::FileFeed::FileItem
- Defined in:
- lib/podcastinator/file_feed.rb
Class Method Summary collapse
Instance Method Summary collapse
- #guid ⇒ Object
-
#initialize(feed, filename) ⇒ FileItem
constructor
A new instance of FileItem.
- #is_guid_permalink? ⇒ Boolean
- #keywords ⇒ Object
- #mime_type ⇒ Object
- #time ⇒ Object
Constructor Details
#initialize(feed, filename) ⇒ FileItem
Returns a new instance of FileItem.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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 .present? && @track.present? then %[#{ album } ##{ track }] end @duration = fileref.audio_properties.length end end |
Class Method Details
.build(feed, files) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/podcastinator/file_feed.rb', line 105 def self.build(feed, files) files.map do |filename| title, subtitle, , time, image_url = nil TagLib::FileRef.open(local_filename) do |fileref| tag = fileref.tag title = tag.title = 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, , time, image_url) end end |
.globs ⇒ Object
101 102 103 |
# File 'lib/podcastinator/file_feed.rb', line 101 def self.globs mime_types.keys.map { |ext| "**/*.#{ ext }" } end |
.mime_types ⇒ Object
95 96 97 98 99 |
# File 'lib/podcastinator/file_feed.rb', line 95 def self.mime_types { "mp3" => "audio/mpeg", } end |
Instance Method Details
#guid ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# 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 |
#is_guid_permalink? ⇒ Boolean
83 84 85 |
# File 'lib/podcastinator/file_feed.rb', line 83 def is_guid_permalink? false end |
#keywords ⇒ Object
91 92 93 |
# File 'lib/podcastinator/file_feed.rb', line 91 def keywords [] end |
#mime_type ⇒ Object
64 65 66 67 68 69 |
# 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 ⇒ Object
87 88 89 |
# File 'lib/podcastinator/file_feed.rb', line 87 def time @time || File.mtime(local_filename) end |