Class: Faceoff::Video
- Inherits:
-
Object
- Object
- Faceoff::Video
- Defined in:
- lib/faceoff/video.rb
Constant Summary collapse
- TITLE_REG =
/"video_title", "([^"]+)"/m
- SRC_REG =
/"video_src", "([^"]+)"/m
- ID_REG =
/"video_id", "([^"]+)"/m
Instance Attribute Summary collapse
-
#fid ⇒ Object
Facebook video id.
-
#name ⇒ Object
Name of the video.
-
#url ⇒ Object
Url of the video.
Class Method Summary collapse
-
.retrieve_all(faceoff, options = {}, &block) ⇒ Object
Retrieve all ‘Videos of Me’.
-
.videos_of_me(faceoff, options = {}, &block) ⇒ Object
Alias for Video::retrieve_all.
Instance Method Summary collapse
-
#initialize(id, url, name) ⇒ Video
constructor
A new instance of Video.
-
#save!(target = "./Videos of me") ⇒ Object
Saves the video the the provided path.
Constructor Details
#initialize(id, url, name) ⇒ Video
Returns a new instance of Video.
62 63 64 65 66 |
# File 'lib/faceoff/video.rb', line 62 def initialize id, url, name @fid = id @url = url @name = name end |
Instance Attribute Details
#fid ⇒ Object
Facebook video id.
53 54 55 |
# File 'lib/faceoff/video.rb', line 53 def fid @fid end |
#name ⇒ Object
Name of the video.
59 60 61 |
# File 'lib/faceoff/video.rb', line 59 def name @name end |
#url ⇒ Object
Url of the video.
56 57 58 |
# File 'lib/faceoff/video.rb', line 56 def url @url end |
Class Method Details
.retrieve_all(faceoff, options = {}, &block) ⇒ Object
Retrieve all ‘Videos of Me’.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/faceoff/video.rb', line 12 def self.retrieve_all faceoff, ={}, &block agent = faceoff.agent limit = [:limit] start = [:start] || 0 page = agent.get "/video/?of=#{faceoff.profile_id}&s=#{start}" summary = page.search("div[@class='summary']").first.text video_count = ($2.to_i - 1) if summary =~ /(of|all) (\d+) videos/ video_count = limit if limit && video_count > limit page = page.link_with(:href => %r{/video.php}).click videos = [] video_count.times do |i| video_title = URI.decode($1.gsub('+', ' ')) if page.body =~ TITLE_REG video_src = URI.decode($1) if page.body =~ SRC_REG video_id = URI.decode($1) if page.body =~ ID_REG videos << new(video_id, video_src, video_title) yield videos.last if block_given? next_link = page.link_with(:text => 'Next') break unless next_link page = next_link.click end videos end |
.videos_of_me(faceoff, options = {}, &block) ⇒ Object
Alias for Video::retrieve_all
47 48 49 |
# File 'lib/faceoff/video.rb', line 47 def self.videos_of_me faceoff, ={}, &block retrieve_all faceoff, , &block end |
Instance Method Details
#save!(target = "./Videos of me") ⇒ Object
Saves the video the the provided path.
72 73 74 75 76 77 78 79 80 |
# File 'lib/faceoff/video.rb', line 72 def save! target="./Videos of me" filename = File.join(target, "#{@name}#{File.extname(@url)}") data = Faceoff.download(@url) Faceoff.safe_save(filename) do |file| file.write data end end |