google-video 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'google-video'
4
+ require File.dirname(__FILE__) + '/video_test_helper'
5
+
6
+ class TestClient < Test::Unit::TestCase
7
+ include VideoTestHelper
8
+
9
+ def test_validation
10
+ # make sure we can do basic client instantiation
11
+ assert_nothing_raised do
12
+ @client = GoogleVideo::Client.new
13
+ end
14
+
15
+ # make sure we get an error if we specify a bad host
16
+ assert_raise GoogleVideo::GoogleVideoException do
17
+ @client = GoogleVideo::Client.new :host => 'nO)domain#!badbadbad'
18
+ request = GoogleVideo::TopVideosRequest.new
19
+ @client.top_videos request
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,76 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'google-video'
4
+ require File.dirname(__FILE__) + '/video_test_helper'
5
+
6
+ class TestTopVideos < Test::Unit::TestCase
7
+ include VideoTestHelper
8
+
9
+ # the number of top videos in the list
10
+ @@TOP_VIDEOS_COUNT = 100
11
+
12
+ def setup
13
+ @client = GoogleVideo::Client.new
14
+ end
15
+
16
+ def test_request_validation
17
+ # make sure an invalid country is detected
18
+ assert_raise ArgumentError do
19
+ GoogleVideo::TopVideosRequest.new(:country => 'foobarbaz')
20
+ end
21
+
22
+ # make sure the top videos method requires an appropriate request object type
23
+ assert_raise ArgumentError do
24
+ @client.top_videos 'foo'
25
+ end
26
+ end
27
+
28
+ # check the basic top video page listings
29
+ def test_top_videos
30
+ request = GoogleVideo::TopVideosRequest.new
31
+ response = @client.top_videos request
32
+ assert_valid_top_videos_response response
33
+ end
34
+
35
+ # make sure specifying a country operates properly
36
+ def test_top_videos_country
37
+ request = GoogleVideo::TopVideosRequest.new(:country => 'Brazil')
38
+ brazil_response = @client.top_videos request
39
+ assert_valid_top_videos_response brazil_response
40
+
41
+ request = GoogleVideo::TopVideosRequest.new(:country => 'Japan')
42
+ japanese_response = @client.top_videos request
43
+ assert_valid_top_videos_response japanese_response
44
+
45
+ # assume that at least one video in the japanese list will differ from the
46
+ # brazilian list, which seems like a safe bet given the number of videos
47
+ # in the list
48
+ diff = false
49
+ japanese_response.videos.each_with_index {
50
+ |jv, index| diff ||= (brazil_response.videos[index].video.doc_id != jv.video.doc_id) }
51
+ assert diff
52
+ end
53
+
54
+ def assert_valid_top_videos_response (response)
55
+ # sanity-check the result
56
+ assert_not_nil response
57
+ assert_valid_google_video_url response.request_url
58
+ assert_not_nil response.videos
59
+ assert_instance_of Array, response.videos
60
+
61
+ # make sure we got the proper number of entries
62
+ assert_equal response.videos.length, @@TOP_VIDEOS_COUNT
63
+
64
+ # validate each entry
65
+ response.videos.each { |video| assert_valid_top_video(video) }
66
+ end
67
+
68
+ def assert_valid_top_video (top_video)
69
+ assert_not_nil top_video
70
+ assert_instance_of GoogleVideo::TopVideo, top_video
71
+ assert ([0, 1, -1].include?(top_video.movement))
72
+ assert (top_video.rank_today >= 0 && top_video.rank_today <= @@TOP_VIDEOS_COUNT)
73
+ assert (top_video.rank_yesterday >= 0 && top_video.rank_yesterday <= @@TOP_VIDEOS_COUNT)
74
+ assert_valid_video(top_video.video)
75
+ end
76
+ end
@@ -0,0 +1,104 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'google-video'
4
+ require File.dirname(__FILE__) + '/video_test_helper'
5
+
6
+ class TestVideoDetails < Test::Unit::TestCase
7
+ include VideoTestHelper
8
+
9
+ @@QUERY = 'christina ricci'
10
+ @@DOC_ID = 5338330163635012030
11
+
12
+ def setup
13
+ @client = GoogleVideo::Client.new
14
+ end
15
+
16
+ def test_request_validation
17
+ # make sure the video details method requires an appropriate request object type
18
+ assert_raise ArgumentError do
19
+ @client.video_details 'foo'
20
+ end
21
+
22
+ # fetch a sample video for parameter testing purposes
23
+ request = GoogleVideo::VideoSearchRequest.new(:query => @@QUERY)
24
+ video = @client.video_search(request).videos.first
25
+
26
+ # make sure general and correct request construction succeeds
27
+ assert_nothing_raised do
28
+ GoogleVideo::VideoDetailsRequest.new(:doc_id => @@DOC_ID)
29
+ GoogleVideo::VideoDetailsRequest.new(:video => video)
30
+ end
31
+
32
+ # make sure an attempt to use nothing fails
33
+ assert_raise ArgumentError do
34
+ GoogleVideo::VideoDetailsRequest.new
35
+ end
36
+
37
+ # make sure an attempt to use both fails
38
+ assert_raise ArgumentError do
39
+ GoogleVideo::VideoDetailsRequest.new(:doc_id => @@DOC_ID, :video => video)
40
+ end
41
+ end
42
+
43
+ def test_video_details_by_video
44
+ # grab a sample video
45
+ request = GoogleVideo::VideoSearchRequest.new(:query => @@QUERY)
46
+ response = @client.video_search request
47
+ assert (response.videos && response.videos.length >= 1)
48
+
49
+ # test running a detail request on each video
50
+ response.videos.each do |video|
51
+ # look up the video's details
52
+ request = GoogleVideo::VideoDetailsRequest.new(:video => video)
53
+ response = @client.video_details request
54
+ # check it out
55
+ assert_valid_video_detail_response(response)
56
+ end
57
+ end
58
+
59
+ def test_video_details_by_doc_id
60
+ request = GoogleVideo::VideoDetailsRequest.new(:doc_id => @@DOC_ID)
61
+ response = @client.video_details request
62
+ assert_valid_video_detail_response(response)
63
+ end
64
+
65
+ # TODO: test the three variants of possible "durationetc" span parsing
66
+
67
+ def assert_valid_playlist_entry (entry)
68
+ assert_not_nil entry
69
+ assert_instance_of GoogleVideo::PlaylistEntry, entry
70
+ assert (entry.title && entry.title.length > 0)
71
+ assert_valid_google_video_url entry.thumbnail_image_url
72
+ assert (entry.duration && entry.duration.length > 0)
73
+ assert_match(/\d+/, entry.duration)
74
+ assert_valid_google_video_url entry.page_url
75
+ end
76
+
77
+ def assert_valid_video_frame_thumbnail (frame)
78
+ assert_not_nil frame
79
+ assert (frame.title && frame.title.length > 0)
80
+ assert_valid_google_video_url frame.thumbnail_image_url
81
+ end
82
+
83
+ def assert_valid_video_detail_response (response)
84
+ # sanity-check a couple of basic things
85
+ assert_valid_google_video_url response.request_url
86
+ video = response.video
87
+
88
+ # poke and prod the video object
89
+ assert_valid_video video
90
+ assert (video.view_count >= video.yesterday_view_count)
91
+ assert_match /http:\/\/video\.google\.com\/videogvp\/[^\.]+\.gvp\?docid=[0-9\-\+]+/, video.video_file_url
92
+ assert_kind_of Numeric, video.rank
93
+ assert_kind_of Numeric, video.rank_delta
94
+ assert_instance_of Time, video.upload_date
95
+
96
+ # check the video frame thumbnails
97
+ assert (video.video_frame_thumbnails && video.video_frame_thumbnails.length > 0)
98
+ video.video_frame_thumbnails.each { |frame| assert_valid_video_frame_thumbnail(frame) }
99
+
100
+ # check the playlist entries
101
+ assert (video.playlist_entries && video.playlist_entries.length > 0)
102
+ video.playlist_entries.each { |entry| assert_valid_playlist_entry(entry) }
103
+ end
104
+ end
@@ -0,0 +1,89 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'google-video'
4
+ require File.dirname(__FILE__) + '/video_test_helper'
5
+
6
+ class TestVideoSearch < Test::Unit::TestCase
7
+ include VideoTestHelper
8
+
9
+ @@RESULTS_PER_PAGE = 10
10
+ @@QUERY_STRING = 'tessa'
11
+ @@DURATION = 'long'
12
+ @@PAGE = 2
13
+
14
+ def setup
15
+ @client = GoogleVideo::Client.new
16
+ end
17
+
18
+ def test_request_validation
19
+ # make sure some general valid requests work ok
20
+ assert_nothing_raised do
21
+ GoogleVideo::VideoSearchRequest.new(:query => @@QUERY_STRING)
22
+ GoogleVideo::VideoSearchRequest.new(:query => @@QUERY_STRING, :sort => 'date')
23
+ GoogleVideo::VideoSearchRequest.new(:query => @@QUERY_STRING, :sort => 'date', :duration => 'all')
24
+ GoogleVideo::VideoSearchRequest.new(:query => @@QUERY_STRING, :duration => 'all')
25
+ GoogleVideo::VideoSearchRequest.new(:query => @@QUERY_STRING, :duration => 'all', :page => 2)
26
+ end
27
+
28
+ # make sure an invalid sort is detected
29
+ assert_raise ArgumentError do
30
+ GoogleVideo::VideoSearchRequest.new(:query => @@QUERY_STRING, :sort => 'monkey')
31
+ end
32
+
33
+ # make sure an invalid duration is detected
34
+ assert_raise ArgumentError do
35
+ GoogleVideo::VideoSearchRequest.new(:query => @@QUERY_STRING, :duration => 'el_pollo_diablo')
36
+ end
37
+
38
+ # make sure a query string is required
39
+ assert_raise ArgumentError do
40
+ GoogleVideo::VideoSearchRequest.new(:duration => 'all')
41
+ end
42
+
43
+ # make sure the video search method requires an appropriate request object
44
+ assert_raise ArgumentError do
45
+ @client.video_search "foo"
46
+ end
47
+ end
48
+
49
+ def test_search
50
+ request = GoogleVideo::VideoSearchRequest.new(:query => @@QUERY_STRING)
51
+ response = @client.video_search request
52
+ assert_valid_search_response response
53
+
54
+ assert_equal response.start_index, 1
55
+ assert_equal response.end_index, @@RESULTS_PER_PAGE
56
+ assert (response.total_result_count >= @@RESULTS_PER_PAGE)
57
+ assert_equal response.videos.length, @@RESULTS_PER_PAGE
58
+ end
59
+
60
+ def test_search_duration
61
+ request = GoogleVideo::VideoSearchRequest.new(:query => @@QUERY_STRING, :duration => @@DURATION)
62
+ response = @client.video_search request
63
+ assert_valid_search_response response
64
+
65
+ assert_equal response.start_index, 1
66
+ assert_equal response.end_index, @@RESULTS_PER_PAGE
67
+ assert (response.total_result_count >= @@RESULTS_PER_PAGE)
68
+ assert_equal response.videos.length, @@RESULTS_PER_PAGE
69
+
70
+ # TODO: make sure all videos are within the specified duration
71
+ end
72
+
73
+ def test_search_paginate
74
+ request = GoogleVideo::VideoSearchRequest.new(:query => @@QUERY_STRING, :duration => @@DURATION, :page => @@PAGE)
75
+ response = @client.video_search request
76
+ assert_valid_search_response response
77
+
78
+ assert_equal response.start_index, @@RESULTS_PER_PAGE + 1
79
+ max_result_index = @@RESULTS_PER_PAGE * @@PAGE
80
+ assert_equal response.end_index, ((response.total_result_count < max_result_index) ? response.total_result_count : max_result_index)
81
+ end
82
+
83
+ def assert_valid_search_response (response)
84
+ assert_not_nil response
85
+ assert_valid_google_video_url response.request_url
86
+ assert (response.execution_time > 0.0)
87
+ response.videos.each { |video| assert_valid_video(video) }
88
+ end
89
+ end
@@ -0,0 +1,19 @@
1
+ module VideoTestHelper
2
+ def assert_valid_video (video)
3
+ assert_not_nil video
4
+ assert_instance_of GoogleVideo::Video, video
5
+ assert_instance_of Bignum, video.doc_id
6
+ assert_valid_google_video_url video.page_url
7
+ # we don't always have a thumbnail image, e.g. on a detail page request
8
+ if (video.thumbnail_image_url)
9
+ assert_valid_google_video_url video.thumbnail_image_url
10
+ end
11
+ assert (video.duration && video.duration.length > 0)
12
+ assert (video.rating_count >= 0)
13
+ assert (video.star_count >= 0)
14
+ end
15
+
16
+ def assert_valid_google_video_url (url)
17
+ assert(url && (url =~ /^http:\/\/video.google.com\//))
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: google-video
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.5.0
7
+ date: 2006-11-09 00:00:00 -08:00
8
+ summary: A Ruby object-oriented interface to Google Video content.
9
+ require_paths:
10
+ - lib
11
+ email: shaper@wgks.org
12
+ homepage:
13
+ rubyforge_project: google-video
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Walter Korman
31
+ files:
32
+ - examples/example.rb
33
+ - examples/get-top-videos.rb
34
+ - examples/get-video-details.rb
35
+ - examples/search-videos.rb
36
+ - lib/google-video.rb
37
+ - test/test_client.rb
38
+ - test/test_top_videos.rb
39
+ - test/test_video_details.rb
40
+ - test/test_video_search.rb
41
+ - test/video_test_helper.rb
42
+ - AUTHORS
43
+ - CHANGELOG
44
+ - README
45
+ - Rakefile
46
+ - TODO
47
+ test_files:
48
+ - test/test_client.rb
49
+ - test/test_top_videos.rb
50
+ - test/test_video_details.rb
51
+ - test/test_video_search.rb
52
+ rdoc_options:
53
+ - --main
54
+ - README
55
+ extra_rdoc_files:
56
+ - README
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ requirements: []
62
+
63
+ dependencies:
64
+ - !ruby/object:Gem::Dependency
65
+ name: hpricot
66
+ version_requirement:
67
+ version_requirements: !ruby/object:Gem::Version::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0.4"
72
+ version:
73
+ - !ruby/object:Gem::Dependency
74
+ name: htmlentities
75
+ version_requirement:
76
+ version_requirements: !ruby/object:Gem::Version::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 3.0.1
81
+ version: