module SportsDb class MediaBuilder def self.update_sn_video require 'open-uri' config = SimpleConfig.for(:feeds) config.sn_video_feeds.each do |feed_title, url| p "Video - #{url}" open( url ) do |file| doc = Nokogiri::XML(file.read) nodes = doc.xpath('//item') media_nodes = doc.xpath('/rss/channel/item/media:content', 'media' => 'http://search.yahoo.com/mrss/') if media_nodes.length > 0 Media.delete_all( "media_type = 'sportingnews_video'") nodes.each do |entry| high_bandwidth_node = entry.at('.//media:content[@medium="video"]', 'media' => 'http://search.yahoo.com/mrss/') high_bandwidth_url = high_bandwidth_node.nil? ? '' : high_bandwidth_node['url'] low_bandwidth_url = high_bandwidth_url image_url_node = entry.at('./media:thumbnail', 'media' => 'http://search.yahoo.com/mrss/') if image_url_node.nil? image_url = "" thumb_url = "" else image_url = image_url_node['url'] thumb_url = CONFIG.image_service + "crop/w/55/h/55/url/#{CGI::escape(CGI::escape(image_url))}" end p "Video added - #{entry.xpath('title').text}" Media.create( :feed_title => feed_title, :title => entry.xpath('title').text, :description => entry.xpath('content:encoded', 'content' => 'http://purl.org/rss/1.0/modules/content/').text, :contents => entry.xpath('content:encoded', 'content' => 'http://purl.org/rss/1.0/modules/content/').text, :high_bandwidth_url => high_bandwidth_url, :low_bandwidth_url => low_bandwidth_url, :media_type => 'sportingnews_video', :thumb_image_url => thumb_url, :article_image_url => image_url, :published_at => DateTime.parse(entry.xpath('pubDate').text) ) end else Rails.logger.info("No URLs available - Did not update videos") end end end rescue Exception => e Zumobi::ExceptionHandler.error e end end end