Permalink
Browse files

added Gvideo::User.new("A005148908335059515423").fetch_video("-283828…

…1997424715962")
  • Loading branch information...
1 parent be35e3d commit 4d4d33688db3bd2486f019be5803e1a374c9e559 @mattetti committed Sep 28, 2008
Showing with 21 additions and 1 deletion.
  1. +5 −0 README
  2. +10 −1 lib/gvideo.rb
  3. +6 −0 spec/gvideo_spec.rb
View
@@ -22,7 +22,12 @@ or use conditions
user.fetch_videos(:title => "Durex: The Garden").first
videos = user.fetch_videos(:title => /Durex/)
+ videos = user.fetch_videos(:duration => 120)
+ videos = user.fetch_videos(:duration => 60..360)
+or finally just retrieve a video by using the docid
+
+ user.fetch_video("6977350643295106940")
Video methods and attributes:
---
View
@@ -83,13 +83,19 @@ def fetch_videos(conditions = {})
# if video_count > 100 get all the videos using a higher cursor
0.upto((video_count/100.to_f).ceil - 1) do |cursor|
p "fetching videos with cursor: #{cursor}" if $Gvideo_verbose
+ # let's not loop through more pages if we already found the document we are looking for
+ return videos if (conditions[:docid] && videos.length > 0)
cursor = (cursor * 100) if cursor > 0
- videos << extract_video_elements_from_raw_data(video_raw_data(cursor), cursor, conditions)
+ videos << extract_video_elements_from_raw_data(video_raw_data(cursor), cursor, conditions).compact
end
videos.flatten
end
+ def fetch_video(docid)
+ fetch_videos(:docid => docid.to_s)
+ end
+
# returns the amount of videos uploaded by the user
def video_count
if @video_count.nil?
@@ -119,6 +125,9 @@ def extract_video(element, conditions)
video_url = element['url']
duration_in_minutes = element.at("div.vli-metadata span.vlim-duration").inner_text
+ if conditions.has_key?(:docid)
+ return if conditions[:docid].is_a?(String) && conditions[:docid] != docid
+ end
if conditions.has_key?(:title)
return if conditions[:title].is_a?(String) && conditions[:title] != title
return if conditions[:title].is_a?(Regexp) && title.match(conditions[:title]).nil?
View
@@ -61,6 +61,12 @@
# videos.length.should < @user.fetch_videos.length
end
+ it "should be able to retrieve a user video using a docid" do
+ video = @user.fetch_video("6977350643295106940")
+ video.should_not be_nil
+ video.length.should == 1
+ end
+
end
describe "Gvideo::Video" do

0 comments on commit 4d4d336

Please sign in to comment.