tubeclip 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +41 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/lib/tubeclip/chain_io.rb +86 -0
  13. data/lib/tubeclip/client.rb +541 -0
  14. data/lib/tubeclip/middleware/faraday_authheader.rb +24 -0
  15. data/lib/tubeclip/middleware/faraday_oauth.rb +21 -0
  16. data/lib/tubeclip/middleware/faraday_oauth2.rb +13 -0
  17. data/lib/tubeclip/middleware/faraday_tubeclip.rb +38 -0
  18. data/lib/tubeclip/model/activity.rb +17 -0
  19. data/lib/tubeclip/model/author.rb +13 -0
  20. data/lib/tubeclip/model/caption.rb +7 -0
  21. data/lib/tubeclip/model/category.rb +11 -0
  22. data/lib/tubeclip/model/comment.rb +18 -0
  23. data/lib/tubeclip/model/contact.rb +19 -0
  24. data/lib/tubeclip/model/content.rb +18 -0
  25. data/lib/tubeclip/model/message.rb +12 -0
  26. data/lib/tubeclip/model/playlist.rb +11 -0
  27. data/lib/tubeclip/model/rating.rb +23 -0
  28. data/lib/tubeclip/model/subscription.rb +7 -0
  29. data/lib/tubeclip/model/thumbnail.rb +20 -0
  30. data/lib/tubeclip/model/user.rb +35 -0
  31. data/lib/tubeclip/model/video.rb +302 -0
  32. data/lib/tubeclip/parser.rb +643 -0
  33. data/lib/tubeclip/record.rb +12 -0
  34. data/lib/tubeclip/request/base_search.rb +76 -0
  35. data/lib/tubeclip/request/error.rb +21 -0
  36. data/lib/tubeclip/request/remote_file.rb +70 -0
  37. data/lib/tubeclip/request/standard_search.rb +49 -0
  38. data/lib/tubeclip/request/user_search.rb +47 -0
  39. data/lib/tubeclip/request/video_search.rb +125 -0
  40. data/lib/tubeclip/request/video_upload.rb +762 -0
  41. data/lib/tubeclip/response/video_search.rb +41 -0
  42. data/lib/tubeclip/version.rb +3 -0
  43. data/lib/tubeclip.rb +85 -0
  44. data/tubeclip.gemspec +44 -0
  45. metadata +259 -0
