beef-youtube-g 0.4.9.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,41 @@
1
+ == 0.4.9.9 / 2008-09-01
2
+
3
+ * Add Geodata information (thanks Jose Galisteo)
4
+ * Added :page and :per_page options, this allows easier usage of the will_paginate
5
+ plugin with the library. The :offset and :max_results options are no longer available. [Daniel Insley]
6
+ * Added ability to get video responses on the instances of the YouTube::Model::Video object. [Daniel Insley]
7
+ * Added and improved the existing documentation [Daniel Insley]
8
+ * Fixed usage of deprecated yt:racy, now using media:rating [Daniel Insley]
9
+ * Renamed can_embed? method to embeddable? [Daniel Insley]
10
+ * Added ability for padingation and ordering on standard feeds. [Daniel Insley]
11
+ * Add error-handling for video upload errors. [FiXato]
12
+ * Add error-handling for authentication errors from YouTube during video upload. [FiXato]
13
+ * Add support for making videos private upon video upload. [FiXato]
14
+ * Fix issue with REXML parsing of video upload response. [FiXato]
15
+ * Fix issue with response code comparison. [FiXato]
16
+ * Authcode is now retrieved for video uploads. [FiXato]
17
+ * Add basic support for uploading videos [thanks Joe Damato]
18
+ * Add basic support for related videos [tmm1]
19
+ * Improve docs for order_by attribute [thanks Jason Arora]
20
+ * Added support for the "racy" parameter (choices are "include" or "exclude") [thanks Jason Arora]
21
+ * Add missing attribute reader for description [tmm1]
22
+ * Fix issue with missing yt:statistics and viewCount [tmm1]
23
+ * Allow Client#video_by to take either a url or a video id [tmm1]
24
+
25
+ == 0.4.1 / 2008-02-11
26
+
27
+ * Added 3GPP video format [shane]
28
+ * Fixed tests [shane]
29
+
30
+ == 0.4.0 / 2007-12-18
31
+
32
+ * Fixed API projection in search URL [Pete Higgins]
33
+ * Fixed embeddable video searching [Pete Higgins]
34
+ * Fixed video embeddable detection [Pete Higgins]
35
+ * Fixed unique id hyphen detection [Pete Higgins, Chris Taggart]
36
+
37
+ == 0.3.0 / 2007-09-17
38
+
39
+ * Initial public release
40
+ * Birthday!
41
+
@@ -0,0 +1,28 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ TODO.txt
6
+ lib/youtube_g.rb
7
+ lib/youtube_g/client.rb
8
+ lib/youtube_g/logger.rb
9
+ lib/youtube_g/model/author.rb
10
+ lib/youtube_g/model/category.rb
11
+ lib/youtube_g/model/contact.rb
12
+ lib/youtube_g/model/content.rb
13
+ lib/youtube_g/model/playlist.rb
14
+ lib/youtube_g/model/rating.rb
15
+ lib/youtube_g/model/thumbnail.rb
16
+ lib/youtube_g/model/user.rb
17
+ lib/youtube_g/model/video.rb
18
+ lib/youtube_g/parser.rb
19
+ lib/youtube_g/record.rb
20
+ lib/youtube_g/request/base_search.rb
21
+ lib/youtube_g/request/standard_search.rb
22
+ lib/youtube_g/request/user_search.rb
23
+ lib/youtube_g/request/video_search.rb
24
+ lib/youtube_g/request/video_upload.rb
25
+ lib/youtube_g/response/video_search.rb
26
+ test/test_client.rb
27
+ test/test_video.rb
28
+ test/test_video_search.rb
@@ -0,0 +1,84 @@
1
+ youtube-g
2
+ by Shane Vitarana and Walter Korman
3
+
4
+ Rubyforge: http://rubyforge.org/projects/youtube-g/
5
+ RDoc: http://youtube-g.rubyforge.org/
6
+ Google Group: http://groups.google.com/group/ruby-youtube-library
7
+
8
+ == DESCRIPTION:
9
+
10
+ youtube-g is a pure Ruby client for the YouTube GData API. It provides an easy
11
+ way to access the latest YouTube video search results from your own programs.
12
+ In comparison with the earlier Youtube search interfaces, this new API and
13
+ library offers much-improved flexibility around executing complex search
14
+ queries to obtain well-targeted video search results.
15
+
16
+ More detail on the underlying source Google-provided API is available at:
17
+
18
+ http://code.google.com/apis/youtube/overview.html
19
+
20
+ == FEATURES/PROBLEMS:
21
+
22
+ * Aims to be in parity with Google's YouTube GData API. Core functionality
23
+ is currently present -- work is in progress to fill in the rest.
24
+
25
+ == SYNOPSIS:
26
+
27
+ Create a client:
28
+
29
+ require 'youtube_g'
30
+ client = YouTubeG::Client.new
31
+
32
+ Basic queries:
33
+
34
+ client.videos_by(:query => "penguin")
35
+ client.videos_by(:query => "penguin", :page => 2, :per_page => 15)
36
+ client.videos_by(:tags => ['tiger', 'leopard'])
37
+ client.videos_by(:categories => [:news, :sports])
38
+ client.videos_by(:categories => [:news, :sports], :tags => ['soccer', 'football'])
39
+ client.videos_by(:user => 'liz')
40
+ client.videos_by(:favorites, :user => 'liz')
41
+
42
+ Standard feeds:
43
+
44
+ client.videos_by(:most_viewed)
45
+ client.videos_by(:most_linked, :page => 3)
46
+ client.videos_by(:top_rated, :time => :today)
47
+
48
+ Advanced queries (with boolean operators OR (either), AND (include), NOT (exclude)):
49
+
50
+ client.videos_by(:categories => { :either => [:news, :sports], :exclude => [:comedy] }, :tags => { :include => ['football'], :exclude => ['soccer'] })
51
+
52
+
53
+ == REQUIREMENTS:
54
+
55
+ * None
56
+
57
+ == INSTALL:
58
+
59
+ * sudo gem install youtube-g
60
+
61
+ == LICENSE:
62
+
63
+ MIT License
64
+
65
+ Copyright (c) 2007 Shane Vitarana and Walter Korman
66
+
67
+ Permission is hereby granted, free of charge, to any person obtaining
68
+ a copy of this software and associated documentation files (the
69
+ 'Software'), to deal in the Software without restriction, including
70
+ without limitation the rights to use, copy, modify, merge, publish,
71
+ distribute, sublicense, and/or sell copies of the Software, and to
72
+ permit persons to whom the Software is furnished to do so, subject to
73
+ the following conditions:
74
+
75
+ The above copyright notice and this permission notice shall be
76
+ included in all copies or substantial portions of the Software.
77
+
78
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
79
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
80
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
81
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
82
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
83
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
84
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ [ ] stub out http request/response cycle for tests
2
+ [ ] allow specifying values as single items where you don't need to wrap in a list, e.g. :tags => :chickens instead of :tags => [ 'chickens' ]
3
+ [ ] make sure symbols will work as well as tags everywhere (again, :tags => :chickens is same as :tags => 'chickens')
4
+ [ ] figure out better structure for class/file (either rename request/video_search.rb or split into one class per file again)
5
+ [ ] restore spaces after method def names
6
+ [ ] use a proxy for testing with static sample result xml so we have repeatable tests
7
+ [ ] Clean up tests using Shoulda to define contexts
8
+ [ ] Allow :category and :categories for query DSL
9
+ [ ] Exception handling
10
+
11
+ == API Features TODO
12
+
13
+ [ ] Profile feed parsing
14
+ [ ] Playlist feeds
15
+ [ ] User subscriptions
16
+ [ ] Video comments
@@ -0,0 +1,29 @@
1
+ require 'logger'
2
+ require 'open-uri'
3
+ require 'net/https'
4
+ require 'digest/md5'
5
+ require 'rexml/document'
6
+ require 'cgi'
7
+
8
+ require File.dirname(__FILE__) + '/youtube_g/client'
9
+ require File.dirname(__FILE__) + '/youtube_g/record'
10
+ require File.dirname(__FILE__) + '/youtube_g/parser'
11
+ require File.dirname(__FILE__) + '/youtube_g/model/author'
12
+ require File.dirname(__FILE__) + '/youtube_g/model/category'
13
+ require File.dirname(__FILE__) + '/youtube_g/model/contact'
14
+ require File.dirname(__FILE__) + '/youtube_g/model/content'
15
+ require File.dirname(__FILE__) + '/youtube_g/model/playlist'
16
+ require File.dirname(__FILE__) + '/youtube_g/model/rating'
17
+ require File.dirname(__FILE__) + '/youtube_g/model/thumbnail'
18
+ require File.dirname(__FILE__) + '/youtube_g/model/user'
19
+ require File.dirname(__FILE__) + '/youtube_g/model/video'
20
+ require File.dirname(__FILE__) + '/youtube_g/request/base_search'
21
+ require File.dirname(__FILE__) + '/youtube_g/request/user_search'
22
+ require File.dirname(__FILE__) + '/youtube_g/request/standard_search'
23
+ require File.dirname(__FILE__) + '/youtube_g/request/video_upload'
24
+ require File.dirname(__FILE__) + '/youtube_g/request/video_search'
25
+ require File.dirname(__FILE__) + '/youtube_g/response/video_search'
26
+
27
+ class YouTubeG #:nodoc:
28
+ VERSION = '0.4.9.9'
29
+ end
@@ -0,0 +1,85 @@
1
+ class YouTubeG
2
+ class Client
3
+ attr_accessor :logger
4
+
5
+ def initialize(logger=false)
6
+ @logger = Logger.new(STDOUT) if logger
7
+ end
8
+
9
+ # Retrieves an array of standard feed, custom query, or user videos.
10
+ #
11
+ # === Parameters
12
+ # If fetching videos for a standard feed:
13
+ # params<Symbol>:: Accepts a symbol of :top_rated, :top_favorites, :most_viewed,
14
+ # :most_popular, :most_recent, :most_discussed, :most_linked,
15
+ # :most_responded, :recently_featured, and :watch_on_mobile.
16
+ #
17
+ # You can find out more specific information about what each standard feed provides
18
+ # by visiting: http://code.google.com/apis/youtube/reference.html#Standard_feeds
19
+ #
20
+ # options<Hash> (optional):: Accepts the options of :time, :page (default is 1),
21
+ # and :per_page (default is 25). :offset and :max_results
22
+ # can also be passed for a custom offset.
23
+ #
24
+ # If fetching videos by tags, categories, query:
25
+ # params<Hash>:: Accepts the keys :tags, :categories, :query, :order_by,
26
+ # :author, :racy, :response_format, :video_format, :page (default is 1),
27
+ # and :per_page(default is 25)
28
+ #
29
+ # options<Hash>:: Not used. (Optional)
30
+ #
31
+ # If fetching videos for a particular user:
32
+ # params<Hash>:: Key of :user with a value of the username.
33
+ # options<Hash>:: Not used. (Optional)
34
+ # === Returns
35
+ # YouTubeG::Response::VideoSearch
36
+ def videos_by(params, options={})
37
+ request_params = params.respond_to?(:to_hash) ? params : options
38
+ request_params[:page] = integer_or_default(request_params[:page], 1)
39
+
40
+ unless request_params[:max_results]
41
+ request_params[:max_results] = integer_or_default(request_params[:per_page], 25)
42
+ end
43
+
44
+ unless request_params[:offset]
45
+ request_params[:offset] = calculate_offset(request_params[:page], request_params[:max_results] )
46
+ end
47
+
48
+ if params.respond_to?(:to_hash) and not params[:user]
49
+ request = YouTubeG::Request::VideoSearch.new(request_params)
50
+ elsif (params.respond_to?(:to_hash) && params[:user]) || (params == :favorites)
51
+ request = YouTubeG::Request::UserSearch.new(params, options)
52
+ else
53
+ request = YouTubeG::Request::StandardSearch.new(params, request_params)
54
+ end
55
+
56
+ logger.debug "Submitting request [url=#{request.url}]." if logger
57
+ parser = YouTubeG::Parser::VideosFeedParser.new(request.url)
58
+ parser.parse
59
+ end
60
+
61
+ # Retrieves a single YouTube video.
62
+ #
63
+ # === Parameters
64
+ # vid<String>:: The ID or URL of the video that you'd like to retrieve.
65
+ #
66
+ # === Returns
67
+ # YouTubeG::Model::Video
68
+ def video_by(vid)
69
+ video_id = vid =~ /^http/ ? vid : "http://gdata.youtube.com/feeds/videos/#{vid}"
70
+ parser = YouTubeG::Parser::VideoFeedParser.new(video_id)
71
+ parser.parse
72
+ end
73
+
74
+ private
75
+
76
+ def calculate_offset(page, per_page)
77
+ page == 1 ? 1 : ((per_page * page) - per_page + 1)
78
+ end
79
+
80
+ def integer_or_default(value, default)
81
+ value = value.to_i
82
+ value > 0 ? value : default
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,25 @@
1
+ class YouTubeG
2
+
3
+ # TODO: Why is this needed? Does this happen if running standalone w/o Rails?
4
+ # Anyway, isn't it easier to debug w/o the really long timestamp & log level?
5
+ # How often do you look at the timestamp and log level? Wouldn't it be nice to
6
+ # see your logger output first?
7
+
8
+ # Extension of the base ruby Logger class to restore the default log
9
+ # level and timestamp formatting which is so rudely taken forcibly
10
+ # away from us by the Rails app's use of the ActiveSupport library
11
+ # that wholesale-ly modifies the Logger's format_message method.
12
+ #
13
+ class Logger < ::Logger
14
+ private
15
+ begin
16
+ # restore original log formatting to un-screw the screwage that is
17
+ # foisted upon us by the activesupport library's clean_logger.rb
18
+ alias format_message old_format_message
19
+
20
+ rescue NameError
21
+ # nothing for now -- this means we didn't need to alias since the
22
+ # method wasn't overridden
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ class YouTubeG
2
+ module Model
3
+ class Author < YouTubeG::Record
4
+ # *String*: Author's YouTube username.
5
+ attr_reader :name
6
+
7
+ # *String*: Feed URL of the author.
8
+ attr_reader :uri
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class YouTubeG
2
+ module Model
3
+ class Category < YouTubeG::Record
4
+ # *String*:: Name of the YouTube category
5
+ attr_reader :label
6
+
7
+ # *String*:: Identifies the type of item described.
8
+ attr_reader :term
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ class YouTubeG
2
+ module Model
3
+ class Contact < YouTubeG::Record
4
+ # *String*:: Identifies the status of a contact.
5
+ #
6
+ # * The tag's value will be accepted if the authenticated user and the contact have marked each other as friends.
7
+ # * The tag's value will be requested if the contact has asked to be added to the authenticated user's contact list, but the request has not yet been accepted (or rejected).
8
+ # * The tag's value will be pending if the authenticated user has asked to be added to the contact's contact list, but the request has not yet been accepted or rejected.
9
+ #
10
+ attr_reader :status
11
+
12
+ # *String*:: The Youtube username of the contact.
13
+ attr_reader :username
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ class YouTubeG
2
+ module Model
3
+ class Content < YouTubeG::Record
4
+ # *Boolean*:: Description of the video.
5
+ attr_reader :default
6
+ # *Fixnum*:: Length of the video in seconds.
7
+ attr_reader :duration
8
+ # YouTubeG::Model::Video::Format:: Specifies the video format of the video object
9
+ attr_reader :format
10
+ # *String*:: Specifies the MIME type of the media object.
11
+ attr_reader :mime_type
12
+ # *String*:: Specifies the URL for the media object.
13
+ attr_reader :url
14
+
15
+ alias :is_default? :default
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ class YouTubeG
2
+ module Model
3
+ class Playlist < YouTubeG::Record
4
+ # *String*:: User entered description for the playlist.
5
+ attr_reader :description
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ class YouTubeG
2
+ module Model
3
+ class Rating < YouTubeG::Record
4
+ # *Float*:: Average rating given to the video
5
+ attr_reader :average
6
+
7
+ # *Fixnum*:: Maximum rating that can be assigned to the video
8
+ attr_reader :max
9
+
10
+ # *Fixnum*:: Minimum rating that can be assigned to the video
11
+ attr_reader :min
12
+
13
+ # *Fixnum*:: Indicates how many people have rated the video
14
+ attr_reader :rater_count
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ class YouTubeG
2
+ module Model
3
+ class Thumbnail < YouTubeG::Record
4
+ # *String*:: URL for the thumbnail image.
5
+ attr_reader :url
6
+
7
+ # *Fixnum*:: Height of the thumbnail image.
8
+ attr_reader :height
9
+
10
+ # *Fixnum*:: Width of the thumbnail image.
11
+ attr_reader :width
12
+
13
+ # *String*:: Specifies the time offset at which the frame shown in the thumbnail image appears in the video.
14
+ attr_reader :time
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ class YouTubeG
2
+ module Model
3
+ class User < YouTubeG::Record
4
+ attr_reader :age
5
+ attr_reader :books
6
+ attr_reader :company
7
+ attr_reader :gender
8
+ attr_reader :hobbies
9
+ attr_reader :hometown
10
+ attr_reader :location
11
+ attr_reader :movies
12
+ attr_reader :music
13
+ attr_reader :occupation
14
+ attr_reader :relationship
15
+ attr_reader :school
16
+ attr_reader :description
17
+ attr_reader :username
18
+ end
19
+ end
20
+ end