如何从 rss 提要中保存不同字段的图像和视频
我有enclosure_url 和enclosure_type
如果此类型是图片保存在图片字段中
例如:
feed = Feedjira::Feed.fetch_and_parse 'http://example.com/feed.xml'
feed.entries.first.enclosure_url # => "http://example.com/d260eb5c"
feed.entries.first.enclosure_type # => "image/jpeg"
feed.entries.last.enclosure_url # => 'https://youtu.be/AnXR-MKhg64'
feed.entries.last.enclosure_type # => "video/x-ms-asf"
feed_entry.rb
class FeedEntry
include Mongoid::Document
include Mongoid::Timestamps
require 'social_shares'
field :enclosure_url, type: String
field :enclosure_type, type: String
field :video, type: String
mount_uploader :picture, PictureUploader
before_save :media_type
def media_type
if self.enclosure_type = /image\//
self.picture = self.enclosure_url
else
self.video = self.enclosure_url
end
end
end