@@ -0,0 +1,18 @@
1
+ class Tubeclip
2
+ module Model
3
+ class Comment < Tubeclip::Record
4
+ attr_reader :content, :published, :title, :updated, :url, :reply_to
5
+
6
+ # Tubeclip::Model::Author:: Information about the YouTube user who owns a piece of video content.
7
+ attr_reader :author
8
+ attr_reader :channel_id
9
+ attr_reader :gp_user_id
10
+
11
+ # unique ID of the comment.
12
+ def unique_id
13
+ url.split(":").last
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,19 @@
1
+ class Tubeclip
2
+ module Model
3
+ class Contact < Tubeclip::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
+
15
+ # *String*:: The Youtube title of the contact.
16
+ attr_reader :title
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ class Tubeclip
2
+ module Model
3
+ class Content < Tubeclip::Record
4
+ # *Boolean*:: Description of the video.
5
+ attr_reader :default
6
+ # *Fixnum*:: Length of the video in seconds.
7
+ attr_reader :duration
8
+ # Tubeclip::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,12 @@
1
+ class Tubeclip
2
+ module Model
3
+ class Message < Tubeclip::Record
4
+ attr_reader :id, :name, :title, :summary, :published
5
+
6
+ def content
7
+ # This tag contains the same value as the <summary> tag.
8
+ self.summary
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ class Tubeclip
2
+ module Model
3
+ class Playlist < Tubeclip::Record
4
+ attr_reader :title, :description, :summary, :author, :videos_count, :playlist_id, :xml, :published, :response_code
5
+ def videos
6
+ Tubeclip::Parser::VideosFeedParser.new(@xml).parse_videos
7
+ end
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,23 @@
1
+ class Tubeclip
2
+ module Model
3
+ class Rating < Tubeclip::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
+
16
+ # *Fixnum*:: Indicates how many people likes this video
17
+ attr_reader :likes
18
+
19
+ # *Fixnum*:: Indicates how many people dislikes this video
20
+ attr_reader :dislikes
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ class Tubeclip
2
+ module Model
3
+ class Subscription < Tubeclip::Record
4
+ attr_reader :id, :title, :published, :youtube_user_name
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ class Tubeclip
2
+ module Model
3
+ class Thumbnail < Tubeclip::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
+
16
+ # *String*:: Specified type of the thumbnail, attribute yt:name in feed
17
+ attr_reader :name
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ class Tubeclip
2
+ module Model
3
+ class User < Tubeclip::Record
4
+ attr_reader :age
5
+ attr_reader :books
6
+ attr_reader :company
7
+ attr_reader :description
8
+ attr_reader :first_name
9
+ attr_reader :gender
10
+ attr_reader :hobbies
11
+ attr_reader :hometown
12
+ attr_reader :last_login
13
+ attr_reader :last_name
14
+ attr_reader :location
15
+ attr_reader :join_date
16
+ attr_reader :max_upload_duration
17
+ attr_reader :movies
18
+ attr_reader :music
19
+ attr_reader :occupation
20
+ attr_reader :relationship
21
+ attr_reader :school
22
+ attr_reader :subscribers
23
+ attr_reader :upload_count
24
+ attr_reader :upload_views
25
+ attr_reader :user_id
26
+ attr_reader :username
27
+ attr_reader :username_display
28
+ attr_reader :videos_watched
29
+ attr_reader :view_count
30
+ attr_reader :avatar
31
+ attr_reader :insight_uri
32
+ attr_reader :channel_uri
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,302 @@
1
+ # TODO
2
+ # * self atom feed
3
+ # * alternate youtube watch url
4
+ # * comments feedLink
5
+
6
+ class Tubeclip
7
+ module Model
8
+ class Video < Tubeclip::Record
9
+ # Describes the various file formats in which a Youtube video may be
10
+ # made available and allows looking them up by format code number.
11
+ class Format
12
+ attr_reader :format_code, :name
13
+
14
+ @@formats = Hash.new
15
+
16
+ # Instantiates a new video format object.
17
+ #
18
+ # == Parameters
19
+ # :format_code<Fixnum>:: The Youtube Format code of the object.
20
+ # :name<Symbol>:: The name of the format
21
+ #
22
+ # == Returns
23
+ # Tubeclip::Model::Video::Format: Video format object
24
+ def initialize(format_code, name)
25
+ @format_code = format_code
26
+ @name = name
27
+
28
+ @@formats[format_code] = self
29
+ end
30
+
31
+ # Allows you to get the video format for a specific format code.
32
+ #
33
+ # A full list of format codes is available at:
34
+ #
35
+ # http://code.google.com/apis/youtube/reference.html#youtube_data_api_tag_media:content
36
+ #
37
+ # == Parameters
38
+ # :format_code<Fixnum>:: The Youtube Format code of the object.
39
+ #
40
+ # == Returns
41
+ # Tubeclip::Model::Video::Format: Video format object
42
+ def self.by_code(format_code)
43
+ @@formats[format_code]
44
+ end
45
+
46
+ # Flash format on YouTube site. All videos are available in this format.
47
+ FLASH = Tubeclip::Model::Video::Format.new(0, :flash)
48
+
49
+ # RTSP streaming URL for mobile video playback. H.263 video (176x144) and AMR audio.
50
+ RTSP = Tubeclip::Model::Video::Format.new(1, :rtsp)
51
+
52
+ # HTTP URL to the embeddable player (SWF) for this video. This format
53
+ # is not available for a video that is not embeddable.
54
+ SWF = Tubeclip::Model::Video::Format.new(5, :swf)
55
+
56
+ # RTSP streaming URL for mobile video playback. MPEG-4 SP video (up to 176x144) and AAC audio.
57
+ THREE_GPP = Tubeclip::Model::Video::Format.new(6, :three_gpp)
58
+ end
59
+
60
+ # *Fixnum*:: Duration of a video in seconds.
61
+ attr_reader :duration
62
+
63
+ # *Boolean*:: Specifies that a video may or may not be 16:9 ratio.
64
+ attr_reader :widescreen
65
+
66
+ # *Boolean*:: Specifies that a video may or may not be embedded on other websites.
67
+ attr_reader :noembed
68
+
69
+ # *Fixnum*:: Specifies the order in which the video appears in a playlist.
70
+ attr_reader :position
71
+
72
+ # *Boolean*:: Specifies that a video is flagged as adult or not.
73
+ attr_reader :safe_search
74
+
75
+ # *String*: Specifies a URI that uniquely and permanently identifies the video.
76
+ attr_reader :video_id
77
+
78
+ # *Time*:: When the video was published on Youtube.
79
+ attr_reader :published_at
80
+
81
+ # *Time*:: When the video's data was last updated.
82
+ attr_reader :updated_at
83
+
84
+ # *Time*:: When the video's was uploaded.
85
+ attr_reader :uploaded_at
86
+
87
+ # *Time*:: When the video's was recorded.
88
+ attr_reader :recorded_at
89
+
90
+ # *Array*:: A array of Tubeclip::Model::Category objects that describe the videos categories.
91
+ attr_reader :categories
92
+
93
+ # *Array*:: An array of words associated with the video.
94
+ attr_reader :keywords
95
+
96
+ # *String*:: Description of the video.
97
+ attr_reader :description
98
+
99
+ # *String*:: Title for the video.
100
+ attr_reader :title
101
+
102
+ # *String*:: Description of the video.
103
+ attr_reader :html_content
104
+
105
+ # *String*:: Description of the video.
106
+ attr_reader :raw_content
107
+
108
+ # Tubeclip::Model::Author:: Information about the YouTube user who owns a piece of video content.
109
+ attr_reader :author
110
+
111
+ # *Array*:: An array of Tubeclip::Model::Content objects describing the individual media content data available for this video. Most, but not all, videos offer this.
112
+ attr_reader :media_content
113
+
114
+ # *Hash*:: string-keyed, string-valued permissions e.g., {'comment'=>'allowed','videoRespond'=>'moderated'}
115
+ attr_reader :access_control
116
+
117
+ # *Array*:: An array of Tubeclip::Model::Thumbnail objects that contain information regarding the videos thumbnail images.
118
+ attr_reader :thumbnails
119
+
120
+ # *String*:: The link to watch the URL on YouTubes website.
121
+ attr_reader :player_url
122
+
123
+ # Tubeclip::Model::Rating:: Information about the videos rating.
124
+ attr_reader :rating
125
+
126
+ # *Fixnum*:: Number of times that the video has been viewed
127
+ attr_reader :view_count
128
+
129
+ # *Fixnum*:: Number of times that the video has been favorited
130
+ attr_reader :favorite_count
131
+
132
+ # *Fixnum*:: Number of comments for this video
133
+ attr_reader :comment_count
134
+
135
+ # *String*:: State of the video (processing, restricted, deleted, rejected and failed)
136
+ attr_reader :state
137
+
138
+ # *String*:: URI for insight for this video, if present; nil otherwise
139
+ attr_reader :insight_uri
140
+
141
+ # *Boolean*:: Whether or not a video is private. Non-standard name to avoid collision with Rubys own 'private' stuff.
142
+ attr_reader :perm_private
143
+
144
+ # Geodata
145
+ attr_reader :position
146
+ attr_reader :latitude
147
+ attr_reader :longitude
148
+
149
+ # Playlist position
150
+ attr_reader :video_position
151
+
152
+ # Videos related to the current video.
153
+ #
154
+ # === Returns
155
+ # Tubeclip::Response::VideoSearch
156
+ def related
157
+ Tubeclip::Parser::VideosFeedParser.new("http://gdata.youtube.com/feeds/api/videos/#{unique_id}/related?v=#{Tubeclip::API_VERSION}").parse
158
+ end
159
+ # Video responses to the current video.
160
+ #
161
+ # === Returns
162
+ # Tubeclip::Response::VideoSearch
163
+ def responses
164
+ Tubeclip::Parser::VideosFeedParser.new("http://gdata.youtube.com/feeds/api/videos/#{unique_id}/responses?v=#{Tubeclip::API_VERSION}").parse
165
+ end
166
+
167
+
168
+ # ID of video in playlist listing
169
+ # Useful if you have to delete this video from a playlist
170
+ #
171
+ # === Example
172
+ # >> video.in_playlist_id
173
+ # => "PLk3UVPlPEkey09s2W02R48WMDKjvSb6Hq"
174
+ #
175
+ # === Returns
176
+ # String the video id
177
+ #
178
+ def in_playlist_id
179
+ @video_id.split(':').last
180
+ end
181
+
182
+ # The ID of the video, useful for searching for the video again without having to store it anywhere.
183
+ # A regular query search, with this id will return the same video.
184
+ #
185
+ # === Example
186
+ # >> video.unique_id
187
+ # => "ZTUVgYoeN_o"
188
+ #
189
+ # === Returns
190
+ # String: The Youtube video id.
191
+ def unique_id
192
+ @unique_id || video_id[/videos\/([^<]+)/, 1] || video_id[/video\:([^<]+)/, 1]
193
+ end
194
+
195
+ # ID of this video in the watch later list (work only if you are listing watch later videos)
196
+ # Can be use to modify or remove the entry from the watch later list
197
+ #
198
+ # === Example
199
+ # >> @client.watchlater.videos.first.watch_later_id
200
+ # => "PL78jdHcOatSF7DGMd4O9K6Mbo0cNlxm_j"
201
+ def watch_later_id
202
+ video_id[/watch_later\:([^:]+)/, 1]
203
+ end
204
+
205
+ # Allows you to check whether the video can be embedded on a webpage.
206
+ #
207
+ # === Returns
208
+ # Boolean: True if the video can be embedded, false if not.
209
+ def embeddable?
210
+ not @noembed
211
+ end
212
+
213
+ # Allows you to check whether the video is listed and searchable on youtube.
214
+ #
215
+ # === Returns
216
+ # Boolean
217
+ def listed?
218
+ access_control['list'] == 'allowed'
219
+ end
220
+
221
+ # Allows you to check whether the video is widescreen (16:9) or not.
222
+ #
223
+ # === Returns
224
+ # Boolean: True if the video is (approximately) 16:9, false if not.
225
+ def widescreen?
226
+ @widescreen
227
+ end
228
+
229
+ # Provides a URL and various other types of information about a video.
230
+ #
231
+ # === Returns
232
+ # Tubeclip::Model::Content: Data about the embeddable video.
233
+ def default_media_content
234
+ @media_content.find { |c| c.is_default? }
235
+ end
236
+
237
+ # Gives you the HTML to embed the video on your website.
238
+ #
239
+ # === Returns
240
+ # String: The HTML for embedding the video on your website.
241
+ def embed_html(width = 425, height = 350)
242
+ <<EDOC
243
+ <object width="#{width}" height="#{height}">
244
+ <param name="movie" value="#{embed_url}"></param>
245
+ <param name="wmode" value="transparent"></param>
246
+ <embed src="#{embed_url}" type="application/x-shockwave-flash"
247
+ wmode="transparent" width="#{width}" height="#{height}"></embed>
248
+ </object>
249
+ EDOC
250
+ end
251
+
252
+ # Gives you the HTML 5 to embed the video on your website.
253
+ # Usefull for mobile that not support flash but has html5 browser
254
+ # === Returns
255
+ # String: The HTML for embedding the video on your website.
256
+ def embed_html5(params = {})
257
+ opts = {:class => params[:class] || "",
258
+ :id => params[:id] || "",
259
+ :width => params[:width] || "425",
260
+ :height => params[:height] || "350",
261
+ :protocol => params[:protocol] || "http",
262
+ :frameborder => params[:frameborder] || "0",
263
+ :url_params => params[:url_params] || {},
264
+ :sandbox => params[:sandbox] || false,
265
+ :fullscreen => params[:fullscreen] || false,
266
+ }
267
+ url_opts = opts[:url_params].empty? ? "" : "?#{Rack::Utils::build_query(opts[:url_params])}"
268
+ <<EDOC
269
+ <iframe class="#{opts[:class]}" id="#{opts[:id]}" type="text/html" width="#{opts[:width]}" height="#{opts[:height]}" src="#{opts[:protocol]}://www.youtube.com/embed/#{unique_id}#{url_opts}" frameborder="#{opts[:frameborder]}" #{" sandbox=\"#{opts[:sandbox]}\" " if opts[:sandbox]} #{"allowfullscreen" if opts[:fullscreen]}></iframe>
270
+ EDOC
271
+ end
272
+
273
+ # Gives you the HTML to embed the video on your website.
274
+ #
275
+ # === Returns
276
+ # String: The HTML for embedding the video on your website.
277
+ def embed_html_with_width(width = 1280)
278
+ height = (widescreen? ? width * 9/16 : width * 3/4) + 25
279
+
280
+ <<EDOC
281
+ <object width="#{width}" height="#{height}">
282
+ <param name="movie" value="#{embed_url}"></param>
283
+ <param name="wmode" value="transparent"></param>
284
+ <embed src="#{embed_url}" type="application/x-shockwave-flash"
285
+ wmode="transparent" width="#{width}" height="#{height}"></embed>
286
+ </object>
287
+ EDOC
288
+ end
289
+
290
+ # The URL needed for embedding the video in a page.
291
+ #
292
+ # === Returns
293
+ # String: Absolute URL for embedding video
294
+ def embed_url
295
+ @player_url.sub('watch?', '').sub('=', '/').sub('feature/', 'feature=')
296
+ end
297
+
298
+
299
+ end
300
+ end
301
+ end
302
+