Class: VideoFeed
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- VideoFeed
- Defined in:
- lib/forge/app/models/video_feed.rb
Class Method Summary collapse
-
.build_vimeo_feed ⇒ Object
Vimeo Import.
- .build_vimeo_item(item) ⇒ Object
-
.build_youtube_feed ⇒ Object
Youtube Import.
- .build_youtube_item(item) ⇒ Object
-
.import_videos(source) ⇒ Object
Video Import.
-
.sources ⇒ Object
Methods.
- .vimeo_types ⇒ Object
Class Method Details
.build_vimeo_feed ⇒ Object
Vimeo Import
66 67 68 69 70 71 72 73 74 |
# File 'lib/forge/app/models/video_feed.rb', line 66 def self.build_vimeo_feed @response = "A channel has not been set. Check your <a href='/forge/settings?tab=video'>settings</a>.".html_safe if MySettings.vimeo_channel.blank? begin @rss = SimpleRSS.parse open("http://vimeo.com/#{MySettings.vimeo_channel}/#{MySettings.vimeo_feed_type == 'Channel' ? 'videos' : MySettings.vimeo_feed_type.downcase}/rss") rescue @response = "Your channel is not valid. Check your <a href='/forge/settings?tab=video'>settings</a>.".html_safe if @response.blank? end @rss.blank? ? @response : @rss end |
.build_vimeo_item(item) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/forge/app/models/video_feed.rb', line 76 def self.build_vimeo_item(item) VideoFeed.new( :video_id => item.link.split("vimeo.com/")[1], :title => item.title, :channel => MySettings.vimeo_channel, :thumbnail_url => item.media_thumbnail_url, :published_at => item.pubDate, :source => item.link.split("://")[1].split(".com")[0] ) end |
.build_youtube_feed ⇒ Object
Youtube Import
44 45 46 47 48 49 50 51 52 |
# File 'lib/forge/app/models/video_feed.rb', line 44 def self.build_youtube_feed @response = "A channel has not been set. Check your <a href='/forge/settings?tab=video'>settings</a>.".html_safe if MySettings.youtube_channel.blank? begin @rss = SimpleRSS.parse open("http://gdata.youtube.com/feeds/api/users/#{MySettings.youtube_channel}/uploads") rescue @response = "Your channel is not valid. Check your <a href='/forge/settings?tab=video'>settings</a>.".html_safe if @response.blank? end @rss.blank? ? @response : @rss end |
.build_youtube_item(item) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/forge/app/models/video_feed.rb', line 54 def self.build_youtube_item(item) VideoFeed.new( :video_id => item.link.split("v=")[1].split("&")[0], :title => item.title, :channel => MySettings.youtube_channel, :thumbnail_url => item.media_thumbnail_url, :published_at => item.published, :source => item.link.split("://")[1].split("/")[0].gsub("www.", "").split(".")[0] ) end |
.import_videos(source) ⇒ Object
Video Import
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/forge/app/models/video_feed.rb', line 25 def self.import_videos(source) VideoFeed.build_youtube_feed if source == "Youtube" VideoFeed.build_vimeo_feed if source == "Vimeo" @response = "A channel has not been set. Check your <a href='/forge/settings?tab=video'>settings</a>.".html_safe if source.blank? # Import unless @response count = 0 @rss.items.each do |item| video = VideoFeed.build_youtube_item(item) if source == "Youtube" video = VideoFeed.build_vimeo_item(item) if source == "Vimeo" count += 1 if video.save end @response = "#{count} new videos added." end @response end |
.sources ⇒ Object
Methods
16 17 18 |
# File 'lib/forge/app/models/video_feed.rb', line 16 def self.sources ["Youtube","Vimeo"] end |
.vimeo_types ⇒ Object
20 21 22 |
# File 'lib/forge/app/models/video_feed.rb', line 20 def self.vimeo_types ["Channel","Likes"] end |